import random
import math
random.seed("basic04")

class TestGen:
    def __init__(self):
        self.test_number = 0

    def generate_samples(self):
        self.print_test(3, 5, 5)
        self.print_test(2, 4, 2)
        self.print_test(1, 8, 3)
        self.print_test(1, 3, 2)

    def generate_min_tests(self):
        for a in range(1, 4):
            for b in range(1, 4):
                for d in range(1, 4):
                    self.print_test(a, b, d)
                                                                    
    def generate_hand_tests(self):
        self.print_test(1, 36, 6)
        self.print_test(36, 36, 6)
        self.print_test(37, 36, 6)
        self.print_test(1, 30000**2, 30000)
        self.print_test(1, 30000**2, 3)
        self.print_test(6, 216, 6)
        self.print_test(6, 216, 2)

    def generate_random_test(self, maxn):
        self.print_test(random.randint(1, maxn), random.randint(1, maxn), random.randint(1, maxn))

    def generate_max_tests(self, maxn):
        self.print_test(10**9 - 1, 10**9, 1)
        self.print_test(10**9, 10**9 - 1, 1)
        self.print_test(10**9, 10**9 - 1, 333667)
        self.print_test(10**9, 10**9 - 1, 333666)
        self.print_test(10**9, 10**9 - 1, 333668)
        self.print_test(1, 931170240, 19)
        self.print_test(1, 931170240, 18)
        self.print_test(1, 931170240, 20)
        self.print_test(29 * 31 * 37 * 41 * 43, 931170240, 43)
        self.print_test(29 * 31 * 37 * 41 * 43, 931170240, 42)
        self.print_test(29 * 31 * 37 * 41 * 43, 931170240, 43 * 5 * 2)
        self.print_test(29 * 31 * 37 * 41 * 43, 931170240, 43 * 2)
        self.print_test(29 * 31 * 37 * 41 * 43, 931170240, 43 * 5)
        self.print_test(23 * 29 * 31 * 41 * 43, 931170240, 43 * 5 * 37)
        self.print_test(999999937, 999999929, 999999937)
        self.print_test(999999937, 999999929, 999999936)
        self.print_test(999999937, 999999929, 10**9)
        self.print_test(999999739, 999999503, 10**9)
        self.print_test(999999937, 499999993 * 2, 10**9)
        self.print_test(999999739, 499999697 * 2, 10**9)
        self.print_test(999999739, 499999697 * 2, 999999739)
        self.print_test(999999739, 499999697 * 2, 999999738)

    def print_test(self, a, b, d):
        self.test_number += 1
        test_name = "../tests/" + "{0:0=2d}".format(self.test_number)
        test_file = open(test_name, "w")
        print(a, b, d, file=test_file)
        test_file.close()

    def generate_all_tests(self):
        maxn = 10**9

        self.generate_samples()
        self.generate_hand_tests()
        self.generate_min_tests()
        
        for i in range(20):
            self.generate_random_test(maxn)
        self.generate_max_tests(maxn)        

import os, shutil
if os.path.exists('../tests'):
    print('Directory tests is already exists')
    shutil.rmtree('../tests', ignore_errors=False, onerror=None)
try:
    os.makedirs('../tests')
except OSError:
    pass

import time
start = time.time()
writer = TestGen()
writer.generate_all_tests()
finish = time.time()
print('All tests were generated. Elapsed time: ', finish - start)