You are given two binary strings A and B, each of length N. You can perform the following operation on string A any number of times:
Select a [prime number] X.
Choose any substring of string A having length X and reverse the substring.

Determine whether you can make the string A equal to B using any (possibly zero) number of operations.

A substring is obtained by deleting some (possibly zero) elements from the beginning and some (possibly zero) elements from the end of the string.

------ Input Format ------ 

- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains an integer N — the length of the strings A and B.
- The second line contains the binary string A.
- The third line contains the binary string B.

------ Output Format ------ 

For each test case, output on a new line, YES, if you can make the string A equal to B using any number of operations and NO otherwise.

You can print each character in uppercase or lowercase. For example, YES, yes, Yes, and yES are all identical.

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

$1 ≤ T ≤ 100$
$1 ≤ N ≤ 10^{5}$
$A_{i}$ and $B_{i}$ contain $0$ and $1$ only.
- The sum of $N$ over all test cases won't exceed $10^{5}$.

----- Sample Input 1 ------ 
4
2
00
00
4
1001
0111
5
11000
10010
5
11000
11010

----- Sample Output 1 ------ 
YES
NO
YES
NO

----- explanation 1 ------ 
Test case $1$: Both the strings are equal. Thus, we do not need any operations.

Test case $2$: It can be shown that we cannot make the string $A$ equal to $B$ using any number of operations.

Test case $3$: Choose $X = 3$ and reverse the substring $A[2,4] = 100$. Thus, the string $A$ becomes $10010$ which is equal to $B$.

Test case $4$: It can be shown that we cannot make the string $A$ equal to $B$ using any number of operations.

Source: codechef | Difficulty: EASY
Tags: String algorithms

Constructive algorithms

Data structures

Ad-hoc


Solutions:
for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	a = str(a)
	b = str(b)
	ca = a.count('1')
	cb = b.count('1')
	if ca == cb:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	az = a.count('0')
	bz = b.count('0')
	if az == bz:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	if a.count('1') == b.count('1'):
		print('YES')
	else:
		print('NO')


from collections import Counter
for _ in range(int(input())):
	a = int(input())
	x = input()[:a]
	y = input()[:a]
	cx = Counter(x)
	cy = Counter(y)
	if x == y:
		print('YES')
	elif cx['1'] == cy['1']:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	if a.count('1') == b.count('1'):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	m = input()
	o = input()
	if m.count('1') == o.count('1'):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	if a.count('0') == b.count('0') or a.count('1') == b.count('1'):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	if a.count('0') == b.count('0') and a.count('1') == b.count('1'):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	p = a.count('0')
	q = b.count('0')
	r = a.count('1')
	s = b.count('1')
	if p == q or r == s:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	a = int(input())
	b = input()
	c = input()
	if b.count('1') == c.count('1'):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	a = int(input())
	n = input()
	m = input()
	l1 = 0
	l2 = 0
	for i in n:
		if i == '1':
			l1 = l1 + 1
	for j in m:
		if j == '1':
			l2 = l2 + 1
	if l1 == l2:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	k = int(input())
	s1 = input()
	s2 = input()
	i1 = 0
	i2 = 0
	for j in range(k):
		if s1[j] == '1':
			i1 += 1
		if s2[j] == '1':
			i2 += 1
	if i1 == i2:
		print('YES')
	else:
		print('NO')


def fun(s):
	c1 = 0
	for i in s:
		if int(i) == 0:
			c1 = c1 + 1
	return c1
for i in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	if fun(a) == fun(b):
		print('YES')
	else:
		print('NO')


def is_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	if sorted(a) != sorted(b):
		print('NO')
		continue
	if a == b:
		print('YES')
		continue
	found = False
	for i in range(2, n + 1):
		if not is_prime(i):
			continue
		for j in range(n - i + 1):
			if a[j:j + i] == b[j:j + i][::-1]:
				found = True
				break
		if found:
			break
	print('YES' if found else 'NO')


for i in range(int(input())):
	try:
		N = int(input())
		A = input().strip()
		B = input().strip()
		if len(A) != N or len(B) != N:
			print('NO')
			continue
		a0 = A.count('0')
		a1 = A.count('1')
		b0 = B.count('0')
		b1 = B.count('1')
		if a0 == b0 and a1 == b1:
			print('YES')
		else:
			print('NO')
	except:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	str(a)
	str(b)
	l1 = list(a)
	l2 = list(b)
	if a == b:
		print('YES')
	elif l1.count('0') == l2.count('0'):
		print('YES')
	else:
		print('NO')


def P(lst1, lst2):
	if lst1.count(1) == lst2.count(1):
		print('YES')
	else:
		print('NO')
for _ in range(int(input())):
	x = int(input())
	lst1 = list(map(int, str(int(input()))))
	lst2 = list(map(int, str(int(input()))))
	P(lst1, lst2)


T = int(input())
stri = ''
for i in range(T):
	N = int(input())
	A = input()
	B = input()
	if B.count('1') == A.count('1'):
		stri += 'YES\n'
	else:
		stri += 'NO\n'
print(stri)


T = int(input())
for i in range(T):
	N = int(input())
	A = input()
	B = input()
	if A == B:
		print('YES')
	elif A.count('0') == B.count('0'):
		print('YES')
	else:
		print('NO')


cases = int(input())
for _ in range(cases):
	n = int(input())
	str1 = input()
	str2 = input()
	if str1.count('1') == str2.count('1'):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	if a == b:
		print('YES')
	else:
		k = a.count('0')
		k1 = b.count('0')
		l = a.count('1')
		l1 = b.count('1')
		if k == k1 and l == l1:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	t = int(input())
	s = input()
	y = input()
	if s.count('1') == y.count('1'):
		print('YES')
	else:
		print('NO')


n = int(input())
while n != 0:
	c = int(input())
	a = str(input())
	b = str(input())
	s_a = 0
	s_b = 0
	for i in a:
		s_a += int(i)
	for j in b:
		s_b += int(j)
	if s_a == s_b:
		print('YES')
	else:
		print('NO')
	n -= 1


for x in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	c = 0
	d = 0
	for i in range(len(a)):
		if a[i] == '0':
			c += 1
		if a[i] == '1':
			d += 1
	e = 0
	f = 0
	for i in range(len(b)):
		if b[i] == '0':
			e += 1
		if b[i] == '1':
			f += 1
	if c == e:
		print('YES')
	else:
		print('NO')


t = int(input())
for x in range(t):
	n = int(input())
	a = input()
	b = input()
	c = 0
	d = 0
	for i in range(n):
		if a[i] == '1':
			c += 1
		if b[i] == '1':
			d += 1
	if c == d:
		print('YES')
	else:
		print('NO')


from collections import Counter
t = int(input())
for _ in range(t):
	str_len = int(input())
	str1 = input()
	str2 = input()
	counter1 = Counter(str1)
	counter2 = Counter(str2)
	if counter1 == counter2:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	z = 0
	o = 0
	for i in range(n):
		if a[i] == '0':
			z += 1
		elif a[i] == '1':
			o += 1
	z1 = 0
	o1 = 0
	for j in range(n):
		if b[j] == '0':
			z1 += 1
		elif b[j] == '1':
			o1 += 1
	if z == z1 and o == o1:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	m = a.count('0')
	n = a.count('1')
	x = b.count('0')
	y = b.count('1')
	if m == x and n == y:
		print('YES')
	else:
		print('NO')


for i in range(0, int(input())):
	a = int(input())
	b = input()
	c = input()
	count = 0
	count1 = 0
	for j in b:
		if j == '0':
			count = count + 1
	for k in c:
		if k == '0':
			count1 = count1 + 1
	count_ = a - count
	count1_ = a - count1
	if count == count1 and count_ == count1_:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	n = int(input())
	a = str(input())
	b = str(input())
	if a.count('1') == b.count('1'):
		print('YES')
		pass
	else:
		print('NO')
		pass
	pass


for i in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	x = 2
	if a == b:
		print('YES')
	elif a.count('1') != b.count('1') or a.count('0') != b.count('0'):
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	n = int(input())
	str1 = input()
	str2 = input()
	lst1 = list(str1)
	lst2 = list(str2)
	sum1 = 0
	sum2 = 0
	for i in range(n):
		if lst1[i] == '1':
			sum1 += 1
	for i in range(n):
		if lst2[i] == '1':
			sum2 += 1
	if sum1 == sum2:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	if s1 == s2:
		print('YES')
	elif s1.count('1') == s2.count('1'):
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	l = int(input())
	k = input()
	m = input()
	if k.count('1') == m.count('1'):
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	n = int(input())
	a = input()
	b = input()
	if a.count('0') == b.count('0') and a.count('1') == b.count('1'):
		print('YES')
	else:
		print('NO')
	t -= 1


n = int(input())
for i in range(n):
	n = int(input())
	A = input()
	B = input()
	print('YES' if A.count('1') == B.count('1') else 'NO')