import random
import json
from cyaron import Graph


AVAILABLE_CHARS = [chr(ord('a')+i) for i in range(26)
                   ]
AVAILABLE_CHARS.extend([chr(ord('A')+i) for i in range(26)])
AVAILABLE_CHARS.append(' ')
RANDOM_SEED = 50
N_SMALL_SAMPLE = 15
N_LARGE_SAMPLE = 9
L_SMALL = 100
L_LARGE = 1000
L_BOUDERY = 500000


class Solution:
    def replaceSpaces(self, S: str, length: int) -> str:
        cnt = 0
        S = list(S)
        cnt += sum((1 for c in S[:length] if c == ' '))
        newLen = length + 2 * cnt
        #print(length, newLen)
        S = S[:newLen]

        for i in range(length - 1, -1, -1):
            if S[i] == ' ':
                S[newLen - 1] = '0'
                S[newLen - 2] = '2'
                S[newLen - 3] = '%'
                newLen -= 3
            else:
                S[newLen - 1] = S[i]
                newLen -= 1
        return ''.join(S)


class StringTestGenerator:
    def __init__(self, out_fun):
        self.output = out_fun

    def gen_a_random_string(self, length):
        ret = []
        i = 0
        while i < length:
            times = min(random.randint(0, int(length/10+1)), length - i)
            i += times
            ret.append(AVAILABLE_CHARS[random.randint(
                0, len(AVAILABLE_CHARS) - 1)]*times)
        self.output(''.join(ret))

    # generate a string that not suitable to compress
    def gen_a_unsutiable_string(self, length):
        ret = []
        i = 0
        while i < length:
            times = min(max(1, random.randint(0, 3)), length - i)
            i += times
            ret.append(AVAILABLE_CHARS[random.randint(
                0, len(AVAILABLE_CHARS) - 1)]*times)
        self.output(''.join(ret))

    # def gen_correct_string(self, length):
    #     ret = []
    #     for _ in range(length):
    #         ret.append(AVAILABLE_CHARS[random.randint(
    #             0, len(AVAILABLE_CHARS) - 1)])
    #     rn = random.randint(0, len(ret) - 1)
    #     ret2 = ret[rn:] + ret[:rn]
    #     self.output(''.join(ret), ''.join(ret2))

    def gen_series_string(self, nsamp, large_L):
        for _ in range(int(nsamp/2)):
            l = random.randint(1, large_L)
            self.gen_a_random_string(l)
            self.gen_a_unsutiable_string(l)


class StringToURLTestcaseGenerator():
    def __init__(self, output):
        self.output = output

    def gen_bad_cases(self, length):
        ret = []
        i = 0
        tail = ""
        while i < length:
            if random.randint(0, 1) % 2 == 0:
                c = AVAILABLE_CHARS[random.randint(
                    0, len(AVAILABLE_CHARS) - 1)]
                ret.append(c)
                if c == ' ':
                    tail += '  '
            else:
                ret.append(' ')
                tail += '  '
            i += 1
            # times = min(max(1, random.randint(0, 3)), length - i)
            # i += times
            # ret.append(AVAILABLE_CHARS[random.randint(
            #     0, len(AVAILABLE_CHARS) - 1)])

        self.output(''.join(ret) + tail)
        self.output(length)

    def gen_random_cases(self, length):
        ret = []
        i = 0
        tail = ''
        while i < length:
           # times = min(random.randint(0, int(length/10+1)), length - i)
            i += 1
            c = AVAILABLE_CHARS[random.randint(
                0, len(AVAILABLE_CHARS) - 1)]
            ret.append(c)
            if c == ' ':
                tail += '  '
        self.output(''.join(ret) + tail)
        self.output(length)

    def gen_series_cases(self, nsamp, large_L):
        for _ in range(0, int(nsamp), 2):
            l = random.randint(1, large_L)
            self.gen_random_cases(l)
            self.gen_bad_cases(l)


class TestCaseGenerator:

    def __init__(self, file_out='input_file', case_num=20):
        random.seed(RANDOM_SEED)
        self.fout = open(file_out, 'w')
        self.listGen = StringToURLTestcaseGenerator(self.output)

    def output(self, *params):
        for para in params:
            if type(para) == str:
                self.fout.write('\"%s\"' % str(para))
            else:
                json.dump(para, self.fout)
            self.fout.write('\n')
            # self.gen_correct_string(l)

    def gen_special_case(self):
        self.output("Mr John Smith    ", 13)
        self.output(' '*15, 5)

        self.output("ds sdfs afs sdfa dfssf asdf             ", 27)
        self.output("      dsfasdfasdfas               ", 19)
        # self.output(12, [[0, 1], [1, 2], [1, 3], [1, 10], [1, 11], [1, 4], [2, 4], [2, 6], [2, 9], [2, 10], [2, 4], [2, 5], [
        #             2, 10], [3, 7], [3, 7], [4, 5], [4, 11], [4, 11], [4, 10], [5, 7], [5, 10], [6, 8], [7, 11], [8, 10]], 2, 3)
        # self.output(25, [[0, 1], [0, 3], [0, 10], [0, 18], [1, 2], [1, 7], [1, 11], [1, 12], [2, 4], [2, 5], [2, 13], [2, 16], [3, 6], [
        #             3, 8], [4, 9], [5, 17], [7, 20], [7, 22], [8, 10], [10, 19], [11, 15], [13, 14], [14, 21], [15, 23], [19, 24], [20, 22]], 0, 12)

    def gen_small_cases(self):
        # self.gen_series_string(N_SMALL_SAMPLE, L_SMALL)
        self.listGen.gen_series_cases(N_SMALL_SAMPLE, L_SMALL)
        pass

    def gen_large_cases(self):
        # self.gen_series_string(N_LARGE_SAMPLE, L_LARGE)
        self.listGen.gen_series_cases(N_LARGE_SAMPLE, L_LARGE)
        pass

    def gen_boundary_case(self):
        # self.gen_a_random_string(L_BOUDERY)
        # self.gen_a_unsutiable_compress_string(L_BOUDERY)
        self.listGen.gen_random_cases(L_BOUDERY)
        self.listGen.gen_bad_cases(L_BOUDERY)
        pass

    def gen_all_cases(self):
        self.gen_special_case()
        self.gen_small_cases()
        self.gen_large_cases()
        self.gen_boundary_case()
        self.fout.close()


def get_res(file_in, file_out):
    lines = []
    sol = Solution()
    with open(file_in, "r") as fin:
        lines = fin.readlines()
    with open(file_out, "w") as fout:
        for i in range(0, len(lines), 2):
            line = json.loads(lines[i])
            times = json.loads(lines[i + 1])
            fout.write('\"%s\"\n' % sol.replaceSpaces(line, times))


if __name__ == "__main__":
    gen = TestCaseGenerator()
    gen.gen_all_cases()
    get_res('input_file', 'output_file')

3bb8089a64e4889a7ae62a57f3d6e0115ebb9305
<mask token>


class StringTestGenerator:
    <mask token>
    <mask token>
    <mask token>
    <mask token>


class StringToURLTestcaseGenerator:

    def __init__(self, output):
        self.output = output

    def gen_bad_cases(self, length):
        ret = []
        i = 0
        tail = ''
        while i < length:
            if random.randint(0, 1) % 2 == 0:
                c = AVAILABLE_CHARS[random.randint(0, len(AVAILABLE_CHARS) - 1)
                    ]
                ret.append(c)
                if c == ' ':
                    tail += '  '
            else:
                ret.append(' ')
                tail += '  '
            i += 1
        self.output(''.join(ret) + tail)
        self.output(length)

    def gen_random_cases(self, length):
        ret = []
        i = 0
        tail = ''
        while i < length:
            i += 1
            c = AVAILABLE_CHARS[random.randint(0, len(AVAILABLE_CHARS) - 1)]
            ret.append(c)
            if c == ' ':
                tail += '  '
        self.output(''.join(ret) + tail)
        self.output(length)

    def gen_series_cases(self, nsamp, large_L):
        for _ in range(0, int(nsamp), 2):
            l = random.randint(1, large_L)
            self.gen_random_cases(l)
            self.gen_bad_cases(l)


class TestCaseGenerator:

    def __init__(self, file_out='input_file', case_num=20):
        random.seed(RANDOM_SEED)
        self.fout = open(file_out, 'w')
        self.listGen = StringToURLTestcaseGenerator(self.output)

    def output(self, *params):
        for para in params:
            if type(para) == str:
                self.fout.write('"%s"' % str(para))
            else:
                json.dump(para, self.fout)
            self.fout.write('\n')

    def gen_special_case(self):
        self.output('Mr John Smith    ', 13)
        self.output(' ' * 15, 5)
        self.output('ds sdfs afs sdfa dfssf asdf             ', 27)
        self.output('      dsfasdfasdfas               ', 19)

    def gen_small_cases(self):
        self.listGen.gen_series_cases(N_SMALL_SAMPLE, L_SMALL)
        pass

    def gen_large_cases(self):
        self.listGen.gen_series_cases(N_LARGE_SAMPLE, L_LARGE)
        pass

    def gen_boundary_case(self):
        self.listGen.gen_random_cases(L_BOUDERY)
        self.listGen.gen_bad_cases(L_BOUDERY)
        pass

    def gen_all_cases(self):
        self.gen_special_case()
        self.gen_small_cases()
        self.gen_large_cases()
        self.gen_boundary_case()
        self.fout.close()


<mask token>

<mask token>


class StringTestGenerator:

    def __init__(self, out_fun):
        self.output = out_fun

    def gen_a_random_string(self, length):
        ret = []
        i = 0
        while i < length:
            times = min(random.randint(0, int(length / 10 + 1)), length - i)
            i += times
            ret.append(AVAILABLE_CHARS[random.randint(0, len(
                AVAILABLE_CHARS) - 1)] * times)
        self.output(''.join(ret))

    def gen_a_unsutiable_string(self, length):
        ret = []
        i = 0
        while i < length:
            times = min(max(1, random.randint(0, 3)), length - i)
            i += times
            ret.append(AVAILABLE_CHARS[random.randint(0, len(
                AVAILABLE_CHARS) - 1)] * times)
        self.output(''.join(ret))
    <mask token>


class StringToURLTestcaseGenerator:

    def __init__(self, output):
        self.output = output

    def gen_bad_cases(self, length):
        ret = []
        i = 0
        tail = ''
        while i < length:
            if random.randint(0, 1) % 2 == 0:
                c = AVAILABLE_CHARS[random.randint(0, len(AVAILABLE_CHARS) - 1)
                    ]
                ret.append(c)
                if c == ' ':
                    tail += '  '
            else:
                ret.append(' ')
                tail += '  '
            i += 1
        self.output(''.join(ret) + tail)
        self.output(length)

    def gen_random_cases(self, length):
        ret = []
        i = 0
        tail = ''
        while i < length:
            i += 1
            c = AVAILABLE_CHARS[random.randint(0, len(AVAILABLE_CHARS) - 1)]
            ret.append(c)
            if c == ' ':
                tail += '  '
        self.output(''.join(ret) + tail)
        self.output(length)

    def gen_series_cases(self, nsamp, large_L):
        for _ in range(0, int(nsamp), 2):
            l = random.randint(1, large_L)
            self.gen_random_cases(l)
            self.gen_bad_cases(l)


class TestCaseGenerator:

    def __init__(self, file_out='input_file', case_num=20):
        random.seed(RANDOM_SEED)
        self.fout = open(file_out, 'w')
        self.listGen = StringToURLTestcaseGenerator(self.output)

    def output(self, *params):
        for para in params:
            if type(para) == str:
                self.fout.write('"%s"' % str(para))
            else:
                json.dump(para, self.fout)
            self.fout.write('\n')

    def gen_special_case(self):
        self.output('Mr John Smith    ', 13)
        self.output(' ' * 15, 5)
        self.output('ds sdfs afs sdfa dfssf asdf             ', 27)
        self.output('      dsfasdfasdfas               ', 19)

    def gen_small_cases(self):
        self.listGen.gen_series_cases(N_SMALL_SAMPLE, L_SMALL)
        pass

    def gen_large_cases(self):
        self.listGen.gen_series_cases(N_LARGE_SAMPLE, L_LARGE)
        pass

    def gen_boundary_case(self):
        self.listGen.gen_random_cases(L_BOUDERY)
        self.listGen.gen_bad_cases(L_BOUDERY)
        pass

    def gen_all_cases(self):
        self.gen_special_case()
        self.gen_small_cases()
        self.gen_large_cases()
        self.gen_boundary_case()
        self.fout.close()


<mask token>

<mask token>


class Solution:

    def replaceSpaces(self, S: str, length: int) ->str:
        cnt = 0
        S = list(S)
        cnt += sum(1 for c in S[:length] if c == ' ')
        newLen = length + 2 * cnt
        S = S[:newLen]
        for i in range(length - 1, -1, -1):
            if S[i] == ' ':
                S[newLen - 1] = '0'
                S[newLen - 2] = '2'
                S[newLen - 3] = '%'
                newLen -= 3
            else:
                S[newLen - 1] = S[i]
                newLen -= 1
        return ''.join(S)


class StringTestGenerator:

    def __init__(self, out_fun):
        self.output = out_fun

    def gen_a_random_string(self, length):
        ret = []
        i = 0
        while i < length:
            times = min(random.randint(0, int(length / 10 + 1)), length - i)
            i += times
            ret.append(AVAILABLE_CHARS[random.randint(0, len(
                AVAILABLE_CHARS) - 1)] * times)
        self.output(''.join(ret))

    def gen_a_unsutiable_string(self, length):
        ret = []
        i = 0
        while i < length:
            times = min(max(1, random.randint(0, 3)), length - i)
            i += times
            ret.append(AVAILABLE_CHARS[random.randint(0, len(
                AVAILABLE_CHARS) - 1)] * times)
        self.output(''.join(ret))

    def gen_series_string(self, nsamp, large_L):
        for _ in range(int(nsamp / 2)):
            l = random.randint(1, large_L)
            self.gen_a_random_string(l)
            self.gen_a_unsutiable_string(l)


class StringToURLTestcaseGenerator:

    def __init__(self, output):
        self.output = output

    def gen_bad_cases(self, length):
        ret = []
        i = 0
        tail = ''
        while i < length:
            if random.randint(0, 1) % 2 == 0:
                c = AVAILABLE_CHARS[random.randint(0, len(AVAILABLE_CHARS) - 1)
                    ]
                ret.append(c)
                if c == ' ':
                    tail += '  '
            else:
                ret.append(' ')
                tail += '  '
            i += 1
        self.output(''.join(ret) + tail)
        self.output(length)

    def gen_random_cases(self, length):
        ret = []
        i = 0
        tail = ''
        while i < length:
            i += 1
            c = AVAILABLE_CHARS[random.randint(0, len(AVAILABLE_CHARS) - 1)]
            ret.append(c)
            if c == ' ':
                tail += '  '
        self.output(''.join(ret) + tail)
        self.output(length)

    def gen_series_cases(self, nsamp, large_L):
        for _ in range(0, int(nsamp), 2):
            l = random.randint(1, large_L)
            self.gen_random_cases(l)
            self.gen_bad_cases(l)


class TestCaseGenerator:

    def __init__(self, file_out='input_file', case_num=20):
        random.seed(RANDOM_SEED)
        self.fout = open(file_out, 'w')
        self.listGen = StringToURLTestcaseGenerator(self.output)

    def output(self, *params):
        for para in params:
            if type(para) == str:
                self.fout.write('"%s"' % str(para))
            else:
                json.dump(para, self.fout)
            self.fout.write('\n')

    def gen_special_case(self):
        self.output('Mr John Smith    ', 13)
        self.output(' ' * 15, 5)
        self.output('ds sdfs afs sdfa dfssf asdf             ', 27)
        self.output('      dsfasdfasdfas               ', 19)

    def gen_small_cases(self):
        self.listGen.gen_series_cases(N_SMALL_SAMPLE, L_SMALL)
        pass

    def gen_large_cases(self):
        self.listGen.gen_series_cases(N_LARGE_SAMPLE, L_LARGE)
        pass

    def gen_boundary_case(self):
        self.listGen.gen_random_cases(L_BOUDERY)
        self.listGen.gen_bad_cases(L_BOUDERY)
        pass

    def gen_all_cases(self):
        self.gen_special_case()
        self.gen_small_cases()
        self.gen_large_cases()
        self.gen_boundary_case()
        self.fout.close()


def get_res(file_in, file_out):
    lines = []
    sol = Solution()
    with open(file_in, 'r') as fin:
        lines = fin.readlines()
    with open(file_out, 'w') as fout:
        for i in range(0, len(lines), 2):
            line = json.loads(lines[i])
            times = json.loads(lines[i + 1])
            fout.write('"%s"\n' % sol.replaceSpaces(line, times))


<mask token>

import random
import json
from cyaron import Graph
AVAILABLE_CHARS = [chr(ord('a') + i) for i in range(26)]
AVAILABLE_CHARS.extend([chr(ord('A') + i) for i in range(26)])
AVAILABLE_CHARS.append(' ')
RANDOM_SEED = 50
N_SMALL_SAMPLE = 15
N_LARGE_SAMPLE = 9
L_SMALL = 100
L_LARGE = 1000
L_BOUDERY = 500000


class Solution:

    def replaceSpaces(self, S: str, length: int) ->str:
        cnt = 0
        S = list(S)
        cnt += sum(1 for c in S[:length] if c == ' ')
        newLen = length + 2 * cnt
        S = S[:newLen]
        for i in range(length - 1, -1, -1):
            if S[i] == ' ':
                S[newLen - 1] = '0'
                S[newLen - 2] = '2'
                S[newLen - 3] = '%'
                newLen -= 3
            else:
                S[newLen - 1] = S[i]
                newLen -= 1
        return ''.join(S)


class StringTestGenerator:

    def __init__(self, out_fun):
        self.output = out_fun

    def gen_a_random_string(self, length):
        ret = []
        i = 0
        while i < length:
            times = min(random.randint(0, int(length / 10 + 1)), length - i)
            i += times
            ret.append(AVAILABLE_CHARS[random.randint(0, len(
                AVAILABLE_CHARS) - 1)] * times)
        self.output(''.join(ret))

    def gen_a_unsutiable_string(self, length):
        ret = []
        i = 0
        while i < length:
            times = min(max(1, random.randint(0, 3)), length - i)
            i += times
            ret.append(AVAILABLE_CHARS[random.randint(0, len(
                AVAILABLE_CHARS) - 1)] * times)
        self.output(''.join(ret))

    def gen_series_string(self, nsamp, large_L):
        for _ in range(int(nsamp / 2)):
            l = random.randint(1, large_L)
            self.gen_a_random_string(l)
            self.gen_a_unsutiable_string(l)


class StringToURLTestcaseGenerator:

    def __init__(self, output):
        self.output = output

    def gen_bad_cases(self, length):
        ret = []
        i = 0
        tail = ''
        while i < length:
            if random.randint(0, 1) % 2 == 0:
                c = AVAILABLE_CHARS[random.randint(0, len(AVAILABLE_CHARS) - 1)
                    ]
                ret.append(c)
                if c == ' ':
                    tail += '  '
            else:
                ret.append(' ')
                tail += '  '
            i += 1
        self.output(''.join(ret) + tail)
        self.output(length)

    def gen_random_cases(self, length):
        ret = []
        i = 0
        tail = ''
        while i < length:
            i += 1
            c = AVAILABLE_CHARS[random.randint(0, len(AVAILABLE_CHARS) - 1)]
            ret.append(c)
            if c == ' ':
                tail += '  '
        self.output(''.join(ret) + tail)
        self.output(length)

    def gen_series_cases(self, nsamp, large_L):
        for _ in range(0, int(nsamp), 2):
            l = random.randint(1, large_L)
            self.gen_random_cases(l)
            self.gen_bad_cases(l)


class TestCaseGenerator:

    def __init__(self, file_out='input_file', case_num=20):
        random.seed(RANDOM_SEED)
        self.fout = open(file_out, 'w')
        self.listGen = StringToURLTestcaseGenerator(self.output)

    def output(self, *params):
        for para in params:
            if type(para) == str:
                self.fout.write('"%s"' % str(para))
            else:
                json.dump(para, self.fout)
            self.fout.write('\n')

    def gen_special_case(self):
        self.output('Mr John Smith    ', 13)
        self.output(' ' * 15, 5)
        self.output('ds sdfs afs sdfa dfssf asdf             ', 27)
        self.output('      dsfasdfasdfas               ', 19)

    def gen_small_cases(self):
        self.listGen.gen_series_cases(N_SMALL_SAMPLE, L_SMALL)
        pass

    def gen_large_cases(self):
        self.listGen.gen_series_cases(N_LARGE_SAMPLE, L_LARGE)
        pass

    def gen_boundary_case(self):
        self.listGen.gen_random_cases(L_BOUDERY)
        self.listGen.gen_bad_cases(L_BOUDERY)
        pass

    def gen_all_cases(self):
        self.gen_special_case()
        self.gen_small_cases()
        self.gen_large_cases()
        self.gen_boundary_case()
        self.fout.close()


def get_res(file_in, file_out):
    lines = []
    sol = Solution()
    with open(file_in, 'r') as fin:
        lines = fin.readlines()
    with open(file_out, 'w') as fout:
        for i in range(0, len(lines), 2):
            line = json.loads(lines[i])
            times = json.loads(lines[i + 1])
            fout.write('"%s"\n' % sol.replaceSpaces(line, times))


if __name__ == '__main__':
    gen = TestCaseGenerator()
    gen.gen_all_cases()
    get_res('input_file', 'output_file')

import random
import json
from cyaron import Graph


AVAILABLE_CHARS = [chr(ord('a')+i) for i in range(26)
                   ]
AVAILABLE_CHARS.extend([chr(ord('A')+i) for i in range(26)])
AVAILABLE_CHARS.append(' ')
RANDOM_SEED = 50
N_SMALL_SAMPLE = 15
N_LARGE_SAMPLE = 9
L_SMALL = 100
L_LARGE = 1000
L_BOUDERY = 500000


class Solution:
    def replaceSpaces(self, S: str, length: int) -> str:
        cnt = 0
        S = list(S)
        cnt += sum((1 for c in S[:length] if c == ' '))
        newLen = length + 2 * cnt
        #print(length, newLen)
        S = S[:newLen]

        for i in range(length - 1, -1, -1):
            if S[i] == ' ':
                S[newLen - 1] = '0'
                S[newLen - 2] = '2'
                S[newLen - 3] = '%'
                newLen -= 3
            else:
                S[newLen - 1] = S[i]
                newLen -= 1
        return ''.join(S)


class StringTestGenerator:
    def __init__(self, out_fun):
        self.output = out_fun

    def gen_a_random_string(self, length):
        ret = []
        i = 0
        while i < length:
            times = min(random.randint(0, int(length/10+1)), length - i)
            i += times
            ret.append(AVAILABLE_CHARS[random.randint(
                0, len(AVAILABLE_CHARS) - 1)]*times)
        self.output(''.join(ret))

    # generate a string that not suitable to compress
    def gen_a_unsutiable_string(self, length):
        ret = []
        i = 0
        while i < length:
            times = min(max(1, random.randint(0, 3)), length - i)
            i += times
            ret.append(AVAILABLE_CHARS[random.randint(
                0, len(AVAILABLE_CHARS) - 1)]*times)
        self.output(''.join(ret))

    # def gen_correct_string(self, length):
    #     ret = []
    #     for _ in range(length):
    #         ret.append(AVAILABLE_CHARS[random.randint(
    #             0, len(AVAILABLE_CHARS) - 1)])
    #     rn = random.randint(0, len(ret) - 1)
    #     ret2 = ret[rn:] + ret[:rn]
    #     self.output(''.join(ret), ''.join(ret2))

    def gen_series_string(self, nsamp, large_L):
        for _ in range(int(nsamp/2)):
            l = random.randint(1, large_L)
            self.gen_a_random_string(l)
            self.gen_a_unsutiable_string(l)


class StringToURLTestcaseGenerator():
    def __init__(self, output):
        self.output = output

    def gen_bad_cases(self, length):
        ret = []
        i = 0
        tail = ""
        while i < length:
            if random.randint(0, 1) % 2 == 0:
                c = AVAILABLE_CHARS[random.randint(
                    0, len(AVAILABLE_CHARS) - 1)]
                ret.append(c)
                if c == ' ':
                    tail += '  '
            else:
                ret.append(' ')
                tail += '  '
            i += 1
            # times = min(max(1, random.randint(0, 3)), length - i)
            # i += times
            # ret.append(AVAILABLE_CHARS[random.randint(
            #     0, len(AVAILABLE_CHARS) - 1)])

        self.output(''.join(ret) + tail)
        self.output(length)

    def gen_random_cases(self, length):
        ret = []
        i = 0
        tail = ''
        while i < length:
           # times = min(random.randint(0, int(length/10+1)), length - i)
            i += 1
            c = AVAILABLE_CHARS[random.randint(
                0, len(AVAILABLE_CHARS) - 1)]
            ret.append(c)
            if c == ' ':
                tail += '  '
        self.output(''.join(ret) + tail)
        self.output(length)

    def gen_series_cases(self, nsamp, large_L):
        for _ in range(0, int(nsamp), 2):
            l = random.randint(1, large_L)
            self.gen_random_cases(l)
            self.gen_bad_cases(l)


class TestCaseGenerator:

    def __init__(self, file_out='input_file', case_num=20):
        random.seed(RANDOM_SEED)
        self.fout = open(file_out, 'w')
        self.listGen = StringToURLTestcaseGenerator(self.output)

    def output(self, *params):
        for para in params:
            if type(para) == str:
                self.fout.write('\"%s\"' % str(para))
            else:
                json.dump(para, self.fout)
            self.fout.write('\n')
            # self.gen_correct_string(l)

    def gen_special_case(self):
        self.output("Mr John Smith    ", 13)
        self.output(' '*15, 5)

        self.output("ds sdfs afs sdfa dfssf asdf             ", 27)
        self.output("      dsfasdfasdfas               ", 19)
        # self.output(12, [[0, 1], [1, 2], [1, 3], [1, 10], [1, 11], [1, 4], [2, 4], [2, 6], [2, 9], [2, 10], [2, 4], [2, 5], [
        #             2, 10], [3, 7], [3, 7], [4, 5], [4, 11], [4, 11], [4, 10], [5, 7], [5, 10], [6, 8], [7, 11], [8, 10]], 2, 3)
        # self.output(25, [[0, 1], [0, 3], [0, 10], [0, 18], [1, 2], [1, 7], [1, 11], [1, 12], [2, 4], [2, 5], [2, 13], [2, 16], [3, 6], [
        #             3, 8], [4, 9], [5, 17], [7, 20], [7, 22], [8, 10], [10, 19], [11, 15], [13, 14], [14, 21], [15, 23], [19, 24], [20, 22]], 0, 12)

    def gen_small_cases(self):
        # self.gen_series_string(N_SMALL_SAMPLE, L_SMALL)
        self.listGen.gen_series_cases(N_SMALL_SAMPLE, L_SMALL)
        pass

    def gen_large_cases(self):
        # self.gen_series_string(N_LARGE_SAMPLE, L_LARGE)
        self.listGen.gen_series_cases(N_LARGE_SAMPLE, L_LARGE)
        pass

    def gen_boundary_case(self):
        # self.gen_a_random_string(L_BOUDERY)
        # self.gen_a_unsutiable_compress_string(L_BOUDERY)
        self.listGen.gen_random_cases(L_BOUDERY)
        self.listGen.gen_bad_cases(L_BOUDERY)
        pass

    def gen_all_cases(self):
        self.gen_special_case()
        self.gen_small_cases()
        self.gen_large_cases()
        self.gen_boundary_case()
        self.fout.close()


def get_res(file_in, file_out):
    lines = []
    sol = Solution()
    with open(file_in, "r") as fin:
        lines = fin.readlines()
    with open(file_out, "w") as fout:
        for i in range(0, len(lines), 2):
            line = json.loads(lines[i])
            times = json.loads(lines[i + 1])
            fout.write('\"%s\"\n' % sol.replaceSpaces(line, times))


if __name__ == "__main__":
    gen = TestCaseGenerator()
    gen.gen_all_cases()
    get_res('input_file', 'output_file')
