Read problems statements in Mandarin Chinese  and Russian. 
This is a very easy warm-up problem.
You are given a string. Your task is to determine whether number of occurrences of some character in the string is equal to the sum of  the numbers of occurrences of other characters in the string. 

------ Input ------ 

The first line of the input contains an integer T denoting the number of test cases. Each of the next T lines contains one string S consisting of lowercase latin letters.

------ Output ------ 

For each test case, output a single line containing "YES" if the string satisfies the condition given above or "NO"  otherwise. 

------ Constraints ------ 

1 ≤ T ≤ 1000
1 ≤ length of S ≤ 50

------ Subtasks ------ 

Subtask #1[28 points]: S contains no more than 2 different letters.
Subtask #2[72 points]: No additional conditions

----- Sample Input 1 ------ 
4
acab
zzqzqq
abc
kklkwwww
----- Sample Output 1 ------ 
YES
YES
NO
YES

Source: codechef | Difficulty: EASY
Tags: Complete search


Solutions:
for i in range(int(input())):
	d = []
	a = input()
	e = 0
	for j in a:
		if j not in d:
			if len(a) - 2 * a.count(j) == 0:
				e = 1
				print('YES')
				break
			else:
				d.append(j)
	if e == 0:
		print('NO')


from collections import Counter
for i in range(int(input())):
	s = input()
	l = []
	y = Counter(s)
	for d in y:
		l.append(y.get(d))
	f = max(l)
	l.remove(f)
	if f == sum(l):
		print('YES')
	else:
		print('NO')


t = int(input())
for k in range(t):
	a = str(input())
	b = []
	c = set(a)
	for i in c:
		b.append(a.count(i))
	d = max(b)
	if d == len(a) - d:
		print('YES')
	else:
		print('NO')


T = int(input())
for i in range(T):
	S = str(input())
	for i in S:
		if S.count(i) == len(S) - S.count(i):
			print('YES')
			break
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = input()
	l = list(s)
	max_c = 0
	for k in range(len(s)):
		max_c = max(max_c, l.count(l[k]))
	len_l = len(l) - max_c
	if len_l == max_c:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = list(input())
	l = 0
	for i in set(s):
		t = s.count(i)
		if t > l:
			l = t
	print('YES' if len(s) - l == l else 'NO')


for i in range(int(input())):
	s = input()
	for i in s:
		if s.count(i) == len(s) - s.count(i):
			print('YES')
			break
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = input()
	dup_s = ''
	if len(s) % 2 == 1:
		print('NO')
	else:
		for i in s:
			if i in dup_s:
				continue
			else:
				c = s.count(i)
				if c == len(s) // 2:
					print('YES')
					break
		else:
			print('NO')
		dup_s += i


for i in range(int(input())):
	s = input()
	s1 = set(s)
	l = []
	for i in s1:
		l.append(s.count(i))
	m = max(l)
	if m == sum(l) - m:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = input()
	a = []
	for x in s:
		a.append(s.count(x))
	if len(s) == max(a) * 2:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	s = input()
	l = []
	l[:0] = s
	se = set(l)
	n = len(s)
	flag = -1
	for item in se:
		if l.count(item) == n // 2 and n % 2 == 0:
			flag = 1
			break
	if flag == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	s = input()
	l = []
	for i in s:
		l.append(s.count(i))
	m = max(l)
	if m * 2 == len(s):
		print('YES')
	else:
		print('NO')
	t = t - 1


t = int(input())
for i in range(t):
	n = input()
	for i in n:
		if n.count(i) == len(n) - n.count(i):
			print('YES')
			break
	else:
		print('NO')


for i in range(int(input())):
	d = dict()
	a = []
	s1 = 0
	s = input()
	for j in s:
		if j in d.keys():
			d[j] += 1
		else:
			d[j] = 1
	for j in d.keys():
		a.append(d.get(j))
	i1 = a.index(max(a))
	for j in range(len(a)):
		if j != i1:
			s1 = s1 + a[j]
	if s1 == a[i1]:
		print('YES')
	else:
		print('NO')


from statistics import mode
for _ in range(int(input())):
	s = list(input())
	print('YES' if s.count(mode(s)) == len(s) / 2 else 'NO')


for i in range(int(input())):
	s = list(str(input()))
	maxnum = 0
	for i in s:
		if s.count(i) > maxnum:
			maxnum = s.count(i)
	if maxnum == len(s) - maxnum:
		print('YES')
	else:
		print('NO')


from collections import Counter
for t in range(int(input())):
	s = input()
	count = Counter(s)
	(_, value) = count.most_common(1)[0]
	num = len(s) - value
	if value == num:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	s = input()
	k = set(s)
	l = []
	p = 0
	for i in k:
		l.append(s.count(i))
	l = sorted(l)
	p = sum(l[:-1])
	if p == l[-1]:
		print('YES')
	else:
		print('NO')
	t = t - 1


goals = int(input())
for distractions in range(goals):
	wife = input()
	for life in wife:
		if wife.count(life) == len(wife) - wife.count(life):
			print('YES')
			break
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	a = set(s)
	c = 0
	for i in a:
		c = max(c, s.count(i))
	n = len(s)
	print('YES' if c == n - c else 'NO')


for _ in range(int(input())):
	love = str(input())
	for girl in love:
		if love.count(girl) == len(love) - love.count(girl):
			print('YES')
			break
	else:
		print('NO')


for i in range(int(input())):
	S = input()
	if len(S) % 2 == 0:
		c = 0
		for j in S:
			if S.count(j) == len(S) // 2:
				print('YES')
				c += 1
				break
		if c == 0:
			print('NO')
	else:
		print('NO')


from collections import Counter
for _ in range(int(input())):
	s = input()
	l1 = Counter(s)
	l2 = list(l1.values())
	l2.sort()
	res = sum(l2) - l2[-1]
	if res == l2[-1]:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	s = input()
	l = [x for x in s]
	l2 = []
	for val in list(set(l)):
		l2.append(l.count(val))
	l2.sort()
	if sum(l2[:len(l2) - 1]) == l2[-1]:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	s = input()
	se = set(s)
	res = 0
	for x in se:
		if s.count(x) > res:
			res = s.count(x)
	if res == len(s) - res:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	a = input()
	a = list(a)
	a.sort()
	c = 0
	i = 0
	e = a[0]
	max = 0
	if len(a) % 2 == 1:
		print('NO')
	else:
		while i < len(a):
			if e == a[i]:
				c = c + 1
			elif e != a[i]:
				if c == len(a) // 2:
					print('YES')
					break
				c = 1
				e = a[i]
			if i == len(a) - 1:
				if c == len(a) // 2:
					print('YES')
					break
			i = i + 1
		else:
			print('NO')


for i in range(int(input())):
	s = input()
	l = []
	for i in set(s):
		l.append(s.count(i))
	if max(l) * 2 == len(s):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	a = input()
	for l in a:
		if a.count(l) == len(a) - a.count(l):
			print('YES')
			break
	else:
		print('NO')


from collections import Counter
for i in range(int(input())):
	s = input()
	l = list(s)
	n = len(s)
	l1 = []
	c = Counter(l)
	for i in c.values():
		l1.append(i)
	e = max(l1)
	if e == n / 2:
		print('YES')
	else:
		print('NO')


from collections import Counter
t = int(input())
for _ in range(t):
	l = list(input())
	s = set(l)
	for i in s:
		if l.count(i) == len(l) - l.count(i):
			val = 1
			break
		else:
			val = 0
			pass
	if val:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	string = list(input())
	n = len(string)
	s = set(string)
	maxi = 0
	for e in s:
		if string.count(e) > maxi:
			maxi = string.count(e)
	print('YES' if 2 * maxi == n else 'NO')


for _ in range(int(input())):
	s = input()
	a = 'NO'
	c = []
	unique = []
	for i in range(len(s)):
		if s[i] not in c:
			c.append(s[i])
			unique.append(s.count(s[i]))
	for j in range(len(unique)):
		val = unique[j]
		sumval = 0
		for k in range(len(unique)):
			if k == j:
				continue
			else:
				sumval += unique[k]
		if sumval == val:
			a = 'YES'
			break
	print(a)


t = int(input())
for v in range(0, t):
	s = input()
	f = 0
	if len(s) % 2 == 0:
		for c in s:
			if s.count(c) == len(s) // 2:
				f = 1
				break
	if f == 1:
		print('YES')
	else:
		print('NO')


from collections import Counter
for _ in range(int(input())):
	S = list(input().strip())
	A = Counter(S)
	B = list(A.values())
	if sum(B) == 2 * max(B):
		print('YES')
	else:
		print('NO')


t = int(input())
while t != 0:
	n = input()
	k = []
	for i in set(n):
		k.append(n.count(i))
	k.sort()
	if k[-1] == sum(k[:-1]):
		print('YES')
	else:
		print('NO')
	t -= 1


t = int(input())
for _ in range(t):
	s = input()
	array = [0] * 26
	for i in range(len(s)):
		array[ord(s[i]) - 97] += 1
	ans = False
	for j in range(26):
		if array[j] == len(s) // 2:
			ans = True
			break
	if ans and len(s) % 2 == 0:
		print('YES')
	else:
		print('NO')


from collections import Counter
for _ in range(int(input())):
	s = Counter(input())
	n = len(list(s.elements()))
	if max(s.values()) == n - max(s.values()):
		print('YES')
	else:
		print('NO')


from collections import Counter
for i in range(int(input())):
	s = input()
	for i in s:
		k = s.count(i)
		if k == len(s) - k:
			print('YES')
			break
	else:
		print('NO')


t = int(input())
while t:
	n = str(input())
	for i in list(n):
		if n.count(i) == len(n) - n.count(i):
			print('YES')
			break
	else:
		print('NO')
	t = t - 1


for i in range(int(input())):
	s = input()
	a = set(s)
	l = []
	for i in a:
		b = s.count(i)
		l.append(b)
	for i in s:
		if s.count(i) == max(l):
			s = s.replace(i, '')
			break
	if max(l) == len(s):
		print('YES')
	else:
		print('NO')


t = int(input())
for tc in range(t):
	s = input()
	for j in s:
		if s.count(j) == len(s) - s.count(j):
			print('YES')
			break
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	d = {}
	for i in s:
		d[i] = d.get(i, 0) + 1
	n = len(s)
	ans = 'NO'
	for y in d.values():
		if y * 2 == n:
			ans = 'YES'
			break
	print(ans)


t = int(input())
for i in range(t):
	s = input()
	a = list(set(s))
	b = []
	for i in a:
		k = s.count(i)
		b.append(k)
	c = max(b)
	b.remove(c)
	if c == sum(b):
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	s = input()
	for i in s:
		if s.count(i) == len(s) - s.count(i):
			print('YES')
			break
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	S = input()
	A = []
	for i in S:
		A.append(S.count(i))
	m = max(A)
	if 2 * m == len(S):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	n = len(s)
	res = ''.join(sorted(s))
	(c, m) = (1, 0)
	for i in range(n - 1):
		if res[i] == res[i + 1]:
			c += 1
		else:
			c = 1
		if c > m:
			m = c
	if n % 2 != 0:
		print('NO')
	elif m == n // 2:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = str(input())
	size = len(s)
	s = list(s)
	from collections import Counter
	d = Counter(s)
	d = dict(d)
	val = d.values()
	if max(val) == size - max(val):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	s = input()
	print('YES' if len(s) % 2 == 0 and len(s) // 2 == s.count(max(s, key=s.count)) else 'NO')


for i in range(int(input())):
	S = input()
	s = set(S)
	count = 0
	for i in s:
		if count < S.count(i):
			count = S.count(i)
	print('YES' if count == len(S) - count else 'NO')


for _ in range(int(input())):
	x = input()
	d = {}
	for i in x:
		try:
			d[i] += 1
		except:
			d[i] = 1
	for i in d:
		if d[i] == len(x) - d[i]:
			print('YES')
			break
	else:
		print('NO')


t = int(input())
while t > 0:
	s = input()
	count = dict()
	for l in s:
		if l in count:
			count[l] += 1
		else:
			count[l] = 1
	c = sorted(count.items(), key=lambda x: x[1], reverse=True)
	m = c[0][1]
	baki = len(s) - m
	if m == baki:
		print('YES')
	else:
		print('NO')
	t -= 1