from os import mkdir
from random import *

seed('cond')

MAXN1 = 1000
MAXN2 = 50000

logger = lambda s : print (s)

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

rand = lambda n, p, c: [(randint(1, p), randint(1, c)) for i in range(n)]

def normalize(a):
    d = max(a)
    if d <= 1000:
        return a
    return [max(1, i * 1000 // d) for i in a]

def normalizeBC(bc):
    return list(zip(normalize(list(map(lambda a:a[0], bc))), 
                    normalize(list(map(lambda a:a[1], bc)))))

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, a, bc):
        a = normalize(a)
        bc = normalizeBC(bc)
        self.tests += 1
        p = self.path + "/" + "%02d"%self.tests
        logger("Printing test %s"%p)
        out = open(p, "w")
        print (len(a), file=out)
        print (' '.join(map(str, a)), file=out)
        print (len(bc), file=out)
        for (b, c) in bc:
            print (b, c, file=out)

prelim = Printer("preliminary")
prelim.print([800], [(800, 1000)])
prelim.print([1, 2, 3], [(1, 10), (1, 5), (10, 7), (2, 3)])

tests = Printer("tests")
# n < 1000, ans \in Int32, 8 tests
## n < 10, 4 tests
tests.print([5] * 5, [(4, 1), (5, 5), (6, 6), (10, 6)])
tests.print([9, 1, 5], rand(9, 10, 10) + [(10, 10)])
tests.print([9, 1, 5], [(10, 1)])
tests.print([1], rand(10, 10, 10))

## 10 <= n < 1000, 4 tests
tests.print([1] * MAXN1, shuffled([(i, MAXN1 - i) for i in range(1, MAXN1)]))
tests.print([i for i in range(1, MAXN1)], 
            shuffled([(i, MAXN1 - i) for i in range(1, MAXN1)]))
tests.print([randint(1, MAXN1) for i in range(MAXN1)], 
            rand(MAXN1 - 1, MAXN1, MAXN1) + [(MAXN1, MAXN1)])
tests.print(shuffled([1] * (MAXN1 // 2) + [5 * 10**8] * (MAXN1 // 2)),
            rand(MAXN1, 10**9, 10**9))

# n < 1000, ans \in Int64, 2 tests
tests.print([10 ** 9] * MAXN1, [(10**9, 10**9)] * MAXN1)
tests.print([randint(1, 10**9) for i in range(1, MAXN1)],
            rand(MAXN1 - 1, 10**9, 10**9) + [(10**9, 10**9)])

# n >= 1000, ans \in Int32, 8 tests
tests.print(list(range(1, MAXN2)), 
            [(i, min(10000, i)) for i in range(1, MAXN2 + 1)])
tests.print([1] * MAXN2, shuffled([(i, MAXN2 - i) for i in range(1, MAXN2)]))
tests.print([i for i in range(1, MAXN1)], 
            shuffled([(i, min(10000, MAXN2 - i)) for i in range(1, MAXN2)]))
tests.print([randint(1, MAXN2) for i in range(MAXN2)], 
            rand(MAXN2 - 1, MAXN2, min(10000, MAXN2)))
tests.print(shuffled([1] * (MAXN2 // 2) + [5 * 10**8] * (MAXN2 // 2)),
            rand(MAXN2, 10**9, 10**9))
tests.print(shuffled(list(range(1, MAXN2))), 
            [(i, i // 10000 + 1) for i in range(1, MAXN2 + 1)])
tests.print(shuffled(2 * list(range(1, MAXN2, 2))),
            shuffled([(i + randint(1, 10), randint(1, i // 20 + 1) + 1) for i in range(1, MAXN2)]))
tests.print([randint(1, i * (10**9 // MAXN2) + 1) for i in range(MAXN2)],
            rand(MAXN2 - 1, 10**9, 100000) + [(10**9, 10**9)])

# n >= 1000, ans \in Int64, 2 tests
tests.print([10 ** 9] * MAXN2, [(10**9, 10**9)] * MAXN2)
tests.print([randint(1, 10**9) for i in range(1, MAXN2)],
            rand(MAXN2 - 1, 10**9, 10**9) + [(10**9, 10**9)])

