Harryxun/stf_run huggingface dataset:
N = int(input())
dp = [[0]*(N+1) for _ in range(3)]
happy = [[0]*N for _ in range(3)]

for i in range(N):
    a, b, c = [int(s) for s in input().split()]
    happy[i][0] = a
    happy[i][1] = b
    happy[i][2] = c

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j!= k:
                dp[i+1][j] = max(dp[i+1][j], dp[i][j] + happy[i][k])

ans = max(dp[N][0],dp[N][1],dp[N][2])
print(ans)

### FIXED CODE ###

N = int(input())
dp = [[0]*3 for _ in range(N+1)]
happy = [[0]*3 for _ in range(N)]

for i in range(N):
    a, b, c = [int(s) for s in input().split()]
    happy[i][0] = a
    happy[i][1] = b
    happy[i][2] = c

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j!= k:
                dp[i+1][k] = max(dp[i+1][k], dp[i][j] + happy[i][j])

ans = max(dp[N][0],dp[N][1],dp[N][2])
print(ans)
input()
li=list(map(int,input().split()))
for i in li:
	sum+=li[i]
print(min(li),max(li),sum)


### FIXED CODE ###

input()
li=list(map(int,input().split()))
sum=0
for i in li:
	sum+=i
print(min(li),max(li),sum)
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, m = input().split(" ")

return comb(n, 2) + comb(m, 2)

### FIXED CODE ###

import math

def comb(n, r):
    try: 
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    except:
        return 0

raw = input()
n, m = [int(i) for i in raw.split(" ")]
 
print(comb(n, 2) + comb(m, 2))
array = []
x = input()
while x != 0:
    array.append(x)
    x = input()
for i, x in enumerate(array):
    print("Case %d: %d" % (i + 1, x))


### FIXED CODE ###

array = []
x = input()
while x != "0":
    array.append(x)
    x = input()
for i, x in enumerate(array):
    print("Case %d: %s" % (i + 1, x))
import math
A, B = map(int, input().split())
g = math.gcd(A, B)
print(A * B // g)

### FIXED CODE ###

def gcd(a, b):
    if a == 0:
        return b
    else:
        return gcd(b % a, a)


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

print(A * B // g)
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

odd_cells = []
for y in range(H):
    for x in range(W):
        x = x if y % 2 == 0 else W-x-1
        if A[y][x] % 2 == 1:
            odd_cells.append([x+1, y+1])

ans_operation = []
for i in range(0, len(odd_cells), 2):
    source = odd_cells[i]
    dist = odd_cells[i+1]
    while not (source[0] == dist[0] and source[1] == dist[1]):
        if dist[1] - source[1] > 1:
            ans_operation.append(source+[source[0], source[1]+1])
            source[1] += 1
        else:
            if (source[0] == W and source[1] % 2 == 1) or\
                    (source[0] == 0 and source[1] % 2 == 0):
                ans_operation.append(source+[source[0], source[1]+1])
                source[1] += 1
            else:
                direction = 1 if source[1] % 2 == 1 else -1
                ans_operation.append(source+[source[0]+direction, source[1]])
                source[0] += direction

print(len(ans_operation))
for ans in ans_operation:
    # x と y が逆
    print(ans[1], ans[0], ans[3], ans[2])


### FIXED CODE ###

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

odd_cells = []
for y in range(H):
    for x in range(W):
        x = x if y % 2 == 0 else W-x-1
        if A[y][x] % 2 == 1:
            odd_cells.append([x+1, y+1])

ans_operation = []
for i in range(0, len(odd_cells)-1, 2):
    source = odd_cells[i]
    dist = odd_cells[i+1]
    while not (source[0] == dist[0] and source[1] == dist[1]):
        if (source[0] == W and source[1] % 2 == 1) or\
                (source[0] == 1 and source[1] % 2 == 0):
            ans_operation.append(source+[source[0], source[1]+1])
            source[1] += 1
        else:
            direction = 1 if source[1] % 2 == 1 else -1
            ans_operation.append(source+[source[0]+direction, source[1]])
            source[0] += direction

print(len(ans_operation))
for ans in ans_operation:
    # x と y が逆
    print(ans[1], ans[0], ans[3], ans[2])
import math
n = input()
a = list(map(int, iput().split()))
ans = float('inf')
for i in a:
  ans = min(ans, len(bin(i)) - bin(i).rfind('1') - 1)
print(round(ans))

### FIXED CODE ###

N = input()
A = list(map(int, input().split()))
cnt = 0
while all(a%2==0 for a in A):
  A = [a/2 for a in A]
  cnt += 1
print(cnt)
S=input()
if(S[0]=="A" and S[2,-1].count("C")==1):
    cnt=0
    for i in S:
        if(97<=ord(i) and ord(i)<=122):
            cnt+=1
    if(cnt==2):
            print("AC")
    else :
            print("WA")
else :
    print("WA")

### FIXED CODE ###

S = input()
if(S[0]=='A' and S[2:-1].count('C') == 1):
  cnt = 0
  for i in S:
    if(not (97<=ord(i) and ord(i)<=122)):
      cnt+=1
  if(cnt==2):
    print('AC')
  else:
    print('WA')
else:
  print('WA')
s = input()

s = s[:-1]
if len(s) % 2 != 0:
    s = s[:-1]


while(True):
    s1, s2 = zip(*[iter(s)]*2)
    if s1 is s2:
        print(s1)
        break

    s = s[:-2]
    

### FIXED CODE ###

s = input()

s = s[:-1]
if len(s) % 2 != 0:
    s = s[:-1]


while(True):
    s1, s2 = s[0:len(s)//2], s[len(s)//2:len(s)]
    if s1 == s2:
        print(len(s1)*2)
        break

    s = s[:-2]
l = [int(input()) for _ in range(5)]
max_distance = input()
l[-1] - l[0] = distance
if max_distance > distance:
  print("Yay!")
else:
  print(":(")

### FIXED CODE ###

l = [int(input()) for _ in range(5)]
max_distance = int(input())
distance = l[-1] - l[0]
if max_distance >= distance:
  print("Yay!")
else:
  print(":(")
N = int(input())

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

counters = []

for i in range(N-1):
    counter = 0
    for j in range(i, N-1):
        if blocks[j] >= blocks[j+1]:
            counter += 1
        else :
            break
    counters.append(counter)
        
print(max(counters))

### FIXED CODE ###

N = int(input())

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

max_cnt = 0
cnt = 0
i = 1
height = blocks[0]

while i <= N-1:
    if height >= blocks[i]:
        cnt += 1
    else :
        cnt = 0
    if cnt >= max_cnt:
        max_cnt = cnt
    height = blocks[i]
    i += 1

print(max_cnt)
N, T = map(int,raw_input().split())
ans = float("inf")

for i in range(N):
    c,t = map(int,input(),split())
    if t <= T:
        ans = min(num,c)

if ans == float("inf"):
    print("TLE")
else:
    print(ans)


### FIXED CODE ###

N = int(input())
if N == 1:
    print("Hello World")
elif N == 2:
    A = int(input())
    B = int(input())
    print(A + B)
N, M = map(int, input().split())

NM = [[0]*(M+2) for _ in range(N+2)]

for i in range(1,N+1):
    for j in range(1,M+1):
        NM[i-1][j-1] = ~NM[i-1][j-1]
        NM[i-1][j-0] = ~NM[i-1][j-0]
        NM[i-1][j+1] = ~NM[i-1][j+1]
        NM[i-0][j-1] = ~NM[i-0][j-1]
        NM[i-0][j-0] = ~NM[i-0][j-0]
        NM[i-0][j+1] = ~NM[i-0][j+1]
        NM[i+1][j-1] = ~NM[i+1][j-1]
        NM[i+1][j-0] = ~NM[i+1][j-0]
        NM[i+1][j+1] = ~NM[i+1][j+1]

print(NM)

ans = 0
for k in range(1,N+1):
    ans += sum(NM[k][1:M+1])

print(-1*ans)


### FIXED CODE ###

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

ans = 0
if N == 1 and M == 1:
    ans = 1
elif N == 1 and M > 1:
    ans = M-2
elif N > 1 and M == 1:
    ans = N-2
else:
    ans = (N-2)*(M-2)

print(ans)
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N,K = MI()
k = K.bit_length()
AB = []
for _ in range(N):
    a,b = MI()
    if a > K:
        continue
    else:
        AB.append(([(a >> i) & 1 for i in range(k-1,-1,-1)],b))

N = len(AB)
K = [(K >> i) & 1 for i in range(k-1,-1,-1)]

ANS = [0]*(k+1)  # A[i] = 上i桁の各桁がKの上i桁の各桁以下であり、i+1桁目が0である非負整数の価値の総和

for i in range(N):
    a,b = AB[i]
    for j in range(k+1):
        if j == 0:
            if a[j] == 0:
                ANS[j] += b
        elif 1 <= j <= k-1:
            if a[j-1] <= K[j-1]:
                if a[j] == 0:
                    ANS[j] += b
            else:
                break
        else:
            if a[j-1] <= K[j-1]:
                ANS[j] += b

print(max(ANS))


### FIXED CODE ###

import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,K = MI()
K += 1
k = K.bit_length()

AB = []

for _ in range(N):
    a,b = MI()
    if a >= K:
        continue
    else:
        AB.append(([(a >> i) & 1 for i in range(k-1,-1,-1)],b))

N = len(AB)
K_bit = [(K >> i) & 1 for i in range(k-1,-1,-1)]

ANS = [0]*k  # 

for i in range(N):
    a,b = AB[i]
    for j in range(k):
        if K_bit[j] == 1:
            if a[j] == 0:
                ANS[j] += b
        else:
            if a[j] == 1:
                break

print(max(ANS))
import itertools

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

index = []

for i, s in enumerate(itertools.permutations(range(1, n+1),n)):
    if s == p or s == q:
        index.append(i)

if len(index) != 0:
    print(abs(index[0]-index[1]))
else:
    print('0')




### FIXED CODE ###

import itertools

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

index = []

for i, s in enumerate(itertools.permutations(range(1, n+1),n)):
    if s == p or s == q:
        index.append(i)


if len(index) == 2:
    print(abs(index[0]-index[1]))
else:
    print('0')
def main():
    N = int(input())
    P = []
    M = []
    for i in range(N):
        s = input()
        st = ST()
        left = 0
        right = 0
        rightmax = 0
        for c in s:
            if c == "(":
                left += 1
            else:
                right += 1
            rightmax = max(rightmax, right - left)
        leftdiff = left - right
        rightmax = rightmax
        if leftdiff > 0:
            P.append((leftdiff, rightmax))
        else:
            M.append((leftdiff, rightmax))

    nleft = 0
    for e in sorted(P, key=lambda _e: _e[1]):
        if nleft - e[1] < 0:
            print("No")
            return
        nleft += e[0]

    for e in sorted(P, key=lambda _e: _e[1], reversed=True):
        if nleft - e[1] < 0:
            print("No")
            return
        nleft += e[0]

    if nleft == 0:
        print("Yes")
    else:
        print("No")


main()


### FIXED CODE ###

def main():
    N = int(input())
    P = []
    M = []
    for i in range(N):
        s = input()
        left = 0
        right = 0
        rightmax = 0
        for c in s:
            if c == "(":
                left += 1
            else:
                right += 1
            rightmax = max(rightmax, right - left)
        leftdiff = left-right
        if leftdiff >= 0:
            P.append((leftdiff, rightmax, 0, s))
            continue
            
        left = 0
        right = 0
        leftmax = 0
        for c in reversed(s):
            if c == "(":
                left += 1
            else:
                right += 1
            leftmax = max(leftmax, left - right)
        M.append((leftdiff, 0, leftmax, s))

    R = []
    for e in sorted(P, key=lambda _e: _e[1]):
        R.append(e[3])
    for e in sorted(M, key=lambda _e: _e[2], reverse=True):
        R.append(e[3])

    nleft = 0
    for c in "".join(R):
        if c == "(":
            nleft += 1
        else:
            nleft -= 1
        if nleft < 0:
            print("No")
            return
        
    if nleft == 0:
        print("Yes")
    else:
        print("No")


main()
import sys,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n = onem()
print(10**5)
a = [i + n//(10**5) for i in range(10**5)]

for i in range(10**5-1):
    if i+1 <= n%(10**5):
        a[i] += 10**5 - n%(10**5) + 1:
    else:
        a[i] -= n%(10**5)
print(jo(a))

### FIXED CODE ###

import sys,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n = onem()
print(50)
a = [i + n//(50) for i in range(50)]

if n%(50) == 0:
    print(jo(a))
else:
    for i in range(50):
        if n%(50) >= i+1:
            a[i] += 50 - n%(50) +1
        else:
            a[i] -= n%(50)
    print(jo(a))
from pprint import pprint

INF = 1000000
dx = [1, -1, 0,  0]
dy = [0,  0, 1, -1]

# 入力
h, w = map(int, input().split())
maze = []
for i in range(h):
    maze.append(list(input()))

# ワーシャルフロイド用に枠を作る。
# 2次元マップしてもいいが面倒なので、１次元にする。[0 - x][0 - y]を[0- x * y]にflattenする
wsmap = lambda a, b: (a * h + b)
dp = []
# 辺がない時はINFを入れのでデフォルト値とする
for i in range(h * w):
    dp.append([INF] * (h * w))

# 迷路ををグラフにする。
for y in range(h):
    for x in range(w):
        if maze[y][x] == "#": # そのマスが壁なら何もしない(他のマストの連結はないので)
            continue
        # ワーシャルフロイドでは自分自身へのコストは0にしておく。
        dp[wsmap(y, x)][wsmap(y, x)] = 0
        # ４方向に移動できるかの判定
        for dir in range(len(dx)):
            nx, ny = x + dx[dir], y + dy[dir]
            if -1 < nx < w and -1 < ny < h: # 枠をはみ出ないかチェック
                if maze[ny][nx] != "#": # そのマスが壁でないなら
                    dp[wsmap(y, x)][wsmap(ny, nx)] = 1 # コストを1にする

# ワーシャルフロイドする
for kk in range(h * w):
    for ii in range(h * w):
        for jj in range(h * w):
            dp[ii][jj] = min(dp[ii][jj], dp[ii][kk] + dp[kk][jj])

# これで結果が出たので
import itertools
res = itertools.chain(*dp) # 二次元配列を一次元にして
res = filter(lambda x: x != INF, res) # INFを取り除き
res = max(res) # 最大値を得る
print(res)


### FIXED CODE ###

from pprint import pprint

INF = 1000000
dx = [1, -1, 0,  0]
dy = [0,  0, 1, -1]

# 入力
h, w = map(int, input().split())
maze = []
for i in range(h):
    maze.append(list(input()))

# ワーシャルフロイド用に枠を作る。
# 2次元マップしてもいいが面倒なので、１次元にする。[0 - x][0 - y]を[0- x * y]にflattenする
wsmap = lambda a, b: (a * w + b)
dp = []
# 辺がない時はINFを入れのでデフォルト値とする
for i in range(h * w):
    dp.append([INF] * (h * w))

# 迷路ををグラフにする。
for y in range(h):
    for x in range(w):
        if maze[y][x] == "#": # そのマスが壁なら何もしない(他のマストの連結はないので)
            continue
        # ワーシャルフロイドでは自分自身へのコストは0にしておく。
        dp[wsmap(y, x)][wsmap(y, x)] = 0
        # ４方向に移動できるかの判定
        for dir in range(len(dx)):
            nx, ny = x + dx[dir], y + dy[dir]
            if -1 < nx and nx < w and -1 < ny and ny < h: # 枠をはみ出ないかチェック
                if maze[ny][nx] != "#": # そのマスが壁でないなら
                    #print(wsmap(y, x))
                    #print("--")
                    #print("y, x {0}, {1}".format(ny, nx))
                    #print(wsmap(ny, nx))
                    dp[wsmap(y, x)][wsmap(ny, nx)] = 1 # コストを1にする

# ワーシャルフロイドする
for kk in range(h * w):
    for ii in range(h * w):
        for jj in range(h * w):
            dp[ii][jj] = min(dp[ii][jj], dp[ii][kk] + dp[kk][jj])

# これで結果が出たので
#print(dp)
res = -1
for i in range(h * w):
    for j in range(h * w):
        if dp[i][j] != INF:
            res = max(res, dp[i][j])
print(res)
n, a, b = map(int, input().split())
if n*a < b
	print (n*a)
else: 
	print (b)

### FIXED CODE ###

n, a, b = map(int, input().split())
if n*a < b:
	print (n*a)
else: 
	print (b)
from itertools import product
import numpy as np

H, W, K = [int(n) for n in input().split()]
arr = np.zeros((H, W))
count = 0

for h in range(H):
    row = input()
    arr[h, :] = np.array([0 if mark=='.' else 1 for mark in row])

print(1)

### FIXED CODE ###

from itertools import product
import numpy as np

H, W, K = [int(n) for n in input().split()]
arr = np.zeros((H, W))
count = 0

for h in range(H):
    row = input()
    arr[h, :] = np.array([0 if mark=='.' else 1 for mark in row])

for row_onehot, col_onehot in product(product(range(2), repeat=H), product(range(2), repeat=W)):
    row_indexes = np.argwhere(np.array(row_onehot)==1).flatten()
    col_indexes = np.argwhere(np.array(col_onehot)==1).flatten()
    arr_ = arr.copy()
    for row_idx in row_indexes:
        arr_[row_idx, :] = 0
    for col_idx in col_indexes:
        arr_[:, col_idx] = 0
    if arr_.sum() == K:
        count += 1

print(count)
n,d=input().split()
N=int(n)
D=int(d)
if N%(2*D+1)==0:
  print(N//(2*D+1))
else:
  print(N//(2*D+1)+1)

### FIXED CODE ###

r=int(input())
print(3*(r**2))
input()
p = [int(x) for x in input()]
q = sorted(p)
d = [(pi, qi) for pi, qi in zip(p, q) if pi != qi]
print("YES" if len(d) == 0 or len(d) == 2 and d[0][0] == d[1][1] and d[1][0] == d[0][1] else "NO")

### FIXED CODE ###

input()
p = [int(x) for x in input().split()]
q = sorted(p)
d = [(pi, qi) for pi, qi in zip(p, q) if pi != qi]
print("YES" if len(d) == 0 or len(d) == 2 and d[0][0] == d[1][1] and d[1][0] == d[0][1] else "NO")
s = input()
ans = 0
S =[]
for i in range(len(s)):
  for j in range(len(s)):
    a = s[i:i+j+2]
    S.append(a)
sa = set(S)
for i in range(len(se)):
  if int(sa[i]) % 2019 == 0:
    ans += 1

print(ans)


### FIXED CODE ###

s,l = (input(),2019)
m,a,r = ([1]+[0]*l,0,0)
for i,e in enumerate(s[::-1]):
    a += int(e)*pow(10,i,l)
    r += m[a%l]
    m[a%l] += 1
print(r)
import sys
input = sys.stdin.readline
N = int(input())
tree = [[] for i in range(N+1)]

for i in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

dist_fennec = [100001] * (N+1)
dist_snuke = [100001] * (N+1)
q = [1]
dist[1] = 0
while q:
    now = q.pop()
    for next in tree[now]:
        if dist_fennec[next] == 100001:
            dist_fennec[next] = dist_fennec[now] + 1
            q.append(next)

q = [N]
dist[N] = 0
while q:
    now = q.pop()
    for next in tree[now]:
        if dist_snuke[next] == 100001:
            dist_snuke[next] = dist_snuke[now] + 1
            q.append(next)

fennec, snuke = 0, 0
for i in range(1, N+1):
    if dist_snuke[i] <= dist_fennec[i]:
        fennec += 1
    else:
        snuke += 1

if fennec > snuke:
    print("Fennec")
else:
    print("Snuke")


### FIXED CODE ###

import sys
input = sys.stdin.readline
N = int(input())
tree = [[] for i in range(N+1)]

for i in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

dist_fennec = [100001] * (N+1)
dist_snuke = [100001] * (N+1)
q = [1]
dist_fennec[1] = 0
while q:
    now = q.pop()
    for next in tree[now]:
        if dist_fennec[next] == 100001:
            dist_fennec[next] = dist_fennec[now] + 1
            q.append(next)

q = [N]
dist_snuke[N] = 0
while q:
    now = q.pop()
    for next in tree[now]:
        if dist_snuke[next] == 100001:
            dist_snuke[next] = dist_snuke[now] + 1
            q.append(next)

fennec, snuke = 0, 0
for i in range(1, N+1):
    if dist_snuke[i] >= dist_fennec[i]:
        fennec += 1
    else:
        snuke += 1

if fennec > snuke:
    print("Fennec")
else:
    print("Snuke")
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
from re import split
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
import re

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
ans = 1
for _ in range(3):
    G = [[] for _ in range(n)]
    m = I()
    for _ in range(m):
        p, q = LI()
        G[p - 1] += [q - 1]
        G[q - 1] += [p - 1]

    visited = [0] * n
    cnt = 0
    for i in range(n - 1, -1, -1):
        if visited[i] == 0:
            visited[i] = 1
            cnt += i + 1
            dq = deque([i])
            while dq:
                u = dq.pop()
                for v in G[u]:
                    visited[v] = 1








### FIXED CODE ###

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
from re import split
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
import re

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


h, w = LI()
L = SR(h)
dp = [[INF] * w for _ in range(h)]
dp[0][0] = 1 if L[0][0] == '#' else 0
for y in range(h):
    for x in range(w):
        if y:
            if L[y][x] == '.' or L[y - 1][x] == '#':
                dp[y][x] = dp[y - 1][x]
            else:
                dp[y][x] = dp[y - 1][x] + 1
        if x:
            if L[y][x] == '.' or L[y][x - 1] == '#':
                dp[y][x] = min(dp[y][x], dp[y][x - 1])
            else:
                dp[y][x] = min(dp[y][x], dp[y][x - 1] + 1)


print(dp[h - 1][w - 1])
#coding: utf-8

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

List = []
for i in range(N):
    l = list(map(int, input().split()))
    #print(l)
    del l[0]
    #print(l)
    List.append(l)
    #print(List[i])
    #print(List)
    #print( )

    if i != 0:
        all_and = set(List[i-1]) & set(List[i])

all_and_list = list(all_and)
print(len(all_and_list))



### FIXED CODE ###

#coding: utf-8

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

List = []
all_and = []
for i in range(N):
    l = list(map(int, input().split()))
    del l[0]
    List.append(l)

    if i ==0:
        all_and = List[0]
    else:
        all_and = set(all_and) & set(List[i])
        all_and = list(all_and)

#print(all_and)
print(len(all_and))