# Programmed by Mike Noseworthy and Andrew Horsman
# Mentored by Ms. Quesnelle
# Dwite 2009-2010 Round 3
# Problem 3
fileIn = open("DATA3.txt", "r")

binarylist = ["00000000"]
binaryStr = ""
currentBin = [0,0,0,0,0,0,0,0]

counter = 0
for i in range(1, 256):
	binaryStr = ""
	currentBin[7] += 1
	for j in range(7, -1, -1):
		if currentBin[j] == 2:
			currentBin[j] = 0
			currentBin[j - 1] += 1
	binaryString = ""		
	for k in range(0, 8):
		binaryStr += str(currentBin[k])
		
	binarylist.append(binaryStr)

outputBuffer = ""

for line in fileIn:
	line = line.strip()
	counter = 0
	for binaryNum in binarylist:
		if line not in binaryNum:
			counter += binaryNum.count("1")
			
	outputBuffer += str(counter) + "\n"
	
fileOut = open("OUT3.txt", "w")
fileOut.write(outputBuffer)			
fileIn.close()
fileOut.close()
			
			
	
	

