import random

maxn = 1000
maxm = 1000
maxp = 1000000

def gen(p, name):
    n = len(p)
    if n < 1 or n > maxn: raise ValueError("Bad job count")
    m = len(p[0])
    if m < 1 or m > maxm: raise ValueError("Bad stage count")
    for l in p:
        if len(l) != m: raise ValueError("Inconsistent stage count")
        for x in l:
            if type(x) != int: raisevalueError("Non integer")
            if x < 1 or x > maxp: raiseValueError("Bad completion time")

    out = open(name, "w")
    print(n, m, file=out)
    for l in p: print(*l, file=out)
    out.close()


def sample1(name):
    gen([[1, 2, 3], [3, 2, 1]], name)


def sample2(name):
    gen([[3, 1], [4, 7], [2, 5]], name)

def fast(n, m, name):
    gen([[1]*m]*n, name)

def slow(n, m, name):
    gen([[maxp]*m]*n, name)

def rando(n, m, name):
    p = [[0]*m for i in range(n)]

    for i in range(n):
        for j in range(m):
            p[i][j] = random.randrange(1, maxp+1)
    gen(p, name)

def inc(name):
    gen([list(range(1,21)), list(range(1,21))], name)

def dec(name):
    gen([list(range(1,21)), list(range(21,1,-1))], name)

if __name__ == "__main__":
    cno = 0

    def next_name():
        global cno

        cno += 1
        return "rm16-jobs-{0:02}.in".format(cno)

    sample1(next_name())
    sample2(next_name())

    inc(next_name())
    dec(next_name())

    fast(1, 1, next_name())
    fast(1, maxm, next_name())
    fast(maxn, 1, next_name())

    rando(1, 1, next_name())
    rando(1, maxm, next_name())
    rando(maxn, 1, next_name())

    slow(1, 1, next_name())
    slow(1, maxm, next_name())
    slow(maxn, 1, next_name())

    fast(maxn, maxm, next_name())

    slow(maxn, maxm, next_name())

    for i in range(10):
        rando(random.randrange(1, maxn//10), random.randrange(1, maxm//10), next_name())
    for i in range(10):
        rando(random.randrange(maxn//2, maxn), random.randrange(maxm//2, maxm), next_name())
