import math

keys1 = 40000
keys2 = 30000
keys3 = 20000
keys4 = 40000
keys5 = 40000
keys6 = 40000
keys7 = 23766
keys7_Max = 50000
keys8 = 27640
keys8_Max = 50000
keys9 = 8167
keys9_Max = 50000
keys10 = 50000

keyFile = "keys.txt"
keyFile_G1 = "keys_G1.txt"
keyFile_G2 = "keys_G2.txt"
keyFile_G3 = "keys_G3.txt"
keyFile_G4 = "keys_G4.txt"
keyFile_G5 = "keys_G5.txt"
keyFile_G6 = "keys_G6.txt"
keyFile_G7 = "keys_G7.txt"
keyFile_G8 = "keys_G8.txt"
keyFile_G9 = "keys_G9.txt"
keyFile_G10 = "keys_G10.txt"

fKey = open(keyFile, "r")
fKey_G1 = open(keyFile_G1, "w")
fKey_G2 = open(keyFile_G2, "w")
fKey_G3 = open(keyFile_G3, "w")
fKey_G4 = open(keyFile_G4, "w")
fKey_G5 = open(keyFile_G5, "w")
fKey_G6 = open(keyFile_G6, "w")
fKey_G7 = open(keyFile_G7, "w")
fKey_G8 = open(keyFile_G8, "w")
fKey_G9 = open(keyFile_G9, "w")
fKey_G10 = open(keyFile_G10, "w")

bitLen = 40
count = 0
keys_G1 = []
keys_G2 = []
keys_G3 = []
keys_G4 = []
keys_G5 = []
keys_G6 = []
keys_G7 = []
keys_G8 = []
keys_G9 = []
keys_G10 = []

#Extract keys
for line in fKey:	
    if count < keys1:
        keys_G1.append(line[:40])
        fKey_G1.write(line[:40] + '\n')
    elif count < keys1 + keys2:
        keys_G2.append(line[:40])
        fKey_G2.write(line[:40] + '\n')
    elif count < keys1 + keys2 + keys3:
        keys_G3.append(line[:40])
        fKey_G3.write(line[:40] + '\n')
    elif count < keys1 + keys2 + keys3 + keys4:
        keys_G4.append(line[:40])
        fKey_G4.write(line[:40] + '\n')
    elif count < keys1 + keys2 + keys3 + keys4 + keys5:
        keys_G5.append(line[:40])
        fKey_G5.write(line[:40] + '\n')
    elif count < keys1 + keys2 + keys3 + keys4 + keys5 + keys6:
        keys_G6.append(line[:40])
        fKey_G6.write(line[:40] + '\n')
    elif count < keys1 + keys2 + keys3 + keys4 + keys5 + keys6 + keys7:
        keys_G7.append(line[:40])
        fKey_G7.write(line[:40] + '\n')
    elif count < keys1 + keys2 + keys3 + keys4 + keys5 + keys6 + keys7 + keys8:
        keys_G8.append(line[:40])
        fKey_G8.write(line[:40] + '\n')
    elif count < keys1 + keys2 + keys3 + keys4 + keys5 + keys6 + keys7 + keys8 + keys9:
        keys_G9.append(line[:40])
        fKey_G9.write(line[:40] + '\n')
    else:
        keys_G10.append(line[:40])
        fKey_G10.write(line[:40] + '\n')

    count = count + 1
fKey.close()
fKey_G1.close()
fKey_G2.close()
fKey_G3.close()
fKey_G4.close()
fKey_G5.close()
fKey_G6.close()

i_1 = 0
for i in range(int(round(0.2 * math.sqrt(keys1 * keys8_Max)))):
    fKey_G8.write(keys_G1[i] + '\n')
    i_1 = i_1 + 1
print 0.4 * math.sqrt(keys1 * keys9_Max)
for i in range(int(round(0.4 * math.sqrt(keys1 * keys9_Max)))):
    fKey_G9.write(keys_G1[i + i_1] + '\n')
for i in range(int(round(0.1 * math.sqrt(keys3 * keys7_Max)))):
    fKey_G7.write(keys_G3[i] + '\n')
print 0.2 * math.sqrt(keys4 * keys9_Max)
for i in range(int(round(0.2 * math.sqrt(keys4 * keys9_Max)))):
    fKey_G9.write(keys_G4[i] + '\n')
i_5 = 0
for i in range(int(round(0.3 * math.sqrt(keys5 * keys8_Max)))):
    fKey_G8.write(keys_G5[i] + '\n')
    i_5 = i_5 + 1
for i in range(int(round(0.5 * math.sqrt(keys5 * keys7_Max)))):
    fKey_G7.write(keys_G5[i + i_5] + '\n')
print 0.3 * math.sqrt(keys10 * keys9_Max)
for i in range(int(round(0.3 * math.sqrt(keys10 * keys9_Max)))):
    fKey_G9.write(keys_G10[i] + '\n')

fKey_G7.close()
fKey_G8.close()
fKey_G9.close()
fKey_G10.close()
