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

Fixed submission:
from collections import Counter
n=int(input())
l=list(map(int,input().split()))
c=Counter(l)

edges=[]
for k,v in c.items():
    if v>=2:
        for i in range(v//2):
            edges.append(k)
if len(edges)>=2:
    edges.sort(reverse=True)
    print(edges[0]*edges[1])
else:
    print(0)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
l=list(map(int,input().split()))
c=Counter(l)

edges=[]
for k,v in c.items():
    if v>=2:
        for i in range(v//2):
            edges.append(k)
edges.sort(reverse=True)
print(edges[0]*edges[1])
Problem p03632 (python)

Fixed submission:
n=[0]*101
a,b,c,d=map(int,input().split())
n[a]+=1
n[b]-=1
n[c]+=1
n[d]-=1
for i in range(100):
  n[i+1]+=n[i]
ans=0
for i in n:
  if i==2:
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=[0]*101
a,b,c,d=map(int,input().split())
n[a]+=1
n[b+1]-=1
n[c]+=1
n[d+1]-=1
for i in range(100):
  n[i+1]+=n[i]
ans=0
for i in n:
  if i==2:
    ans+=1
print(ans)
Problem p03633 (python)

Fixed submission:
import numpy as np
n=int(input())
T=np.array([int(input()) for _ in range(n)], dtype=np.int64)

def gcd(x,y):
    if x<y:
        x,y=y,x
    if y==0:
        return x
    return gcd(y, x%y)

ans=1
for t in T:
    ans*=t//gcd(t, ans)

print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
T=[int(input()) for _ in range(n)]
T.sort(reverse=True)

def gcd(x,y):
    if x<y:
        x,y=y,x
    if y==0:
        return x
    return gcd(y, x%y)

ans=int(T[0]/gcd(T[0], T[1]))*T[1]
for i in range(2, n):
    ans=int(T[i]/gcd(ans,T[i]))*ans

print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
T=[int(input()) for _ in range(n)]
T.sort(reverse=True)

def gcd(x,y):
    if x<y:
        x,y=y,x
    if y==0:
        return x
    return gcd(y, x%y)

ans=int(T[0]/gcd(T[0], T[1]))*T[1]
for i in range(2, n):
    ans=int(T[i]/gcd(ans,T[i]))*ans

print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
T=[int(input()) for _ in range(n)]

def gcd(x,y):
    if x<y:
        x,y=y,x
    if y==0:
        return x
    return gcd(y, x%y)

ans=1
for t in T:
    g=gcd(ans, t)
    ans=int(ans*t/g)

print(ans)
Problem p03693 (python)

Fixed submission:
a=list(input().split())
n=int("".join(a))
if n%4==0:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
rgb=list(input())
rgb = int("".join(rgb))
if rgb%4==0:
  print("YES")
else:
  print("NO")
Problem p03700 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, A, B = map(int, readline().split())
H = [int(readline()) for _ in range(N)]


def C(T):
    """
    T回爆発させて、魔物全滅できるか
    """
    damage = B * T
    cnt = 0
    for h in H:
        h -= damage
        if h <= 0:
            continue
        cnt += (h + (A - B) - 1) // (A - B)
    return cnt <= T


left = 0
right = 10 ** 18
while right - left > 1:
    mid = (right + left) // 2
    if C(mid):
        right = mid
    else:
        left = mid

ans = right
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, A, B = map(int, input().split())
H = np.array([int(input()) for _ in range(N)], dtype=np.int64)


def C(X):
    """
    x回爆発して、全部消滅させれるとTrue
    """
    HP = np.copy(H)
    HP -= B * X
    cnt = ((HP + A - B - 1) // (A - B)).sum()
    return cnt <= X


l = -1
r = 10 ** 18
while r - l > 1:
    m = (r + l) // 2
    if C(m):
        r = m
    else:
        l = m

ans = r
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
input = sys.stdin.readline

N, A, B = map(int, input().split())
H = [int(input()) for _ in range(N)]
H = np.array(H, dtype=np.int64)


def C(X):
    """
    x回爆発して、全部消滅させれるとTrue
    """
    HP = np.copy(H)
    HP -= B * X
    HP[HP <= 0] = 0
    cnt = ((HP + A - B - 1) // (A - B)).sum()
    return cnt <= X


l = -1
r = 10 ** 18
while r - l > 1:
    m = (r + l) // 2
    if C(m):
        r = m
    else:
        l = m

ans = r
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
input = sys.stdin.readline

N, A, B = map(int, input().split())
H = [int(input()) for _ in range(N)]
H = np.array(H, dtype=np.int64)


def C(X):
    """
    x回爆発して、全部消滅させれるとTrue
    """
    HP = np.copy(H)
    HP -= B * X
    HP[HP <= 0] = 0
    cnt = ((HP + A - B - 1) // (A - B)).sum()
    return cnt <= X


l = 0
r = 10 ** 18
while r - l > 1:
    m = (r + l) // 2
    if C(m):
        r = m
    else:
        l = m

ans = r
print(ans)
Problem p03712 (python)

Fixed submission:
h,w=map(int,input().split())
pic=[["#" for i in range(w+2)]]
for i in range(h):
  s=list(input())
  s=["#"]+s+["#"]
  pic.append(s)
pic.append(["#" for i in range(w+2)])

for i in pic:
  print("".join(i))

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
pic=[["#" for i in range(w+2)]]
for i in range(h):
  s=list(input())
  s="#"+s+"#"
  pic.append(s)
pic.append(["#" for i in range(w+2)])

for i in pic:
  print("".join(i))
Problem p03827 (python)

Fixed submission:
n=int(input())
S=input()

ans=[0]*(n+1)
for i,s in enumerate(S):
  if s=="I":
    ans[i+1]=ans[i]+1
  elif s=="D":
    ans[i+1]=ans[i]-1

print(max(ans))

Buggy submission (verdict: Runtime Error):
n=int(input())
S=input()

ans=[0]*(n+1)
for i,s in S:
  if s=="I":
    ans[i+1]=ans[i]+1
  elif s=="D":
    ans[i+1]=ans[i]-1

print(max(ans))
Problem p03854 (python)

Fixed submission:
s=input()[::-1]

isOk=False
while len(s)>=5:
    if s[:5]=="maerd" or s[:5]=="esare":
        s=s[5:]
    elif len(s)>=6 and s[:6]=="resare":
        s=s[6:]
    elif len(s)>=7 and s[:7]=="remaerd":
        s=s[7:]
    else:
        break
    
    if len(s)==0:
        isOk=True

print("YES") if isOk else print("NO")

Buggy submission (verdict: Runtime Error):
s=input()[::-1]

phrase=("dream"[::-1],
        "dreamer"[::-1],
        "erase"[::-1],
        "eraser"[::-1])


def dayDream(word):
    if word[:7] in phrase:
        return dayDream(word[7:])
    elif word[:6] in phrase:
        return dayDream(word[6:])
    elif word[:5] in phrase:
        return dayDream(word[5:])
    
    if len(word)==0:
        return True
    else:
        return False

print("YES") if dayDream(s) else print("NO")

Buggy submission (verdict: Runtime Error):
s=input()[::-1]

phrase=("dream"[::-1],
        "dreamer"[::-1],
        "erase"[::-1],
        "eraser"[::-1])


def dayDream(word):
    if word[:7] in phrase:
        return dayDream(word[7:])
    elif word[:6] in phrase:
        return dayDream(word[6:])
    elif word[:5] in phrase:
        return dayDream(word[5:])
    
    if len(word)==0:
        return True
    else:
        return False


print(dayDream(s))
Problem p03962 (python)

Fixed submission:
print(len(set(list(input().split()))))

Buggy submission (verdict: Runtime Error):
print(len(set([input().split()])))
Problem p04026 (python)

Fixed submission:
from collections import defaultdict
import numpy as np
S = input()

d = defaultdict(list)
for i, s in enumerate(S):
    d[s].append(i + 1)


ans = (-1, -1)
for k, v in d.items():
    dif = np.diff(v).tolist()
    if 1 in dif:
        i = dif.index(1)
        ans = (v[i], v[i + 1])
        break
    elif 2 in dif:
        i = dif.index(2)
        ans = (v[i], v[i + 1])
        break

print(*ans, sep=" ")

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import numpy as np
S = input()

d = defaultdict(list)
for i, s in enumerate(S):
    d[s].append(i + 1)


ans = (-1, -1)
for _, v in d.items():
    dif = np.diff(v).tolist()
    if 1 in dif:
        i = dif.index(1)
        ans = (v[i], v[i + 1])
        break
    elif 2 in dif:
        i = dif.index(1)
        ans = (v[i], v[i + 1])
        break

print(*ans, sep=" ")
Problem p02853 (python)

Fixed submission:
x,y=map(int, input().split())
if x==y==1:
    print(1000000)
else:
    t=0
    if x<=3: t+=[300000,200000,100000][x-1]
    if y<=3: t+=[300000,200000,100000][y-1]
    print(t)

Buggy submission (verdict: Runtime Error):
x,y=map(int, input().split())
if x==y==1:
    print(1000000)
else:
    print([300000,200000,100000][x-1]+[300000,200000,100000][y-1])
Problem p02579 (python)

Fixed submission:
#: 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

########################################
def valid(a,b):
	#print(a,b)
	if 0<=a<=h-1 and 0<=b<=w-1 and arr[a][b] == ".":
		return True
	else:
		return False


h , w = map(int , input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
ch-=1
cw-=1
dh-=1
dw-=1
arr = [input() for i in range(h)]
#print(arr)
can_vis = []
dist = [[10**10]*w for i in range(h)]
q = deque()
ans = float("inf")
q.append((ch,cw))
dist[ch][cw] = 0
#print(dh,dw,ch,cw)
while q:
	#print(q.popleft())
	#print(q)
	curx , cury = q.popleft()
	#can_vis.append((curx,cury))
	for dx,dy in [[1,0],[0,1],[-1,0],[0,-1]]:
		if valid(curx+dx, cury+dy) and dist[curx+dx][cury+dy] > dist[curx][cury]:
			dist[curx+dx][cury+dy] = dist[curx][cury]
			q.appendleft((curx+dx, cury+dy))
	for dx in range(-2,3):
		for dy in range(-2,3):
			if valid(curx+dx, cury+dy) and dist[curx+dx][cury+dy] > dist[curx][cury] + 1:
				dist[curx+dx][cury+dy] = dist[curx][cury] + 1 
				q.append((curx+dx, cury+dy))


if dist[dh][dw] == 10**10:
	print(-1)
else:
	print(dist[dh][dw])

Buggy submission (verdict: Runtime Error):
#: 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

########################################
def valid(a,b):
	#print(a,b)
	if 0<=a<=h-1 and 0<=b<=w-1 and arr[a][b] == ".":
		return True
	else:
		return False


h , w = map(int , input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
ch-=1
cw-=1
dh-=1
dw-=1
arr = [list(input()) for i in range(h)]
#print(arr)
can_vis = []
dist = [[float("inf")]*w for i in range(h)]
q = deque()
ans = float("inf")
q.append((ch,cw,0))
dist[ch][cw] = 0
#print(dh,dw,ch,cw)
while q:
	#print(q.popleft())
	#print(q)
	curx , cury = q.popleft()
	#can_vis.append((curx,cury))
	f = 0
	if curx == dh and cury == dw:
		ans = min(ans, magic)
	for dx,dy in [[1,0],[0,1],[-1,0],[0,-1]]:
		if valid(curx+dx, cury+dy) and dist[curx+dx][cury+dy] > dist[curx][cury]:
			dist[curx+dx][cury+dy] = dist[curx][cury]
			q.append((curx+dx, cury+dy))
	for dx in range(-2,3):
		for dy in range(-2,3):
			if valid(curx+dx, cury+dy) and dist[curx+dx][cury+dy] > dist[curx][cury]:
				dist[curx+dx][cury+dy] = dist[curx][cury] + 1 
				q.append((curx+dx, cury+dy))


if dist[dh][dw] == float("inf"):
	print(-1)
else:
	print(dist[dh][dw])
Problem p02607 (python)

Fixed submission:
#: 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

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

n = int(input())
arr = list(map(int , input().split()))
ans = 0
for i in range(1,n+1):
	if arr[i-1]&1 and i&1:
		ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
#: 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

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

n = int(input())
arr = list(map(int , input().split()))
ans = 0
for i in range(1,n+1):
	if arr[i]&1 and i&1:
		ans+=1
print(ans)
Problem p02639 (python)

Fixed submission:
#: 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

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

x = list(map(int , input().split()))
for i in range(len(x)):
	if x[i] == 0:
		print(i+1)
		exit()

Buggy submission (verdict: Runtime Error):
#: 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

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

x = list(map(int , input().split()))
for i in range(x):
	if x[i] == 0:
		print(i+1)
		exit()
Problem p02658 (python)

Fixed submission:
ans = 1
n = int(input())
arr = sorted(list(map(int , input().split())))
f  = 1
for i in range(n):
	ans*=arr[i]
	#print(ans)
	if ans > 10**18:
		f = 0
		break
#print(ans)
if f: print(ans)
else: print(-1)

Buggy submission (verdict: Runtime Error):
input = sys.stdin.readline
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"

ans = 1
n = int(input())
arr = list(map(int , input().split()))
for i in range(n):
	ans*=arr[i]
if ans > 10**18:
	print(-1)
else:
	print(ans)
Problem p02665 (python)

Fixed submission:

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"
n = int(input())
a= list(map(int , input().split()))
s = sum(a)
f = 1
if n == 0:
  if a[0] != 1:
    print(-1)
    exit()
  else:
    print(1)
    exit()
elif a[0]!=0:
  print(-1)
  exit()
ans = 1
node = 1
for i in range(1,n+1):
  node=min(2*node, s)
  ans+=node
  node-=a[i]
  s-=a[i]
  if node < 0:
    print(-1)	
    exit()
if f: print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
arr = list(map(int , input().split()))
s = sum(arr)
f = 1
if n == 0:
  if arr[0] != 1:
    print(-1)
    exit()
  else:
    print(1)
    exit()
elif a[0]!=0:
  print(-1)
  exit()
ans = 1
node = 1
for i in range(1,n+1):
  node=min(2*node, s)
  ans+=node
  node-=a[i]
  s-=a[i]
  if node < 0:
    print(-1)
  	f = 0
    exit()
if f: print(ans)
Problem p02677 (python)

Fixed submission:
from decimal import Decimal
import math
a , b, h , m = map(int , input().split())
angh = (h/12)*360 + (m/60)*30
angm = (m/60)*360
#print("h , m ",angh,angm)
ang = abs(angh-angm)
#ang = min(360-ang,ang)
#print("ang :",ang)
#if ang == 180: print(0); exit()
#if ang == 0: print(0); exit()
val = a*a + b*b - 2*a*b*math.cos(math.radians(ang))
print(val**0.5)

Buggy submission (verdict: Runtime Error):
from decimal import Decimal
import math
a , b, h , m = map(int , input().split())
angh = (h/12)*360 + (m/60)*30
angm = (m/60)*360
#print("h , m ",angh,angm)
ang = abs(angh-angm)
ang = min(360-ang,ang)
#print("ang :",ang)
#if ang == 180: print(0); exit()
if ang == 0: print(0); exit()
print("{:.50f}".format(Decimal((a*a + b*b - 2*a*b*math.cos(Decimal(math.radians(ang)))).sqrt())))
Problem p02678 (python)

Fixed submission:
from collections import defaultdict
from collections import deque
n , m = map(int , input().split())
g = defaultdict(list)
for i in range(m):
	u , v = map(int , input().split())
	g[u].append(v)
	g[v].append(u)
#print(g)
visited = [False]*(n+1)
a = [10**10]*(n+1)
q = deque()
q.append(1)
while q:
	node = q.popleft()
	visited[node] = True
	for ele in g[node]:
		if not visited[ele]:
			if a[ele] != 10**10: 
				continue
			a[ele] = node
			q.append(ele)
#print(ans)
#print(a)
print("Yes")
for i in a[2:]:
	print(i)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from collections import deque
n , m = map(int , input().split())
g = defaultdict(list)
for i in range(m):
	u , v = map(int , input().split())
	g[u].append(v)
	g[v].append(u)
#print(g)
visited = [False]*(n+1)
a = [10**10]*(n+1)
q = deque()
q.append(1)
while q:
	node = q.popleft()
	visited[node] = True
	for ele in g[node]:
		if not visited[ele]:
			a[ele] = node
			q.append(ele)
	depth+=1
#print(ans)
#print(a)
print("YES")
for i in a[2:]:
	print(i)
Problem p02684 (python)

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)
n , k = map(int , input().split())
arr = list(map(int , input().split()))
dic = defaultdict(int)
for i in range(1,n+1):
	dic[i] = arr[i-1]
cycle = []
visited = [False]*(10**6)
curr = 1
while True:
	cycle.append(curr)
	visited[curr] = True
	curr = dic[curr]
	#k -= 1
	if visited[curr]:
		break

csize = 0
ind = 0
for i in range(len(cycle)-1,-1,-1):
	if cycle[i] == curr:
		ind = i + 1
		break
	csize += 1
offset = len(cycle) - csize - 1
#print(cycle,csize+1, k , curr,offset)
if k - offset < 0:
	exit(print(cycle[k]))
k -= offset
k %= csize + 1
print(cycle[offset + k])

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)
n , k = map(int , input().split())
arr = list(map(int , input().split()))
dic = defaultdict(int)
for i in range(1,n+1):
	dic[i] = arr[i-1]
cycle = []
visited = [False]*(10**6)
curr = 1
if k <= n:
	curr = 1
	count = 0
	while count != k:
		curr = dic[count]
		count+=1
	exit(print(curr))
while True:
	cycle.append(curr)
	visited[curr] = True
	curr = dic[curr]
	#k -= 1
	if visited[curr]:
		break

csize = 0
ind = 0
for i in range(len(cycle)-1,-1,-1):
	if cycle[i] == curr:
		ind = i + 1
		break
	csize += 1
'''
offset = len(cycle) - csize - 1
#print(cycle,csize+1, k , curr,offset)
k -= offset
k %= csize + 1
print(cycle[offset + k])
'''
print(cycle[ind + ((k-ind)%csize)])

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)
n , k = map(int , input().split())
arr = list(map(int , input().split()))
dic = defaultdict(int)
for i in range(1,n+1):
	dic[i] = arr[i-1]
cycle = []
def dfs(node):
	if node in cycle:
		return node
	else:
		cycle.append(node)
		k = dfs(dic[node])
	return k
cyele = dfs(1)
ind = 0
offset = 0
for i in range(len(cycle)):
	if cycle[i] == cyele:
		ind = i
		break
	offset+=1
#rem = k - offset
csize = len(cycle[ind:])
rem=rem%csize

count = 0
curr = 1
while count != rem:
	curr = dic[curr]
	count+=1
print(curr)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
n , k = map(int , input().split())
arr = list(map(int , input().split()))
dic = defaultdict(int)
for i in range(1,n+1):
	dic[i] = arr[i-1]
cycle = []
def dfs(node):
	if node in cycle:
		return node
	else:
		cycle.append(node)
		k = dfs(dic[node])
	return k
cyind = dfs(1)
#print(cycle, cyind)
csize = len(arr[cyind:])
k -= cyind - 1
k %= csize
count = 0
curr = 1
#print("k " , k)
while count != k:
	curr = dic[curr]
	count+=1
print(curr)
Problem p02755 (python)

Fixed submission:
import math
a,b = map(int, input().split())
for i in range(1 , 100000):
    a2 = math.floor(i*0.08)
    b2 = math.floor(i*0.1)
    if a2 == a and b2 == b:
        exit(print(i))
print(-1)

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int, input().split())
for i in range(1 , 1e5):
    a2 = math.floor(i*0.08)
    b2 = math.floor(i*0.1)
    if a2 == a and b2 == b:
        exit(print(i))
    print(-1)
Problem p02558 (python)

Fixed submission:
code = r"""
# distutils: language=c++
# distutils: include_dirs=/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include
# cython: boundscheck=False
# cython: wraparound=False
from libcpp cimport bool
from libcpp.vector cimport vector
cdef extern from "/opt/atcoder-stl/atcoder/dsu.hpp" namespace "atcoder":
    cpdef cppclass dsu:
        dsu(int n)
        int merge(int a, int b)
        bool same(int a, int b)
        int leader(int a)
        int size(int a)
        vector[vector[int]] groups()
cdef class dsu_:
    cdef dsu *ptr
    def __cinit__(self, int n): self.ptr = new dsu(n)
    def __dealloc__(self): del self.ptr
    def merge(self,a,b): return self.ptr.merge(a,b)
    def same(self,a,b): return self.ptr.same(a,b)
    def leader(self,a): return self.ptr.leader(a)
    def size(self,a): return self.ptr.size(a)
    def groups(self): return self.ptr.groups()
"""
import os
try:
    from dsu import *
except:
    open('dsu.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b dsu.pyx')

N,Q=map(int,input().split())
TUV=[list(map(int,input().split())) for i in range(Q)]
d=dsu_(N)
for t,u,v in TUV:
    if t==0:
        d.merge(u,v)
    else:
        print(1 if d.same(u,v) else 0)

Buggy submission (verdict: Runtime Error):
code = r"""
# distutils: language=c++
# distutils: include_dirs=[/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include,/opt/atcoder-stl]
# cython: boundscheck=False
# cython: wraparound=False
from libcpp cimport bool
from libcpp.vector cimport vector
cdef extern from "/opt/atcoder-stl/atcoder/dsu.hpp" namespace "atcoder":
    cpdef cppclass dsu:
        dsu(int n)
        int merge(int a, int b)
        bool same(int a, int b)
        int leader(int a)
        int size(int a)
        vector[vector[int]] groups()
cdef class dsu_:
    cdef dsu *ptr
    def __cinit__(self, int n): self.ptr = new dsu(n)
    def __dealloc__(self): del self.ptr
    cpdef int merge(self,a,b): return self.ptr.merge(a,b)
    cpdef bool same(self,a,b): return self.ptr.same(a,b)
    cpdef int leader(self,a): return self.ptr.leader(a)
    cpdef int size(self,a): return self.ptr.size(a)
    cpdef vector[vector[int]] groups(self): return self.ptr.groups()

cdef extern from "/opt/atcoder-stl/atcoder/fenwicktree.hpp" namespace "atcoder":
    cdef cppclass fenwick_tree[T]:
        fenwick_tree(int n)
        void add(int p, T x)
        T sum(int l, int r)
cdef class fenwick_tree_:
    cdef fenwick_tree[long] *ptr
    def __cinit__(self, int n): self.ptr = new fenwick_tree[long](n)  
    def __dealloc__(self): del self.ptr
    cpdef void add(self, int p, long x): self.ptr.add(p, x)
    cpdef long sum(self, int l, int r): return self.ptr.sum(l, r)
"""
import os
try:
    from atcoder import *
except:
    open('atcoder.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b atcoder.pyx')

N,Q=map(int,input().split())
A=list(map(int,input().split()))
QRS=[list(map(int,input().split())) for i in range(Q)]
f=fenwick_tree_(N)
for i in range(N):
    f.add(i,A[i])
a=[]
for q,r,s in QRS:
    if q==0:
        f.add(r,s)
    else:
        a.append(f.sum(r,s))
print(*a,sep='\n')
Problem p02609 (python)

Fixed submission:
N=int(input())
X=input()
c=X.count('1')
r1=int(X,2)%(c-1) if c>1 else 0
r2=int(X,2)%(c+1)
d=[0]*(N+1)
for i in range(N):
    d[i+1]=d[(i+1)%bin(i+1).count('1')]+1
for i in range(N):
    if X[i]=='0':
        n=(r2+pow(2,N-i-1,c+1))%(c+1)
    else:
        if c==1:
            print(0)
            continue
        n=(r1-pow(2,N-i-1,c-1))%(c-1)
    print(d[n]+1)

Buggy submission (verdict: Runtime Error):
N=int(input())
X=input()
c=X.count('1')
r1=int(X,2)%(c-1)
r2=int(X,2)%(c+1)
d=[0]*(N+1)
for i in range(N):
    d[i+1]=d[(i+1)%bin(i+1).count('1')]+1
for i in range(N):
    if X[i]=='0':
        n=(r2+pow(2,N-i-1,c+1))%(c+1)
    else:
        if c==1:
            print(0)
            continue
        n=(r1-pow(2,N-i-1,c-1))%(c-1)
    print(d[n]+1)