import sys
import random

currentTest = 0

def printTest(n, k, wishes):
  global currentTest
  currentTest += 1
  print('Generating test #', currentTest)

  FOUT = open("../tests/%02d" % currentTest, 'w');
  FOUT.write(str(n) + ' ' + str(k) + '\n')
  FOUT.write(' '.join(wishes) + '\n')
  FOUT.close()

def genSameWishes(n, k, w):
  wishes = []
  for i in range(0, int(n)):
    wishes.append(str(w))
  printTest(n, k, wishes)

def genTwoBlocks(n1, n2, k, w1, w2):
  wishes = []
  for i in range(0, int(n1)):
    wishes.append(str(w1))
  for i in range(0, int(n2)):
    wishes.append(str(w2))
  printTest(n1 + n2, k, wishes)

def genRandom(n, k, lim):
  wishes = []
  for i in range(0, int(n)):
    wishes.append(str(max(1, min(k, int(random.random() * lim)))))
  printTest(n, k, wishes)

def genRandomTwoBlocks(n1, n2, k, lim1, lim2):
  wishes = []
  for i in range(0, int(n1)):
    wishes.append(str(max(1, min(k, int(random.random() * lim1)))))
  for i in range(0, int(n2)):
    wishes.append(str(max(1, min(k, int(random.random() * lim2)))))
  printTest(n1 + n2, k, wishes)

def main():
#tests from statement
  printTest(2, 100, [str(5), str(10)])
  printTest(4, 10, [str(7), str(8), str(3), str(5)])
#manual tests
  printTest(1, 1, [str(1)])
  printTest(10, 10, [str(1), str(2), str(3), str(4), str(5), str(6), str(7), str(8), str(9), str(10)])
  printTest(10, 10, [str(10), str(2), str(3), str(4), str(5), str(6), str(7), str(8), str(9), str(2)])
  printTest(4, 100, [str(95), str(10), str(10), str(95)])
  printTest(2, 1, [str(1), str(1)])
  printTest(6, 10, [str(8), str(1), str(8), str(1), str(8), str(8)])
  printTest(5, 10, [str(2), str(8), str(2), str(8), str(8)])
  printTest(1, 100, [str(50)])
  printTest(2, 100, [str(50), str(50)])
  printTest(5, 15, [str(8), str(7), str(6), str(7), str(6)])
  printTest(5, 18, [str(8), str(7), str(6), str(7), str(6)])
  printTest(5, 15, [str(8), str(7), str(6), str(3), str(6)])

  random.seed(239)
#all wishesh are the same
  genSameWishes(1, 1000000000, 1000000000)
  genSameWishes(100000, 1000000000, 1000000000)
  genSameWishes(100000, 100000, 1)
  genSameWishes(100000, 1000000000, 10000)
  genSameWishes(100000, 99999, 1)
  genSameWishes(100000, 1000000000, 100000)
#two big blocks of wishes of same size
  genTwoBlocks(50000, 50000, 1000000000, 20, 10)
  genTwoBlocks(99999, 1, 1000000000, 1000000000, 1)
  genTwoBlocks(99998, 2, 1000000000, 1, 1000000000)
  genTwoBlocks(50000, 50000, 1000000000, 1000, 999000000)
  genTwoBlocks(99999, 1, 1000000000, 1000000, 1000000000)
#just large random tests
  genRandom(100000, 1000000000, 10)
  genRandom(100000, 1000000000, 1000)
  genRandom(100000, 1000000000, 100000)
  genRandom(100000, 1000000000, 10000000)
  genRandom(100000, 1000000000, 1000000000)
#random tests with two data blocks
  genRandomTwoBlocks(50000, 50000, 1000000000, 1000, 1000000)
  genRandomTwoBlocks(99000, 1000, 1000000000, 100000, 100000000)
  genRandomTwoBlocks(99000, 1000, 1000000000, 1000000, 1000000000)

if __name__ == "__main__":
  main()
