Harryxun/stf_run huggingface dataset:
n,a,b,c=map(int,input().split())
ans=[]
for i in range(n):
    s=input()
    if s=="AB":
        if a==0:
            a+=1
            b-=1
        elif b==0:
            a-=1
            b+=1
        elif a>b:
            a-=1
            b+=1
            ans.append("A")
        else:
            a+=1
            b-=1
            ans.append("B")
    elif s=="AC":
        if a==0:
            a+=1
            c-=1
        elif c==0:
            a-=1
            c+=1
        elif a>c:
            a-=1
            c+=1
            ans.append("A")
        else:
            a+=1
            c-=1
            ans.append("C")
    else:
        if b==0:
            b+=1
            c-=1
        elif c==0:
            b-=1
            c+=1
        elif b>c:
            b-=1
            c+=1
            ans.append("B")
        else:
            b+=1
            c-=1
            ans.append("C")
    if a<0 or b<0 or c<0:
        ans.clear()
        break
if len(ans)==0:
    print("No")
else:
    print("Yes")
    for i in range(n):
        print(ans[i])


### FIXED CODE ###

n,a,b,c=map(int,input().split())
ans=[]
slist=[]
for i in range(n):
    s=input()
    slist.append(s)
for i in range(n):
    s=slist[i]
    if s=="AB":
        if a==0:
            a+=1
            b-=1
            ans.append("A")
        elif b==0:
            a-=1
            b+=1
            ans.append("B")
        elif slist[(i+1)%n]=="AB":
            if a>b:
                a-=1
                b+=1
                ans.append("B")
            else:
                a+=1
                b-=1
                ans.append("A")
        elif slist[(i+1)%n]=="AC":
            a+=1
            b-=1
            ans.append("A")
        else:
            a-=1
            b+=1
            ans.append("B")
    elif s=="AC":
        if a==0:
            a+=1
            c-=1
            ans.append("A")
        elif c==0:
            a-=1
            c+=1
            ans.append("C")
        elif slist[(i+1)%n]=="AC":
            if a>c:
                a-=1
                c+=1
                ans.append("C")
            else:
                a+=1
                c-=1
                ans.append("A")
        elif slist[(i+1)%n]=="AB":
            a+=1
            c-=1
            ans.append("A")
        else:
            a-=1
            c+=1
            ans.append("C")
    else:
        if b==0:
            b+=1
            c-=1
            ans.append("B")
        elif c==0:
            b-=1
            c+=1
            ans.append("C")
        elif slist[(i+1)%n]=="BC":
            if b>c:
                b-=1
                c+=1
                ans.append("C")
            else:
                b+=1
                c-=1
                ans.append("B")
        elif slist[(i+1)%n]=="AC":
            c+=1
            b-=1
            ans.append("C")
        else:
            c-=1
            b+=1
            ans.append("B")
    if a<0 or b<0 or c<0:
        ans.clear()
        break
if len(ans)==0:
    print("No")
else:
    print("Yes")
    for i in range(n):
        print(ans[i])
a,b,c=input().split()
arr=sorted([a,b,c])
print(arr[0]*arr[1])
return arr[0]*arr[1]



### FIXED CODE ###

a,b,c=map(int,input().split())
arr=sorted([a,b,c])
print(int(arr[0]*arr[1]/2))
def solve(n):
    if n==0:
        return 1
    else:
        return n*solve(n-1)
    
N = int(input())
print(solve(N)%(10**9+7))

### FIXED CODE ###

def solve(n):
    ans = 1 
    for i in range(n):
        ans = (i+1)*ans%(10**9+7)
        
            
    return ans

N = int(input())
print(solve(N))
#!/usr/bin/env python3

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

a = [int(input()) for _ in range(m)]

mod = 1000000007

if n == 1:
    print(1)
    exit()
elif n == 2:
    if a[0] == 1:
        print(1)
    else:
        print(2)
    exit()

if a[0] == 1:
    a_2, a_1 = 1, 0
    index = 1
else:
    a_2, a_1 = 1, 1
    index = 0

for i in range(2, n+1):
    if index < len(a):
        if i == a[index]:
            a_now = 0
            index += 1
            a_1, a_2 = a_now, a_1
            continue

    a_now = (a_1+a_2) % mod
    # print(a_now)
    a_1, a_2 = a_now, a_1
    # print(a_now)
print(a_now % mod)

# 0, 1, 2, 3, 4, 5, 6

# 1, 1, 2, 0, 2, 2, 4


### FIXED CODE ###

#!/usr/bin/env python3

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

if m != 0:
    a = [int(input()) for _ in range(m)]
else:
    a = [-1]

mod = 1000000007

if n == 1:
    print(1)
    exit()
elif n == 2:
    if a[0] == 1:
        print(1)
    else:
        print(2)
    exit()


if a[0] == 1:
    a_2, a_1 = 1, 0
    index = 1
else:
    a_2, a_1 = 1, 1
    index = 0

for i in range(2, n+1):
    if index < len(a):
        if i == a[index]:
            a_now = 0
            index += 1
            a_1, a_2 = a_now, a_1
            continue

    a_now = (a_1+a_2) % mod
    # print(a_now)
    a_1, a_2 = a_now, a_1
    # print(a_now)
print(a_now % mod)

# 0, 1, 2, 3, 4, 5, 6

# 1, 1, 2, 0, 2, 2, 4
import sys
N, M = map(int, input().split())

a_list = [0] * M

for m in range(M):
    a_list[m] = int(input())

for m in range(M - 1):
    if a_list[m] + 1 == a_list[m + 1]:
        print(0)
        sys.exit()
    else:
        continue

range_list = [i for i in range(1, N + 1)]
new_list = [0] * (M + 1)

new_list[0] = [0] + range_list[0: a_list[0] - 1]
new_list[M] = range_list[a_list[M - 1]:]

if M - 1 >= 1:
    for m in range(1, M):
        new_list[m] = range_list[a_list[m - 1]: a_list[m] - 1]

MOD = 1000000007

def fib(n):
    dp_list = [0] * n
    dp_list[0] = 1
    if n == 1:
        return 1
    dp_list[1] = 2
    
    for i in range(2, n):
        dp_list[i] = dp_list[i - 1] + dp_list[i - 2]
    return dp_list[n - 1]
print(new_list)
count = 1
for item in new_list:
    if not item or len(item) == 1:
        continue
    else:
        count *= (fib(len(item) - 1) % MOD)
        count %= MOD
        #print(count)
print(count)

### FIXED CODE ###

import sys
N, M = map(int, input().split())

MOD = 1000000007

def fib(n):
    dp_list = [0] * n
    dp_list[0] = 1
    if n == 1:
        return 1
    dp_list[1] = 2
    
    for i in range(2, n):
        dp_list[i] = dp_list[i - 1] + dp_list[i - 2]
    return dp_list[n - 1]

if M == 0:
    print(fib(N) % MOD)
    sys.exit()

a_list = [0] * M

for m in range(M):
    a_list[m] = int(input())

for m in range(M - 1):
    if a_list[m] + 1 == a_list[m + 1]:
        print(0)
        sys.exit()
    else:
        continue

range_list = [i for i in range(1, N + 1)]
new_list = [0] * (M + 1)


new_list[0] = [0] + range_list[0: a_list[0] - 1]
new_list[M] = range_list[a_list[M - 1]:]

if M - 1 >= 1:
    for m in range(1, M):
        new_list[m] = range_list[a_list[m - 1]: a_list[m] - 1]

count = 1
for item in new_list:
    if not item or len(item) == 1:
        continue
    else:
        count *= (fib(len(item) - 1) % MOD)
        count %= MOD
        #print(count)
print(count)
A = input()
a,b,c,d = A[0],A[1],A[2],A[3]
e1 = a+b+c+d
e2 = a+b+c-d
e3 = a+b-c+d
e4 = a+b-c-d
e5 = a-b+c+d
e6 = a-b+c-d
e7 = a-b-c+d
e8 = a-b+c-d
if eval(e1) == 7:
    print(e1)
elif eval(e2) == 7:
    print(e2)
elif eval(e3) == 7:
    print(e3)
elif eval(e4) == 7:
    print(e4)
elif eval(e5) == 7:
    print(e5)
elif eval(e6) == 7:
    print(e6)
elif eval(e7) == 7:
    print(e7)
elif eval(e8) == 7:
    print(e8)

### FIXED CODE ###

A = input()
a,b,c,d = A[0],A[1],A[2],A[3]
e1 = a+'+'+b+'+'+c+'+'+d
e2 = a+'+'+b+'+'+c+'-'+d
e3 = a+'+'+b+'-'+c+'+'+d
e4 = a+'+'+b+'-'+c+'-'+d
e5 = a+'-'+b+'+'+c+'+'+d
e6 = a+'-'+b+'+'+c+'-'+d
e7 = a+'-'+b+'-'+c+'+'+d
e8 = a+'-'+b+'+'+c+'-'+d
if eval(e1) == 7:
    print(e1+'=7')
elif eval(e2) == 7:
    print(e2+'=7')
elif eval(e3) == 7:
    print(e3+'=7')
elif eval(e4) == 7:
    print(e4+'=7')
elif eval(e5) == 7:
    print(e5+'=7')
elif eval(e6) == 7:
    print(e6+'=7')
elif eval(e7) == 7:
    print(e7+'=7')
elif eval(e8) == 7:
    print(e8+'=7')
N = int(input())

proof = [[] for _ in range(N)]
for i in range(N):
    for j in range(int(input())):
        x, y = map(int, input().split())
        proof[i].append([x-1, y])

ans = 0
for i in range(1, 2**N):
    flag = 0
    for j in range(N):
        if (i>>j) & 1 == 1:
            for x, y in proof[j]:
                if (i>>x)&1 != state:
                    flag = 1
                    break
    if flag == 0:
        ans = max(ans, bin(i)[2:].count('1'))
print(ans)

### FIXED CODE ###

N = int(input())

proof = [[] for _ in range(N)]
for i in range(N):
    for j in range(int(input())):
        x, y = map(int, input().split())
        proof[i].append([x-1, y])

ans = 0
for i in range(1, 2**N):
    flag = 0
    for j in range(N):
        if (i>>j) & 1 == 1:
            for x, y in proof[j]:
                if (i>>x)&1 != y:
                    flag = 1
                    break
    if flag == 0:
        ans = max(ans, bin(i)[2:].count('1'))
print(ans)
n,q=map(int,input().split())
s=input()
i=0
d=""
while i<n:
	if s[i]=="A" and s[i+1]=="C":
		d+="0"*2
		i+=2
	else:
		d+=s[i]
		i+=1
num=[0]*n
cnt=0
for i in range(n):
	if d[i]=="0":
		cnt+=1
	num[i]=cnt//2
for i in range(q):
	x,y=map(int,input().split())
	print(num[y-1]-num[x-1])


### FIXED CODE ###

n,q=map(int,input().split())
s=input()
i=0
d=""
while i<n-1:
	if s[i]=="A" and s[i+1]=="C":
		d+="0"*2
		i+=2
	else:
		d+=s[i]
		i+=1
d+=s[-1]
num=[0]*n
cnt=0
for i in range(n):
	if d[i]=="0":
		cnt+=1
	num[i]=cnt//2
for i in range(q):
	x,y=map(int,input().split())
	print(num[y-1]-num[x-1])
h,w,k = list(map(int,input().split()))
arr = [[int(i) for i in input()] for _ in range(h)]

from itertools import product
ans = [0]*(2**(h-1))

for idx,cond in enumerate(product((True,False),repeat=h-1)):
    div = sum(cond)
    spl = [arr[0][:]]
    for i in range(h-1):
        if h_cond[i]:
            spl.append(arr[i+1][:])
        else:
            spl[-1] = [spl[-1][j] + arr[i+1][j] for j in range(w)]
    num = len(spl)
    cnt = [0]*num
    
    for v in range(w):
        tmp = [spl[i][v] for i in range(num)]
        if max(tmp) > k:
            break
        if max([cnt[i] + tmp[i] for i in range(num)]) > k:
            div += 1
            cnt = tmp[:]
        else:
            cnt  = [cnt[i] + tmp[i] for i in range(num)]
    else:    
        ans = min(ans,div)
            
print(min(ans))

### FIXED CODE ###

h,w,k = list(map(int,input().split()))
arr = [[int(i) for i in input()] for _ in range(h)]

from itertools import product
ans = 2000

for idx,cond in enumerate(product((True,False),repeat=h-1)):
    div = sum(cond)
    spl = [arr[0][:]]
    for i in range(h-1):
        if cond[i]:
            spl.append(arr[i+1][:])
        else:
            spl[-1] = [spl[-1][j] + arr[i+1][j] for j in range(w)]
    num = len(spl)
    cnt = [0]*num
    
    for v in range(w):
        tmp = [spl[i][v] for i in range(num)]
        if max(tmp) > k:
            break
        if max([cnt[i] + tmp[i] for i in range(num)]) > k:
            div += 1
            cnt = tmp[:]
        else:
            cnt  = [cnt[i] + tmp[i] for i in range(num)]
    else:    
        ans = min(ans,div)
            
print(ans)
#A = list(map(int, input().split()))
a, b, c = map(int, input().split())
k = int(input())
import math

if a >= b:
  p = int(math.log(a, b))
else:
  p = 0
  
if b*p*2 >= c:
  q = int(math.log(b*2*p, c))
else:
  q = 0
#print(p)
#print(q)

if (p + q) <= k:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

#A = list(map(int, input().split()))
a, b, c = map(int, input().split())
k = int(input())
import math

if a >= b:
  p = int(math.log(a/b,2)) +1
else:
  p = 0
  
if b*(2**p) >= c:
  q = int(math.log(b*(2**p)/c,2)) +1
else:
  q = 0
#print(p)
#print(q)

if (p + q) <= k:
  print("Yes")
else:
  print("No")
MOD = 1000000007

N, K = map(int, input().split())
uv = {}
for i in range(N-1):
    a, b = map(int, input().split())
    if a in uv:
        uv[a].append(b)
    else:
        uv[a] = [b]

    if b in uv:
        uv[b].append(a)
    else:
        uv[b] = [a]

f = 1
for u in uv:
    if len(uv[u]) == 1:
        f = u
        break
#print(uv)

ans = 1
b = [False] * (N+1)
ulist = [[f, 0]]
while ulist:
    u, pNum = ulist[-1]
    ulist.pop()
    b[u] = True

    uPtn = K - pNum
    ans = ans*uPtn % MOD

    #print(u)
    cnt = 1
    if pNum == 0:
        cnt = 0
    for v in uv[u]:
        if b[v]:
            continue
        ulist.append([v, 1 + cnt])
        cnt += 1

print(ans)


### FIXED CODE ###

MOD = 1000000007

N, K = map(int, input().split())
uv = {}
for i in range(N-1):
    a, b = map(int, input().split())
    if a in uv:
        uv[a].append(b)
    else:
        uv[a] = [b]

    if b in uv:
        uv[b].append(a)
    else:
        uv[b] = [a]

f = 1
for u in uv:
    if len(uv[u]) == 1:
        f = u
        break
#print(uv)

ans = 1
b = [False] * (N+1)
ulist = [[f, 0]]
while ulist:
    u, pNum = ulist[-1]
    ulist.pop()
    b[u] = True

    uPtn = K - pNum
    ans = ans*uPtn % MOD

    #print(u)
    cnt = 1
    if pNum == 0:
        cnt = 0
    if u in uv:
        for v in uv[u]:
            if b[v]:
                continue
            ulist.append([v, 1 + cnt])
            cnt += 1

print(ans)
n, a, b = [int(i) for i in input().split()]
ans = []
flag = False

while flag is False:
    ans += [1]*a
    ans += [0]*b
    if len(ans) > n:
        flag = True
        #print(ans)
print(sum(ans[:n]))

### FIXED CODE ###

n, a, b = [int(i) for i in input().split()]
l = min(n % (a+b),a)
s = n // (a+b)
print(s*a+l)
N, K, C = map(int, input().split())
S = input().strip()
dp1 = [0]*(N+2)
dp2 = [0]*(N+2)
c = 10*18
cc = 0
for i in range(N):
    if S[i] == "o" and c >= C:
        cc += 1
        c = 0
    else:
        c += 1
    dp1[i+1] = cc
c = 10*18
cc = 0
for i in range(N-1, -1, -1):
    if S[i] == "o" and c >= C:
        cc += 1
        c = 0
    else:
        c += 1
    dp2[i+1] = cc
rs = []
for i in range(N):
    if S[i+1] == "o" and dp1[i] + dp2[i+2] == K-1:
        rs.append(i+1)

#print(dp1, dp2)
for r in rs:
    print(r)


### FIXED CODE ###

N, K, C = map(int, input().split())
S = input().strip()
dp1 = [0]*(N+2)
dp2 = [0]*(N+2)
c = 10*18
cc = 0
for i in range(N):
    if S[i] == "o" and c >= C:
        cc += 1
        c = 0
    else:
        c += 1
    dp1[i+1] = cc
c = 10*18
cc = 0
for i in range(N-1, -1, -1):
    if S[i] == "o" and c >= C:
        cc += 1
        c = 0
    else:
        c += 1
    dp2[i+1] = cc
rs = []
for i in range(N):
    if S[i] == "o" and dp1[i] + dp2[i+2] == K-1 and dp1[i+1] + dp2[i+1] - 1 == K:
        rs.append(i+1)

#print(dp1, dp2)
for r in rs:
    print(r)
import numpy as np
h,w,m = map(int,input().split())
bomb = list(tuple(map(lambda x: int(x)-1,input().split())) for i in range(m))
bombX = [0]*w
bombY = [0]*h
for i,j in bomb:
    bombX[i] += 1
    bombY[j] += 1
maxX = max(bombX)
maxY = max(bombY)
maxX_index = list(i for i in range(h) if bombX[i] == maxX)
maxY_index = list(i for i in range(w) if bombY[i] == maxY)
for i in maxX_index:
    for j in maxY_index:
        if (i,j) not in bomb:
            print(maxX+maxY)
            exit()
print(maxX+maxY-1)


### FIXED CODE ###

h,w,m = map(int,input().split())
bombX = [0]*h
bombY = [0]*w
bomb = set()
maxX = maxY = 0
for i in range(m):
    i,j = map(lambda x:int(x)-1, input().split())
    bomb.add((i,j))
    bombX[i] += 1
    bombY[j] += 1
    maxX = max(maxX,bombX[i])
    maxY = max(maxY,bombY[j])
maxX_index = list(i for i in range(h) if bombX[i] == maxX)
maxY_index = list(i for i in range(w) if bombY[i] == maxY)
for i in maxX_index:
    for j in maxY_index:
        if (i,j) in bomb: continue
        print(maxX+maxY)
        exit()
print(maxX+maxY-1)
import numpy as np
import itertools


N, M=map(int, input().split())
a =[]
c = []
for i in range(2*M):
  if i%2 == 0:
    temp,_=map(int, input().split()) 
    a.append(temp)
  else:
    temp=list(map(int, input().split()))
    c.append(temp)
a = np.array(a) 

row = 2**M 
con = [bin(i)[2:].zfill(M) for i in range(row)]
boo = np.array([[int(j[i]) for i in range(M)] for j in con])
table = np.zeros((row,N), dtype = 'int8')

for i in range(row):
    ind_temp = np.array(list(set(itertools.chain.from_iterable(c*boo[i]))),dtype = int) -1
    table[i][ind_temp] = 1

ind = np.where(np.all(table, axis=1))
price = np.array([np.sum(a*boo[ind], axis = 1)])
if price:
    print(np.min(price))
else:
    print(-1)

### FIXED CODE ###

N, M = map(int, input().split())
Inf = 10**8
Dp = [Inf]*(2**N)
Dp[0] = 0

for i in range(M): #カギiで
    a,_=map(int, input().split())
    c = list(map(int, input().split()))
    d = sum((1<<p-1) for p in c) #iで開けられる宝箱の2bit表記
    for j in range(2**N):
        ope = j|d
        Dp[ope] = min(Dp[ope], Dp[j] + a)

if Dp[-1] == Inf:
    print(-1)
else:
    print(Dp[-1])
A = input()
B = input()
C = input()

if A[-1]==B[0] and B[-1] == C[0]:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

A,B,C = input().split()
if A[-1]==B[0] and B[-1] == C[0]:
    print("YES")
else:
    print("NO")
import math
from functools import reduce

N = int(input())
ANs = list(map(int,input().split()))

def lcm_base(x, y):
	return (x * y) // math.gcd(x, y)
	
lcmNum = ANs[0]
for a in ANs[1:]:
	lcmNum = lcm_base(lcmNum,a)
	
#print(lcmNum)

f = 0
for a in ANs:
	f += (lcmNum-1)%a
print(f)

### FIXED CODE ###

N = int(input())
ANs = list(map(int,input().split()))

m_1 = 0
for a in ANs:
	m_1 += a-1
	
print(m_1)
S = int(input())
s = int(input())
a = int(h = (S / 3600), m = ((S % 3600) / 60), for s in range(0, 60))
print('a')

### FIXED CODE ###

S = int(input())

s = S % 60
m = S // 60 % 60
h = S // 60 // 60

print("{0}:{1}:{2}".format(h,m,s))
x=raw_input().split()

for i in range(len(x))
print x[::-1]

### FIXED CODE ###

n = int(raw_input())
a = map(int,raw_input().split())
a.reverse()
for i in a:
    print i,
#abc108 a
k=int(input())
ans=0
for i in range(2,k+1):
    for j in range(2,k+1):
        if i%2==0 and j%2==1:
            cnt+=1
print(ans)


### FIXED CODE ###

#abc108 a
k=int(input())
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        if i%2==0 and j%2==1:
            ans+=1
print(ans)
h,w=map(int,input().split())
c=list(h)
for i in range(h):
  c[i]=input()
  
for i in range(h):
  print(c[i])
  print(c[i])

### FIXED CODE ###

h,w=map(int,input().split())
c=[input() for i in range(h)]
  
for i in range(h):
  print(c[i])
  print(c[i])
s=input()
t=input()
if s.sort() == t.sort():
  print("Yes")
else:
  print("No")


### FIXED CODE ###

s=list(input())
t=list(input())
for i in range(len(s)):
  if s==t:
    print("Yes")
    exit()
  s.append(s[0])
  s=s[1:]
print("No")
a, b, k = map(int,input().split())
if a <= k:
  print(0,(b - k + a), sep=" ")
elif a+b => k:
  print((a-k),b,sep=" ")
else:
  print(0, 0,sep+" ")

### FIXED CODE ###

a, b, k = map(int,input().split())
if a >= k:
  print(a-k, b)
elif k-a <= b:
  print(0, b-k+a)
else:
  print(0, 0)
input = list(map(int, input().split()))
N = input[0]
M = input[1]

if iN == M:
    print("Yes")
else:
    print("No")

### FIXED CODE ###


input = list(map(int, input().split()))
N = input[0]
M = input[1]

if N == M:
    print("Yes")
else:
    print("No")
a, b = map(int, input().split())
if a > 8 or b > 8:
  print(":(")
elif:
  print("Yay!")


### FIXED CODE ###

a, b = map(int, input().split())
if a <= 8 and b <= 8:
  print("Yay!")
else:
  print(":(")
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=-10**10
for st in range(N):
  now = st+1
  temp=[0]
  while(P[now-1] != st+1):
    temp.append(temp[-1]+C[P[now-1]-1])
    now = P[now-1]
    temp.append(temp[-1]+C[P[now-1]-1])
  if len(temp)>=K+1:
    ans=max(ans, max(temp[1:K+1]))
    continue
  if temp[-1]<=0:
    ans = max(ans, (max(temp[1:])))
  else::
    t=temp[-1]*(K//(len(temp)-1))-temp[-1]
    t+=max(temp+[temp[-1]+temp[i+1] for i in range(K%(len(temp)-1)+1)])
    ans=max(ans, t)
		
print(int(ans))


### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(lambda x: int(x) - 1, input().split()))
C = list(map(int, input().split()))

maxscore = -(10 ** 18)

for st in range(N):
	cumsum = [0]
	now = st
	while(P[now] != st):
		now = P[now]
		cumsum.append(cumsum[-1] + C[now])
	cumsum.append(cumsum[-1] + C[st])
	
	m = len(cumsum) - 1
	loopsum = cumsum[-1]
	
	if loopsum < 0:
		maxscore = max(maxscore, max(cumsum[1:min(K + 1, m + 1)]))
		continue
	
	score = (K // m - 1) * loopsum
	extended_cumsum = cumsum + [cumsum[i] + loopsum for i in range(1, K % m + 1)]
	score += max(extended_cumsum)
	maxscore = max(maxscore, score)
print(maxscore)
# -*- coding: utf-8 -*-

N, Q = tuple(map(int, input().split()))

tree = [[-1, 1]  for _ in range(N)] # [next, rank]

def find(i):
    if tree[i][0] == -1:
        group = i
    else:
        group = find(tree[i][0])
    
    return group

def unite(x, y):
    px = find(x)
    py = find(y)
    
    if tree[px][1] == tree[py][1]: # rank is same
        tree[py][0] = px
        tree[px][1] += 1
    else:
        if tree[px][1] < tree[py][1]:
            px, py = py, px
        tree[py][0] = px

for _ in range(Q):
    com, x, y = tuple(map(int, input().split()))
    if com: # same
        print(int(find(x) == find(y)))
    else: # unite
        unite(x, y)

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10000)
 
N, Q = tuple(map(int, input().split()))
 
tree = [[-1, 1]  for _ in range(N)] # [next, rank]
 
def find(i):
    if tree[i][0] == -1:
        group = i
    else:
        group = find(tree[i][0]) 
        tree[i][0] = group
    return group
 
def unite(x, y):
    px = find(x)
    py = find(y)
     
    if tree[px][1] == tree[py][1]: # rank is same
        tree[py][0] = px
        tree[px][1] += 1
    else:
        if tree[px][1] < tree[py][1]:
            px, py = py, px
        tree[py][0] = px
 
for _ in range(Q):
    com, x, y = tuple(map(int, input().split()))
    if com: # same
        print(int(find(x) == find(y)))
    else: # unite
        if not int(find(x) == find(y)):
            unite(x, y)
N,M = map(int,input().split())
List = list(map(int,input().split()))

a = [0,2,5,5,4,5,6,3,7,6]

kazu = [a[List[i]] for i in range(M)]

def dddd(kazu,X):
  dp = [ [ 0 for j in range(X+1)]  for i in range(M)]

  for i in range(M):
    for j in range(X):
      if kazu[i] <= j:
        dp[i][j+1] = max(dp[i][j+1-kazu[i]] + 1,dp[i-1][j+1])
      else:
        dp[i][j+1] = dp[i-1][j+1]
  return dp[-1][-1]
   
keta = dddd(kazu,N)
List.sort(reverse=True)
ans = []

for i in range(keta):
  for aa in List:
    k = a[aa]
    if N-k > 0:
      if dddd(kazu,N-k) == keta-i-1:
        ans.append(aa)
        N = N-k
        if N == 0:
          break
        continue
    elif N == k and keta-i-1 == 1:
      ans.append(aa)
      N = 0
  if N == 0:
    break
ans.sort(reverse=True)
print(int(''.join(map(str,ans))))

### FIXED CODE ###

N,M = map(int,input().split())
List = list(map(int,input().split()))

a = [0,2,5,5,4,5,6,3,7,6]

kazu = [a[List[i]] for i in range(M)]

def dddd(kazu,X):
  dp = [ [ -float('inf') for j in range(X+1)]  for i in range(M)]
  for i in range(M):
    dp[i][0] = 0

  for i in range(M):
    for j in range(X+1):
      if kazu[i] <= j:
        dp[i][j] = max(dp[i][j-kazu[i]] + 1,dp[i-1][j])
      else:
        dp[i][j] = dp[i-1][j]
  return dp[-1]
   
keta_arr = dddd(kazu,N)
keta = keta_arr[-1]
List.sort(reverse=True)
ans = []

while keta>0:
  for aa in List:
    k = a[aa]
    if N-k < 0:
      continue
    if N-k >= 0:
      if keta_arr[N-k] == keta-1:       
        ans.append(aa)
        N = N-k
        keta -= 1
        break
ans.sort(reverse=True)
print(int(''.join(map(str,ans))))
inp = raw_input()
list = inp.split()
x = int(list[0])
a = int(list[1])
b = int(list[2])
if abs(a-x)<abs(b-x):
  print('A')
else:
  print('B')


### FIXED CODE ###

inp = raw_input()#raw_input accept number and literary,input accept number only
list = inp.split()
x = int(list[0])
a = int(list[1])
b = int(list[2])
if abs(a-x)<abs(b-x):
  print('A')
else:
  print('B')
n,d = map(int,input().split())
for i in range(n):
    if (d*2+1)*i >= n:
        a = i
        break
print(a)

### FIXED CODE ###

n,d = map(int,input().split())
for i in range(1,n+1):
    if (d*2+1)*i >= n:
        a = i
        break
print(a)