#!/usr/bin/python3

import random, shutil
from subprocess import call

problemId = 'game'
inFN = '%s.in' % problemId
outFN = "%s.out" % problemId
fastFN = "%s.fast" % problemId
slowFN = "%s.slow" % problemId

call(["javac", "game_av.java"])
call(["javac", "game_av_wa5.java"])
#call(["g++", "game_ek.cpp"])


def randomArray(n, m):
    return [random.randint(1, m) for _ in range(n)]

def writeInput(n, m, k, a):
    inputFile = open(inFN, "w")
    print(1, file=inputFile)
    print(n, m, k, file=inputFile)
    print(' '.join(map(str, a)), file=inputFile)
    inputFile.close()


iter = 0
random.seed('1')
while True:
    iter += 1
    n = random.randint(10, 20)
    m = random.randint(1, n)
    k = random.randint(1, m)
    a = randomArray(n, m)
    writeInput(n, m, k, a)
        
    call(["java", "game_av"])
    shutil.copyfile(outFN, fastFN)
    call(["java", "game_av_wa5"])
	#   call(["a.exe"])
    shutil.copyfile(outFN, slowFN)
    
    import filecmp
    if not filecmp.cmp(slowFN, fastFN):
        print("FAIL")
        print("".join(open(inFN).readlines()))
        print("Fast solution:")
        print("".join(open(fastFN).readlines()))
        print("Slow solution:")
        print("".join(open(slowFN).readlines()))
        
        import sys
        sys.exit(1)


    if (iter % 100) == 0:
        print("iter =", iter)
