from os import mkdir
from random import *

seed('sochi')

MAXN = 100000

def shuffled(a):
    b = a[:]
    shuffle(b)
    return b

logger = lambda s : print (s)

class Printer:
    def __init__(self, path):
        self.path = "../" + path
        self.tests = 0
        try:
            logger("Creating directory %s"%self.path)
            mkdir(self.path)
        except:
            logger("...Directory already exists")

    def print(self, d, a):
        self.tests += 1
        p = self.path + "/" + "%02d"%self.tests
        logger("Printing test %s"%p)
        out = open(p, "w")
        print (len(a), d, file=out)
        print (' '.join(map(str, a)), file=out)

tests = Printer("tests")

tests.print(10, [25, 50])
tests.print(2, [4,5,6,7,8])
tests.print(1, [1])
tests.print(10, [1])
tests.print(2, [1])
tests.print(1, [2])
tests.print(2, [3])
tests.print(1, [3])

g = [lambda d : 2 * d - 1, lambda d : 2 * d, lambda d : 2 * d + 1]
for f1 in g:
    for f2 in g:
        d = 10
        tests.print(d, [f1(d), f2(d)])

for (n,d,m) in [(100,10,1000), (1000,100,1000), (100000, 10**3 // 3, 10**3)]:
    less = lambda : randint(1, 2 * d - 1)
    mid = lambda : randint(2 * d, 3 * d)
    greater = lambda : randint(3*d, m)
    repeat = lambda n, f: [f() for i in range(n)]
    tests.print(d, repeat(n, less))
    tests.print(d, repeat(n, mid))
    tests.print(d, repeat(n, greater))
    tests.print(d, shuffled(
        repeat(n // 3, less) + repeat(n // 3, mid) + repeat(n // 3, greater)))

for d in [1,2,3,5,10,50,51,100,999,1000]:
    tests.print(d, list([min(1000, x) for x in range(1,MAXN + 1)]))

tests.print(1, [1] * MAXN)
tests.print(1, [1000] * MAXN)
tests.print(10**3 // 3, [10**3] * MAXN)
tests.print(10**3 // 2, [10**3] * MAXN)
tests.print(10**3 // 3 + 1, [10**3] * MAXN)

