CodeEff/ECCO huggingface dataset:
# Original solution
A, P = list(map(int, input().split()))
print(((A * 3 + P) // 2))

# Optimized solution
a, p = list(map(int, input().split()))
print(((a*3 + p) // 2))
# Original solution
#coding:utf-8
N,Q = list(map(int,input().split()))
rank = [0 for i in range(N)]

class Tree:
    def __init__(self,par,key):
        self.par = par
        self.key = key

List = [Tree(i,i) for i in range(N)]
for i in range(Q):
    com, x,y = list(map(int,input().split()))
    while type(x) != int or List[x].par != x:
        x = List[x].par.key
    a = rank[x]
            
    while type(y) != int or List[y].par != y:
        y = List[y].par.key
    b = rank[y]

    if com == 0:
        if a <= b:
            if a == b:
                rank[x] += 1
            List[y].par = List[x]
            
        else:
            List[x].par = List[y]

    else:
        if x == y:
            print("1")
        else:
            print("0")




# Optimized solution
#coding:utf-8
import time

N,Q = list(map(int,input().split()))
rank = [0 for i in range(N)]

class Tree:
    def __init__(self,par,key):
        self.par = par
        self.key = key

List = [Tree(i,i) for i in range(N)]
for i in range(Q):
    com, x,y = list(map(int,input().split()))
    x1,y1 = x,y
    while List[x1].par != x1:
        x1 = List[x1].par
    a = rank[x1]
            
    while List[y1].par != y1:
        y1 = List[y1].par
    b = rank[y1]

    if com == 0:
        if a <= b:
            if a == b:
                rank[x1] += 1
            List[y1].par = x1
            
        else:
            List[x1].par = y1

    else:
        if x1 == y1:
            print("1")
        else:
            print("0")
# Original solution
#coding:utf-8
import time

N,Q = list(map(int,input().split()))
rank = [0 for i in range(N)]

class Tree:
    def __init__(self,par,key):
        self.par = par
        self.key = key

List = [Tree(i,i) for i in range(N)]
for i in range(Q):
    com, x,y = list(map(int,input().split()))
    x1,y1 = x,y
    while List[x1].par != x1:
        x1 = List[x1].par
    a = rank[x1]
            
    while List[y1].par != y1:
        y1 = List[y1].par
    b = rank[y1]

    if com == 0:
        if a <= b:
            if a == b:
                rank[x1] += 1
            List[y1].par = x1
            
        else:
            List[x1].par = y1

    else:
        if x1 == y1:
            print("1")
        else:
            print("0")




# Optimized solution
#coding:utf-8
import time

N,Q = list(map(int,input().split()))
rank = [0 for i in range(N)]

class Tree:
    def __init__(self,par,key):
        self.par = par
        self.key = key

List = [Tree(i,i) for i in range(N)]

def unit(x,y):
    while List[x].par != x:
        x = List[x].par
    a = rank[x]
            
    while List[y].par != y:
        y = List[y].par
    b = rank[y]
    if a <= b:
        if a == b:
            rank[x] += 1
        List[y].par = x
    else:
        List[x].par = y



def Find(x,y):
    Q = []
    P = []
    while List[x].par != x:
        x = List[x].par
        Q.append(x)
            
    while List[y].par != y:
        y = List[y].par
        P.append(y)
    for xi in Q:
        List[xi].par = x
        rank[xi] = 1
    for yi in P:
        List[yi].par = y
        rank[yi] = 1
    if x == y:
        print((1))
    else:
        print((0))
    
        
for i in range(Q):
    com, x,y = list(map(int,input().split()))

    if com == 0:
        unit(x,y)
            
    else:
        Find(x,y)
# Original solution
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""


input:
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0

output:
0
0
1
1
1
0
1
1

"""

import sys


class UnionFind(object):
    __slots__ = ('size', 'rank', 'p_list')

    def __init__(self, size):
        self.size = int(size)
        self.rank = [0] * self.size
        self.p_list = [i for i in range(self.size)]

    def find_set(self, x):
        if x != self.p_list[x]:
            self.p_list[x] = self.find_set(self.p_list[x])
        return self.p_list[x]

    def same(self, x, y):
        return self.find_set(x) == self.find_set(y)

    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.p_list[y] = x
        else:
            self.p_list[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def unite(self, x, y):
        self.link(self.find_set(x), self.find_set(y))


def action(cmd):
    for _, each in enumerate(cmd):
        cmd, ele_1, ele_2 = list(map(int, each))
        if cmd == 0:
            case.unite(ele_1, ele_2)
        elif cmd == 1:
            if case.same(ele_1, ele_2):
                print('1')
            else:
                print('0')
    return case


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    ele_num, cmd_num = list(map(int, _input[0].split()))
    cmd_list = [x.split() for x in _input[1:]]

    case = UnionFind(size=ele_num)

    ans = action(cmd_list)

# Optimized solution
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""


input:
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0

output:
0
0
1
1
1
0
1
1

"""

import sys


class UnionFind(object):
    __slots__ = ('size', 'rank', 'p_list')

    def __init__(self, size):
        self.size = int(size)
        self.rank = [0] * self.size
        self.p_list = [i for i in range(self.size)]

    def _find(self, x):
        if x != self.p_list[x]:
            self.p_list[x] = self._find(self.p_list[x])
        return self.p_list[x]

    def same(self, x, y):
        return self._find(x) == self._find(y)

    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.p_list[y] = x
        else:
            self.p_list[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def union(self, x, y):
        self.link(self._find(x), self._find(y))


def action(cmd):
    for _, each in enumerate(cmd):
        cmd, ele_1, ele_2 = list(map(int, each))
        if cmd == 0:
            case.union(ele_1, ele_2)
        elif cmd == 1:
            if case.same(ele_1, ele_2):
                print('1')
            else:
                print('0')
    return case


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    ele_num, cmd_num = list(map(int, _input[0].split()))
    cmd_list = [x.split() for x in _input[1:]]

    case = UnionFind(size=ele_num)

    ans = action(cmd_list)
# Original solution
n, q = list(map(int, input().split()))

s =[set([i]) for i in range(n)]
p =[i for i in range(n)]

for i in range(q):
    com, x, y = list(map(int, input().split()))
    if com:
        if y in s[p[x]]: print((1))
        else: print((0))
    else:
        s[p[x]] = s[p[x]] | s[p[y]]
        p_x_tmp = p[x]
        p_y_tmp = p[y]
        for j in range(n):
            if p[j] == p_y_tmp: p[j] = p_x_tmp

# Optimized solution
def find(x):
    global s
    if s[x] == x:
        return x
    s[x] = find(s[x])
    return s[x]

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

s =[i for i in range(n)]

for i in range(q):
    com, x, y = list(map(int, input().split()))
    if com:
        if find(x) == find(y): print((1))
        else: print((0))
    else:
        s[find(y)] = find(x)
# Original solution
import sys

f_i = sys.stdin

n, q = list(map(int, f_i.readline().split()))

S = [[i] for i in range(n)]

def unite(sets, v1, v2):
    s1 = None
    s2 = None
    for s in sets:
        if v1 in s and v2 in s:
            return None
        elif v1 in s:
            s1 = s
        elif v2 in s:
            s2 = s
        if s1 and s2:
            break
    sets.append(s1 + s2)
    sets.remove(s1)
    sets.remove(s2)

def same(sets, v1, v2):
    for s in sets:
        if v1 in s and v2 in s:
            print((1))
            break
        elif v1 in s or v2 in s:
            print((0))
            break

for l in f_i:
    com, x, y = list(map(int, l.split()))
    if com == 0:
        unite(S, x, y)
    else:
        same(S, x, y)

# Optimized solution
import sys

f_i = sys.stdin

n, q = list(map(int, f_i.readline().split()))

S = set([frozenset([i]) for i in range(n)])

def unite(sets, v1, v2):
    s1 = None
    s2 = None
    for s in sets:
        if v1 in s and v2 in s:
            return None
        elif v1 in s:
            s1 = s
        elif v2 in s:
            s2 = s
        if s1 and s2:
            break
    sets.discard(s1)
    sets.discard(s2)
    s3 = s1.union(s2)
    sets.add(s3)

def same(sets, v1, v2):
    for s in sets:
        if v1 in s and v2 in s:
            print((1))
            break
        elif v1 in s or v2 in s:
            print((0))
            break

for l in f_i:
    com, x, y = list(map(int, l.split()))
    if com == 0:
        unite(S, x, y)
    else:
        same(S, x, y)
# Original solution
import sys

f_i = sys.stdin

n, q = list(map(int, f_i.readline().split()))

S = set(frozenset([i]) for i in range(n))

def unite(sets, v1, v2):
    s1 = None
    s2 = None
    t_s = frozenset([v1, v2])
    for s in sets:
        if t_s <= s:
            return None
        elif s1 and s2:
            break
        elif v1 in s:
            s1 = s
        elif v2 in s:
            s2 = s
    sets.discard(s1)
    sets.discard(s2)
    s3 = s1.union(s2)
    sets.add(s3)

def same(sets, v1, v2):
    t_s = frozenset([v1, v2])
    for s in sets:
        if t_s <= s:
            print((1))
            break
        elif v1 in s or v2 in s:
            print((0))
            break

for l in f_i:
    com, x, y = list(map(int, l.split()))
    if com == 0:
        unite(S, x, y)
    else:
        same(S, x, y)

# Optimized solution
import sys
 
f_i = sys.stdin
 
n, q = list(map(int, f_i.readline().split()))
 
S = set([frozenset([i]) for i in range(n)])
 
def unite(sets, v1, v2):
    s1 = None
    s2 = None
    t_s = {v1, v2}
    for s in sets:
        if t_s <= s:
            return None
        elif v1 in s:
            s1 = s
        elif v2 in s:
            s2 = s
        if s1 and s2:
            break
    sets.discard(s1)
    sets.discard(s2)
    s3 = s1.union(s2)
    sets.add(s3)
 
def same(sets, v1, v2):
    for s in sets:
        t_s = {v1, v2}
        if t_s <= s:
            print((1))
            break
        elif v1 in s or v2 in s:
            print((0))
            break
 
for l in f_i:
    com, x, y = list(map(int, l.split()))
    if com == 0:
        unite(S, x, y)
    else:
        same(S, x, y)
# Original solution
import sys
 
f_i = sys.stdin
 
n, q = list(map(int, f_i.readline().split()))
 
S = set([frozenset([i]) for i in range(n)])
 
def unite(sets, v1, v2):
    s1 = None
    s2 = None
    t_s = {v1, v2}
    for s in sets:
        if t_s <= s:
            return None
        elif v1 in s:
            s1 = s
        elif v2 in s:
            s2 = s
        if s1 and s2:
            break
    sets.discard(s1)
    sets.discard(s2)
    s3 = s1.union(s2)
    sets.add(s3)
 
def same(sets, v1, v2):
    for s in sets:
        t_s = {v1, v2}
        if t_s <= s:
            print((1))
            break
        elif v1 in s or v2 in s:
            print((0))
            break
 
for l in f_i:
    com, x, y = list(map(int, l.split()))
    if com == 0:
        unite(S, x, y)
    else:
        same(S, x, y)

# Optimized solution
import sys
 
f_i = sys.stdin
 
n, q = list(map(int, f_i.readline().split()))
 
S = set(frozenset([i]) for i in range(n))
 
def unite(sets, v1, v2):
    s1 = None
    s2 = None
    for s in sets:
        if v1 in s and v2 in s:
            return None
        elif v1 in s:
            s1 = s
        elif v2 in s:
            s2 = s
        if s1 and s2:
            break
    sets.discard(s1)
    sets.discard(s2)
    s3 = s1.union(s2)
    sets.add(s3)
 
def same(sets, v1, v2):
    for s in sets:
        if v1 in s and v2 in s:
            print((1))
            break
        elif v1 in s or v2 in s:
            print((0))
            break
 
for l in f_i:
    com, x, y = list(map(int, l.split()))
    if com == 0:
        unite(S, x, y)
    else:
        same(S, x, y)
# Original solution
#! python3
# disjoint_set_union_find_tree.py

n, q = [int(x) for x in input().split(' ')]

sets = [set([i]) for i in range(n)]

def unite(Sx, Sy):
    return Sx | Sy

def search(x):
    global sets
    flag = False
    for i in range(len(sets)):
        if x in sets[i]:
            flag = True
            break
    if flag:
        return i
    else:
        return None

def same(x, y):
    global sets
    flag = 0
    for set in sets:
        if x in set:
            if y in set:
                 flag = 1
            break
    return flag

for i in range(q):
    query, x, y = input().split(' ')
    x, y = int(x), int(y)
    if query == '0':
        # unite
        i_x = search(x)
        i_y = search(y)
        if i_x != None and i_y != None and i_x != i_y:
            sets[i_x] = unite(sets[i_x], sets[i_y])
            del sets[i_y]
    elif query == '1':
        # same
        print((same(x, y)))


# Optimized solution
#! python3
# disjoint_set_union_find_tree.py

class UnionFindTree():
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.find(self.par[x])

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

n, q = [int(x) for x in input().split(' ')]
uft = UnionFindTree(n-1)

for i in range(q):
    com, x, y = [int(x) for x in input().split(' ')]
    if com == 0:
        uft.unite(x, y)
    elif com == 1:
        if uft.same_check(x, y):
            print((1))
        else:
            print((0))
# Original solution
n,m = list(map(int,input().split()))

arr = []

for i in range(n):
	arr.append(i)

def root(i):
	t = i
	while arr[t] != t:
		t = arr[t]

	return t

for i in range(m):
	query,x,y = list(map(int,input().split()))

	if query == 0:
		arr[root(y)] = x

	else :
		print(1 if root(x) == root(y) else 0)


# Optimized solution
n,m = list(map(int,input().split()))

arr = []

for i in range(n):
	arr.append(i)

def root(i):
	t = i
	while arr[t] != t:
		t = arr[t]

	return t

for i in range(m):
	query,x,y = list(map(int,input().split()))

	if query == 0:
		if root(y) == root(x):
			next 
		else :
			arr[root(y)] = root(x)

	else :
		print(1 if root(x) == root(y) else 0)
# Original solution
from sys import stdin
high = [0] * 10000
par = [i for i in range(10000)]
def findSet(x):
    if par[x] == x: return x
    par[x] = findSet(par[x])
    return par[x]
def unite(x, y):
    x = findSet(x)
    y = findSet(y)
    if x == y: return
    if high[x] > high[y]: par[y] = x;
    else:
        par[x] = y
        if high[x] == high[y]: high[y] += 1
def same(x, y):
    return findSet(x) == findSet(y)
n, q = map(int, stdin.readline().split())
ans = []
ans_append = ans.append
for i in range(q):
    t, a, b = map(int, stdin.readline().split())
    if t == 0: unite(a, b);
    elif t == 1: ans_append(1 if same(a, b) else 0)
print(*ans, sep='\n')


# Optimized solution
from sys import stdin
n, q = map(int, stdin.readline().split())
ans = []
ans_append = ans.append
high = [0] * n
par = [i for i in range(n)]
def findSet(x):
    if par[x] == x: return x
    par[x] = findSet(par[x])
    return par[x]
def unite(x, y):
    x = findSet(x)
    y = findSet(y)
    if x == y: return
    if high[x] > high[y]: par[y] = x;
    else:
        par[x] = y
        if high[x] == high[y]: high[y] += 1
def same(x, y):
    return findSet(x) == findSet(y)
for i in range(q):
    t, a, b = map(int, stdin.readline().split())
    if t == 0: unite(a, b);
    elif t == 1: ans_append(1 if same(a, b) else 0)
print(*ans, sep='\n')
# Original solution
# encoding: "utf-8"

class Unreachable(Exception):
    pass

def main():
    n, q = [int(x) for x in input().split()]
    setlist = list()
    for i in range(n):
        setlist.append({i})

    for _ in range(q):
        run(setlist)


def run(setlist):
    com, x, y = [int(x) for x in input().split()]
    if com == 0:
        # unite
        new_set = setlist[x] | setlist[y]
        for i in new_set:
            setlist[i] = new_set

    elif com == 1:
        # same
        if y in setlist[x]:
            print((1))
        else:
            print((0))
    else:
        raise Unreachable

if __name__ == "__main__":
    main()

# Optimized solution
# encoding: "utf-8"

class Unreachable(Exception):
    pass

def main():
    n, q = [int(x) for x in input().split()]
    setlist = list()
    for i in range(n):
        setlist.append({i})

    commands = list()
    for _ in range(q):
        com, x, y = [int(x) for x in input().split()]
        commands.append((com, x, y))
    
    for command in commands:
        run(setlist, command)


def run(setlist, command):
    com, x, y = command
    if com == 0:
        # unite
        new_set = setlist[x] | setlist[y]
        for i in new_set:
            setlist[i] = new_set

    elif com == 1:
        # same
        if y in setlist[x]:
            print((1))
        else:
            print((0))
    else:
        raise Unreachable

if __name__ == "__main__":
    main()
# Original solution
class DisjointSet():
    def __init__(self):
        self.parent = None


def ancestor(elems, x):
    s = elems[x]
    while s.parent is not None:
        s = s.parent
    return s


def unite(elems, x, y):
    parent = DisjointSet()
    ancestor(elems, x).parent = parent
    ancestor(elems, y).parent = parent


def same(elems, x, y):
    return ancestor(elems, x) is ancestor(elems, y)


def main():
    n, q = [int(x) for x in input().split()]
    elems = [DisjointSet() for _ in range(n)]

    for _ in range(q):
        com, x, y = [int(x) for x in input().split()]
        if com == 0:
            unite(elems, x, y)
        else:
            print((1 if same(elems, x, y) else 0))


if __name__ == '__main__':
    main()



# Optimized solution
class DisjointSet():
    def __init__(self):
        self.parent = None


def ancestor(elems, x):
    s = elems[x]
    while s.parent is not None:
        s = s.parent
    return s


def unite(elems, x, y):
    ax = ancestor(elems, x)
    ay = ancestor(elems, y)
    if ax is not ay:
        parent = DisjointSet()
        ax.parent = ay.parent = parent


def same(elems, x, y):
    return ancestor(elems, x) is ancestor(elems, y)


def main():
    n, q = [int(x) for x in input().split()]
    elems = [DisjointSet() for _ in range(n)]

    for _ in range(q):
        com, x, y = [int(x) for x in input().split()]
        if com == 0:
            unite(elems, x, y)
        else:
            print((1 if same(elems, x, y) else 0))


if __name__ == '__main__':
    main()
# Original solution
from sys import stdin


class DisjointSet():
    def __init__(self):
        self.parent = None
        self.ancestor = self


def ancestor(elems, x):
    s = elems[x].ancestor
    while s.parent is not None:
        s = s.parent
    elems[x].ancestor = s
    return s


def unite(elems, x, y):
    ax = ancestor(elems, x)
    ay = ancestor(elems, y)
    if ax is not ay:
        ax.parent = ay
        ax.ancestor = ay.ancestor


def same(elems, x, y):
    return ancestor(elems, x) is ancestor(elems, y)


def main():
    n, q = [int(x) for x in input().split()]
    elems = [DisjointSet() for _ in range(n)]

    for _ in range(q):
        com, x, y = [int(x) for x in input().split()]
        if com == 0:
            unite(elems, x, y)
        else:
            print((1 if same(elems, x, y) else 0))


if __name__ == '__main__':
    main()



# Optimized solution
class DisjointSetElement():
    def __init__(self):
        self.parent = None
        self.anc = self

    def ancestor(self):
        s = self.anc
        while s.parent is not None:
            s = s.parent
        self.anc = s
        return s

    def unite(self, y):
        ax = self.ancestor()
        ay = y.ancestor()
        if ax is not ay:
            ax.parent = ay
            ax.anc = ay.anc

    def same(self, y):
        return self.ancestor() is y.ancestor()


def main():
    n, q = [int(x) for x in input().split()]
    elems = [DisjointSetElement() for _ in range(n)]

    for _ in range(q):
        com, x, y = [int(x) for x in input().split()]
        if com == 0:
            elems[x].unite(elems[y])
        else:
            print((1 if elems[x].same(elems[y]) else 0))


if __name__ == '__main__':
    main()
# Original solution
class DisjointSetElement():
    def __init__(self):
        self.parent = None
        self.anc = self

    def ancestor(self):
        s = self.anc
        while s.parent is not None:
            s = s.parent
        self.anc = s
        return s

    def unite(self, y):
        ax = self.ancestor()
        ay = y.ancestor()
        if ax is not ay:
            ax.parent = ay
            ax.anc = ay.anc

    def same(self, y):
        return self.ancestor() is y.ancestor()


def main():
    n, q = [int(x) for x in input().split()]
    elems = [DisjointSetElement() for _ in range(n)]

    for _ in range(q):
        com, x, y = [int(x) for x in input().split()]
        if com == 0:
            elems[x].unite(elems[y])
        else:
            print((1 if elems[x].same(elems[y]) else 0))


if __name__ == '__main__':
    main()



# Optimized solution
class DisjointSetElement():
    def __init__(self, x):
        self.parent = x
        self.rank = 0


class DisjointSet():
    def __init__(self, n):
        self.elems = [DisjointSetElement(n) for n in range(n)]

    def _find_set(self, x):
        if x != self.elems[x].parent:
            self.elems[x].parent = self._find_set(self.elems[x].parent)
        return self.elems[x].parent

    def same(self, x, y):
        return self._find_set(x) == self._find_set(y)

    def _link(self, x, y):
        if self.elems[x].rank > self.elems[y].rank:
            self.elems[y].parent = x
        else:
            self.elems[x].parent = y
            if self.elems[x].rank == self.elems[y].rank:
                self.elems[y].rank += 1

    def unite(self, x, y):
        self._link(self._find_set(x), self._find_set(y))


def main():
    n, q = [int(x) for x in input().split()]
    ds = DisjointSet(n)

    for _ in range(q):
        com, x, y = [int(x) for x in input().split()]
        if com == 0:
            ds.unite(x, y)
        else:
            print((1 if ds.same(x, y) else 0))


if __name__ == '__main__':
    main()