Problem:


Score : 400 points

Problem Statement

There are two persons, numbered 0 and 1, and a variable x whose initial value is 0.
The two persons now play a game.
The game is played in N rounds. The following should be done in the i-th round (1 \leq i \leq N):

Person S_i does one of the following:

Replace x with x \oplus A_i, where \oplus represents bitwise XOR.

Do nothing.

Person 0 aims to have x=0 at the end of the game, while Person 1 aims to have x \neq 0 at the end of the game.

Determine whether x becomes 0 at the end of the game when the two persons play optimally.

Solve T test cases for each input file.

Constraints

1 \leq T \leq 100

1 \leq N \leq 200

1 \leq A_i \leq 10^{18}

S is a string of length N consisting of 0 and 1.

All numbers in input are integers.

Input

Input is given from Standard Input in the following format.
The first line is as follows:

T

Then, T test cases follow.
Each test case is given in the following format:

N
A_1 A_2 \cdots A_N
S

Output

For each test case, print a line containing 0 if x becomes 0 at the end of the game, and 1 otherwise.

Sample Input 1

3
2
1 2
10
2
1 1
10
6
2 3 4 5 6 7
111000

Sample Output 1

1
0
0

In the first test case, if Person 1 replaces x with 0 \oplus 1=1, we surely have x \neq 0 at the end of the game, regardless of the choice of Person 0.

In the second test case, regardless of the choice of Person 1, Person 0 can make x=0 with a suitable choice.



Sample input:
3
2
1 2
10
2
1 1
10
6
2 3 4 5 6 7
111000


Sample output:
1
0
0

Submission status: Wrong Answer

Solution code:
L = []
test = int(input())
for t in range(test):
  x = i = 0
  n = int(input())
  A = list(map(int, input().split()))
  s = input()
  for r in range(n):
    if s[i] == '0':
      if i == n-1:
        if x == 0:
          L.append(0)
        else:
          x = x ^ A[i]
          if x == 0:
            L.append(0)
          else:
            L.append(1)
      else:
        if x == 0:
          if s[i+1] == '1' and A[i+1] == x^A[i]:
            x = x^A[i]
          else:
            continue
        else:
          x = x ^ A[i]
          
    if s[i] == '1':
      if i == n-1:
        if x != 0:
          L.append(1)
        else:
          x = x ^ A[i]
          if x != 0:
            L.append(1)
          else:
            L.append(0)
      else:
        if x != 0:
          if s[i+1] == '0' and A[i+1] != x^A[i]:
            x = x^A[i]
          else:
            continue
        else:
          x = x ^ A[i]
    i += 1
for l in L:
  print(l)

Submission status: Wrong Answer

Solution code:
import sys 

input = sys.stdin.readline

def main():
  t = int(input().rstrip())
  
  for i in range(t):
    n = int(input().rstrip())
    a = list(map(int, input().rstrip().split()))
    s = input().rstrip()
    x = 0
    
    for k in range(n):
      if s[k] == "1" and x ^ int(a[k]) != 0:
        x = x ^ int(a[k])
      if s[k] == "0" and x ^ int(a[k]) == 0:
        x = x ^ int(a[k])
    if x == 0:
      print(0)
    else:
      print(1)
  
if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
T = int(input())

def canZero():
    N = int(input())
    A = list(map(int, input().split()))[::-1]
    S = list(map(int, input()))[::-1]

    for d in range(64):
        mask = 1 << d
        for s, a in zip(S, A):
            if (mask & a) != 0 and s == 1:
                return False
    return True

for _ in range(T):
    print('0' if canZero() else '1')

Submission status: Wrong Answer

Solution code:
t = int(input())
n = []
a = []
s = []
for i in range(t):
    nn = int(input())
    n.append(nn)
    aa = list(map(int,input().split()))
    a.append(aa)
    ss = input()
    s.append(ss)
for i in range(t):
    x = 0
    for j in range(n[i]):
        if s[i][j] == "0":
            if j < n[i]-1:
                if x ^ a[i][j] ^ a[i][j+1] == 0 and s[i][j+1] == "0":
                    x = x ^ a[i][j]
                elif x ^ a[i][j] == 0:
                    x = x ^ a[i][j]
            elif x ^ a[i][j] == 0:
                x = x ^ a[i][j]
        else:
            if j < n[i]-1:
                if x ^ a[i][j] ^ a[i][j+1] == 1 and s[i][j+1] == "1":
                    x = x ^ a[i][j]
                elif x ^ a[i][j] != 0:
                    x = x ^ a[i][j]
            elif x ^ a[i][j] != 0:
                x = x ^ a[i][j]
    print(x)

Submission status: Wrong Answer

Solution code:
t = int(input())
for i in range(t):
    N = int(input())
    A = [x for x in map(int,input().split())]
    S = input()
    x = 0
    i = 0
    while i < N:
        if S[i] == "1":
            temp = x
            x = x ^ A[i] if x not in A[i:] else temp
        if S[i] == "0":
            temp = x
            x = x ^ A[i] if x in A[i:] else temp
        i+= 1
    print(0 if x == 0 else 1)

Submission status: Wrong Answer

Solution code:
T = int(input())

def canZero():
    N = int(input())
    A = list(map(int, input().split()))[::-1]
    S = list(map(int, input()))[::-1]

    for d in range(64):
        mask = 1 << d
        for s, a in zip(S, A):
            if (mask & a) != 0:
                return s == 0
    return True

for _ in range(T):
    print('0' if canZero() else '1')

Submission status: Wrong Answer

Solution code:
"""
NTC here
"""
 
 
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

profile = 0
pypy = 1
 
 
def iin(): return int(input())


def lin(): return list(map(int, input().split()))


def main():
    T = iin()
    while T:
        T-=1
        n = iin()
        a = lin()
        s = input()
        a1, a2 = set(), set()
        for i in range(n):
            if s[i] == '0':
                a1.add(a[i])
            else:
                a2.add(a[i])
        x1 = 0
        x2 = 0
        for i in a1:x1 ^= i
        for i in a2:x2 ^= i
        print(+ (not (x1==x2 or x2 in a1) ))
        # print(a1, a2, x1, x2)
    

        

                

        

 
 
 
 
 
 
# region fastio
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
if pypy:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
    input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# endregion
 
if __name__ == "__main__":
    if profile:
        import cProfile
        cProfile.run('main()')
    else:
        main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
for _ in range(int(input())):
    n= int(input())
    L=list(map(int,input().split()))
    s=list(input().rstrip())
    x=0
    d={'0':[],'1':[]}
    for i in range(n):
        if s[i]=='0':
            d[s[i]].append(L[i])
        else:
            d[s[i]].append(L[i])
    for i in range(n):
        val = x^L[i]
        if s[i]=='1':
            if val != 0 and (val not in d['0']):
                x = val
    if x in d['0']:
        x=0
    
    if x==0:
        print('0')
    else:
        print('1')

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

def I(): return int(sys.stdin.readline().rstrip())
def LI():return list(map(int,sys.stdin.readline().rstrip().split()))
def LS():return list(sys.stdin.readline().rstrip().split())


def solver():
    N = I()
    A = deque(LI())
    S = list(sys.stdin.readline().rstrip())[::]
    X = 0
    # print("N=",N)
    # print("A=",A)
    # print("S=",S)
    # print("X=",X)

    for s in S:
        _x = X^A.popleft()
        # print("_x=",_x)
        if s == '1':
            if _x != 0:
                X = _x
        else:
            if _x == 0:
                X = 0

        # print("s=",s," X=",X)

    return "0" if X==0 else "1"

def main():
    T = I()
    # print("T=",T)

    for _ in range(T):
        # print("ANS=",solver())
        print(solver())


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = []
for i in range(N):
    x = 0
    n = int(input())
    lst = list(map(int, input().split()))
    p = input()
    for i in p:
        if i == '1':
            if x ^ lst[0] != 0:
                x = (x ^ lst.pop(0))
        else:
            if x ^ lst[0] == 0:
                x = (x ^ lst.pop(0))
    ans.append(x)



for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
T = int(input())
for t in range(T):
    x = 0
    N = int(input())
    L = list(map(int, input().split()))
    S = input()
    #print(N,L,S)
    for i in range(N):
        if S[i] == '0':
            if x != 0 and x^L[i] == 0 :
                x = 0
        else:
            if x == 0 and x^L[i] != 0:
                x = x^L[i]
        print(x)
    if x==0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
def resolve():
    T = int(input())

    for t in range(T):
        n = int(input())
        A = list(map(int, input().split()))
        s = input()
        a = 0
        b = 0

        for i in range(n):
            if s[i] == "0":
                a |= A[i]
            else:
                b |= A[i]

        if a - b == 0:
            print(0)
        else:
            print(1)

resolve()

Submission status: Wrong Answer

Solution code:
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################


for ii in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	#we start with x = 0
	x = 0
	for i in range(n):
		if s[i] == "0":
			if x != 0:
				if x^arr[i] == 0:
					x = x^arr[i]
				if x^arr[i] < x:
					x = x^arr[i]
		else:
			if x==0:
				if x^arr[i] != 0:
					x = x^arr[i]
			elif arr[i] !=  x:
				x = x^arr[i]
		#print(i," : ",x)
	if x == 0:
		print(0)
	else:
		print(1)

Submission status: Wrong Answer

Solution code:
num=int(input().rstrip())
for i in range(num):
    num_i=int(input().rstrip())
    line=input().rstrip().split()
    main=[]
    for j in range(num_i):
        main.append(int(line[j]))
    jyunnjyo=input().rstrip()
    mains=[]
    for k in range(num_i):
        if main[k]%2==1:
            mains.append(k)
    if mains==[]:
        print(0)
    else:
        print(jyunnjyo[mains[len(mains)-1]])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


t = I()
for _ in range(t):
    n = I()
    A = LI()
    s = S()
    flg = 0
    for l in range(61):
        for j in range(n - 1, -1, -1):
            new_flg = set()
            k = A[j] >> l & 1
            m = int(s[j])
            if m == 0 and k:
                break
            elif m == 1 and k:
                flg = 1
                break
        if flg:
            print(1)
            break
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from sys import setrecursionlimit
import numpy as np
setrecursionlimit(10 ** 7)

t = int(stdin.readline().rstrip())

for _ in range(t):
    n = int(stdin.readline().rstrip())
    a = list(map(int,stdin.readline().rstrip().split()))
    s = stdin.readline().rstrip()
    now = np.zeros(62,dtype=np.int64)
    for i,j in zip(a,s):
        if j == "0":
            # 合計が0になるようにしたい>できる限り０１の逆を行く個数を増やす
            b = np.array([(i>>k)&1 for k in range(62)])
            c = now^b
            if np.count_nonzero(now) > np.count_nonzero(c):
                now = c
        else:
            # 合計が0以外になるようにしたい>できる限り１の個数を増やす
            b = np.array([(i>>k)&1 for k in range(62)])
            c = now^b
            if np.count_nonzero(now) < np.count_nonzero(c):
                now = c
    if np.count_nonzero(now==0) == 62:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################


for ii in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	#we start with x = 0
	x = 0
	for i in range(n):
		if s[i] == "0":
			if x != 0:
				if x^arr[i] == 0:
					x = x^arr[i]
				if x^arr[i] < x:
					x = x^arr[i]
		else:
			if x==0:
				if x^arr[i] != 0:
					x = x^arr[i]
			elif x^arr[i] !=  x:
				x = x^arr[i]
		#print(i," : ",x)
	if x == 0:
		print(0)
	else:
		print(1)

Submission status: Wrong Answer

Solution code:
T = int(input())

for _ in range(T):
  _ = input()
  _ = input()
  print(input())

Submission status: Wrong Answer

Solution code:
t = int(input())
N = []
A = []
S = []
total = []
sum = 0
count = 0
for i in range(t):
    N.append(int(input()))
    A.append(list(map(int, input().split()))) 
    S.append(int(input()))

for a in A:
    for b in a:
        if sum ^ b == 0:
            if count % 2 == 0:
                sum ^= b
            else:
                continue
        else:
            if count % 2 == 0:
                continue
            else:
                sum ^= b
        count += 1
    
    total.append(sum)
    sum = 0
    count = 0
for to in total:
    if to == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
import collections
import fractions
import itertools

def solve():
    print("hello")
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    b=list(input())
    x=0
    for i in range(n):

        if x==0 and b[i]=='0':
            continue
        elif x!=0 and b[i]=='0':
            x=x^a[i]
        elif b[i]=='1':

            x=x^a[i]
    if x==0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
t = int(input())
for _ in range(t):
	x = 0
	n = int(input())
	a = list(map(int,input().split()))
	s = input()
	for i in range(n):
		mode = int(s[i])
		target = x^a[i]
		if mode == 0:
			if target == 0:
				x = target
		else:
			if target != 0:
				x = target
	print(["0", "1"][x!=0])

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
for _ in range(int(input())):
    n= int(input())
    L=list(map(int,input().split()))
    s=list(input().rstrip())
    x=0
    d={'0':[],'1':[]}
    for i in range(n):
        if s[i]=='0':
            d[s[i]].append(L[i])
        else:
            d[s[i]].append(L[i])
    for i in range(n):
        val = x^L[i]
        if s[i]=='1':
            if val != 0:
                x = val
    
    if x in d['0']:
        x=0

    if x==0:
        print('0')
    else:
        print('1')

Submission status: Wrong Answer

Solution code:
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################


for ii in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	#we start with x = 0
	x = 0
	for i in range(n):
		if s[i] == "0":
			if x != 0:
				if x^arr[i] == 0:
					x = x^arr[i]
		else:
			if x==0:
				if x^arr[i] != 0:
					x = x^arr[i]
			elif x^arr[i]!=0:
				x = x^arr[i]
		#print(i,x)
	if x == 0:
		print(0)
	else:
		print(1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from sys import setrecursionlimit
import numpy as np
setrecursionlimit(10 ** 7)

t = int(stdin.readline().rstrip())

for _ in range(t):
    n = int(stdin.readline().rstrip())
    a = list(map(int,stdin.readline().rstrip().split()))
    s = stdin.readline().rstrip()
    now = np.zeros(50,dtype=np.int64)
    for i,j in zip(a,s):
        if j == "0":
            # 合計が0になるようにしたい>できる限り０１の逆を行く個数を増やす
            b = np.array([(i>>k)&1 for k in range(50)])
            c = now^b
            if np.count_nonzero(now) > np.count_nonzero(c):
                now = c
        else:
            # 合計が0以外になるようにしたい>できる限り１の個数を増やす
            b = np.array([(i>>k)&1 for k in range(50)])
            c = now^b
            if np.count_nonzero(now) < np.count_nonzero(c):
                now = c
    if np.count_nonzero(now==0) == 50:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
"""AtCoder Grand Contest 045: A - 
https://atcoder.jp/contests/agc045/tasks/agc045_a
"""

__author__ = 'bugttle <bugttle@gmail.com>'

def main():
    T = int(input())

    for _ in range(T):
        N = int(input())
        As = list(map(int, input().split()))
        S = input()
        x = 0

        for n in range(N):
            a = As[n]
            s = S[n]
            v = x ^ a
            if s == '0': # wants to be x == 0
                if v == 0:
                    x = v
            else: # wants to be x != 0
                if v != 0:
                    x = v
        if x == 0:
            print(0)
        else:
            print(1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    b=list(input())
    x=0
    for i in range(n):
        
        if x==0 and b[i]=='0':
            continue
        elif x!=0 and b[i]=='0':
            x=x^a[i]
        elif x!=a[i] and b[i]=='1':

            x=x^a[i]
    if x==0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
t = int(input())

for i in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    s = input()
    x = 0
    for i in range(n):
        if s[i] == "1":
            if x ^ a[i] != 0:
                x = x ^ a[i]
        if s[i] == "0":
            if x ^ a[i] == 0:
                x = x ^ a[i]
    #print(x)
    if x == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
from collections import defaultdict
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def solve(N, A, S):
    x = 0
    before = 0
    for i in range(N):
        nx = x ^ A[i]
        after = 0
        for bit in range(60):
            if nx & (1 << bit):
                after += 1
        if S[i] == "0" and before > after:
            x = nx
            before = after
        elif S[i] == "1" and before < after:
            x = nx
            before = after
    if x == 0:
        print(0)
    else:
        print(1)


# 処理内容
def main():
    T = int(input())
    for _ in range(T):
        N = int(input())
        A = list(map(int, input().split()))
        S = input()[:-1]
        solve(N, A, S)
    


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import functools
import heapq
import itertools
import logging
import math
import os
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict, deque
from copy import deepcopy
from io import BytesIO, IOBase
from typing import Dict, List, Optional, Set, Tuple


def get_bits(n: int) -> Set[int]:
    result = set()
    i = 0
    while n:
        n, r = divmod(n, 2)
        if r:
            result.add(i)
        i += 1
    return result


def solve(values: List[int], _nb: int, s: str) -> bool:
    bits_0 = set()
    bits_1 = set()
    for p, n in zip(s, values):
        new_bits = get_bits(n)
        if p == "0":
            bits_0.update(new_bits)
        else:
            bits_1.update(new_bits)
    # LOG.debug((bits_0, bits_1))
    return bits_0.issuperset(bits_1)


def do_job(stdin, stdout):
    "Do the work"
    LOG.debug("Start working")
    # first line is number of test cases
    T = int(stdin.readline().strip())
    for _ in range(T):
        N = int(stdin.readline().strip())
        values = list(map(int, stdin.readline().split()))
        S = stdin.readline().strip()
        result = solve(values, N, S)
        print(0 if result else 1, file=stdout)


def print_output(testcase: int, result, stdout) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case #{}: {}".format(testcase + 1, result), file=stdout)
    # 6 digits float precision {:.6f} (6 is the default value)
    # print("Case #{}: {:f}".format(testcase + 1, result), file=stdout)


BUFSIZE = 8192


class FastIO(IOBase):
    # pylint: disable=super-init-not-called, expression-not-assigned
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    # pylint: disable=super-init-not-called
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def configure_log() -> None:
    "Configure the log output"
    log_formatter = logging.Formatter("L%(lineno)d - " "%(message)s")
    handler = logging.StreamHandler(IOWrapper(sys.stderr))
    handler.setFormatter(log_formatter)
    LOG.addHandler(handler)


LOG = None
# for interactive call: do not add multiple times the handler
if not LOG:
    LOG = logging.getLogger("template")
    configure_log()


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="run as verbose mode",
    )
    args = parser.parse_args(argv)
    if args.verbose:
        LOG.setLevel(logging.DEBUG)
    stdin = IOWrapper(sys.stdin)
    stdout = IOWrapper(sys.stdout)
    do_job(stdin, stdout)
    stdout.flush()
    for h in LOG.handlers:
        h.flush()
    return 0


if __name__ == "__main__":
    sys.exit(main())

Submission status: Wrong Answer

Solution code:
t = int(input())
n = []
a = []
s = []
for i in range(t):
    nn = int(input())
    n.append(nn)
    aa = list(map(int,input().split()))
    a.append(aa)
    ss = input()
    s.append(ss)
for i in range(t):
    x = 0
    for j in range(n[i]):
        if s[i][j] == "0":
            if x ^ a[i][j] == 0:
                x = x ^ a[i][j]
        else:
            if x ^ a[i][j] != 0:
                x = x ^ a[i][j]
    print(x)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop


def calcSpace():
    H = []
    hpush = lambda x: heappush(H, -x)
    hpop = lambda: -heappop(H)
    for x in X:
        hpush(x)
    
    E = [0] * 60
    while H:
        x = hpop()
        b = x.bit_length() - 1
        if E[b]:
            x ^= E[b]
            if x: hpush(x)
        else:
            E[b] = x
    
    return E
    
def chk(y):
    y0 = y
    for i in range(60)[::-1]:
        if y >> i & 1:
            if V[i]:
                y ^= V[i]
                # print("chk", y0, "OK", V)
                if y == 0: return 1
            else:
                return 0


T = int(input())
for _ in range(T):
    N = int(input())
    A = [int(a) for a in input().split()]
    S = [int(a) for a in input()]
    
    if 0:
        print("N =", N)
        print("A =", A)
        print("S =", S)
    
    X = []
    i = N - 1
    while i >= 0:
        if S[i]: break
        X.append(A[i])
        i -= 1
    Y = []
    while i >= 0:
        if S[i] == 0: break
        Y.append(A[i])
        i -= 1
    
    # print("X =", X)
    # print("Y =", Y)
    V = calcSpace()
    # print("V =", V)
    for y in Y:
        if chk(y) == 0:
            print(1)
            break
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    s = input()
    x = 0
    
    for i in range(n):
        if s[i] == 0 and x != 0:
                x ^= a[i]
        if s[i] == 1 and x == 0:
                x ^= a[i]
    print(0 if x==0 else 1)

Submission status: Wrong Answer

Solution code:
# 整数1個だけ
T = int(input().strip())


def calc(S, A):
    x = 0
    for i, s in enumerate(S):
        y = x ^ A[i]
        count_x = "{0:b}".format(x).count("1")
        count_y = "{0:b}".format(y).count("1")
        if s == "0" and count_x <= count_y:
            continue
        if s == "1" and count_y <= count_x:
            continue
        x = y
    return "1" if x > 0 else "0"


for _ in range(T):
    N = int(input().strip())
    A = [int(x) for x in input().strip().split(" ")]
    S = input().strip()
    # import pdb; pdb.set_trace()
    print(calc(S, A))

Submission status: Wrong Answer

Solution code:
t = int(input())

list= []
n = int(input())

Submission status: Wrong Answer

Solution code:
T = int(input())
ans = [0] * T

for _ in range(T):
    # 入力
    x = 0
    N = int(input())
    A = list(map(int, input().split()))
    S = input()

    for i in range(N):
        x = x ^ A[i]
        #print(x)

    # 出力
    if x == 0:
        ans[_] = 0
    else:
        ans[_] = 1

for _ in range(T):
    print(ans[_])

Submission status: Wrong Answer

Solution code:
T = int(input())

answers = []

for i in range(T):
  x = 0
  
  N = int(input())
  A = list(map(lambda x:int(x), input().split()))
  S = input()
  
  #print(N)
  #print(A)
  #print(S)
  
  for j,a in enumerate(A):
    if S[j] == '1':
      x = x|a
    else:
      x = x&(~a)
    #print(x)
  if x == 0:
    answers.append(0)
  else:
    answers.append(1)
    
#print(answers)
for i in answers:
  print(i)

Submission status: Wrong Answer

Solution code:
t = int(input())
for _ in range(t):
	x = 0
	n = int(input())
	a = list(map(int,input().split()))
	s = input()
	for i in range(n):
		mode = int(s[i])
		target = x^a[i]
		if mode == 0:
			if target == 0:
				x = target
		else:
			if target != 0:
				x = target
	print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())

for i in range(n):
    a= input()
    if len(a)==1:
        print("1")
    else:
        print("0")

Submission status: Wrong Answer

Solution code:
t = int(input())

for i in range(t):
  
  n = int(input())
  a = list(map(int, input().split()))
  s = input()
  x = 0
  
  for j, k in enumerate(s):
    y = x ^ a[j]
    #0の人の行動
    if k == '0':
      if x > y:
        x = y
        
    #1の人の行動    
    else:
      if x < y:
        x = y
        
  if x == 0:
    print('0')
  else:
    print('1')

Submission status: Wrong Answer

Solution code:
t = int(input())
for _ in range(t):
	x = 0
	n = int(input())
	a = list(map(int,input().split()))
	s = input()
	for i in range(n):
		mode = int(s[i])
		target = a[i]
		if mode == 0:
			if target^x == 0:
				x = target^x
		else:
			if target^x == 1:
				x = target^x
	print(x)

Submission status: Wrong Answer

Solution code:
#!python3

LI = lambda: list(map(int, input().split()))

# input
T = int(input())


def solve(N, A, S):
    w = [0] * 65
    for a, s in zip(A, S):
        b = format(a, "b")[::-1]
        n = len(b)
        for i in range(n):
            if b[i] == "1":
                w[i] = 0 if s == "0" else 1
    if sum(w) == 0:
        return "0"
    else:
        return "1"


def main():
    for _ in range(T):
        # input
        N = int(input())
        A = LI()
        S = input()
        ans = solve(N, A, S)
        print(ans)


if __name__ == "__main__":
    main()