Getting wrong answer for buy1 get1 question although output and logic is correct

//This is the code in python for the same

z=input()

i=0
list=[]
def find(i):
dict1={}
for j in i:
dict1[j]=0
for j in i:
dict1[j]=dict1[j]+1
cost=0
cost1=0
for i in dict1:
if dict1[i]%2==0:
cost=cost+(dict1[i]/2);
else:
cost1=cost1+(dict1[i]%2)+(dict1[i]/2)
return cost+cost1

while(i<z):
list.append(raw_input())
i=i+1
for i in list:
cost=find(i)
print cost

//