guys i need help with a code
I have been trying to solve a problem
here is the code.please help me i can never get any code right on codechef
n = int(input())
while(n!=0):
x = input()
flag =0
len1 = len(x)
if(len1%2 != 0 ):
len1 = int(len1 /2)
dict1 = {}
dict2 = {}
list1 = []
list2 = []
for i in range(0,len1):
list1.append(x[i])
for i in range(len1+1,len(x)):
list2.append(x[i])
for i in range(0,len(list1)):
count = 1
for j in range(0,len(list1)):
if(i != j and list1[i] == list1[j]):
count+= 1
dict1[list1[i]] = count
for i in range(0,len(list2)):
count = 1
for j in range(0,len(list2)):
if(i != j and [i] == list2[j]):
count+= 1
dict2[list2[i]] = count
for key,value in dict1.items():
count2 = 0
for i,j in dict2.items():
if(key == i):
if(value != j):
flag = 1
else:
count2 += 1
if(count2 == len(dict1)):
flag = 1
else:
len1 = int(len1 /2)
dict1 = {}
dict2 = {}
list1 = []
list2 = []
for i in range(0,len1):
list1.append(x[i])
for i in range(len1,len(x)):
list2.append(x[i])
for i in range(0,len(list1)):
count = 1
for j in range(0,len(list1)):
if(i != j and list1[i] == list1[j]):
count+= 1
dict1[list1[i]] = count
for i in range(0,len(list2)):
count = 1
for j in range(0,len(list2)):
if(i != j and [i] == list2[j]):
count+= 1
dict2[list2[i]] = count
for key,value in dict1.items():
count2 = 0
for i,j in dict2.items():
if(key == i):
if(value != j):
flag = 1
else:
count2 += 1
if(count2 == len(dict1)):
flag = 1
if(flag == 1):
print('NO')
else:
print('YES')
n-=1