Harryxun/stf_run huggingface dataset:
class UnionFind:
    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.par[x]

    # 併合
    def union(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)

    def ans(self):
        print(len(set(self.par))-1)

n,m=map(int,input().split())
uf=UnionFind(n)
l=[[] for i in range(m)]
for i in range(n):
    k=list(map(int,input.split()))
    k=[1:]
    for j in k:
        l[j-1].append(i)
    
for i in range(m):
    if len(l[i])>0:
        ll=l[i][0]
        for j in range(len(l[i])-1):
            uf.union(ll,l[i][j+1])

for i in range(1,n+1):
    uf.find(i)

if uf.ans()==1:
    print('YES')
else:
    print('NO')


### FIXED CODE ###

class UnionFind:
    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.par[x]

    # 併合
    def union(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)

    def ans(self):
        return (len(set(self.par))-1)

n,m=map(int,input().split())
uf=UnionFind(n)
l=[[] for i in range(m)]
for i in range(n):
    k=list(map(int,input().split()))
    k=k[1:]
    for j in k:
        l[j-1].append(1+i)
    
for i in range(m):
    if len(l[i])>0:
        ll=l[i][0]
        for j in range(len(l[i])-1):
            uf.union(ll,l[i][j+1])

for i in range(1,n+1):
    uf.find(i)

if uf.ans()==1:
    print('YES')
else:
    print('NO')
def dpWcount(a,b,dpW,k):
    count = int(0)
    if S[a][b]==".":
        if b<W-1:
            k +=1
            dpW[a][b] = dpWcount(a,b+1,dpW,k)
        else:
            dpW[a][b] = k+1
            k = int(0)
        return dpW[a][b]
    else:
       dpW[a][b] = 0
       count = k
       k = int(0)
       return count
def dpHcount(a,b,dpH,k):
    count = int(0)
    if S[a][b]==".":
        if a<H-1:
            k +=1
            dpH[a][b] = dpHcount(a+1,b,dpH,k)
        else:
            dpH[a][b] = k+1
            k = int(0)
        return dpH[a][b]
    else:
       dpH[a][b] = 0
       count = k
       k = int(0)
       return count

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LIS(): return list(map(str,sys.stdin.readline().split()))
ans = int(1)
ansC = int(0)

H, W = LI()
S = [str(input()) for _ in range(H)]
dpW = [[0]*W for _ in range(H)]
dpH = [[0]*W for _ in range(H)]

for i in range(H):
    w = int(0)
    while w<W:
        k = int(0)
        w += max(dpWcount(i,w, dpW, k),1)

### FIXED CODE ###

def examC():
    N, M = LI()
    A = [I() for _ in range(M)]
    A.append(N+1)
    fib = [1]*(N+2)
    for i in range(1,N):
        fib[i+2] = fib[i+1] + fib[i]
    fib[0] = 0
#    print(fib)
    ans = fib[A[0]]%mod
    for i in range(M):
        ans *= fib[A[i+1]-A[i]-1]
        ans %=mod
    print(ans)
    return

def examD():
    H, W = LI()
    S = [SI() for _ in range(H)]
    width = [[0]*W for _ in range(H)]
    height = [[0]*W for _ in range(H)]
    for i in range(H):
        cur = 0; keep = []
        for j in range(W):
            if S[i][j]==".":
                cur +=1
                keep.append(j)
            else:
                for k in keep:
                    width[i][k] = cur
                cur = 0; keep = []
        if keep:
            for k in keep:
                width[i][k] = cur
    for j in range(W):
        cur = 0; keep = []
        for i in range(H):
            if S[i][j]==".":
                cur +=1
                keep.append(i)
            else:
                for k in keep:
                    height[k][j] = cur
                cur = 0; keep = []
        if keep:
            for k in keep:
                height[k][j] = cur
    ans = 0
    for i in range(H):
        for j in range(W):
            cur = width[i][j] + height[i][j]
            if ans<cur:
                ans = cur
    print(ans-1)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examD()
N = int(input())
count = 0
A = [int(x) for x in input().split()]
while all(i % 2 == 0 for i in A):
    A = [i/2 for i in A]
    count += 1
print(count)

### FIXED CODE ###

s1 = input()
print(s1.count('1'))
s = input()
    print(s.replace(',', ' '))

### FIXED CODE ###

K , S = map(int, input().split())
x , y , z , cnt = 0 , 0 , 0 , 0
A = K + 1
if K * 3 == S:
    cnt = 1
else :
    for i in range(A):
        for j in range(A):
            if  S - (i + j) <= K :
                if 0 <= S - (i + j): 
                    cnt += 1
print(cnt)
#!/usr/bin/env python3

A, B = map(int input().split())

if B % A == 0:
    print(A + B)
else:
    print(B -A)
    



### FIXED CODE ###

#!/usr/bin/env python3

A, B = map(int, input().split())

if B % A == 0:
    print(A + B)
else:
    print(B -A)
N = input()
a=(map(str, raw_input().split()))

odd=a[1::2]
even=a[0::2]

if N%2==0:
    print ' '.join(reversed(odd))+' '+' '.join(even)
else:
    print ' '.join(reversed(even))+' '+' '.join(odd)
~                                                       

### FIXED CODE ###

N = input()
a=(map(str, raw_input().split()))

odd=a[1::2]
even=a[0::2]

if N%2==0:
    print ' '.join(reversed(odd))+' '+' '.join(even)
else:
    print ' '.join(reversed(even))+' '+' '.join(odd)
a,b = list(map(int,input().split()))
if a == "D" and b == "D":
    print("H")
elif a == "D" and b == "H":
    print("D")
elif a == "H" and b == "H":
    print("H")
else:
    print("D")

### FIXED CODE ###

a,b = list(map(str,input().split()))
if a == "D" and b == "D":
    print("H")
elif a == "D" and b == "H":
    print("D")
elif a == "H" and b == "H":
    print("H")
else:
    print("D")
S=list(input())
s=0
i=0
if S[i]==S[i+1]==0 or S[i]==S[i+1]==1:
  s=s
  i+=1
else:
  s+=2
  del S[i:i+2]
  i=0
print(s)

### FIXED CODE ###

S=input()
N=len(S)
a=S.count('0')
b=S.count('1')
t=min(a,b)
print(2*t)
N = int(input()) #1行目のNを取得する
A = [int(input()) for i in range(N)] #複数行の数値の入力を取得
    
for i in A:
  B = i%2
  if B==0:
    if i%3 == i%5:
      print("APPROVED")
    else:
      print("DENIED")
  else:
    print("DENIED")

### FIXED CODE ###

a,b,c = [int(x) for x in input().split()]
if (a == b and b!=c) or (a==c and a!=b) or (b==c and b!=a):
  print("Yes")
else:
  print("No")
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if max(a,b,c,d,e) - min(a,b,c,d,e) > k:
    print(":(")
else:
    print("Yay!"）

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if max(a,b,c,d,e) - min(a,b,c,d,e) > k:
    print(":(")
else:
    print("Yay!")
a, b, c, d = map(int, input().split())

total = b - a + 1

c_1 = b//c - a//c if a%c!=0 else b//c - a//c + 1
d_1 = b//d - a//d if a%d!=0 else b//d - a//d + 1

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z

div = int(c * d / gcd(c, d))

cd = b//div - a//div if a%div!=0 else b//div - a//div + 1

print(total - c_1 - d_1 + cd)


### FIXED CODE ###

s = input()
a = 0
for i in range(3):
    if s[i]==s[i+1]:
        print("Bad")
        a = 1
        break
if a == 0:
    print("Good")
n,c,k=map(int,input().split())
t=[int(input()) for i in range(n)]
t=sorted(t)
ans=0
cnt=0
first_time=t[0]
for i in range(n):
    time=t[i]-first_time
    cnt+=1
    if time==0:
        if i<=n-2 and t[i+1]-first_time>k:
            ans+=1
            first_time=t[i+1]
            cnt=0
        elif cnt==c:
            ans+=1
            first_time=t[i+1]
            cnt=0

    elif time>k:
        ans+=1
        first_time=t[i]
        cnt=0
    elif cnt==c:
        ans+=1
        first_time=t[i+1]
        cnt=0

    if i==n-1 and cnt!=0:
        ans+=1

print(ans)



### FIXED CODE ###

n,c,k=map(int,input().split())
t=[int(input()) for i in range(n)]
t=sorted(t)
time=t[0]
cnt=0
ans=0
for i in range(n):
    #制限時間以内かつC人以内
    if time+k>=t[i] and cnt<=c-1:
        cnt+=1

    else:
        ans+=1
        time=t[i]
        cnt=1
print(ans+1)
A, B = map(int, raw_input())
if A<=5:
  print 0
elif A<=12:
  print B/2
else:
  print B


### FIXED CODE ###

A, B = map(int, raw_input().split())
if A<=5:
  print 0
elif A<=12:
  print B/2
else:
  print B
N,yen=map(int,input().split())
count=0
end=0
# print(N)
# print(yen)

for i in range(N):
    if end==1:
        break
    for j in range(N-i+1):
        # print(i)
        # print(j)
        k=N-i-j
        # print(k)
        sum=i*10000+j*5000+k*1000
        # print(sum)
        if sum==yen:
            man=i
            gosen=j
            sen=k
            end=1
            break


print(str(man)+" "+str(gosen)+" "+str(sen))


### FIXED CODE ###

N,yen=map(int,input().split())
count=0
end=0
man=0
gosen=0
sen=0
# print(N)
# print(yen)

for i in range(N+1):
    if end==1:
        break
    for j in range(N-i+1):
        # print(i)
        # print(j)
        k=N-i-j
        # print(k)
        sum=i*10000+j*5000+k*1000
        # print(sum)
        if sum==yen:
            man=i
            gosen=j
            sen=k
            end=1
            break

if man==0 and gosen==0 and sen==0:
    print("-1 -1 -1")
else:
    print(str(man)+" "+str(gosen)+" "+str(sen))
N,M = map(int, input().split())
a = [0]*M
for i in range(M): a[i] = int(input())

mod = [1]*N
inv = [1]*N
inf = 10**9+7
for i in range(N-1): mod[i+1] = mod[i]*(i+2)%inf
inv[N-1] = pow(mod[N-1], inf-2, inf)
for i in range(2,N+1): inv[N-i] = inv[N-i+1]*(N-i+2)%inf

def comb(cur,ai):
    if ai - cur == 1:
        return 1
    elif ai <= cur:
        return 0
    return(comb(cur, ai-1)+comb(cur,ai-2))

cur = 1
if a[0] == 1: cur += 1
cnt = 0
for i in range(M):
    if cur == a[i]:
        cnt = 0
        break
    cnt += comb(cur,a[i])
    cur = a[i]+1

print(cnt)

### FIXED CODE ###

P,Q,R = map(int, input().split())
print(min(P+Q,Q+R,R+P))
def prime_factorize(n):
    a = set([1])
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n not in a:
        a.add(n)
    return a
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
a, b = list(map(int, input().split()))
x = gcd(a, b)
print(len(prime_factorize(x)))


### FIXED CODE ###

def prime_factorize(n):
    a = set([1])
    while n % 2 == 0:
        a.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.add(f)
            n //= f
        else:
            f += 2
    a.add(n)
    return a
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
  
a, b = list(map(int, input().split()))
x = gcd(a, b)
print(len(prime_factorize(x)))
rr = raw_input
rri = lambda: int(raw_input())
rrm = lambda: map(int, raw_input().split())

from collections import deque
def solve(N, A):
    ans = 0
    todo = N * (N-1)
    to_inspect = range(N)
    while True:
        ans += 1
        found = False
        to_inspect2 = set()
        for i in to_inspect:
            row = A[i]
            if row:
                j = row[0]
                if (i not in to_inspect2 and j not in to_inspect2 and
                        A[j] and A[j][0] == i):
                    pairings[i] = j
                    pairings[j] = i
                    row.popleft()
                    A[j].popleft()
                    found = True
                    todo -= 2
                    to_inspect2.add(i)
                    to_inspect2.add(j)
        if not todo: return ans
        if not found: return -1
        to_inspect = to_inspect2


N = rri()
A = []
for _ in xrange(N):
    row = rrm()
    A.append(deque(x-1 for x in row))
print solve(N, A)


### FIXED CODE ###

rr = raw_input
rri = lambda: int(raw_input())
rrm = lambda: map(int, raw_input().split())

from collections import deque
def solve(N, A):
    ans = 0
    todo = N * (N-1)
    to_inspect = range(N)
    while True:
        ans += 1
        found = False
        to_inspect2 = set()
        for i in to_inspect:
            row = A[i]
            if row:
                j = row[0]
                if (i not in to_inspect2 and j not in to_inspect2 and
                        A[j] and A[j][0] == i):
                    row.popleft()
                    A[j].popleft()
                    found = True
                    todo -= 2
                    to_inspect2.add(i)
                    to_inspect2.add(j)
        if not todo: return ans
        if not found: return -1
        to_inspect = to_inspect2


N = rri()
A = []
for _ in xrange(N):
    row = rrm()
    A.append(deque(x-1 for x in row))
print solve(N, A)
s = input()
c = 0
if(s[0] == "1"):
    c++


if(s[1] == "1"):
    c++


if(s[2] == "1"):
    c++




### FIXED CODE ###

s = input()
c = 0
if(s[0] == "1"):
    c += 1


if(s[1] == "1"):
    c += 1


if(s[2] == "1"):
    c += 1

print(c)
a = int(input())
list = [22,23,24,25]
message = ['Christmas Eve Eve Eve','Christmas Eve Eve', 'Christmas Eve', 'Christmas']
index = list.index(a)
print(message[a])

### FIXED CODE ###

a = int(input())
list = [22,23,24,25]
message = ['Christmas Eve Eve Eve','Christmas Eve Eve', 'Christmas Eve', 'Christmas']
index = list.index(a)
print(message[index])
n = int(input())

l = [int(i) for i in input().split()]

total = sum(l)

for i in range(1,n,2):
    total -= l[i] * 2

ans = [total]

for i in range(1,n):
    ans.append(2*l[i-1] - ans[i-1])
    ans = [str(i) for i in ans]
    
print(' '.join(ans))
    


### FIXED CODE ###

n = int(input())

l = [int(i) for i in input().split()]

total = sum(l)

for i in range(1,n,2):
    total -= l[i] * 2

ans = [total]

for i in range(1,n):
    ans.append(2*l[i-1]-ans[i-1])
ans = [str(i) for i in ans]
    
print(' '.join(ans))
N,K = map(int,input().split())
S = input()
if S[K]=='A':
  S[K]='a'
elif S[K]=='B':
    S[K]='b'
else:
     S[K]='c'
print(S)


### FIXED CODE ###

N,K = map(int,input().split())
S = input()
n = K-1
ans = ""
for i in range(N):
    if i == n:
        ans = ans +S[i].lower()
    else:
        ans = ans + S[i]
print(ans)
N = int(input())
e = [[] for _ in range(2*N)]
for _ in range(N-1):
  u, v, w = map(int, input().split())
  e[u].append((v,w))
  e[v].append((u,w))

col = [-1 for _ in range(2*N)]
def dfs(x, c):
    col[x] = c
    for v, w in e[x]:
        if col[v] == -1:
            dfs(v, (c+w%2)%2)

dfs(1, 0)

for c in col[1:]:
    print(c)

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

N = int(input())
e = [[] for _ in range(N+1)]
for _ in range(N-1):
  u, v, w = map(int, input().split())
  e[u].append((v,w))
  e[v].append((u,w))

col = [-1 for _ in range(N+1)]
def dfs(x, c):
    col[x] = c
    for v, w in e[x]:
        if col[v] == -1:
            dfs(v, (c+w%2)%2)

dfs(1, 0)

for c in col[1:]:
    print(c)
import sys
sys.setrecursionlimit(10**７)

def main():
    n, q = map(int, input().split())
    # バラバラに持ちたいなら
    # for i in range(n-1):
    #     a, b = map(int, input().split())
    # for i in range(q):
    #     q, x = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(n-1)]
    px = [list(map(int, input().split())) for i in range(q)]
    # print(ab)
    # print(qx)
    # indexがノード
    adj = [[] for _ in range(n+1)]
    for a, b in ab:
            adj[a].append(b)
            adj[b].append(a)
    # print(adj)
    # indexが直接初めにノードに加えられる得点
    v = [0] * (n+1)
    for p,x in px:
        v[p] += x

    def dfs(cur, parent):
        for chl in adj[cur]:
            if chl == parent: 
                continue
            v[chl] += v[cur] 
            dfs(chl, cur)

    dfs(1, 0)
    ans = ' '.join(map(str,v[1:]))
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
from collections import deque
# sys.setrecursionlimit(10**7)

def main():
    n, q = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(n-1)]
    px = [list(map(int, input().split())) for i in range(q)]
    adj = [[] for _ in range(n+1)]
    for a, b in ab:
            adj[a].append(b)
            adj[b].append(a)
    # indexが直接初めにノードに加えられる得点
    v = [0] * (n+1)
    for p,x in px:
        v[p] += x
    # 子をindexで、親ノードを要素で
    parent = [None] * (n+1)
    q = deque([1])
    while q:
        par = q.pop()
        for chl in adj[par]:
            if chl == parent[par]:
                continue
            v[chl] += v[par]
            parent[chl] = par
            q.append(chl)
    ans = ' '.join(map(str,v[1:]))
    print(ans)
    
    # def dfs(cur, parent):
    #     for chl in adj[cur]:
    #         print('p', parent)
    #         if chl == parent: 
    #             continue
    #         v[chl] += v[cur]
    #         print('chl,cur', chl, cur)
    #         dfs(chl, cur)

    # dfs(1, 1)
    # ans = ' '.join(map(str,v[1:]))
    # print(ans)

if __name__ == '__main__':
    main()
def p_c():
    N, M = map(int, input().split())
    switch = [0] * N
    light = [0] * (1 << M)
    light[0] = 1
    for i in range(M):
        for s in list(map(int, input().split()))[1:]:
            switch[s - 1] += (1 << i)

    all_value = 0
    ps = list(map(int, input().split()))
    for i, p in enumerate(ps):
        all_value += p << (M - i - 1)

    for i in range(N):
        next_light = light.copy()
        for j in range(len(light)):
            next_light[j ^ switch[i]] += light[j]
        light = next_light

    print(light[all_value])
    
p_c()

### FIXED CODE ###

def p_c():
    n, m = map(int, input().split())
    s = [list(map(int, input().split()))[1:] for _ in range(m)]
    *p, = map(int, input().split())
    b = []
    for _s in s:
        bit = 0
        for i in _s:
            bit += (1 << (i - 1))
        b.append(bit)
    ans = 0
    for i in range(1 << n):
        for j, k in enumerate(b):
            if bin(i & k).count("1") & 1 != p[j]:
                break
        else:
            ans += 1
    print(ans)
    
p_c()
import sys
import numpy as np
from numba import njit
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


@numba.njit("i4(i4,i4[:])", cache=True)
def proc(N, P):
    ans = 0
    Removed = np.zeros((500, 500), dtype=np.int8)
    Mat = np.zeros((500, 500), dtype=np.int16)
    Dy, Dx = np.array([1,0,-1,0]), np.array([0,1,0,-1])

    for y in range(N):
        for x in range(N):
            Mat[y, x] = min(y, N-1-y, x, N-1-x)
    #print(Mat)
    Buf = [(0, 0) for _ in range(1<<17)]
    Buf_idx = 0
    for i in range(N*N):
        p = P[i]
        y, x = divmod(p, N)
        ans += Mat[y,x]
        Removed[y,x] = 1
        Buf[Buf_idx] = (y, x)
        Buf_idx += 1
        while Buf_idx:
            Buf_idx -= 1
            vy, vx = Buf[Buf_idx]
            vr = Removed[vy,vx]
            val = Mat[vy,vx]
            #for dy, dx in zip(Dy, Dx):
            for j in range(4):
                uy, ux = vy + Dy[j], vx + Dx[j]
                if not (0<=uy<N and 0<=ux<N):
                    continue
                ur = Removed[uy,ux]
                if vr:
                    if Mat[uy,ux] >= val+1:
                        Mat[uy,ux] = val
                        Buf[Buf_idx] = (uy, ux)
                        Buf_idx += 1
                else:
                    if Mat[uy,ux] >= val+2:
                        Mat[uy,ux] = val+1
                        Buf[Buf_idx] = (uy, ux)
                        Buf_idx += 1
    return ans
print(proc(N, P))

N = int(readline())
P = np.array(read().split(), np.int32)
 
print(solve(N, P))

### FIXED CODE ###

import numba
import numpy as np
N = int(input())
P = np.array([int(c)-1 for c in input().split()])

#from random import shuffle
#N = 500
#P = list(range(N*N))
#shuffle(P)
#P = np.array(P)

@numba.njit("void(i8,i8[:])")
def proc(N, P):
    ans = 0
    Removed = np.zeros((500, 500), dtype=np.int8)
    Mat = np.zeros((500, 500), dtype=np.int16)
    Dy, Dx = [1,0,-1,0], [0,1,0,-1]

    for y in range(N):
        for x in range(N):
            Mat[y, x] = min(y, N-1-y, x, N-1-x)
    #print(Mat)
    for i in range(N*N):
        p = P[i]
        y, x = divmod(p, N)
        ans += Mat[y,x]
        Removed[y,x] = 1
        st = [(y, x)]
        while st:
            vy, vx = st.pop()
            vr = Removed[vy,vx]
            val = Mat[vy,vx]
            #for dy, dx in zip(Dy, Dx):
            for j in range(4):
                dy = Dy[j]
                dx = Dx[j]
                uy = vy + dy
                ux = vx + dx
                if not (0<=uy<N and 0<=ux<N):
                    continue
                ur = Removed[uy,ux]
                if vr:
                    if Mat[uy,ux] >= val+1:
                        Mat[uy,ux] = val
                        st.append((uy, ux))
                else:
                    if Mat[uy,ux] >= val+2:
                        Mat[uy,ux] = val+1
                        st.append((uy, ux))
    # for m in Mat:
    #     print(m)
    print(ans)
proc(N, P)
a=input()
b=input()
Z=list['1','2','3']
X=Z.remove(a,b)

print(X)


### FIXED CODE ###

a=int(input())
b=int(input())
Z=[1,2,3]
Z.remove(a)
Z.remove(b)

print(Z[0])
a,b=map(int,input().split())
c=2*b
d=a-c
if a>c:
print(d)
else:
print(0)

### FIXED CODE ###

a,b = map(int,input().split())
c = 2*b
d = a-c
if d > 0:
 print(d)
elif d <= 0:
 print(0)
a, b, k = map(int, input().split())

def cookie(t, s, p):
        if t > 0:
            t = t - 1
        elif s > 0:
            s = s - 1
        else:
            pass
        p -= 1
        if p > 0:
            cookie(t, s, p)
        return t, s
    
res = cookie(a, b, k)
t, s = res
print(t, s)

### FIXED CODE ###

a, b, k = map(int, input().split())

if a > k:
    print(a - k, b)
else:
    print(0, max(0, a + b - k))
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        int b = inp.nextInt();
        int c = inp.nextInt();
        boolean flag = false;
        if ((a + b) == c) flag = true;
        if ((a + c) == b) flag = true;
        if ((b + c) == a) flag = true;
        System.out.println(flag ? "Yes" : "No");
    }
}

### FIXED CODE ###

a, b, c = map(int, input().split())
if (a + b == c or a + c == b or b + c == a):
    print("Yes")
else:
    print("No")
S = {}
S['a'] = input()
S['b'] = input()
S['c'] = input()


next = 'a'
lens = {'a':len(S['a']), 'b':len(S['b']), 'c':len(S['c'])}
counts = {'a':0, 'b':0, 'c':0}

while True:
  now = next
  if counts[now] == len[now]:
    print(now)
    exit()
  next = S[now][counts[now]]
  counts[now] += 1


### FIXED CODE ###

S = {}
S['a'] = input()
S['b'] = input()
S['c'] = input()


next = 'a'
lens = {'a':len(S['a']), 'b':len(S['b']), 'c':len(S['c'])}
counts = {'a':0, 'b':0, 'c':0}

while True:
  now = next
  counts[now]
  if counts[now] == lens[now]:
    print(now.upper())
    exit()
  next = S[now][counts[now]]
  counts[now] += 1