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

Fixed submission:
num=int(input())
list1=[]
flag=0
j=0

for i in range(num):

    a=input()



    if a in list1:
        flag+=1
    list1.append(a)
    if j>0:
        if list1[i-1][len(list1[i-1])-1]==list1[i][0]:
           pass

        else:
          flag+=2

    j=1

if flag>0:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
from collections import Counter
f = open('pokemon', 'r')
names = []
for line in f:
    names.append(line)
max_length = 0
pokemon = ''
for i in range(len(names)):
    p = [names[i]]
    start = names[i][-2]
    shiritori = True
    count = 1
    while shiritori == True:
        shiritori = False
        for j in range(len(names)):
            if i != j and names[j][0] == start and not names[j] in p:
                count += 1
                start = names[j][-2]
                shiritori = True
                p.append(names[j])
                if count > max_length:
                    max_length = count
                    pokemon = names[i]
                break
    print (p)
print (pokemon + str(max_length))

Buggy submission (verdict: Runtime Error):
import sys
n = int (input())
words = []
No=" "
for i in range (n) :
    words.append(input())
for x in range(len(words)):
    if words.count(words[x]) > 1 or words[x+1][0] != words[x][-1]:
        No="No"
        print (No)
        sys.exit() 
If No != "No":
     print ("Yes")
Problem p03264 (python)

Fixed submission:
k=int(input())
if (k%2)==1 and k<=100:
    a=k//2
    b=k//2+1
elif (k%2)==0 and k<=100:
    a=k//2
    b=k//2
print(a*b)

Buggy submission (verdict: Runtime Error):
n=input (int()) 
x=0
if n%2==0:
    x=(n/2)**2
else:
    x=((n//2)+1)*(n//2)
print(x)

Buggy submission (verdict: Runtime Error):
team=input()
x=team[0]
flag=0
d=0
for i in range(Len(team)):
   if team[i]==x:
       flag+=1
   else:
        x=team[i]
        flag=0
   if flag==7:
       print("yes")
        d=1
       break
if d!=1:
    print("no")

Buggy submission (verdict: Runtime Error):
k=input()
pair=0
odd=0
even=0
for i in range(1,k+1) 
     if i%2==0:
        even+=1
     else:
            odd+=1
print(odd*even)

Buggy submission (verdict: Runtime Error):
K = map(int, input().split())
if K%2 ==0:
    print((K/2) ** 2)
else:
    print((K**2 - 1)/4)

Buggy submission (verdict: Runtime Error):
k = map(int, input())
if k%2 == 0:
    evens = k/2
    odds = k/2
    total = evens*odds
else:
    evens = (k-1)/2
    odds = k - evens
    total = evens*odds
print(total)
Problem p03316 (python)

Fixed submission:
n=int(input())
t=n
s=0

while t>0:
  a=t%10
  s=s+a
  t//=10
  
if n%s==0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
t=n
s=0

while t>n:
  a=t%10
  s=s+a
  t//=10
  
if n%s==0:
  print("Yes")
else:
  print("No")
Problem p03331 (python)

Fixed submission:
n = input()

powers10 = [10**i for i in range(1, 6)]
print(10 if int(n) in powers10 else sum(int(d) for d in n))

Buggy submission (verdict: Runtime Error):
n=int(raw_input())
maxv=n
for a in xrang(1,n+1):
  b=n-a
  if a>b: break
  sa=sum([int(x) for x in str(a)])
  sb=sum([int(x) for x in str(b)])
  maxv=min(maxv, sa+sb)
print(maxv)
Problem p03337 (python)

Fixed submission:
a, b = map(int, input().split())
c = max([a +b, a-b, a*b])
print(c)

Buggy submission (verdict: Runtime Error):
maior=0
A = int(input())
B = int(input())
lista = [A+B, A-B, A*B]
for i in range(0,3):
    if lista[i]> maior:
        maior = lista[i]
print(maior)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if(a+b > a * b and a+b > a-b):
    print(a+b)
elif(a*b > a + b and a*b > a - b):
    print(a*b)
else:
    print(a-b)
Problem p03360 (python)

Fixed submission:
line = input()

a, b, c = [int(n) for n in line.split()]
k = int(input())

max_val = max(a, b, c)
max_val_mem = max_val

amax = False
bmax = False
cmax = False

for _ in range(k):
    max_val *= 2

if max_val_mem == a:
    amax = True
    print(str(max_val+ b+ c))
elif max_val_mem == b:
    bmax = True
    print(str(max_val+ a+ c))
elif max_val_mem == c:
    cmax = True
    print(str(max_val+ a+ b))

Buggy submission (verdict: Runtime Error):
line = input()
a, b, c, k = [int(n) for n in line.split()]
numbers = [a, b, c]
numbers.sort(reverse=True)
numbers[0] *= 2 ** k
print(sum(numbers))

Buggy submission (verdict: Runtime Error):
line = input()
A, B ,C , K = [int(u) for u in line.split()]
u=[A,B,C]
j = max(u)
u.remove(j)
u.append(j*2**K)
print(sum(u))

Buggy submission (verdict: Runtime Error):
line = input()
A, B, K = [int(u) for u in line.split()]
u=[A,B,C]
j = max(u)
u.remove(j)
u.append(j*2**K)
print(sum(u))
Problem p03416 (python)

Fixed submission:
a,b=input().split()
a=int(a)
b=int(b)
c=0
for i in range(a,b+1):
    i=str(i)
    if i[0]==i[4] and i[1]==i[3]:
        c+=1
print(c)

Buggy submission (verdict: Runtime Error):
a=int(input(''))
for i in range(1,pow(10,a)):
    b=int(i/100000)
    c=int(i/10000%10)
    d=int(i/1000%10)
    e=int(i/100%10)
    f=int(i/10%10)
    g=int(i%10)
    if((b**5+c**5+d**5+e**5+f**5+g**5)==i):
        print(i)
Problem p03424 (python)

Fixed submission:
n = int(input())
li = []
count =0

liste = [x for x in input().split()]
temp = []

for i in range(len(liste)):
    if liste[i] not in temp:
        temp.append(liste[i])

if len(temp)==3:
    print("Three")

else:
    print("Four")

Buggy submission (verdict: Runtime Error):
N=int(input())

for i in range(0,N):
    s1=input()
    s2='PWGY'
    c=0
    s1=set(s1)
    for j in s1:
        if j in s2:
            c+=1
    
    #o=['One','Two','Three','Four']
    #print(o[c-1])
    if c==1:
        print("One")
    elif c==2:
        print("Two")
    elif c==3:
        print("Three")
    else:
        print("Four")
Problem p03447 (python)

Fixed submission:
total = int(input())
cake = int(input())
donut = int(input())
money = total - cake
while money >= donut:
    money = money - donut
print(money)

Buggy submission (verdict: Runtime Error):
x=int(input())
y=int(input())
z=int(input())
left=x-y
// Input
print(left%z)
Problem p03448 (python)

Fixed submission:
#!/usr/bin/env python3
from itertools import product
import sys
 
 
def solve(AA: int, BB: int, CC: int, XX: int):
    print(sum(
        1
        for a, b, c in product(range(AA + 1), range(BB + 1), range(CC + 1))
        if a * 500 + b * 100 + c * 50 == XX
    ))
 
 
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    solve(A, B, C, X)
 
 
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
x = int(input())
 
 result= 0
 
for xx in range(a+1):
    A = 500*xx
    for y in range(b+1) :
        B = 100*y
        for z in range(c+1):
            C = 50*z
            if x == A+B+C:
                result += 1
            else:
                continue
 
 
print(result)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
x = int(input())
 
ans = 0
 
for xx in range(a+1):
    A = 500*xx
    for y in range(b+1):
        B = 100*y
        for z in range(c+1):
            C = 50*z
            if x == A+B+C:
                ans += 01
            else:
                continue
 
 
print(ans)
Problem p03474 (python)

Fixed submission:
A, B =map(int, input().split())
S = input()
NUM = list(range(10))
X = 0
while X != A+B+1:
    if X == A:
        if S[X] != "-":
            print("No")
            quit()
        X += 1
    else:
        if S[X] == "-":
            print("No")
            quit()
        if int(S[X]) in NUM:
            X += 1
        else:
            print("No")
            quit()
print("Yes")

Buggy submission (verdict: Runtime Error):
    a, b = map(int, input().split())
    s = input()
     
    if s[a] == '-' and s[:a].isdigit() and s[a+1:].isdigit():
        print('Yes')
    else:
        print('No')
Problem p03481 (python)

Fixed submission:
X,Y = map(int,input().split())
ans = 0
while X <= Y:
	ans += 1
	X *= 2
print(ans)

Buggy submission (verdict: Runtime Error):
X,Y = map(int,input())
ans = 0
while X <= Y:
	ans += 1
	X *= 2
print(ans)

Buggy submission (verdict: Runtime Error):
X,Y = map(int,input().split())
ans = 0
while X <= Y:
	ans += 1
	X * = 2
print(ans)
Problem p03487 (python)

Fixed submission:
from collections import Counter
a = int(input())
l = list(map(int, input().split()))
#i = 1

c=Counter(l)
d = dict(c)
kv = []
for k,v in d.items():
    if k>v:
        kv.append(v)
    elif k<v:
        t = v-k
        kv.append(t)
s = sum(kv)
print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
arr = []
out = {}

for i in range(n):
	arr.append(int(input()))
	
	if out.get(arr[-1], False):
		out[arr[-1]] += 1
	else:
		out[arr[-1]] = 1

count = 0
for key in out:
	if key > out[key]:
		count += out[key]
	else:
		count += out[key] - key

print(count)

Buggy submission (verdict: Runtime Error):
from collections import Counter
a = int(input())
l = []
for i in range(0,a):
    b = int(input())
    l.append(b)
c=Counter(l)
d = dict(c)
kv = []
for k,v in d.items():
    if k>v:
        kv.append(v)
    elif k<v:
        t = v-k
        kv.append(t)
s = sum(kv)
print(s)

Buggy submission (verdict: Runtime Error):
from collections import Counter
a = int(input())
l = []
for i in range(0,a):
    b = int(input())
    l.append(b)
c=Counter(l)
d = dict(c)
kv = []
for k,v in d.items():
    if k>v:
        t = v
        kv.append(t)
    elif k<v:
        t = v-k
        kv.append(t)
    elif k==v:
       t= 0
       kv.append(t)        
s = sum(kv)
print(s)
Problem p03555 (python)

Fixed submission:
rli,cli=list(input()),list(input())
if rli[0]==cli[2] and rli[1]==cli[1] and rli[2]==cli[0]:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
m = input().split()

a = m[0]

if a[::-1] == m[1]:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a=[]
a[1]=[]
a[2]=[]
for i in range (3):
	a[1].append(input())
for i in range (3):
	a[2].append(input())
for i in range (3):
	if a[1][i]!=a[2][2-i]:		
		print("NO")
 		break
 	else:
 		if i==2:
 			print("YES")
  		continue
Problem p03563 (python)

Fixed submission:
#asfddddddd
n = int(input())
m = int(input())
print(m + m - n)

Buggy submission (verdict: Runtime Error):
#asfddddddd
n, m  = map(int, input().split())
print(m + m - n)
Problem p03633 (python)

Fixed submission:

def computeGCD(x, y): 
   while(y):
   		x, y = y, x % y
   return x 
n=int(raw_input())
ar=[]
for i in range(0,n):
	k=int(raw_input())
	ar.append(k)

an=ar[0]
for x in range(1,n):
	an=(an*ar[x])/computeGCD(an,ar[x]);
print(an)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    if(a == 0):
        return b
    return gcd(b % a, a)
def lcm(a, b):
    return (a / gcd(a, b)) * b 
t = int(input())
ans = 1
while(t != 0):
    t -= 1
    n = int(input())
    ans = lcm(ans, n)
print(int(ans))

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
n = int(input())
res = int(input())
while n > 1:
	x = int(input())
	res = (res * x) / gcd(res, x);
	n -= 1
print(res)

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
ar=list(map(int,input().split()))

an=ar[0]
for x in range(1,len(ar)):
	an=(an*ar[x])/math.gcd(an,ar[x]);
print(an)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import math

# code start
def lcm(a,b):
	return a*b/math.gcd(int(a),int(b))

def main():
	count = int(input())
	i = 0
	temp = 1
	while(i<count):
		i+=1
		num = int(input())
		temp = lcm(temp,num)
	print(int(temp))


if __name__ == '__main__':
    main()

# code end
Problem p03635 (python)

Fixed submission:
from sys import stdin, stdout

def main():
    line = stdin.readline()
    parts = line.split()
    m= int(parts[0])
    n = int(parts[1])
    stdout.write(str((n-1)*(m-1)))

main()

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split(" ''))
print((a-1) * (b-1))
Problem p03647 (python)

Fixed submission:
# 10 5
# 1 2
# 1 3
# 1 4
# 8 10
# 1 8

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

ends = []
starts = []
possible = False
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        starts.append([a, b])
    elif b == n:
        ends.append([a, b])

starts.sort(key=lambda x: x[1])
ends.sort(key=lambda x: x[0])

if not (starts and ends):
    print("IMPOSSIBLE")
    import sys

    sys.exit()

i = 0
j = 0
while i != len(starts) and j != len(ends):
    to = starts[i][1]
    fr = ends[j][0]

    if to == fr:
        possible = True
        break

    if to < fr:
        i += 1
    elif fr < to:
        j += 1

while j != len(ends):
    fr = ends[j][0]
    if to == fr:
        possible = True
        break
    j += 1

while i != len(starts):
    to = starts[i][1]
    if to == fr:
        possible = True
        break
    i += 1

print("POSSIBLE") if possible else print("IMPOSSIBLE")

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

ends = []
starts = []
possible = False
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        starts.append([a, b])
    elif b == n:
        ends.append([a, b])

starts.sort(key=lambda x: x[1])
ends.sort(key=lambda x: x[0])

i = 0
j = 0
to = starts[i][1]
fr = ends[j][0]
while i != len(starts) and j != len(ends):
    to = starts[i][1]
    fr = ends[j][0]

    if to == fr:
        possible = True
        break

    if to > fr:
        i += 1
    elif fr > to:
        j += 1

while j != len(ends):
    fr = ends[j][0]
    if to == fr:
        possible = True
        break

    j += 1

while i != len(starts):
    to = starts[i][1]

    if to == fr:
        possible = True
        break

    i += 1

print("POSSIBLE") if possible else print("IMPOSSIBLE")
Problem p03697 (python)

Fixed submission:
A, B = [int(x) for x in input().split(" ")]

ans = A + B

print("error" if ans >= 10 else ans)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if 1<=A and A<=9 and 1<=B and B<=9:
    if (A+B)<=9:
        print(A+B)
    else:
        print("error")

Buggy submission (verdict: Runtime Error):
A, B = [int(x) for x in input().split(" ")]

ans = A + B

printf("error" if ans >=10 else ans)

Buggy submission (verdict: Runtime Error):
A,B=[int(x) for x in input().split(" ")]

ans=A+B

printf("error" if ans >=10 else ans)

Buggy submission (verdict: Runtime Error):
A,B={int(x) for x in input().split(" ")}

ans=A+B

printf("error" if ans >=10 else ans)

Buggy submission (verdict: Runtime Error):
A,B={int(x) for x in input().split(" ")}

ans A+B

printf("error" if ans >=10 else ans)
Problem p03738 (python)

Fixed submission:
a=int(input())
b=int(input())
if a>b :
	print("GREATER")
elif a<b:
	print("LESS")
else :
	print("EQUAL")

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  string s, t; cin >> s >> t;
  int n = s.length();
  int m = s.length();
  if(n > m) {
    printf("GREATER");
  }
  else if(n < m) {
    printf("LESS");
  }
  else {
    if(s > t) {
      printf("GREATER");
    }
    else if(s < t) {
      printf("LESS");
    }
    else {
      printf("EQUAL");
    }
  }
}
Problem p03759 (python)

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

a=int(a)
b=int(b)
c=int(c)

if b-a==c-b:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a=int(input("Enter the height a in meters="))
b=int(input("Enter the height b in meters="))
c=int(input("Enter the height c in meters="))
if(1<=a and 1<=b and 1<=c and a<=100 and b<=100 and c<=100):
    if(b-a==c-b):
        print("Yes")
    elif(c-b==b-a):
        print("Yes")
    else:
        print("NO")

Buggy submission (verdict: Runtime Error):
for i in range(1,100):
    a=int(input("Enter the height a in meters="))
    b=int(input("Enter the height b in meters="))
    c=int(input("Enter the height c in meters="))
    if(b-a==c-b):
        print("Yes")
        print('Since'+str(b)+ '-' +str(a)+ '=' +str(c)+ '-' +str(b)+ ',this arrangement of poles is beautiful.')
    elif(c-b==b-a):
        print("Yes")
        print('Since'+str(c)+ '-' +str(b)+ '=' +str(b)+ '-' +str(a)+ ',this arrangement of poles is beautiful.')
    else:
        print("NO")
        print('Since'+str(b)+ '-' +str(a)+ '≠' +str(c)+ '-' +str(b)+ ',this arrangement of poles is not beautiful.')

Buggy submission (verdict: Runtime Error):
import math
a, b, c = input().split()
d = math.fabs(b-a)
e = math.fabs(c-a)
if d == e:
 print('YES')
else:
 print('NO')

Buggy submission (verdict: Runtime Error):
def beautiful:
     a,b,c = input().split()
      if abs(b-a) == abs(c-b):
            print('YES')
      else:
            print('NO')

beautiful()
Problem p03826 (python)

Fixed submission:
A ,B ,C, D = [int(x) for x in input().strip().split(' ')]
r1 ,r2  =A*B, C*D
if (r1 > r2):
    print(r1)
elif(r2 >r1):
    print(r2)
else:
    print(r1)

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
c = input()
d = input()
if a*b > c*d:
    print a*b
elif c*d > a*b:
    print c*d
else:
    print a*b

Buggy submission (verdict: Runtime Error):
A=int(input())
B=int(input())
C=int(input())
D=int(input())
if A*B>=C*D:
  print (A*B)
else:
  print (C*D)
Problem p03844 (python)

Fixed submission:
print eval(raw_input())
# print eval(raw_input())

Buggy submission (verdict: Runtime Error):
st=input()
print(int(st))
#Stay safe
#IndiaFightsCorona
#FightBack
#StayHome
#StaySafe

Buggy submission (verdict: Runtime Error):
a,op,b = input().split("")
if(op=='+'):
    print(int(a)+int(b))
else:
    print(int(a)-int(b))
Problem p03845 (python)

Fixed submission:
n = input()
a = map(int, raw_input().split())
s = sum(a)
m = input()
for i in xrange(m):
	p, x = map(int, raw_input().split())
	p -= 1
	print s - a[p] + x

Buggy submission (verdict: Runtime Error):
n = int(input()) 
t = list(map(int,input().strip().split()))[:n] 
m = int(input())
p=[]
x=[]
for _ in range(m):
    a,b = map(int,input().split())
    p.append(a)
    x.append(b)
s=sum(t)
for i in range(m):
    s-=t[p[i]-1]
    s+=x[p[i]-1]
    print(s)
Problem p03852 (python)

Fixed submission:
letter = input()
vowels = ['a' , 'e' , 'o' , 'u' , 'i' ]

if letter in vowels:
    print ("vowel")
else:
    print ("consonant")

Buggy submission (verdict: Runtime Error):
ch = input("Enter a character: ")

if(ch=='A' or ch=='a' or ch=='E' or ch =='e' or ch=='I'
 or ch=='i' or ch=='O' or ch=='o' or ch=='U' or ch=='u'):
    print(ch, "is a Vowel")
else:
    print(ch, "is a Consonant")
Problem p03861 (python)

Fixed submission:
a, b, x = map(int, input().split())
c = b // x - a // x
if a  % x == 0:
	c += 1
print(c)

Buggy submission (verdict: Runtime Error):
/*
	Suvash Kumar SUMON
	B.Sc. Engineering
	Dept. of Computer Science & Engineering (CSE)
	University of Rajshahi
	suvashsumon@outlook.com
*/

#include<bits/stdc++.h>
#define congrats_bro_you_solved_it return 0;
#define cholo_suru_kora_jak() int main()

using namespace std;

int countDivisibles(long long int A, long long int B, long long int M) 
{ 
    
    if (A % M == 0) 
        return (B / M) - (A / M) + 1; 
  
    
    return (B / M) - (A / M); 
} 

cholo_suru_kora_jak()
{
	long long int a, b, c, count=0;
	cin>>a>>b>>c;
	long long int ans = (b /c) - ((a - 1)  / c);
	//cout<<countDivisibles(a,b,c);
	cout<<ans;
	congrats_bro_you_solved_it;
}
Problem p03962 (python)

Fixed submission:
l=map(int,input().split())
ls=[]
for i in l:
     ls.append(i)
k=set(ls)
n=len(k)
print(n)

Buggy submission (verdict: Runtime Error):
from collections import counter
n=[]
n=input()
p=counter(n). keys()
print(p)

Buggy submission (verdict: Runtime Error):
l=list(map(int(input().split()))
n=1
ml=[]
for i in l:
 if i not in ml:
  ml.append(i)
print(len(ml))
Problem p04019 (python)

Fixed submission:
from sys import stdin

def main():
    M = stdin.readline().strip()
    S,E,N,W=False,False,False,False
    for i in M:
        if i == 'S':
            S = True
        elif i == 'E':
            E = True
        elif i == 'N':
            N = True
        elif i == 'W':
            W = True
    if S == N and E == W:
        print('Yes')
    else:
        print('No')

main()

Buggy submission (verdict: Runtime Error):
def main():
    for line in sys.stdin:
		s = line
		if (('N' in s) and ('S' in s)) and not (('W' in s) or ('E' in s)):
			print("Yes")
		elif (('W' in s) and ('E' in s)) and not (('N' in s) or ('S' in s)):
			print("Yes")
		elif (('W' in s) and ('E' in s)) and (('N' in s) and ('S' in s)):
			print("Yes")
		else:
			print("No")
Problem p04044 (python)

Fixed submission:
a,b=map(int,input().split())
S=[input() for i in range(a)]
S.sort()
print("".join(S))

Buggy submission (verdict: Runtime Error):
# cook your dish here
s=input()
m=s.split()
n=int(s[0]);
l=int(s[2]);
list=[]
for i in range(n):
    st=input()
    list.append(st)
list.sort()
for i in list:
    print(i,end="")
Problem p02558 (python)

Fixed submission:
#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        tank = []
        while par[x] >= 0:
            tank.append(x)
            x = par[x]
        for elt in tank:
            par[elt] = x
        return x
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]


import sys
input = sys.stdin.readline

n,q = map(int,input().split())

#初期化
#根なら-size,子なら親の頂点
par = [-1]*n

for i in range(q):
    t,u,v = map(int,input().split())
    if t == 0:
        unite(u,v)
    elif same(u,v):
        print(1)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        tank = []
        while par[x] >= 0:
            tank.append(x)
            x = par[x]
        for elt in tank:
            par[elt] = x
        return x
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]


import sys
input = sys.stdin.readline

n,q = map(int,input().split())

#初期化
#根なら-size,子なら親の頂点
par = [-1]*n

for i in range(q):
    t,u,v = map(int,input().split())
    if t == 0:
        unite(u,v)
    elif same(x,y):
        print(1)
    else:
        print(0)