Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02623 (python)

Fixed submission:
n,m,k=map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a = [0]+a
for i in range(1,n+1):
    a[i] += a[i-1]
b = [0]+b
for i in range(1,m+1):
    b[i] += b[i-1]

ans,j = 0,m
for i in range(n+1):
    if a[i] > k:
        break
    while b[j] > k-a[i]:
        j -= 1
    ans = max(ans,i+j)
print(ans)

Buggy submission (verdict: Runtime Error):
def can(x):
    i = min(n,x)
    end = min(m,i)
    t = a[i]+b[x-i]
    for k in range(x-i,end+1):
        t = min(t, a[i]+b[k])
        i -= 1
    if t<=k:
        return True
    else:
        return False

n,m,k=map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a = [0]+a
for i in range(1,n+1):
    a[i] += a[i-1]
b = [0]+b
for i in range(1,m+1):
    b[i] += b[i-1]

lo = 0
hi = n+m
while lo<hi:
    mid=lo+((hi-lo+1)>>1)
    if can(mid):
        lo=mid
    else:
        hi = mid-1
print(lo)
Problem p02688 (python)

Fixed submission:
n,k = map(int, input().split())
hs = [False]*n
for _ in range(k):
  d = int(input())
  s = [int(i) for i in input().split()]
  for p in s:
    if not hs[p-1]:
      hs[p-1]=True
res=0
for i in range(n):
  if not hs[i]:
    res+=1
print(res)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
haveSnack = [False]*n
for _ in range(k):
  d = int(input(d))
  for __ in range(d):
    s = [int(i) for i in input().split()]
    for sk in s:
      if not haveSnack[sk-1]:
        haveSnack[sk-1] = True
res=0
for i in range(n):
  if not haveSnack[i]:
    res+=1
print(res)
Problem p02622 (python)

Fixed submission:
S = input()
T = input()
cnt = 0
for i in range(len(S)):
    if S[i] != T[i] :
        cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
cnt = 0
for i in range(len(S)):
    if S[i] != T[i] :
        cnt += 1
prrint(cnt)
Problem p02676 (python)

Fixed submission:
K = int(input())
S = input()
if len(S) <= K:
    print(S)
else:
    s = ""
    for i in range(K):
        s += S[i]
    s += "..."
    print(s)

Buggy submission (verdict: Runtime Error):
K = int(input())
S = input()
if len(S) <= K:
    print(s)
else:
    s = ""
    for i in range(K):
        s += S[i]
    s += "..."
    print(s)
Problem p02955 (python)

Fixed submission:
import math
from collections import deque


def check(A, d, K):
    diff = []
    for a in A:
        if a % d != 0:
            diff.append(a % d)
    totalinc = 0
    diff.sort()
    q = deque(diff)
    cnt = 0
    while len(q):
        x = q.popleft()
        cnt += x
        totalinc += x
        while len(q) and q[-1] + totalinc >= d:
            y = q.pop()
            totalinc -= d-y
    cnt += totalinc
    return cnt <= K


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    total = sum(A)
    divs = [1, total]
    rt = int(math.sqrt(total))
    for i in range(2, rt+1):
        if total % i == 0:
            divs.append(i)
            if i**2 != total:
                divs.append(total//i)
    ans = 0
    for d in divs:
        if check(A, d, K):
            ans = max(ans, d)
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math


def check(A, d, K):
    modcnt = [0] * d
    cnt = 0
    for a in A:
        modcnt[a % d] += 1
    mx = d-1
    for i in range(d):
        while modcnt[i] > 0:
            modcnt[i] -= 1
            cnt += i
            pls = i
            while pls > 0:
                while modcnt[mx] == 0 and mx > 1:
                    mx -= 1
                if mx + pls >= d:
                    modcnt[mx] -= 1
                    pls -= d - mx
                else:
                    modcnt[mx] -= 1
                    modcnt[mx+pls] += 1
                    mx = mx+pls
                    pls = 0
    return cnt <= K


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    total = sum(A)
    divs = [1, total]
    rt = int(math.sqrt(total))
    for i in range(2, rt+1):
        if total % i == 0:
            divs.append(i)
            if i**2 != total:
                divs.append(total//i)
    ans = 0
    for d in divs:
        if check(A, d, K):
            ans = max(ans, d)
    print(ans)


if __name__ == "__main__":
    main()
Problem p03202 (python)

Fixed submission:
def is_possible(x, A):
    current = {}
    length = 0
    for a in A:
        if a <= length:
            if x == 1:
                return False
            current = {k: current[k] for k in current if k < a}
            i = a - 1
            if i not in current:
                current[i] = 0
            current[i] += 1
            while i in current and current[i] >= x:
                if i == 0:
                    return False
                if (i-1) not in current:
                    current[i-1] = 0
                current[i-1] += 1
                del current[i]
                i -= 1
        length = a

    return True


def main():
    N = int(input())
    A = list(map(int, input().split()))
    left = 1
    right = N
    while left < right:
        center = (left + right) // 2
        if is_possible(center, A):
            right = center
        else:
            left = center + 1
    print(left)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def is_possible(x, A):
    current = []
    length = 0
    for a in A:
        if a <= length:
            current = current[:a] + [0] * (a-len(current))
            i = a - 1
            current[i] += 1
            while current[i] >= x:
                if i == 0:
                    return False
                current[i-1] += 1
                current[i] = 0
                i -= 1
        length = a

    return True


def main():
    N = int(input())
    A = list(map(int, input().split()))
    left = 1
    right = N
    while left < right:
        center = (left + right) // 2
        if is_possible(center, A):
            right = center
        else:
            left = center + 1
    print(left)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def is_possible(x, A):
    current = []
    for a in A:
        if len(current) < a:
            current = current + [1]*(a-len(current))
        else:
            current = current[:a]
            i = a - 1
            current[i] += 1
            while current[i] > x:
                if i == 0:
                    return False
                current[i-1] += 1
                current[i] = 1
                i -= 1
    return True


def main():
    N = int(input())
    A = list(map(int, input().split()))
    left = 1
    right = N
    while left < right:
        center = (left + right) // 2
        if is_possible(center, A):
            right = center
        else:
            left = center + 1
    print(left)


if __name__ == "__main__":
    main()
Problem p03332 (python)

Fixed submission:
MOD = 998244353
MAX = int(3e5 + 1)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
    FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
    INV[i-1] = (INV[i] * i) % MOD


def main():
    N, A, B, K = map(int, input().split())
    ans = 0
    # solve Ax + By = K
    for x in range(N+1):
        By = K - x * A
        if By >= 0 and By % B == 0 and By <= B * N:
            y = By // B
            tmp1 = FACT[N] * INV[x] * INV[N-x] % MOD
            tmp2 = FACT[N] * INV[y] * INV[N-y] % MOD
            ans = (ans + tmp1 * tmp2) % MOD
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
MOD = 998244353
MAX = int(3e5 + 10)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
    FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
    INV[i-1] = (INV[i] * i) % MOD


def main():
    N, A, B, K = map(int, input().split())
    ans = 0
    # solve Ax + By = K
    for x in range(N+1):
        By = K - x * A
        if By >= 0 and By % B == 0:
            y = By // B
            tmp1 = FACT[N] * INV[x] * INV[N-x] % MOD
            tmp2 = FACT[N] * INV[y] * INV[N-y] % MOD
            ans = (ans + tmp1 * tmp2) % MOD
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
MOD = 998244353
MAX = int(3e5 + 1)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
    FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
    INV[i-1] = (INV[i] * i) % MOD


def main():
    N, A, B, K = map(int, input().split())
    ans = 0
    for x in range(N+1):
        By = K - x * A
        if By >= 0 and By % B == 0:
            y = By // B
            tmp1 = FACT[N] * INV[x] * INV[N-x] % MOD
            tmp2 = FACT[N] * INV[y] * INV[N-y] % MOD
            ans = (ans + tmp1 * tmp2) % MOD
    print(ans)

if __name__ == "__main__":
    main()
Problem p03345 (python)

Fixed submission:
import numpy as np

def main():
    A, B, C, K = map(int, input().split())
    if K == 0:
        print(A-B)
        return
    base = np.matrix([[0, 1, 1], [1, 0, 1], [1 ,1 ,0]])
    X = base ** K
    result = np.matrix([[A, B, C]]) \
        .dot(X) \
        .dot(np.matrix([[1], [-1], [0]]))
    ans = result[0, 0]
    if ans > 10**18:
        print("Unfair")
    else:
        print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    _, _ = map(int, input().split())
    L = list(map(int, input().split()))
    R = list(map(int, input().split()))
    lcnt = [0] * 31
    rcnt = [0] * 31
    for l in L:
        lcnt[l-10] += 1
    for r in R:
        rcnt[r-10] += 1
    ans = sum(map(min, zip(lcnt, rcnt)))
    print(ans)


if __name__ == "__main__":
    main()
Problem p03724 (python)

Fixed submission:
def main():
    N, M = map(int, input().split())
    cnt = [0] * N
    for _ in range(M):
        a, b = map(int, input().split())
        cnt[a-1] += 1
        cnt[b-1] += 1
    for i in range(N):
        if cnt[i] % 2 == 1:
            print("NO")
            return
    print("YES")


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N, M = map(int, input().split())
    cnt = [0] * N
    for _ in range(N):
        a, b = map(int, input().split())
        cnt[a-1] += 1
        cnt[b-1] += 1
    for i in range(N):
        if cnt[i] % 2 == 1:
            print("NO")
            return
    print("YES")


if __name__ == "__main__":
    main()
Problem p02831 (python)

Fixed submission:
a, b = map(int, input().split())

def dcd(x, y):
  while 1:
    r = x % y
    if r == 0:
      return y
    x = y
    y = r

def lcm(x, y):
  return x * y // dcd(x, y)

print(lcm(a, b))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
# from fractions import gcd
from math import gcd
def lcm(x, y):
  return x // gcd(x, y) * y

def solve():
    a, b = MI()
    print(lcm(a, b))

if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
# from fractions import gcd
from math import gcd
def lcm(x, y):
  return x // gcd(x, y) * y

def solve():
    a, b = MI()
    print(lcm(a, b))

if __name__ == '__main__':
    solve()
Problem p02847 (python)

Fixed submission:
s = input()
 
weekday = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
 
idx = -1
for i, w in enumerate(weekday):
  if w == s:
    idx = i
 
print(7 - idx)

Buggy submission (verdict: Runtime Error):
s = input()

weekday = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']

idx = -1
for w in weekday:
  if w == s:
    idx = w

print(7 - idx)
Problem p02897 (python)

Fixed submission:
n = int(input())
g = n // 2
print((n-g) / n)

Buggy submission (verdict: Runtime Error):
n = int(input()))
g = n // 2
print((n-g) / n)
Problem p02948 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return input().split()

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
from heapq import heapify, heappush, heappop


def solve():
    n, m = MI()

    jobs = [[] for _ in range(m)]
    for i in range(n):
        a, b = MI()
        if m-a >= 0:
            jobs[m-a].append(b)

    # print(jobs)
    hp = []
    heapify(hp)
    ans = 0
    for i in range(m-1, -1, -1):
        js = jobs[i]
        for j in js:
            heappush(hp, -j)

        if len(hp) > 0:
            ans += -heappop(hp)
    print(ans)





if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return input().split()

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
import heapq


def solve():
    n, m = MI()

    AB = []
    for i in range(n):
        a, b = MI()
        AB.append((a, b))

    AB = sorted(AB, key=lambda x: x[0])
    # print(AB)

    q = [AB[0][1]]
    pre = AB[0][0]
    memo = {}
    for i in range(1, n):
        a, b = AB[i]
        if a == pre:
            q.append(b)
        else:
            memo[pre] = deque(sorted(q))
            q = [b]
            pre = a
    memo[pre] = deque(sorted(q))

    # print(memo)

    ans = 0
    for i in range(1, m+1):
        q = memo.get(i, deque([]))

        # print(i, hp)
        if len(q) > 0:
            ans += q.pop()

        q.extend(memo.get(i + 1, []))

        memo[i+1] = deque(sorted(q)[-m-i:])
    print(ans)


if __name__ == '__main__':
    solve()
Problem p02987 (python)

Fixed submission:
from collections import defaultdict
S = input()
dct = defaultdict(int)
for s in S:
  dct[s] += 1
for key, val in dct.items():
  if not val == 2:
    print('No')
    exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
S = input()
dct = defaultdict(int)
for s in S:
  dct[s] += 1
for key, val in dct.items():
  if not val == 2:
    print('No')
    exit(1)
print('Yes')
Problem p03011 (python)

Fixed submission:
p, q, r = map(int, input().split())
print(min(p+q, min(q+r, r+p)))

Buggy submission (verdict: Runtime Error):
import sys
 
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7
 
 
def input():
    return sys.stdin.readline().strip()
 
 
def main():
    N, M = map(int, input().split())
    dp = [0] * (N + 1)
    safe = [True] * (N + 1)
    for _ in range(M):
        a = int(input())
        safe[a] = False
 
    dp[0] = 1
    for i in range(1, N + 1):
        if i == 1 and safe[i]:
            dp[i] = dp[i - 1]
        else:
            if safe[i]:
                dp[i] = dp[i - 1] + dp[i - 2]
                dp[i] %= MOD
 
    print(dp[-1])
 
 
if __name__ == "__main__":
    main()
Problem p03250 (python)

Fixed submission:
L = list(map(int, input().split()))

L = sorted(L)[::-1]

s = '{}{}+{}'.format(L[0], L[1], L[2])
print(eval(s))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    S = list(input())
    T = list(input())

    ds = {}
    dt = {}
    ids = ''
    idt = ''
    cids = 0
    cidt = 0
    for i in range(len(S)):
        # S
        s = S[i]
        if s in ds:     # 出現済みの文字なら、その文字のIDを追加する
            idss = ds[s]
            ids = ids + str(idss)
        else:           # 新たに出現した文字なら、新しいIDを追加し、メモしておく
            cids += 1
            ds[s] = cids
            ids = ids + str(cids)

        # T
        t = T[i]
        if t in dt:
            idst = dt[t]
            idt = idt + str(idst)
        else:
            cidt += 1
            dt[t] = cidt
            idt = idt + str(cidt)

        if ids != idt:
            print('No')
            return

    print('Yes')



if __name__ == '__main__':
    solve()
Problem p02550 (python)

Fixed submission:
#周期m以下

n,x,m=map(int, input().split())

used = [0]*(m+1)
used_list=[]
pre=x

flag0=False
s=-1;t=-1
for i in range(m+1):
    if pre==0:
        flag0=True
        break
    now=(pre*pre)%m
    if used[pre]:
        s=used[pre]
        break
    used[pre]=i
    used_list.append(pre)
    pre=now
    
l=len(used_list[s:])
try:
    ans=sum(used_list[:s])+sum(used_list[s:])*((n-s)//l)+sum(used_list[s:s+(n-s)%l])
    if not flag0:
        print(ans)
    else:
        print(sum(used_list))
except:
    print(sum(used_list))

Buggy submission (verdict: Runtime Error):
#周期m以下

n,x,m=map(int, input().split())

used = [0]*(m+1)
used_list=[]
pre=x

flag0=False
s=-1;t=-1
for i in range(m+1):
    if pre==0:
        flag0=True
        break
    now=(pre*pre)%m
    if used[pre]:
        s=used[pre]
        break
    used[pre]=i
    used_list.append(pre)
    pre=now
    
l=len(used_list[s:])
ans=sum(used_list[:s])+sum(used_list[s:])*((n-s)//l)+sum(used_list[s:s+(n-s)%l])
if not flag0:
    print(ans)
else:
    print(sum(used_list))
Problem p02624 (python)

Fixed submission:
n=int(input())
ans=0
for i in range(1,n+1):
    k=n//i
    ans+=i*k*(k+1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n=int(input())
cnt=np.zeros(n+1,dtype = int)
for i in range(1,n+1):
    cnt[i::i]+=1
ans=cnt*np.arrange(n+1)
print(ans)
Problem p02685 (python)

Fixed submission:
n,m,k=map(int, input().split( ))
mod = 998244353

ans=0
if m==1:##コーナー
  	print(1 if k==n-1 else 0)
  	exit()
tmp=m*pow(m-1,n-1,mod)
m_inv=pow(m-1,mod-2,mod)
invs=[0]+[pow(i+1,mod-2,mod) for i in range(n)]
for i in range(1,k+2):
    ans+=tmp
    #print(ans)
    tmp*=m_inv
    if i<n:##?
        tmp*=n-i
        tmp*=invs[i]
    tmp%=mod
print(ans%mod)

Buggy submission (verdict: Runtime Error):
n,m,k=map(int, input().split( ))
mod = 998244353

ans=0
if m==1:##コーナー
  	print(1 if k==n-1 else 0)
    exit()
tmp=m*pow(m-1,n-1,mod)
m_inv=pow(m-1,mod-2,mod)
invs=[0]+[pow(i+1,mod-2,mod) for i in range(n)]
for i in range(1,k+2):
    ans+=tmp
    #print(ans)
    tmp*=m_inv
    if i<n:##?
        tmp*=n-i
        tmp*=invs[i]
    tmp%=mod
print(ans%mod)
Problem p02695 (python)

Fixed submission:
#20C10のcombinatrics全探索？
#本番でCでこれ見たら凍るw
#少なくとも combinatrics が組込みでなかったら C問題 じゃないな
n,m,q=map(int, input().split( ))
qs=tuple(tuple(map(int, input().split( ))) for _ in range(q))
import itertools
ans=0
for comb in itertools.combinations(range(1,n+m),n):##+1ない?
    tmp=0
    comb2=[comb[i]-i for i in range(n)]
    for ai,bi,ci,di in qs:
        if comb2[bi-1]-comb2[ai-1]==ci:
            tmp+=di 
    ans=max(ans,tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
#dfs試す
n,m,q=map(int, input().split( ))
qs=tuple(tuple(map(int, input().split( ))) for _ in range(q))
def dfs(ll):
    if len(ll)==n+1:
        sm=0
        for ai,bi,ci,di in qs:
            if ll[bi]-ll[ai]==ci:
                sm+=di 
        return sm
    res=[]
    for i in range(ll[-1]+1,m+1):#+1
        ll2=ll+[i]
        res.append(dfs(ll2))
    return(max(res))
l=[0]
print(dfs(l))
Problem p02736 (python)

Fixed submission:
#editorial参照

#偶奇
import numpy as np
n=int(input())
a_ = list(map(int, list(input())))
a = np.array(a_)-1###
div2=[0]
cnt=0
ex1 = False

if 1 in a:
    ex1 = True
else:
    a//=2
tst=1
tsts=[1]
for i in range(n-1):
    cnt += bin(n-i-1)[::-1].find('1')
    cnt -= bin(i+1)[::-1].find('1')
    #tst*=n-i-1
    #tst//=i+1
    div2.append(cnt)
    tsts.append(tst)

div2=np.array(div2)###これは2で割れる数のカウント
dv2=1-(div2>0)##これが2で割れるか否か
#print(a)
#print(tsts)
#print(dv2)
tmp= (a*dv2).sum()%2
if tmp:
    if ex1:
        print(1)
    else:
        print(2)

else:
    print(0)

Buggy submission (verdict: Runtime Error):
#editorial参照

#偶奇
import numpy as np
import sys
input = sys.stdin.readline
n=int(input())
a_ = list(map(int, list(input())))
a = np.array(a_)
div2=[1]
cnt=0
ex1 = False

if 1 in a:
    ex1 = True
else:
    a//=2
for i in range(1,n):
    cnt += bin(n-i)[::-1].find('1')
    cnt -= bin(i)[::-1].find('1')
    div2.append(cnt)

div2=np.array(div2)

tmp= (a*div2%2).sum()%2
if tmp:
    if ex1:
        print(1)
    else:
        print(2)

else:
    print(0)