Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left

@lru_cache(maxsize=None)
def index(a, x):
    ''' Locate the leftmost value exactly equal to x
    http: // docs.python.jp / 3.5 / library / bisect.html
    '''
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError


if __name__ == '__main__':
    # ??????????????\???
    # S = [1, 2, 3, 4, 5]
    # T = [3, 4, 1]
    num = int(input())
    S = [int(x) for x in input().split(' ')]
    num = int(input())
    T = [int(x) for x in input().split(' ')]

    # ????´¢??????
    found = 0
    for t in T:
        try:
            index(S, t)
        except ValueError:
            pass
        else:
            found += 1

    # ???????????????
    print(found)

Fixed submission:
from bisect import bisect_left
#from functools import lru_cache

#@lru_cache(maxsize=None)
def index(a, x):
    ''' Locate the leftmost value exactly equal to x
    http: // docs.python.jp / 3.5 / library / bisect.html
    '''
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError


if __name__ == '__main__':
    # ??????????????\???
    # S = [1, 2, 3, 4, 5]
    # T = [3, 4, 1]
    num = int(input())
    S = tuple(int(x) for x in input().split(' '))
    num = int(input())
    T = [int(x) for x in input().split(' ')]

    # ????´¢??????
    found = 0
    for t in T:
        try:
            index(S, t)
        except ValueError:
            pass
        else:
            found += 1

    # ???????????????
    print(found)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
from functools import lru_cache

@lru_cache(maxsize=None)
def index(a, x):
    ''' Locate the leftmost value exactly equal to x
    http: // docs.python.jp / 3.5 / library / bisect.html
    '''
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError


if __name__ == '__main__':
    # ??????????????\???
    # S = [1, 2, 3, 4, 5]
    # T = [3, 4, 1]
    num = int(input())
    S = tuple(int(x) for x in input().split(' '))
    num = int(input())
    T = [int(x) for x in input().split(' ')]

    # ????´¢??????
    found = 0
    for t in T:
        try:
            index(S, t)
        except ValueError:
            pass
        else:
            found += 1

    # ???????????????
    print(found)

Fixed submission:
from bisect import bisect_left
#from functools import lru_cache

#@lru_cache(maxsize=None)
def index(a, x):
    ''' Locate the leftmost value exactly equal to x
    http: // docs.python.jp / 3.5 / library / bisect.html
    '''
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError


if __name__ == '__main__':
    # ??????????????\???
    # S = [1, 2, 3, 4, 5]
    # T = [3, 4, 1]
    num = int(input())
    S = tuple(int(x) for x in input().split(' '))
    num = int(input())
    T = [int(x) for x in input().split(' ')]

    # ????´¢??????
    found = 0
    for t in T:
        try:
            index(S, t)
        except ValueError:
            pass
        else:
            found += 1

    # ???????????????
    print(found)
Buggy python submission (verdict: Runtime Error):
def partition(A, p, r):
    """
    ???????????????????????????????????????A[r]?????°?????????????????????????????????????????????A[r-1]??¨?´??????????????????§??¨???
    """
    x = A[r]p
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            temp = A[i]
            A[i] = A[j]
            A[j] = temp
    temp = A[i+1]
    A[i+1] = A[r]
    A[r] = temp
    return i+1


if __name__ == '__main__':
    # ??????????????\???
    # A = [13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11]
    num_of_data = int(input())
    A = [int(x) for x in input().split(' ')]

    # ???????????????
    p = partition(A, 0, len(A)-1)  # ????????????????????????????????????len(A)??§?????????-1???????????????????????????

    # ???????????¨???
    left = A[:p]
    partition = A[p]
    right = A[p+1:]
    print('{0} [{1}] {2}'.format(' '.join(map(str, left)), partition, ' '.join(map(str, right))))

Fixed submission:
def partition(A, p, r):
    """
    ???????????????????????????????????????A[r]?????°?????????????????????????????????????????????A[r-1]??¨?´??????????????????§??¨???
    """
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            temp = A[i]
            A[i] = A[j]
            A[j] = temp
    temp = A[i+1]
    A[i+1] = A[r]
    A[r] = temp
    return i+1


if __name__ == '__main__':
    # ??????????????\???
    # A = [13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11]
    num_of_data = int(input())
    A = [int(x) for x in input().split(' ')]

    # ???????????????
    p = partition(A, 0, len(A)-1)  # ????????????????????????????????????len(A)??§?????????-1???????????????????????????

    # ???????????¨???
    left = A[:p]
    partition = A[p]
    right = A[p+1:]
    print('{0} [{1}] {2}'.format(' '.join(map(str, left)), partition, ' '.join(map(str, right))))
Buggy python submission (verdict: Runtime Error):
def max_heapify(A, i):
    l = 2 * i
    r = 2 * i + 1
    largest = i
    if l <= len(A) and A[l] > A[i]:
        largest = l
    else:
        largest = i
    if r < len(A) and A[r] > A[largest]:
        largest = r

    if largest != i:
        temp = A[i]
        A[i] = A[largest]
        A[largest] = temp
        max_heapify(A, largest)


def build_maxheap(A):
    i = len(A) // 2
    while i >= 1:
        max_heapify(A, i)
        i -= 1


if __name__ == '__main__':
    # ??????????????\???
    num_of_data = int(input())
    A = [int(x) for x in input().split(' ')]
    A.insert(0, 0) # ?????????1??????????????????????????????????????????

    # ???????????????
    build_maxheap(A)
    A = A[1:]  # ???????????????????????????

    # ???????????????
    print(' {0}'.format(' '.join(map(str, A))))

Fixed submission:
def max_heapify(A, i):
    l = 2 * i
    r = 2 * i + 1
    largest = i
    if l < len(A) and A[l] > A[i]:
        largest = l
    else:
        largest = i
    if r < len(A) and A[r] > A[largest]:
        largest = r

    if largest != i:
        temp = A[i]
        A[i] = A[largest]
        A[largest] = temp
        max_heapify(A, largest)


def build_maxheap(A):
    i = len(A) // 2
    while i >= 1:
        max_heapify(A, i)
        i -= 1


if __name__ == '__main__':
    # ??????????????\???
    num_of_data = int(input())
    A = [int(x) for x in input().split(' ')]
    A.insert(0, 0) # ?????????1??????????????????????????????????????????

    # ???????????????
    build_maxheap(A)
    A = A[1:]  # ???????????????????????????

    # ???????????????
    print(' {0}'.format(' '.join(map(str, A))))
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

if __name__ == '__main__':
    # ??????????????\???
    # ???????????????
    h = []
    while True:
        raw_input = input()
        if raw_input == 'end':
            break
        if raw_input.startswith('insert'):
            data = raw_input.split(' ')
            heappush(h, (-1*int(data[1]), data[1]))
        elif raw_input == 'extract':
            pri, item = heappop(h)
            print(item)

Fixed submission:
from heapq import heappush, heappop

if __name__ == '__main__':
    # ??????????????\???
    # ???????????????
    h = []
    while True:
        raw_input = input()
        if raw_input == 'extract':
            pri, item = heappop(h)
            print(item)
        elif raw_input == 'end':
            break
        else:
            cmd, pri = raw_input.split()
            heappush(h, (-1*int(pri), pri))

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

if __name__ == '__main__':
    # ??????????????\???
    # ???????????????
    h = []
    while True:
        raw_input = input()
        if raw_input == 'end':
            break
        if raw_input == 'extract':
            pri, item = heappop(h)
            print(item)
        else:
            data = raw_input.split(' ')
            heappush(h, (-1*int(data[1]), data[1]))

Fixed submission:
from heapq import heappush, heappop

if __name__ == '__main__':
    # ??????????????\???
    # ???????????????
    h = []
    while True:
        raw_input = input()
        if raw_input == 'extract':
            pri, item = heappop(h)
            print(item)
        elif raw_input == 'end':
            break
        else:
            cmd, pri = raw_input.split()
            heappush(h, (-1*int(pri), pri))
Buggy python submission (verdict: Runtime Error):
class LargestSquare():
    def __init__(self, map):
        self.max_width = 0
        self.map = []
        self.dp = []
        for r in map:
            self.dp.append([int((x==0)) for x in r])
            self.map.append(r[:])

    def find(self):
        for row in range(1, len(self.dp)):
            for col in range(1, len(self.dp[0])):
                if self.map[row][col] == 1:
                    self.dp[row][col] = 0
                else:
                    self.dp[row][col] = min(self.dp[row-1][col-1], min(self.dp[row-1][col], self.dp[row][col-1])) + 1
                    self.max_width = max(self.max_width, self.dp[row][col])
        return self.max_width * self.max_width



if __name__ == '__main__':
    # ??????????????\???
    f = open('input.txt')
    height, width = [int(x) for x in f.readline().strip().split(' ')]
    map = []
    for _ in range(height):
        map.append([int(x) for x in f.readline().strip().split(' ')])


    # ???????????????
    S = LargestSquare(map)
    result = S.find()

    # ???????????¨???
    print(result)

Fixed submission:
class LargestSquare():
    def __init__(self, map):
        self.max_width = 0
        self.map = []
        self.dp = []
        for r in map:
            self.dp.append([int((x==0)) for x in r])
            self.map.append(r[:])
            if 0 in r:
                self.max_width = 1

    def find(self):
        for row in range(1, len(self.dp)):
            for col in range(1, len(self.dp[0])):
                if self.map[row][col] == 1:
                    self.dp[row][col] = 0
                else:
                    self.dp[row][col] = min(self.dp[row-1][col-1], min(self.dp[row-1][col], self.dp[row][col-1])) + 1
                    self.max_width = max(self.max_width, self.dp[row][col])
        return self.max_width * self.max_width



if __name__ == '__main__':
    # ??????????????\???
    # f = open('input.txt')
    #height, width = [int(x) for x in f.readline().strip().split(' ')]
    height, width = [int(x) for x in input().strip().split(' ')]

    map = []
    for _ in range(height):
        # map.append([int(x) for x in f.readline().strip().split(' ')])
        map.append([int(x) for x in input().strip().split(' ')])


    # ???????????????
    S = LargestSquare(map)
    result = S.find()

    # ???????????¨???
    print(result)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""


"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    N, V = map(int, input().split())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]
    D = [int(x) for x in input().split()]

    AB = []
    for i in A:
        for j in B:
           AB.append(i+j)
    AB.sort()

    CD = []
    for i in C:
        for j in D:
           CD.append(i+j)
    CD.sort()

    count = 0
    for ab in AB:
        count += CD.count(V-ab)

    print(count)





if __name__ == '__main__':
    main(sys.argv[1:])

Fixed submission:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_4_A
AC
"""
import sys
from sys import stdin
from bisect import bisect_right, bisect_left
input = stdin.readline


def main(args):
    N, V = map(int, input().split())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]
    D = [int(x) for x in input().split()]

    AB = tuple(a+b for a in A for b in B)

    CD = [c+d for c in C for d in D]
    CD.append(float('-inf'))
    CD.append(float('inf'))
    CD.sort()

    count = 0
    for ab in AB:
        i = bisect_left(CD, V - ab)
        j = bisect_right(CD, V - ab)
        count += (j-i)

    print(count)


if __name__ == '__main__':
    main(sys.argv[1:])
Buggy python submission (verdict: Runtime Error):
if __name__ == '__main__':
    from math import pi
    radius = int(input())

    area = radius**2 * pi
    perimeter = 2 * radius * pi

    print('{0:.6f} {1:.6f}'.format(area, perimeter))

Fixed submission:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_4_B&lang=jp

"""
import sys
from sys import stdin
from math import pi
input = stdin.readline


def main(args):
    r = float(input())
    print('{:.6f} {:.6f}'.format(r**2*pi, 2*pi*r))


if __name__ == '__main__':
    main(sys.argv[1:])

Buggy python submission (verdict: Runtime Error):
import math


if __name__ == '__main__':
    radius = int(input())

    area = radius**2 * math.pi
    perimeter = 2 * radius * math.pi

    print('{0:.6f} {1:.6f}'.format(area, perimeter))

Fixed submission:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_4_B&lang=jp

"""
import sys
from sys import stdin
from math import pi
input = stdin.readline


def main(args):
    r = float(input())
    print('{:.6f} {:.6f}'.format(r**2*pi, 2*pi*r))


if __name__ == '__main__':
    main(sys.argv[1:])
Buggy python submission (verdict: Time Limit Exceeded):
def find_divisors(n):
    divisors = []
    d = 2
    while n > 1:
        while n % d == 0:
            divisors.append(d)
            n //= d
        d += 1
    return divisors


if __name__ == '__main__':
    # ??????????????\???
    target_number = int(input())

    # ?¨?????????????
    results = find_divisors(target_number)

    # ???????????¨???
    print('{0}: {1}'.format(target_number, ' '.join(map(str, results))))

Fixed submission:
def create_prime_list(limit):
    """ ??¨??????????????????????????§limit?????§????´???°?????????????±???????
    https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9
    """
    x = limit**0.5
    primes = []
    # print('x={0}'.format(x))
    nums = [x for x in range(2, limit+1)]
    while nums[0] <= x:
        primes.append(nums[0])
        current_prime = nums[0]
        nums = [x for x in nums if x % current_prime != 0]
    primes.extend(nums)
    # print(primes)
    return primes



def calc_divisors(n):
    """ n????????????????????¨?????§????????°????????? """
    if n in Primes:
        return [n]
    results = []
    i = 2
    start_num = n
    while n >= i**2:
        if n%i==0:
            while n%i==0:
                results.append(i)
                n //= i
            if n in Primes:
                results.append(n)
                n = 1
        i += 1
    #print('{0}????´???°: {1}'.format(start_num, results))
    if not results:
        results = [start_num]
    return results


Primes = set()
if __name__ == '__main__':
    # ??????????????\???
    target_number = int(input())
    # target_number = 999993031
    # target_number = 1463616



    # ?¨?????????????
    Primes = set(create_prime_list(int(10**4.5)+1))
    results = calc_divisors(target_number)

    # ???????????¨???
    print('{0}: {1}'.format(target_number, ' '.join(map(str, results))))
Buggy python submission (verdict: Runtime Error):
def insertion_sort(A, N):
  for i in range(len(N):
    v = A[i]
    j = i - 1
    while j >= 0 and a[j] > v:
      A[j + 1] = A[j]
      j--
    A[j + 1] = v

if __name__=='__main__':
   n=int(input()) 
   A=list(map(int,input().split()))
   insertion_sort(A)
   print(*A)

Fixed submission:
# -*- coding: utf-8 -*-


def insertion_sort(a, n):
    for i in range(n):
        tmp = a[i]
        j = i - 1
        while j >= 0 and a[j] > tmp:
            a[j + 1] = a[j]
            j -= 1
        a[j + 1] = tmp
        print(' '.join(map(str, a)))

if __name__ == '__main__':
    n = int(input())
    a = [int(n) for n in input().split()]
    insertion_sort(a, n)
Buggy python submission (verdict: Runtime Error):
class MyStack:
    def __init__(self, size):
        self.stack = [0 for i in range(size)]
        self.size = size
        self.top = 0

    def initialize(self):
        self.top = 0

    def push(self, elm):
        self.top += 1
        self.stack[self.top] = elm
        return self.stack

    def pop(self):
        ret = self.stack[self.top]
        self.stack[self.top] = 0
        self.top -= 1
        return ret

    def is_empth(self):
        if not self.is_full():
            return True
        return False

    def is_full(self):
        if self.size-1 is self.top:
            return True
        return False


def main(expr):
    stack = MyStack(100)
    for i, elm in enumerate(expr):
        if expr[i] is '+':
            a = stack.pop()
            b = stack.pop()
            stack.push(int(a) + int(b))
        elif expr[i] is '-':
            a = stack.pop()
            b = stack.pop()
            stack.push(int(b) - int(a))
        elif expr[i] is '*':
            a = stack.pop()
            b = stack.pop()
            stack.push(int(a) * int(b))
        else:
            stack.push(elm)
    return stack.pop()


if __name__ == '__main__':
    expr = [str(s) for s in input().split()]
    print(main(expr))

Fixed submission:
class MyStack:
    def __init__(self, size):
        self.stack = [0 for i in range(size)]
        self.size = size
        self.top = 0

    def initialize(self):
        self.top = 0

    def push(self, elm):
        self.top += 1
        self.stack[self.top] = elm
        return self.stack

    def pop(self):
        ret = self.stack[self.top]
        self.stack[self.top] = 0
        self.top -= 1
        return ret

    def is_empth(self):
        if not self.is_full():
            return True
        return False

    def is_full(self):
        if self.size-1 is self.top:
            return True
        return False


def main(expr):
    stack = MyStack(1000)
    for i, elm in enumerate(expr):
        if expr[i] is '+':
            a = stack.pop()
            b = stack.pop()
            stack.push(int(a) + int(b))
        elif expr[i] is '-':
            a = stack.pop()
            b = stack.pop()
            stack.push(int(b) - int(a))
        elif expr[i] is '*':
            a = stack.pop()
            b = stack.pop()
            stack.push(int(a) * int(b))
        else:
            stack.push(elm)
    return stack.pop()


if __name__ == '__main__':
    expr = [str(s) for s in input().split()]
    print(main(expr))
Buggy python submission (verdict: Runtime Error):
for i in range(1,10):
????????????for j in range(1,10):
????????????????????????print("{0}{1}{2}{3}{4}".format(i,"x",j,"=",i*j))

Fixed submission:
for i in range(1,10):
    for j in range(1,10):
        print("{0}{1}{2}{3}{4}".format(i,"x",j,"=",i*j))

Buggy python submission (verdict: Runtime Error):
for i in range(1,10):
????????????for j in range(1,10):
????????????????????????print("{0}{1}{2}{3}{4}".format(i,"x",j,"=",i*j))

Fixed submission:
for i in range(1,10):
    for j in range(1,10):
        print("{0}{1}{2}{3}{4}".format(i,"x",j,"=",i*j))
Buggy python submission (verdict: Runtime Error):
l = map(int, raw_input().split())
l1 = [int(i) for i in l]
sum = (l1[0] + l1[1])
import math
print(int(math.log10(sum) + 1))

Fixed submission:
while True:
    try:
        a,b = map(int, input().split())
        print(len(str(a+b)))
    except EOFError:
        break

Buggy python submission (verdict: Runtime Error):
l = map(int, raw_input().split())
l1 = [int(i) for i in l]
sum = (l1[0] + l1[1])
print(int(math.log10(sum) + 1))

Fixed submission:
while True:
    try:
        a,b = map(int, input().split())
        print(len(str(a+b)))
    except EOFError:
        break

Buggy python submission (verdict: Runtime Error):
while True:
    try:
        l = map(int, raw_input().split())
        l1 = [int(i) for i in l]
        sum = (l1[0] + l1[1])
        import math
        print(int(math.log10(sum) + 1))
    except EOFError:
        break

Fixed submission:
while True:
    try:
        a,b = map(int, input().split())
        print(len(str(a+b)))
    except EOFError:
        break

Buggy python submission (verdict: Runtime Error):
import math
while True:
    try:
        l = map(int, raw_input().split())
        l1 = [int(i) for i in l]
        sum = (l1[0] + l1[1])
        print(int(math.log10(sum) + 1))
    except EOFError:
        break

Fixed submission:
while True:
    try:
        a,b = map(int, input().split())
        print(len(str(a+b)))
    except EOFError:
        break
Buggy python submission (verdict: Runtime Error):
for i in range(1,10):
	for j in range(1,100):
		print(str(i)+"x"+str(j)+"="str(i*j))

Fixed submission:
for i in range(1,10):
	for j in range(1,10):
		print(str(i)+"x"+str(j)+"="+str(i*j))
Buggy python submission (verdict: Runtime Error):
l=[]
for i in range(10):
	l.append(int(input()))
l.sort().reverse()
print(l[0])
print(l[1])
print(l[2])

Fixed submission:
l=[]
for i in range(10):
	l.append(int(input()))
l.sort(reverse=True)
print(l[0])
print(l[1])
print(l[2])

Buggy python submission (verdict: Runtime Error):
l=[]
for i in range(10):
	l.append(int(input()))
l.sort().reversed()
print(l[0])
print(l[1])
print(l[2])

Fixed submission:
l=[]
for i in range(10):
	l.append(int(input()))
l.sort(reverse=True)
print(l[0])
print(l[1])
print(l[2])
Buggy python submission (verdict: Runtime Error):
# ?????????O(n)????????£???????????????
class union_find(object):
 	"""union-find tree"""
 	def __init__(self, length):
 		self.length = length
 		self.unionnumber=0
 		self.unionlist=[[]]
 		self.num=list(-1 for i in range(length))

 	def unite(self,i,j):
 		if self.num[i]==-1:
 			if self.num[j]==-1:
 				self.unionlist[self.unionnumber].extend([i,j])
 				self.num[i]=self.unionnumber
 				self.num[j]=self.unionnumber
 				self.unionnumber+=1
 				self.unionlist.append([])
 			else:
 				tmp=i 
 				i=j 
 				j=tmp 
 		if self.num[i]!=-1:
 			if self.num[j]!=-1:
 				if self.num[i]==self.num[j]:
 					pass
 				else:
 					self.unionlist[self.num[i]].extend(self.unionlist[self.num[j]])
 					tmp=self.num[j]
 					for k in self.unionlist[self.num[j]]:
 						self.num[k]=self.num[i]
 					self.unionlist[tmp]="del"
 			else:
 				self.num[j]=self.num[i]
 				self.unionlist[self.num[i]].append(j)

 	def same(self,i,j):
 		print(self.num[i]==self.num[j])


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

l=[]
union=union_find(n)
for i in range(m):
	com,a,b=input().split()
	a=int(a)
	b=int(b)
	if com="unite":
		union.unite(a,b)
	else:
		union.same(a,b)

Fixed submission:
# ?????????O(n)????????£?????????
class union_find(object):
 	"""union-find tree"""
 	def __init__(self, length):
 		self.length = length
 		self.unionnumber=0
 		self.unionlist=[[]]
 		self.num=list(-1 for i in range(length))

 	def unite(self,i,j):
 		if self.num[i]==-1:
 			if self.num[j]==-1:
 				self.unionlist[self.unionnumber].extend([i,j])
 				self.num[i]=self.unionnumber
 				self.num[j]=self.unionnumber
 				self.unionnumber+=1
 				self.unionlist.append([])
 			else:
 				tmp=i 
 				i=j 
 				j=tmp 
 		if self.num[i]!=-1:
 			if self.num[j]!=-1:
 				if self.num[i]==self.num[j]:
 					pass
 				else:
 					self.unionlist[self.num[i]].extend(self.unionlist[self.num[j]])
 					tmp=self.num[j]
 					for k in self.unionlist[self.num[j]]:
 						self.num[k]=self.num[i]
 					self.unionlist[tmp]="del"
 			else:
 				self.num[j]=self.num[i]
 				self.unionlist[self.num[i]].append(j)

 	def same(self,i,j):
 		if self.num[i]==-1 or self.num[j]==-1:
 			return(False)
 		else:
 			return(self.num[i]==self.num[j])


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

l=[]
union=union_find(n)
for i in range(m):
	com,a,b=input().split()
	a=int(a)
	b=int(b)
	if com=="0":
		union.unite(a,b)
	else:
		if union.same(a,b):
			print(1)
		else:
			print(0)