Harryxun/stf_run huggingface dataset:
#Union Find

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

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

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


import sys
input = sys.stdin.readline

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

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

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

### FIXED CODE ###

#Union Find

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

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

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


import sys
input = sys.stdin.readline

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

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

for i in range(q):
    t,u,v = map(int,input().split())
    if t == 0:
        unite(u,v)
    elif same(u,v):
        print(1)
    else:
        print(0)
A, B, K = [int(x) for x in input().split()]
list_ = []
for k in range(1, min(A,B)):
  if A % k == 0 and B % k == 0:
    list_.append(k)
print(list_[len(list_)-K+1])

### FIXED CODE ###

A, B, K = [int(x) for x in input().split()]
list_ = []
for k in range(1, min(A,B)+1):
  if A % k == 0 and B % k == 0:
    list_.append(k)
print(list_[::-1][K-1])
import sys

lines = sys.stdin.readlines()
N, M, X = map(int, lines[0].split())
A = []
C = []

for i in range(N):
    line = list(map(int, lines[i+1].split()))
    A.append(line[1:])
    C.append(line[0])

# return []
def full_search():
    costs = []
    for i in range(2**N):
        vals = [0] * M
        cost = 0

        # iを二進数に直して扱う。それぞれのビットがn冊目の本を買うかどうかに匹敵。
        for j in range(N):
            # ビットを移動しながらn冊目の本を買う際のコストと経験値を計算する
            if ((i >> j) & 1):
                # 現在の組み合わせに対して
                # 全てのアルゴリズム分を計算
                cost += C[j]

                # 全てのアルゴリズム(m)に対して経験値を求める
                for m in range(M):
                    vals[m] += A[j][m]

        combination_ok = True
        for m in range(M):
            if vals[m] >= X:
                continue
            else:
                combination_ok = False
                break

        if combination_ok:
            costs.append(cost)
    return costs

costs = full_search()
if len(costs) == 0:
    print(-1)
else:
    print(min(costs))


### FIXED CODE ###

import sys

N, K = map(int, input().split())
A = list(map(int, input().split()))

i = 1
l = [1] * N
s = set([1])
n = 1
while True:
    n = A[n-1]
    if n in s:
        l = l[:i]
        mod = i - l.index(n)
        init_len = l.index(n)
        break
    else:
        l[i] = n
        s.add(n)
        i += 1

if K < init_len:
    print(l[K])
else:
    rest = ((K-init_len) % mod)
    print(l[init_len+rest])
import math

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

s_num = [0] * n
t_num = [0] * m
s_num[0], t_num[0] = 1, 1
l = n * m / math.gcd(n, m)

for i in range(1, n):
    s_num[i] = i * l / n + 1

for i in range(1, m):
    t_num[i] = i * l / m + 1

match_num = list(set(s_num) & set(t_num))
ans = l

for i in range(len(match_num)):
    s_str = s[s_num.index(match_num[i])]
    t_str = t[t_num.index(match_num[i])]

    if s_str != t_str:
        print('-1')
        exit()

print(int(ans))


### FIXED CODE ###

import fractions


def binary_search(list, number, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) // 2
        guess = list[mid][0]
        if guess == number:
            if list[mid][1] == item:
                return False
            else:
                return True
        if guess > number:
            high = mid - 1
        else:
            low = mid + 1
    # 見つからなかったとき
    return False


n, m = map(int, input().split())
s = input()
t = input()
check = []
l = n * m // fractions.gcd(n, m)
for i in range(n):
    check.append([i * l // n, s[i]])
for i in range(m):
    if binary_search(check, i * l // m, t[i]):
        print(-1)
        exit()
print(l)
def cmb(n, r, p):
	if (r < 0) or (n < r):
		return 0
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % p


def cmb(n, r, p):
	if (r < 0) or (n < r):
		return 0
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % p


p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
	fact.append((fact[-1] * i) % p)
	inv.append((-inv[p % i] * (p // i)) % p)
	factinv.append((factinv[-1] * inv[-1]) % p)


n,a,b=map(int,input().split())
ans=((pow(2,n)-1)%(10**9+7)-cmb(n,a,p)%p-cmb(n,b,p)%p)
print(int(ans))


### FIXED CODE ###

mod=10**9+7
n,a,b=map(int,input().split())
ans=pow(2,n,mod)-1 #n種類の花を使って花束を作る総数は2^n-1通り
comb1=1 #nCaの計算
for i in range(n-a+1,n+1): #n*(n-1)*…*(n-a+1)を計算
 comb1*=i
 comb1%=mod
for i in range(1,a+1): #1/a!=1/(1*2*…*a)=1^(p-2)*2^(p-2)*…*a^(p-2) (p=10**9+7)を計算
 comb1*=pow(i,mod-2,mod)
 comb1%=mod
comb2=1
for i in range(n-b+1,n+1): #n*(n-1)*…*(n-b+1)を計算
 comb2*=i
 comb2%=mod
for i in range(1,b+1): #1/b!=1/(1*2*…*b)=1^(p-2)*2^(p-2)*…*b^(p-2) (p=10**9+7)を計算
 comb2*=pow(i,mod-2,mod)
 comb2%=mod
ans-=(comb1+comb2) #nCa、nCbを総数から引く
ans%=mod
print(ans)
n,k = map(int, input().split())
H = sorted(list(map(int, input().split())))
if k >= n: ans = 0
elif k == 0: ans = sum(H)
else: ans = sum(H[-k])
print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
H = list(map(int, input().split()))
H.sort()
for i in range(K):
  if len(H) <= 0:
    break
  H.pop(-1)
print(sum(H) if len(H) > 0 else 0)
from math import ceil
from itertools import permutations
from heapq import *
from collections import defaultdict
from copy import deepcopy
from math import log
N,K=map(int,input().split())
AB=[0]*N
dic=defaultdict(int)
n=int(ceil(log(K,2)))+1
for i in range(N):
    a,b=map(int,input().split())
    if a in dic.keys():
        AB[dic[a]]=[a,AB[dic[a]][1]+b]
    else:
        dic[a]=i
        AB[i]=[a,b]
        n=max(n,int(ceil(log(a,2)))+1)
AB_=[]
for i in AB:
    if i==0:
        continue
    k=bin(i[0])[2:].zfill(n)
    AB_.append([k,i[1]])
AB=AB_
k=bin(K)[2:].zfill(n)
l=len(AB)
Klist=[k]
for i in range(n):
    if k[i]=="1":
        if i+1>=len(k)-1:
            Klist.append(k[:i]+"0")
            continue
        Klist.append(k[:i]+"0"+"1"*len(k[i+1:]))
#print(Klist)
ans=0
for i in Klist:
    sum=0
    for j,h in AB:
        if int(i,2)|int(j,2)<=int(i,2):
            #print(i,j,int(i,2)|int(j,2),int(i,2))
            sum+=h
    ans=max(sum,ans)
print(ans)


### FIXED CODE ###

N,K=map(int,input().split())
AB=[]
for i in range(N):
    a,b=map(int,input().split())
    AB.append([a,b])
ans=sum([b for a,b in AB if K|a==K])

for i in range(int.bit_length(K)-1,0,-1):
    if not K &(1<<i):
        continue
    m=K & ~(1<<i)|(1<<i)-1
    s=sum([b for a,b in AB if m | a ==m])
    ans=max(s,ans)
print(ans)
s = list(input())

flag = 0
pos_a, pos_z = 1, 1
length = 0

for i, ltr in enumerate(s, 1):
  if ltr == 'A':
    pos_a = i
    flag = 1
  elif ltr == 'Z' and flag == 1:
    pos_z = i
      if pos_z - (pos_a -1) > length:
        length = pos_z - (pos_a -1)
      else:
        flag = 0

print(length)

### FIXED CODE ###

s = list(input())

flag = 0
pos_a, pos_z = 1, 1
length = 0

for i, ltr in enumerate(s, 1):
  if ltr == 'A' and flag == 0:
    pos_a = i
    flag = 1
  elif ltr == 'Z' and flag == 1:
    pos_z = i
    if pos_z - (pos_a -1) > length:
      length = pos_z - (pos_a -1)
    else:
      flag = 0

print(length)
H,W = map(int,(input().split()))
a = [[] for _ in range(H)]
for i in range(H):
    a[i] = list(map(int,(input().split())))

ans = []
for i in range(H):
    for j in range(W-1):
        if a[i][j] %2 == 1:
            a[i][j+1] += 1
            ans.append([i+1,j+1,i+1,j+2])

for i in range(H-1):
    if a[i][W-1] %2 == 1:
        a[i+1][W-1] += 1
        ans.append(i+1,W,i+2,W)

print(len(ans))
for i in range(len(ans)):
    print(*ans[i])

### FIXED CODE ###

H,W = map(int,(input().split()))
a = [[] for _ in range(H)]
for i in range(H):
    a[i] = list(map(int,(input().split())))

ans = []
for i in range(H):
    for j in range(W-1):
        if a[i][j] %2 == 1:
            a[i][j+1] += 1
            ans.append([i+1,j+1,i+1,j+2])

for i in range(H-1):
    if a[i][W-1] %2 == 1:
        a[i+1][W-1] += 1
        ans.append([i+1,W,i+2,W])

print(len(ans))
for i in range(len(ans)):
    print(*ans[i])
for i in range(6):
  A[i]=int(input())
  
isOK=True
for i in range(5):
  for j in range(5):
    if(abs(A[i]-A[j]) > A[6]):
      isOK=False
      
if(isOK):
  print("Yay!")
else:
  print(":(")

### FIXED CODE ###

A=[0]*6
for i in range(6):
  A[i]=int(input())
  
isOK=True
for i in range(5):
  for j in range(i,5):
    if(abs(A[i]-A[j]) > A[5]):
      isOK=False
      
if(isOK):
  print("Yay!")
else:
  print(":(")
N = int(input())
ans = []
for i in range(1,N+1):
  for j in range(i+1,N+1):
    ans.append(sorted([i,j]))

if N%2==1:
  for i in range(1, N//2+1):
    del ans[ans.index(sorted([i, N-i]))]
else:
  for i in range(1, N//2+1):
    del ans[ans.index(sorted([i, N-i]))]

print(len(ans))
[print(*a) for a in ans]

### FIXED CODE ###

N = int(input())
ans = []
for i in range(1,N+1):
  for j in range(i+1,N+1):
    ans.append(sorted([i,j]))

if N%2==1:
  for i in range(1, N//2+1):
    del ans[ans.index(sorted([i, N-i]))]
else:
  for i in range(1, N//2+1):
    del ans[ans.index(sorted([i, N-i+1]))]

print(len(ans))
[print(*a) for a in ans]
def mi(): return map(int,input().split())
def lmi(): return list(map(int,input().split()))
def ii(): return int(input())
def isp(): return input().split()
 
n=ii()
a=lmi()
suma=sum(a)
counter=[0]*(10**5)
for i in a:
  counter[i]+=1
#print(counter)
q=ii()
 
for i in range(q):
  b,c=mi()
  suma+=(c-b)*counter[b]
  
  counter[c]+=counter[b]
  counter[b]=0
  #print(counter)
  print(suma)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
suma=sum(a)
q=int(input())
b=[]
c=[]
for i in range(q):
  b_,c_=map(int,input().split())
  b.append(b_)
  c.append(c_)

counter=[0]*(10**5+1)
for i in a:
  counter[i]+=1
new_sum=suma
for i in range(q):
  new_sum=new_sum-b[i]*counter[b[i]]+c[i]*counter[b[i]]
  
  counter[c[i]]+=counter[b[i]]
  counter[b[i]]=0
  print(new_sum)
N, X = map(int,input().split())
L = list(map(int,input().split()))

ans = 0
D = 0
for i in range(N + 1):
  if D <= X:
    D += L[i]
    ans += 1
  else:
    break

print(ans)


### FIXED CODE ###

N, X = map(int,input().split())
L = list(map(int,input().split()))

ans = 0
D = 0
for i in range(N + 1):
  if i == 0:
    ans += 1
  else:
    D += L[i - 1]
    if D <= X:
      ans += 1
    else:
      break

print(ans)
a, b = map(int, input().splot())
print(str(a * b) + str(2 * a + 2 * b))


### FIXED CODE ###

a, b = map(int, input().split())
print(str(a * b) + " " + str(2 * a + 2 * b))
import math
N = int(input())
A = list(map(int, input().split()))
a = 0
for i in range(N):
    a = math.gcd(a, A[i])
print(a)


### FIXED CODE ###

import fractions
N = int(input())
A = list(map(int, input().split()))
a = 0
for i in range(N):
    a = fractions.gcd(a, A[i])
print(a)
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    X, Y, A, B, C = map(int, input().split())
    p = sorted(list(map(int, input().split())), reverse=True)
    q = sorted(list(map(int, input().split())), reverse=True)
    r = sorted(list(map(int, input().split())), reverse=True)

    ans = 0
    i = 0 # pのindex
    j = 0 # qのindex
    k = 0 # rのindex
    for l in range(X):
        if p[i] < r[k] and k < C:
            ans += r[k]
            k += 1
        else:
            ans += p[i]
            i += 1
            

    for l in range(Y):
        if q[j] < r[k] and k < C:
            ans += r[k]
            k += 1
        else:
            ans += q[j]
            j += 1
    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    X, Y, A, B, C = map(int, input().split())
    p = sorted(list(map(int, input().split())), reverse=True)
    q = sorted(list(map(int, input().split())), reverse=True)
    r = sorted(list(map(int, input().split())), reverse=True)

    now = sum(p[:X]) + sum(q[:Y])
    ans = now
    i = X-1
    j = Y-1

    for k in range(min(C,X+Y)):
        if i < 0:
            now += r[k]-q[j]
            j -= 1
        elif j < 0:
            now += r[k]-p[i]
            i -= 1
        elif p[i] < q[j]:
            now += r[k]-p[i]
            i -= 1
        else:
            now += r[k]-q[j]
            j -= 1
        ans = max(ans,now)
    print(ans)

if __name__ == "__main__":
    main()
nCr = {}


def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = cmb(n-1, r) + cmb(n-1, r-1)
    nCr[(n, r)] = nCr[(n, r)]
    return nCr[(n, r)]


def acinput():
    return list(map(int, input().split(" ")))


N = int(input())
dct = {}

for i in range(N):
    tmp = input()
    #print("head   ",tmp)
    tmp = "".join(sorted(tmp))
    try:
        dct[tmp] += 1
    except:

        dct[tmp] = 1


res = 0
for sdct in dct:
    if dct[sdct] > 1:
        res += cmb(dct[sdct], 2)

print(res)



### FIXED CODE ###


import sys

sys.setrecursionlimit(1000000)

nCr = {}


def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = cmb(n-1, r) + cmb(n-1, r-1)
    nCr[(n, r)] = nCr[(n, r)]
    return nCr[(n, r)]


def acinput():
    return list(map(int, input().split(" ")))


N = int(input())
dct = {}

for i in range(N):
    tmp = input()
    #print("head   ",tmp)
    tmp = "".join(sorted(tmp))
    try:
        dct[tmp] += 1
    except:

        dct[tmp] = 1


res = 0
for sdct in dct:
    if dct[sdct] > 1:
        res += cmb(dct[sdct], 2)

print(res)


#print(dct)
n = int(input())
s = []
for i in range(n):
    s += [int(input())]

if sum(s) % 10 != 0:
    print(sum(s))
else:
    a = []
    for i in range(n):
        a += [s[i]]
        if a[i] % 10 != 0 and (sum(s) - sum(a)) % 10 != 0:
            print(sum(s) - sum(a))
            f = 0
            exit()
        else:
            f = 1
if f:
    print(0)

### FIXED CODE ###

n = int(input())
s = []
for i in range(n):
    s += [int(input())]
s = sorted(s)
a = sum(s)
if a % 10 != 0:
    print(a)
    exit()
else:
    for i in range(n):
        if s[i] % 10 != 0:
            a -= s[i]
            if a % 10 != 0:
                print(a)
                f = 0
                exit()
        else:
            f = 1
if f:
    print(0)
H, W = int(input().split())
h, w = int(input().split())

print((H - h) * (W - w))


### FIXED CODE ###

H, W = map(int, input().split())
h, w = map(int, input().split())

print((H - h) * (W - w))
n = int( input())
A = list( map( int, input().split()))
ansp = 0
sums = A[0]
if sums == 0:
    ansp += 1
    sums += 1
for i in range(1,n-1):
    sums += A[i]
    if i%2 == 1:
        if sums < 0:
            pass
        else:
            ansp += abs(-1-sums)
            sums = -1
    else:
        if sums > 0:
            pass
        else:
            ansp += abs(1 - sums)
            sums = 1
if (n-1)%2 == 0:
    if A[n-1] > 0:
        sums += A[n-1]
        pass
    else:
        ansp += abs(1-A[n])
        sums += 1
else:
    if A[n-1] < 0:
        sums += A[n-1]
        pass
    else:
        ansp += abs(-1-A[n-1])
        sums -= 1
if sums == 0:
    ansp += 1

sums = A[0]
ansm = 0
if sums == 0:
    ansm += 1
    sums -= 1
for i in range(1,n-1):
    sums += A[i]
    if i%2 == 0:
        if sums < 0:
            pass
        else:
            ansm += abs(-1-sums)
            sums = -1
    else:
        if sums > 0:
            pass
        else:
            ansm += abs(1 - sums)
            sums = 1
if (n-1)%2 == 1:
    if A[n-1] > 0:
        sums += A[n-1]
        pass
    else:
        ansm += abs(1-A[n-1])
        sums += 1
else:
    if A[n-1] < 0:
        sums += A[n-1]
        pass
    else:
        ansm += abs(-1-A[n-1])
        sums -= 1
if sums == 0:
    ansm += 1
print( min(ansp, ansm))

### FIXED CODE ###

N = int( input())
A = list( map( int, input().split()))
ans = 10**15
for i in [1, -1]:
    ansi, sums = 0, 0
    for a in A:
        sums += a
        if sums*i <= 0:
            ansi += abs(sums-i)
            sums = i
        i *= -1
    ans = min( ans, ansi)
print(ans)
#!/usr/bin/env python3
import sys

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(n+1):
        if is_prime[i]:
            yield i

def gcd(a,b):
    while b != 0:
        a,b = b,a%b
    return a

def solve(A: int, B: int):
    G = gcd(A,B)
    P = primes(G)

    n = 1
    for p in P:
        if A % p == 0 and B % p == 0:
            n += 1

    print(n)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import math

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(n+1):
        if is_prime[i]:
            yield i

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

def cf(x1,x2):
    for i in range(1,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            yield i

def gcd(a,b):
    while b != 0:
        a,b = b,a%b
    return a

def prime_factorize(n):
    a = set()
    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
    if n != 1:
        a.add(n)
    return a


def solve(A: int, B: int):
    AP = prime_factorize(A)
    BP = prime_factorize(B)
    print(len(AP & BP) + 1)

    return



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()
N, K = map(int, input().split())
x = list(map(int,input().split()))


#最初と最後だけ調べればOK
for i in range(N - K + 1):
    tmp_min = x[i]
    tmp_max = x[i + K - 1]

    if tmp_min < 0:
        #混合の場合
        if tmp_max < 0:
            #+に先に行く場合
            if abs(tmp_min) > tmp_max:
                tmp = tmp_max * 2
                tmp += abs(tmp_min)
            #-に先に行く場合
            else:
                tmp = abs(tmp_min) * 2
                tmp += tmp_max
        #すべてマイナスの場合
        else:
            tmp = abs(tmp_min)
    else:
        tmp = tmp_max
    ans = min(ans, tmp)
print(ans)





### FIXED CODE ###

N, K = map(int, input().split())
x = list(map(int,input().split()))

ans = 100000000000
#最初と最後だけ調べればOK
for i in range(N - K + 1):
    tmp_min = x[i]
    tmp_max = x[i + K - 1]
    tmp = 0
    if tmp_min < 0:
        #混合の場合
        if tmp_max > 0:
            #+に先に行く場合
            if abs(tmp_min) > tmp_max:
                tmp = tmp_max * 2
                tmp += abs(tmp_min)
            #-に先に行く場合
            else:
                tmp = abs(tmp_min) * 2
                tmp += tmp_max
        #すべてマイナスの場合
        else:
            tmp = abs(tmp_min)
    else:
        tmp = tmp_max
    ans = min(ans, tmp)
print(ans)
while True:
	try:
		a,b = map(int, input.split(" "))
		print(len(str(a + b)))
     
	expect: break


### FIXED CODE ###

while True:
  try:
    a, b = map(int, input().split(" "))
    print(len(str(a + b)))

  except:
    break
s = input()

flg = "AC"

if s[0] != "A":
    flg ="WA"

if {"C"}  <= set(list(s)[2:-2]):
    pass
elif list(s)[2:-2].count("C") !=1
    flg = "WA" 
else:
    flg ="WA"

a = [chr(i) for i in range(97, 97+26)]
a.append("A")
a.append("C")
if  set(list(s)) <= set(a):
    pass
else:
    flg == "WA"
    
print(flg)


### FIXED CODE ###

s = list(input())

a = [chr(i) for i in range(97, 97+26)]
A = [chr(i) for i in range(65, 65+26)]

flg = "AC"

if not s[0] == "A":
    flg = "WA"

if not s[2:-1].count("C") ==1:
    flg = "WA"

b = set(s)-set(["A","C"])

if not b<=set(a):
    flg = "WA"

print(flg)
a = list(map(int,input().split()))
b = 0
c = 0
for i in a:
  if i == 5:
    b = b + 1
  if i == 7:
    c = c+1
if b ==2 and c==1:
  print(YES)
else:
  print(NO)

### FIXED CODE ###

a = list(map(int,input().split()))
b = 0
c = 0
for i in a:
  if i == 7:
    b += 1
  elif i == 5:
    c += 1
 
if b == 1 and c == 2:
  print("YES")
else:
  print("NO")
if X>=30:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

X = int(input())
if X>=30:
  print('Yes')
else:
  print('No')
ans1 = abs(N - K)
cnt = 0
if N > ans1:
    while True:
        ans2 = abs(ans1 - K)
        if ans1 > ans2:
            ans1 = ans2
            cnt = 1
            cnt += 1
        else:
            ANS = ans1
            break
elif N <= ans1:
    ANS = N

# print(ans1, ans2)
print(ANS)
# print(cnt)

### FIXED CODE ###

N, K = map(int, input().split())

t = N % K
ANS = min(t, K-t)
print(ANS)
x = input()
z = [a,b,c,d,e,f,g,h,i,j,k,l,n,m,o,p,q,r,s,t,u,v,w,x,y,z]
xi = z.index(x)
print(z[xi+a1])

### FIXED CODE ###

x = input()
z = ord(x)
xi = chr(z+1)
print(xi)
while True:
	try:
		N = map(int, input().split(' '))
		sums = N[0] + N[1]
		keta = list(str(sums))
		print(len(kata))
	except EOFError:
		break

### FIXED CODE ###

import sys
L = sys.stdin.readlines()
for line in L:
	N = line[:-1].split(' ')
	sums = int(N[0]) + int(N[1])
	print(len(str(sums)))
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0

for i in range(2**n):
    bulb = [0] * m
    for j in range(n):
        if i>>j & 1:
            for k in range(m):
                if j+1 in lst[k][1:]:
                    bulb[k] += 1


    if bulb[l] % 2 == p[l]:
        ans += 1

print (ans)


### FIXED CODE ###

n, m = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0

for i in range(2**n):
    bulb = [0] * m
    for j in range(n):
        if i>>j & 1:
            for k in range(m):
                if j+1 in lst[k][1:]:
                    bulb[k] += 1

    flag = True
    for l in range(m):
        if bulb[l] % 2 != p[l]:
            flag = False
    if flag:
        ans += 1

print (ans)