Harryxun/stf_run huggingface dataset:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import operator

N,H,W = map(int,readline().split())
RCA = [int(x) for x in read().split()]
it = iter(RCA)
RCA = sorted(zip(it,it,it),key=operator.itemgetter(2),reverse=True)

root = list(range(H+W))
size = [0] * (H+W)
no_cycle = [True] * (H+W)

def find_root(x):
    y = root[x]
    if x == y:
        return y
    z = find_root(y)
    root[x] = z
    return z

def merge(x,y):
    x,y = find_root(x),find_root(y)
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    no_cycle[x] = (no_cycle[x] and no_cycle[y])

answer = 0
for R,C,A in RCA:
    x,y = R-1,H+C-1
    rx,ry = find_root(x),find_root(y)
    if rx == ry:
        if not no_cycle[rx]:
            continue
        no_cycle[rx] = False
    else:
        if (not no_cycle[rx]) and (not no_cycle[ry]):
            continue
        merge(rx,ry)
    #answer += A

print(answer)


### FIXED CODE ###

import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N,H,W = map(int,readline().split())
RCA = [tuple(int(x) for x in line.split()) for line in readlines()]

RCA.sort(key = lambda x: -x[2])

RCA

root = list(range(H+W))
size = [0] * (H+W)
no_cycle = [True] * (H+W)

def find_root(x):
    y = root[x]
    if x == y:
        return y
    z = find_root(y)
    root[x] = z
    return z

def merge(x,y):
    x,y = find_root(x),find_root(y)
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    no_cycle[x] = no_cycle[x] and no_cycle[y]

answer = 0
for R,C,A in RCA:
    x,y = R-1,H+C-1
    rx,ry = find_root(x),find_root(y)
    if rx == ry:
        if not no_cycle[rx]:
            continue
        no_cycle[rx] = False
    else:
        if (not no_cycle[rx]) and (not no_cycle[ry]):
            continue
        merge(rx,ry)
    answer += A

print(answer)
N,K,M = input().split()
N = int(N)
K = int(K)
M = int(N)
A = input().split()
A = [int(s) for s in A]
AN = M * N - sum(A)
if (AN <= K) and (AN >= 0):
	print (AN)
elif AN < 0:
	print (0)
else:
	print (-1)

### FIXED CODE ###

a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
C = input()
if (C != 'z') and (C in a):
	i = a.index(C)
	print (a[i+1])
"""
考え方:
    頂点 n までの最大パスを, y = n である有向パスのすべての x の最大パス n' + 1 の中で最大のものから求める.
    x の最大パスが計算されていない場合は先に x の最大パスを同じ方法で求める.
    y = n となる有効パスが存在しない場合, n の最大パスは 0 とする. 有効閉路は存在しないのでループは発生しない.
    計算量は O(N + M) = O(2n) = O(n) .

提出一回目の反省:
    debug 用の print 外し忘れてた
    
"""


N, M = map(int, input().split())
Y = [[] for _ in range(N + 1)]
for _ in range(M):
    x, y = map(int, input().split())
    Y[y].append(x)

dp = [-1] * (N + 1)

def solve(num):
    re = 0
    if dp[num] != -1:
        # すでに計算済みのパスは再計算しない.
        re = dp[num]
    else:
        for x in Y[num]:
            if dp[x] == -1:
                dp[x] = solve(x)
            re = max(re, dp[x] + 1)
    return re

for n in range(1, N + 1):
    dp[n] = solve(n)

print(max(dp))


### FIXED CODE ###

"""
考え方:
    頂点 n までの最大パスを, y = n である有向パスのすべての x の最大パス n' + 1 の中で最大のものから求める.
    x の最大パスが計算されていない場合は先に x の最大パスを同じ方法で求める.
    y = n となる有効パスが存在しない場合, n の最大パスは 0 とする. 有効閉路は存在しないのでループは発生しない.
    計算量は O(N + M) = O(2n) = O(n) .

提出1回目の反省:
    debug 用の print 外し忘れてた

提出2回目の反省:
    なぜ RE になるんじゃぁ
    -> python の最大再帰回数の問題である可能性. あんまりよくない気もするけど設定変更してみよう.
    
提出3回目の反省:
    10000 に設定してみたけどケース1_01ではじかれる. どうも設定値 - 1回目の呼び出しでエラーになるようだ.
    少し余裕をもって10020と設定.

提出4回目の反省:
    それでもケース1_01がダメ. なぜ...
    
"""

import sys
sys.setrecursionlimit(10 ** 6)


N, M = map(int, input().split())
Y = [[] for _ in range(N + 1)]
# print(len(Y), Y)
for _ in range(M):
    x, y = map(int, input().split())
    Y[y].append(x)

dp = [-1] * (N + 1)

def solve(num):
    re = 0
    if dp[num] != -1:
        # すでに計算済みのパスは再計算しない.
        re = dp[num]
    else:
        for x in Y[num]:
            if dp[x] == -1:
                dp[x] = solve(x)
            re = max(re, dp[x] + 1)
    return re

for n in range(1, N + 1):
    dp[n] = solve(n)

print(max(dp))
N = int(input())
A = [int(i) for i in input().split()]

res = [""] * N
for i in range(N):
  res[A[i]-1] = i+1

print(" ".join(res))


### FIXED CODE ###

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

res = [""] * N
for i in range(N):
  res[A[i]-1] = str(i+1)

print(" ".join(res))
A, B = list(map(int,(input().split())))
C = A - 2 * B
if C < 0:
  return 0
else :
  return C


### FIXED CODE ###

A, B = list(map(int,(input().split())))
C = A - 2 * B
if C < 0:
	C = 0
else :
	pass
print(C)
from random import randint
random.seed(0)

D = int(input())
C = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for j in range(D)]

def score_calc(T):
    total = 0
    last = [0] * 26
    for i in range(1, D+1):
        t = T[i-1]
        total += S[i-1][t-1]
        last[t-1] = i
        for j in range(26):
            total -= C[j] * (i - last[j])
    return total

total = 0
last = [0] * 26
ans = []
for i in range(1, D+1):
    score = [0] * 26
    for t in range(26):
        score[t] += S[i-1][t]
        for j in range(26):
            if j != t:
                score[t] -= C[j] * (i - last[j])
    total += max(score)
    last[score.index(max(score))] = i
    ans.append(score.index(max(score))+1)

N = 1000
Q = [[randint(0, (D-1)), randint(0, 25)] for i in range(N)]
for d, q in Q:
    old = ans[d]
    ans[d] = q + 1
    if score_calc(ans) > total:
        total = score_calc(ans)
    else:
        ans[d] = old

for i in range(D):
    print(ans[i])

### FIXED CODE ###

D = int(input())
C = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for j in range(D)]

total = 0
last = [0] * 26
ans = []
for i in range(1, D+1):
    score = [0] * 26
    for t in range(26):
        score[t] += S[i-1][t-1]
        for j in range(26):
            if j != t:
                score[t] -= C[j] * (i - last[j])
    total += max(score)
    last[score.index(max(score))] = i
    ans.append(score.index(max(score))+1)

for i in range(D):
    print(ans[i])
def gcd(x, y):
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

def lcm(x, y):
    return x // gcd(x, y) * y

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

l = 1
for i in range(n):
    a[i] //= 2
    l = lcm(a[i], l)

flg = True
for x in a:
    if (l / x) % 2 == 0:
        flg = False
        continue

if flg:
    print(m // l - m // (l * 2))
else:
    print(0)

### FIXED CODE ###

def gcd(x, y):
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

def lcm(x, y):
    return x // gcd(x, y) * y

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

l = 1
for i in range(n):
    a[i] //= 2
    l = lcm(a[i], l)

flg = True
for x in a:
    if (l // x) % 2 == 0:
        flg = False
        break

if flg:
    print(m // l - m // (l * 2))
else:
    print(0)
K = int(input())
S = input()
if len(S) > K:
    new_S = S[:K]
    new_S += '...'
    print(new_S)
else:
    print(S)

### FIXED CODE ###

N = int(input())
 
if N % 10 == 3:
	print('bon')
elif N%10 == 0 or N%10 == 1 or N%10 == 6 or N%10 == 8:
	print('pon')
else: print('hon')
n,m = map(int,input().split())
a = [0]*n
b = [0]*n
c = [0]*m
d = [0]*m

for i in range(n):
    a[i],b[i] = map(int,input().split())
for i in range(m):
    c[i],d[i] = map(int,input().split())
    
D = [[0]*m]*n
for i in range(n):
    for j in range(m):
        D[i][j] = abs(a[i]-c[i])+abs(b[i]-d[i])

for i in range(n):
    print(D[i].index(min(D[i]))+1)

### FIXED CODE ###

n,m = map(int,input().split())
a,b = [[] for i in range(n)],[[] for i in range(n)]
c,d = [[] for i in range(m)],[[] for i in range(m)]
for i in range(n):
    a[i],b[i] = map(int,input().split())
for i in range(m):
    c[i],d[i] = map(int,input().split())

check = [[] for i in range(m)]
for i in range(n):
    for j in range(m):
        check[j] = abs(a[i]-c[j])+abs(b[i]-d[j])
    print(check.index(min(check))+1)
N = int(input())

# 最初の符号
print(0, flush=True)
first = input()

if first == 'Vacant':
    exit()

if first == 'Male':
    first = 1
else:
    first = -1

notHas = 1
has = N - 1

while has - notHas > 1:
    print('--{} , {}--'.format(notHas, has))
    mid = (notHas + has) // 2
    print(mid, flush=True)
    ret = input()

    if ret == 'Vacant':
        exit()

    if ret == 'Male':
        ret = 1
    else:
        ret = -1

    trueValue = first * (-1)**(mid % 2)
    if ret == trueValue:
        notHas = mid
    else:
        has = mid

print(notHas, flush=True)
ret = input()

if ret == 'Vacant':
    exit()

print(has, flush=True)
exit()

### FIXED CODE ###

N = int(input())

# 最初の符号
print(0, flush=True)
first = input()

if first == 'Vacant':
    exit()

if first == 'Male':
    first = 1
else:
    first = -1

notHas = 1
has = N - 1

while has - notHas > 1:
    mid = (notHas + has) // 2
    print(mid, flush=True)
    ret = input()

    if ret == 'Vacant':
        exit()

    if ret == 'Male':
        ret = 1
    else:
        ret = -1

    trueValue = first * (-1)**(mid % 2)
    if ret == trueValue:
        notHas = mid
    else:
        has = mid

print(notHas, flush=True)
ret = input()

if ret == 'Vacant':
    exit()

print(has, flush=True)
input()
exit()
class Telp:
    def __init__(self, to, idx):
        self.to = to
        self.idx = idx
        self.visited = False
        self.step = -1

    def visit(self, step):
        self.visited = True
        self.step = step

    def is_visited(self):
        return self.visited


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

a = list(map(int, input().split()))

net = {}

for i in range(n):
    net[i] = Telp(a[i], i)

current = net[0]
count = 0
path = [0]

while not current.visited:
    # print(current.to)
    current.visit(count)
    current = net[current.to - 1]
    path.append(current)
    count += 1
    # print("count", count)

offset = current.step
loop = count - offset
fact_idx = (k - offset) % loop

# print("count, offset, loop, fact_idx", count, offset, loop, fact_idx)
# print("ans", path[offset + fact_idx - 1].to)

print(path[offset + fact_idx - 1].to)


### FIXED CODE ###

class Telp:
    def __init__(self, to, idx):
        self.to = to
        self.idx = idx
        self.visited = False
        self.step = -1

    def visit(self, step):
        self.visited = True
        self.step = step

    def is_visited(self):
        return self.visited


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

a = list(map(int, input().split()))

net = {}

for i in range(n):
    net[i] = Telp(a[i], i)

current = net[0]
count = 0
path = []

while not current.visited:
    # print(current.to)
    path.append(current)
    current.visit(count)
    current = net[current.to - 1]
    count += 1
    if count == k:
        print(path[-1].to)
        exit(0)
    # print("count", count)

offset = current.step
loop = count - offset
fact_idx = (k - offset) % loop

# print("count, offset, loop, fact_idx", count, offset, loop, fact_idx)
# print("ans", path[offset + fact_idx - 1].to)

print(path[offset + fact_idx - 1].to)
N = int(input())
SList = []
PList = []
dic = {}
Slist = []
aa = []
for _ in range(N):
    S, P = input().split()
    dic[S] = int(P)
    Slist.append(S)
    aa.append((int(P), S))
dic = sorted(dic.items())

sortedS = list(sorted(set(Slist)))

for i in range(len(sortedS)):
    tempV = []
    tempI = []
    for j in range(N):
        if aa[j][1] == sortedS[i]:
            tempV.append(aa[j][0])
            tempI.append(j)
    indexList = np.argsort(tempV)
    for k in reversed(indexList):
        print(tempI[k] + 1)


### FIXED CODE ###

A, P = map(int, input().split())
P = A * 3 + P
print(int(P // 2))
N, M = map(int, input().split( ))
datas = list(map(int, input().split( )))
datas.sort()
Ms = M - 1

dest = list()
K = 0
i = 0
for i in range(Ms):
  K = datas[i+1] - datas[i]
  dest.append(K)
  dest.sort()

L = 0
MN = M - N

for j in range(MN):
  L = L + dest[j]

print(L)

### FIXED CODE ###

a, b = map(int, input().split( ))
k = round((a / b), 10)
print("{0:.10f}".format(k))
import sys

i = 0
x = 1

while x != 0:
  x = sys.stdin.readline()
  i += 1
  print 'Case %d: %s', %(i,x)
  

### FIXED CODE ###

i = 0
d = 0

while d == 0:
    x = input()
    if x != 0:
        i += 1
        print("Case %d: %d" %(i, x))
    else:
        d = 1
def rep(N,X):
    if N == 1:
        if X == 1 or X == 5:
            return(0)
        else:
            return(X-1)
    elif X == 1:
        return(0)
    else:
        n = 2**(N+2)-3
        a = n//2-(X-1)
        p = 2**N-1
        if a < -1:
            return(rep(N-1, abs(a)) + p + 1)
        elif a == -1 or a == 0 or a == 1:
            return(p + 1)
        else:
            return(rep(N-1, X-1))
print(rep(N,X))

### FIXED CODE ###

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

def rep(N,X):
    if N == 1:
        if X == 1:
            return(0)
        elif X == 5:
            return(3)
        else:
            return(X-1)
    elif X == 1:
        return(0)
    else:
        n = 2**(N+2)-3
        p = 2**N-1 # N-1のPの個数
        if X <= n//2:
            return(rep(N-1, X-1))
        elif X == n//2+1:
            return(p + 1)
        else:
            if n-1 == X-1:
                return(rep(N-1, X-1-n//2-1) + p + 1)
            else:
                return(rep(N-1, X-1-n//2) + p + 1)
print(rep(N,X))
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 8 + 1
dp = [inf] * n
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
    for j in range(1, k):
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
print(dp[n - 1])

### FIXED CODE ###

n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])
def main():
  out = 0
  for i in range(1, n+1):
    if dp[i]:
      out = max(out, dp[i])
    else:
      out = max(out, cal(i))
  print(out)

def cal(a):
  if xy[a]:
    ans = []
    for b in xy[a]:
      num = cal(b)
      dp[b] = num
      ans.append(num+1)
    return max(ans)
  return 0

if __name__ == "__main__":
  n, m = map(int, input().split())
  xy = [set() for _ in range(n+1)]
  dp = [None]*(n+1)
  for _ in range(m):
    x, y = map(int, input().split())
    xy[x].add(y)
  main()



### FIXED CODE ###

import sys

def main():
  out = 0
  for i in range(1, n+1):
    if dp[i]:
        di = dp[i]
        if di > out:
            out = di
    else:
        di = cal(i)
        if di > out:
            out = di
  print(out)

def cal(a):
  if xy[a]:
    ans = 0
    for b in xy[a]:
      if dp[b]:
        num = dp[b]
      else:
        num = cal(b)
        dp[b] = num
      if num+1 > ans:
        ans = num+1
    return ans
  return 0

if __name__ == "__main__":
  sys.setrecursionlimit(100000)
  n, m = map(int, input().split())
  xy = [set() for _ in range(n+1)]
  dp = [None]*(n+1)
  for _ in range(m):
    x, y = map(int, input().split())
    xy[x].add(y)
  main()
import numpy as np
S = np.array([list(map(int, input().split())) for _ in range(3)])
n = int(input())
for _ in range(n):
    S = np.where(S==int(input()), 0, S)
if min(np.sum(S, axis=0))==0 or min(np.sum(S, axis=1))==0:
    print('Yes')
    exit()
if (S[0][0] == 0 and S[1][1] == 0 and S[2][2]) or (S[2][0] == 0 and S[1][1] == 0 and S[0][2]):
    print('Yes')
    exit()
print('No')

### FIXED CODE ###

import numpy as np
S = np.array([list(map(int, input().split())) for _ in range(3)])
n = int(input())
for _ in range(n):
    S = np.where(S==int(input()), 0, S)
if min(np.sum(S, axis=0))==0 or min(np.sum(S, axis=1))==0:
    print('Yes')
    exit()
if (S[0][0] == 0 and S[1][1] == 0 and S[2][2] == 0) or (S[2][0] == 0 and S[1][1] == 0 and S[0][2] == 0):
    print('Yes')
    exit()
print('No')
n = input()
num = []
num = input().split(" ")
 
t = 0 
a=0 
while True: 
  num2=[] 
  for i in num: 
    if not (int(i)%2): 
     a =1 
       break 
    num2.append(int(i)%2) 
  num = num2 
  t+=1 
  if a==1: 
     print(t) 
     break

### FIXED CODE ###

n = input()
num = []
num = input().split(" ")
 
t = 0 
a=0 
while True: 
  num2=[] 
  for i in num: 
    if not int(i)%2==0:
      a =1
      break
    num2.append(int(i)/2)
  num = num2
  if a==1: 
     print(t) 
     break
  t+=1
a = int(input())
op = str(input())
b = int(input())
print(a + b if op == "+" else a - b)

### FIXED CODE ###

a, op, b = map(str, input().split())
a = int(a)
b = int(b)
print(a + b if op == "+" else a - b)
import numpy as np
H = input()
H = str.split(H)
H = np.array(H, int)
x = []
y = []
for i in range(len(H)):
    x.append(i%2)
    y.append((i+1)//2)
print(H == np.array(x))
print(H == np.array(y))
a = sum(H == np.array(x))
b = sum(H == np.array(y))

if(a>=b):
    print(len(H)-a)
else:
    print(len(H)-b)

### FIXED CODE ###

import numpy as np
tmp = str(input())

H = []
for i in range(len(tmp)):
    H.append(int(tmp[i]))

#print(H)
H = np.array(H, int)

#print(H)
x = []
y = []
for i in range(len(H)):
    x.append(i%2)
    y.append((i+1)%2)
#print(H == np.array(x))
#print(H == np.array(y))
a = sum(H == np.array(x))
b = sum(H == np.array(y))

if(a>=b):
    print(len(H)-a)
else:
    print(len(H)-b)
a,b,c = map(int,input().split())
print("YES" if a[-1] == b[0] and b[-1] == c[0] else "NO")

### FIXED CODE ###

a,b,c = input().split()
print("YES" if a[-1] == b[0] and b[-1] == c[0] else "NO")
N = int(input())
S = str(N)

f = 0
for i in range(len(N)):
    f += int(S[i])
if N % f == 0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

N = int(input())
S = str(N)

f = 0
for i in range(len(S)):
    f += int(S[i])
if N % f == 0:
    print("Yes")
else:
    print("No")
# input
h, w = [int(i) for i in input().split()]
ary = []
for y in range(h):
    line = input()
    ary.append(line)

pass


max_val = pow(10, 6)

def convert_ary(ary):
    # #. -> 0, 1, 2
    tmp = [[] for i in range(w)]
    for y in range(h):
        for x in range(w):
            tmp[y].append(None if ary[y][x] == '.' else 0)

    return tmp

ary = convert_ary(ary)

def upd_left(ary, y, x):
    if x == 0:
        return ary
    if ary[y][x-1] is None:
        ary[y][x-1] = ary[y][x] + 1
    else:
        ary[y][x-1] = min(ary[y][x-1], ary[y][x] + 1)
    return ary

def upd_right(ary, y, x):
    if x == w - 1:
        return ary
    if ary[y][x+1] is None:
        ary[y][x+1] = ary[y][x] + 1
    else:
        ary[y][x+1] = min(ary[y][x+1], ary[y][x] + 1)
    return ary

def upd_up(ary, y, x):
    if y == 0:
        return ary
    if ary[y-1][x] is None:
        ary[y-1][x] = ary[y][x] + 1
    else:
        ary[y-1][x] = min(ary[y-1][x], ary[y][x] + 1)
    return ary

def upd_down(ary, y, x):
    if y == h - 1:
        return ary
    if ary[y+1][x] is None:
        ary[y+1][x] = ary[y][x] + 1
    else:
        ary[y+1][x] = min(ary[y+1][x], ary[y][x] + 1)
    return ary

# from copy import deepcopy

def update_ary(ary):
    # tmp = deepcopy(ary)
    for y in range(h):
        for x in range(w):
            if ary[y][x] is None:
                continue
            ary = upd_left(ary, y, x)
            ary = upd_right(ary, y, x)
            ary = upd_up(ary, y, x)
            ary = upd_down(ary, y, x)
    return ary

def is_complete(ary):
    for line in ary:
        if None in line:
            return False
    return True

while not is_complete(ary):
    ary = update_ary(ary)

print(max(elem for line in ary for elem in line))


### FIXED CODE ###

# input
h, w = [int(i) for i in input().split()]
ary = []
for y in range(h):
    ary.append([None if i == '.' else 0 for i in input()])


from collections import deque

update_q = deque((y, x) for y, line in enumerate(ary) for x, elem in enumerate(line) if elem == 0)

def update(ary, update_q):
    for _ in range(len(update_q)):
        pos = update_q.popleft()
        y, x = pos
        if x > 0:
            uy, ux = y, x-1
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if x < w-1:
            uy, ux = y, x+1
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if y > 0:
            uy, ux = y-1, x
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
        if y < h-1:
            uy, ux = y+1, x
            if ary[uy][ux] is None:
                ary[uy][ux] = ary[y][x] + 1
                update_q.append((uy, ux))
    return ary, update_q


black_count = len(update_q)
update_count = 0
while black_count < w * h:
    ary, update_q = update(ary, update_q)
    black_count += len(update_q)
    update_count += 1


print(update_count)
N = int(input())
ls = []
w = []
for i in range(N):
  ls.append(str(input())
for j in range(1,N):
  if ls[j-1][(len(ls[j])-1):] and ls[j][(len(ls[j])-1):]
    if ls[j-1] in w:
      print("No")
    else:
      w.append(ls[j-1])
  else:
    print("No")
    break

### FIXED CODE ###

N = int(input())
word = []
S = input()
word.append(S)
flag = 0
for i in range(N-1):
  S = input()
  if S[0] == word[i][-1]:
    if S not in word:
      word.append(S)
    else:
      print("No")
      flag +=1
      break
  else:
    print("No")
    flag += 1
    break
if flag == 0:
  print("Yes")
print([i for i in input()[:int(input())]if i!="1"][0])

### FIXED CODE ###

s=input()
k=int(input())
for i in range(k):
    if s[i] !="1":
        print(s[i])
        exit()
print("1")
A = [list(map(int,input().split())) for i in range(3)]
N = int(input())
b = list(map(int,input().split()))
import numpy as np
A = np.array(A)
l = []
for i in range(N):
  if b[i] in A:
    l.append(tuple(nd[0] for nd in np.where(A == b[i])))
if (0, 0) in l and (1, 0) in l and (2, 0) in l:
  print("Yes")
elif (0, 0) in l and (1, 1) in l and (2, 2) in l:
  print("Yes")
elif (0, 1) in l and (1, 1) in l and (2, 1) in l:
  print("Yes")
elif (0, 2) in l and (1, 1) in l and (2, 0) in l:
  print("Yes")
elif (0, 2) in l and (1, 2) in l and (2, 2) in l:
  print("Yes")
elif (0, 0) in l and (0, 1) in l and (0, 2) in l:
  print("Yes")
elif (1, 0) in l and (1, 1) in l and (1, 2) in l:
  print("Yes")
elif (2, 0) in l and (2, 1) in l and (2, 2) in l:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

A = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for i in range(N)]
    
import numpy as np
A = np.array(A)
l = []
for i in range(N):
  if b[i] in A:
    l.append(tuple(nd[0] for nd in np.where(A == b[i])))
if (0, 0) in l and (1, 0) in l and (2, 0) in l:
  print("Yes")
elif (0, 0) in l and (1, 1) in l and (2, 2) in l:
  print("Yes")
elif (0, 1) in l and (1, 1) in l and (2, 1) in l:
  print("Yes")
elif (0, 2) in l and (1, 1) in l and (2, 0) in l:
  print("Yes")
elif (0, 2) in l and (1, 2) in l and (2, 2) in l:
  print("Yes")
elif (0, 0) in l and (0, 1) in l and (0, 2) in l:
  print("Yes")
elif (1, 0) in l and (1, 1) in l and (1, 2) in l:
  print("Yes")
elif (2, 0) in l and (2, 1) in l and (2, 2) in l:
  print("Yes")
else:
  print("No")
a,b = map(int, [i for i in input().split(' ')])
print a*2, b*2

### FIXED CODE ###

import sys
a,b = map(int, [i for i in sys.stdin.readline().split(" ")])
print a*b, (a+b)*2