A ticket is a string consisting of six digits. A ticket is considered lucky if the sum of the first three digits is equal to the sum of the last three digits. Given a ticket, output if it is lucky or not. Note that a ticket can have leading zeroes.


-----Input-----

The first line of the input contains an integer $t$ ($1 \leq t \leq 10^3$) — the number of testcases.

The description of each test consists of one line containing one string consisting of six digits.


-----Output-----

Output $t$ lines, each of which contains the answer to the corresponding test case. Output "YES" if the given ticket is lucky, and "NO" otherwise.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).


-----Examples-----

Input
5
213132
973894
045207
000000
055776
Output
YES
NO
YES
YES
NO


-----Note-----

In the first test case, the sum of the first three digits is $2 + 1 + 3 = 6$ and the sum of the last three digits is $1 + 3 + 2 = 6$, they are equal so the answer is "YES".

In the second test case, the sum of the first three digits is $9 + 7 + 3 = 19$ and the sum of the last three digits is $8 + 9 + 4 = 21$, they are not equal so the answer is "NO".

In the third test case, the sum of the first three digits is $0 + 4 + 5 = 9$ and the sum of the last three digits is $2 + 0 + 7 = 9$, they are equal so the answer is "YES".

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
for _ in range(int(input())):
	a = input()
	x = int(a[0])
	b = int(a[1])
	c = int(a[2])
	d = int(a[3])
	e = int(a[4])
	f = int(a[5])
	if x + b + c == d + e + f:
		print('YES')
	else:
		print('NO')


t = int(input())
for k in range(t):
	s = input()
	if int(s[0]) + int(s[1]) + int(s[2]) == int(s[3]) + int(s[4]) + int(s[5]):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	N = list(map(int, list(input())))
	if sum(N[:3]) == sum(N[3:]):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	s = input()
	sum = 0
	for i in range(3):
		sum += int(s[i])
	for i in range(-1, -4, -1):
		sum -= int(s[i])
	if sum == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = input()
	if int(n[0]) + int(n[1]) + int(n[2]) == int(n[3]) + int(n[4]) + int(n[5]):
		print('YES')
	else:
		print('NO')


t = int(input())
for iter in range(t):
	n = str(input())
	if int(n[0]) + int(n[1]) + int(n[2]) == int(n[3]) + int(n[4]) + int(n[5]):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	s1 = list(map(int, s[0:3]))
	s2 = list(map(int, s[3:]))
	if sum(s1) == sum(s2):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = input()
	if sum(map(int, n[:3])) == sum(map(int, n[3:])):
		print('YES')
	else:
		print('NO')


(yes, no) = ('YES', 'NO')

def solve(ticket):
	(fst, snd) = (0, 0)
	for i in range(3):
		fst += int(ticket[i])
	for j in range(3, 6):
		snd += int(ticket[j])
	if fst == snd:
		return yes
	return no
tc = int(input())
for _ in range(tc):
	ticket = input()
	print(solve(ticket))


for _ in range(int(input())):
	l = [int(i) for i in input()]
	if sum(l[:3]) == sum(l[3:]):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	a = input()
	f = int(a[0]) + int(a[1]) + int(a[2])
	l = int(a[-1]) + int(a[-2]) + int(a[-3])
	if f == l:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	st = input()
	if int(st[0]) + int(st[1]) + int(st[2]) == int(st[3]) + int(st[4]) + int(st[5]):
		print('YES')
	else:
		print('NO')


trials = int(input())
for trial in range(trials):
	s = list(map(int, list(input())))
	if sum(s[:3]) == sum(s[3:]):
		print('YES')
	else:
		print('NO')


def equal(s):
	a = int(s[0]) + int(s[1]) + int(s[2])
	b = int(s[3]) + int(s[4]) + int(s[5])
	return a == b

def main():
	t = int(input())
	for _ in range(t):
		s = input()
		if equal(s):
			print('YES')
		else:
			print('NO')
main()


for _ in range(int(input())):
	a = input()
	sa = 0
	sb = 0
	for (i, ai) in enumerate(a):
		if i <= 2:
			sa += int(ai)
		else:
			sb += int(ai)
	print('YES' if sa == sb else 'NO')


inp_size = int(input())
for i in range(inp_size):
	n = input()
	s1 = int(n[0]) + int(n[1]) + int(n[2])
	s2 = int(n[3]) + int(n[4]) + int(n[5])
	if s1 == s2:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = input()
	if int(n[0]) + int(n[1]) + int(n[2]) == int(n[-1]) + int(n[-2]) + int(n[-3]):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = input()
	s1 = 0
	s2 = 0
	s1 += int(s[0]) + int(s[1]) + int(s[2])
	s2 += int(s[3]) + int(s[4]) + int(s[5])
	if s1 == s2:
		print('YES')
	else:
		print('NO')


def solution(content):
	count = 0
	left = 0
	right = 0
	for i in content:
		count += 1
		if count <= 3:
			left += int(i)
		else:
			right += int(i)
	if left == right:
		print('YES')
	else:
		print('NO')
t = int(input())
for i in range(t):
	content = input()
	solution(content)


a = int(input())
while a:
	x = input()
	s1 = 0
	s2 = 0
	for i in range(3):
		s1 += int(x[i])
	for i in range(3, 6):
		s2 += int(x[i])
	if s1 == s2:
		print('YES')
	else:
		print('NO')
	a -= 1


for _ in range(int(input())):
	s = input()
	a = int(s[0]) + int(s[1]) + int(s[2])
	b = int(s[3]) + int(s[4]) + int(s[5])
	if a == b:
		print('YES')
	else:
		print('NO')


n = int(input())
for _ in range(n):
	t = input()
	if sum((int(i) for i in t[:3])) == sum((int(i) for i in t[3:])):
		print('YES')
	else:
		print('NO')


tc = int(input())

def solve():
	n = input()
	sum3 = 0
	suml3 = 0
	for i in range(3):
		sum3 += int(n[i])
	for i in range(3, 6):
		suml3 += int(n[i])
	if sum3 == suml3:
		print('YES')
	else:
		print('NO')
for i in range(tc):
	solve()


for i in range(int(input())):
	num = input()
	sum1 = int(int(num[0]) + int(num[1]) + int(num[2]))
	sum2 = int(int(num[3]) + int(num[4]) + int(num[5]))
	if sum1 == sum2:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	s = input()
	a = list(s[:len(s)])
	x = int(a[0]) + int(a[1]) + int(a[2])
	y = int(a[3]) + int(a[4]) + int(a[5])
	if x == y:
		print('YES')
	else:
		print('NO')


mk = int(input())
while mk != 0:
	t = input()
	n1 = int(t[0:3])
	n2 = int(t[3:])
	(s1, s2) = (0, 0)
	while n1 != 0:
		d = n1 % 10
		s1 = s1 + d
		n1 = n1 // 10
	while n2 != 0:
		d = n2 % 10
		s2 = s2 + d
		n2 = n2 // 10
	if s1 == s2:
		print('YES')
	else:
		print('NO')
	mk = mk - 1


t = int(input())
cases = []
for i in range(t):
	s = input()
	cases.append(s)

def sol(s):
	s1 = int(s[0])
	s2 = int(s[1])
	s3 = int(s[2])
	s4 = int(s[3])
	s5 = int(s[4])
	s6 = int(s[5])
	if s1 + s2 + s3 == s4 + s5 + s6:
		return 'YES'
	else:
		return 'NO'
for i in range(t):
	print(sol(cases[i]))


t = int(input())
for i in range(t):
	A = str(input())
	if int(A[0]) + int(A[1]) + int(A[2]) == int(A[-1]) + int(A[-2]) + int(A[-3]):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	l = [int(i) for i in s]
	sum1 = l[0] + l[1] + l[2]
	sum2 = l[3] + l[4] + l[5]
	if sum1 == sum2:
		print('YES')
	else:
		print('NO')


tt = int(input())
for i in range(tt):
	n = input()
	sum1 = 0
	sum2 = 0
	for i in n[:3]:
		sum1 += int(i)
	for i in n[3:]:
		sum2 += int(i)
	if sum1 == sum2:
		print('YES')
	else:
		print('NO')


def fun(a):
	for i in range(7):
		if len(a) < 6:
			a = '0' + a
	return 'YES' if int(a[0]) + int(a[1]) + int(a[2]) == int(a[-1]) + int(a[-2]) + int(a[-3]) else 'NO'
for i in range(int(input())):
	a = input()
	print(fun(a))


import sys
N = int(sys.stdin.readline().strip())
res = []
for inNum in range(N):
	inNumber = str(sys.stdin.readline().strip())
	leftSum = int(inNumber[0]) + int(inNumber[1]) + int(inNumber[2])
	rightSum = int(inNumber[3]) + int(inNumber[4]) + int(inNumber[5])
	if leftSum == rightSum:
		res.append('YES')
	else:
		res.append('NO')
for result in res:
	print(result)


i = int(input())
for x in range(i):
	number = input()
	t1 = 0
	t2 = 0
	for x in range(3):
		t1 += int(number[x])
	for x in range(3, len(number)):
		t2 += int(number[x])
	if t1 == t2:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	ticket = list(input())
	ticket = list(map(int, ticket))
	if sum(ticket[:3]) == sum(ticket[3:]):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	s = input()
	a = 0
	b = 0
	for i in s[:3]:
		a += int(i)
	for i in s[3:]:
		b += int(i)
	if a == b:
		print('YES')
	else:
		print('NO')


from math import *
import os
for _ in range(int(input())):
	N = int(input())
	a1 = N // 100000 % 10
	a2 = N // 10000 % 10
	a3 = N // 1000 % 10
	b1 = N // 100 % 10
	b2 = N // 10 % 10
	b3 = N % 10
	z = a1 + a2 + a3
	x = b1 + b2 + b3
	if z == x:
		print('YES')
	else:
		print('NO')


t = int(input(''))
while t > 0:
	num = int(input(''))
	num1 = num % 10
	num = num // 10
	num2 = num % 10
	num = num // 10
	num3 = num % 10
	num = num // 10
	num4 = num % 10
	num = num // 10
	num5 = num % 10
	num = num // 10
	num6 = num % 10
	if num1 + num2 + num3 == num4 + num5 + num6:
		print('YES')
	else:
		print('NO')
	t = t - 1


testcases = int(input())
for x in range(testcases):
	luckynumber = input()
	one = int(luckynumber[0])
	two = int(luckynumber[1])
	three = int(luckynumber[2])
	thirdlast = int(luckynumber[-3])
	secondlast = int(luckynumber[-2])
	firlast = int(luckynumber[-1])
	first = one + two + three
	last = thirdlast + secondlast + firlast
	if first == last:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	s = input()
	s = list(map(int, s))
	if s[0] + s[1] + s[2] == s[3] + s[4] + s[5]:
		print('YES')
	else:
		print('NO')


n = int(input())
for x in range(n):
	number = input()
	a = number[:3]
	b = number[-3:]
	suma1 = 0
	suma2 = 0
	for y in range(3):
		suma1 = suma1 + int(a[y])
		suma2 = suma2 + int(b[y])
	if suma1 == suma2:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	a = input()
	x = int(a[0]) + int(a[1]) + int(a[2])
	y = int(a[3]) + int(a[4]) + int(a[5])
	if x == y:
		print('YES')
	else:
		print('NO')


from array import array
t = int(input())
a = []
for i in range(t):
	a.append(input())
for i in range(t):
	x = int(a[i][0]) + int(a[i][1]) + int(a[i][2])
	y = int(a[i][3]) + int(a[i][4]) + int(a[i][5])
	if x == y:
		print('YES')
	else:
		print('NO')


def test(ch):
	l1 = list()
	l2 = list()
	for i in range(3):
		l1.append(int(ch[i]))
	for j in range(3, 6):
		l2.append(int(ch[j]))
	if sum(l1) == sum(l2):
		return 'YES'
	else:
		return 'NO'
a = int(input())
l = list()
for i in range(a):
	ch = input()
	l.append(test(ch))
for j in l:
	print(j)


x = int(input())
for jj in range(x):
	a = [int(i) for i in list(input())]
	if sum(a[:3]) == sum(a[3:]):
		print('YES')
	else:
		print('NO')


def checkFun(arr):
	x = int(arr[0]) + int(arr[1]) + int(arr[2])
	y = int(arr[3]) + int(arr[4]) + int(arr[5])
	if x == y:
		return 'YES'
	else:
		return 'NO'
iter = int(input())
finalarr = []
for i in range(iter):
	arr = list(input())
	finalarr.append(checkFun(arr))
for j in range(iter):
	print(finalarr[j])


t = int(input())
for i in range(t):
	code = list(input())
	code = list(map(int, code))
	if sum(code[0:3]) == sum(code[3:]):
		print('YES')
	else:
		print('NO')


t = int(input())
l = []
for i in range(t):
	x = input()
	l.append(x)
for j in l:
	if int(j[0]) + int(j[1]) + int(j[2]) == int(j[3]) + int(j[4]) + int(j[5]):
		print('YES')
	else:
		print('NO')


n = int(input())
l = []
su = []
for i in range(0, n):
	s = input()
	l.append(s)
for k in range(0, n):
	for j in range(0, 6):
		su.append(int(l[k][j]))
	a = sum(su[0:3])
	b = sum(su[3:])
	if a == b:
		print('YES')
	else:
		print('NO')
	su = []


n = int(input())
while n:
	n -= 1
	arr = [int(item) for item in input()]
	l = len(arr)
	if sum(arr[:l // 2]) == sum(arr[l // 2:]):
		print('YES')
	else:
		print('NO')


n = int(input())
s = []
for i in range(n):
	s.append(input())

def Sum(s):
	a = list(map(int, s[:3]))
	b = list(map(int, s[3:]))
	return sum(a) == sum(b)
for i in range(n):
	if Sum(s[i]) == True:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(a, b, c, d, e, f) = input()
	n = int(a) + int(b) + int(c)
	m = int(d) + int(e) + int(f)
	if n == m:
		print('YES')
	else:
		print('NO')


a = int(input())
ans = []
for i in range(a):
	c = input()
	(q1, q2) = (0, 0)
	for i in c[0:3]:
		q1 += int(i)
	for i in c[3:]:
		q2 += int(i)
	if q1 == q2:
		ans.append('YES')
	else:
		ans.append('NO')
print(*ans, sep='\n')


import math
t = int(input())
for _ in range(t):
	arr = list(map(int, input()))
	p1 = arr[0] + arr[1] + arr[2]
	p2 = arr[3] + arr[4] + arr[5]
	print('YES') if p1 == p2 else print('NO')


t = int(input())
results = []
for i in range(t):
	ticket = list(input())
	if int(ticket[0]) + int(ticket[1]) + int(ticket[2]) == int(ticket[3]) + int(ticket[4]) + int(ticket[5]):
		results.append('YES')
	else:
		results.append('NO')
for result in results:
	print(result)


testcases = int(input())
for i in range(testcases):
	part1sum = 0
	part2sum = 0
	ticket = list(map(int, input().strip()))
	if len(ticket) != 6:
		break
	for s in range(0, 3, 1):
		part1sum += ticket[s]
	for j in range(3, 6, 1):
		part2sum += ticket[j]
	if part1sum == part2sum:
		print('YES')
	else:
		print('NO')


l = []

def check(inp):
	if int(inp[0]) + int(inp[1]) + int(inp[2]) == int(inp[4]) + int(inp[5]) + int(inp[3]):
		return 'YES'
	else:
		return 'NO'
a = int(input())
for x in range(a):
	l.append(check(input()))
for x in range(a):
	print(l[x])


for s in [*open(0)][1:]:
	(a, b, c, d, e, f, _) = map(ord, s)
	print('YNEOS'[a + b + c != d + e + f::2])


while True:
	t = int(input())
	if 1 <= t <= 1000:
		break
l = []
for i in range(t):
	while True:
		g = input()
		if len(g) == 6:
			break
	l.append(g)
for j in l:
	if int(j[0]) + int(j[1]) + int(j[2]) == int(j[3]) + int(j[4]) + int(j[5]):
		print('YES')
	else:
		print('NO')


t = int(input())
for k in range(t):
	a = input()
	b = list(map(int, str(a)))
	sum1 = 0
	sum2 = 0
	n = len(b)
	for i in range(0, 3):
		sum1 += b[i]
	for j in range(n - 3, n):
		sum2 += b[j]
	if sum1 == sum2:
		print('YES')
	else:
		print('NO')


a = int(input())
b = []
for i in range(a):
	b.append(input())
for i in b:
	if int(i[0]) + int(i[1]) + int(i[2]) == int(i[3]) + int(i[4]) + int(i[5]):
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(0, n):
	d = str(input())
	m = list(str(d))
	s1 = int(m[0]) + int(m[1]) + int(m[2])
	s2 = int(m[-1]) + int(m[-3]) + int(m[-2])
	if s1 == s2:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	li = list(map(int, input().strip()))
	print('YES' if sum(li[:3]) == sum(li[-3:]) else 'NO')


t = int(input())
for _ in range(t):
	l = list(map(int, input()))
	e = sum(l[:3])
	d = sum(l[3:])
	print('YES' if e == d else 'NO')


from sys import stdin
for _ in range(int(stdin.readline())):
	word = stdin.readline()
	msg = 'NO'
	acu1 = int(word[0]) + int(word[1]) + int(word[2])
	acu2 = int(word[3]) + int(word[4]) + int(word[5])
	if acu1 == acu2:
		msg = 'YES'
	print(msg)


casos = int(input())
res = []
for x in range(casos):
	ticket = str(input())
	comeco = 0
	fim = 0
	comeco = int(ticket[0]) + int(ticket[1]) + int(ticket[2])
	fim = int(ticket[3]) + int(ticket[4]) + int(ticket[5])
	res.append('YES' if fim == comeco else 'NO')
for i in res:
	print(i)


tests = int(input())
for t in range(tests):
	str_input = input()
	sum_left = 0
	for c in str_input[:3]:
		sum_left += int(c)
	sum_right = 0
	for c in str_input[-3:]:
		sum_right += int(c)
	print('YES' if sum_left == sum_right else 'NO')


t = int(input())
for _ in range(t):
	ticket = [int(x) for x in input('')]
	if sum(ticket[:3]) == sum(ticket[3:]):
		print('YES')
	else:
		print('NO')


def sumDigits(n):
	r = 0
	while n:
		(r, n) = (r + n % 10, n // 10)
	return r
n = int(input())
for _ in range(n):
	string = input()
	if sumDigits(int(string[-3:])) == sumDigits(int(string[:3])):
		print('YES')
	else:
		print('NO')


teste = int(input())
for i in range(0, teste):
	caso = str(input())
	if int(caso[0]) + int(caso[1]) + int(caso[2]) == int(caso[3]) + int(caso[4]) + int(caso[5]):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	s = input()
	sum1 = sum2 = 0
	for j in range(3):
		sum1 += int(s[j])
		sum2 += int(s[j + 3])
	if sum1 == sum2:
		print('YES')
	else:
		print('NO')


a = int(input())
for i in range(a):
	b = str(input())
	A = list(map(int, b))
	if A[0] + A[1] + A[2] == A[3] + A[4] + A[5]:
		print('YES')
	else:
		print('NO')


a = int(input())
s_1 = 0
s_2 = 0
d = []
for i in range(1, a + 1):
	b = input()
	c_1 = b[0:3]
	c_2 = b[3:]
	for z in c_1:
		s_1 += int(z)
	for x in c_2:
		s_2 += int(x)
	if s_1 == s_2:
		d.append(1)
	else:
		d.append(0)
	s_1 = 0
	s_2 = 0
for v in d:
	if v == 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	s = input()
	a = int(s[0])
	b = int(s[1])
	c = int(s[2])
	x = int(s[3])
	y = int(s[4])
	z = int(s[5])
	if a + b + c == x + y + z:
		print('YES')
	else:
		print('NO')