Harryxun/stf_run huggingface dataset:
N=int(input())

S=[[-1]*N for _ in range(N)]
for _ in range(N):
  A=int(input())
  for i in range(A):
    x, y=map(int, input().split())
    
for s in range(2**N):
  ok=True
  for i in range(N):
    #正直者について見ていく
    if (s<<i&1)==1:
      for j in range(N):
        #それぞれ正直者の証言が矛盾ないか
        if g[i][j]!=-1 and (s>>j&1)!=g[i][j]:
          ok=False
  if ok:
    ans=max(ans, bin(s).count("1"))
    
print(ans)
      

### FIXED CODE ###

n = int(input())

g = [[-1 for j in range(n)] for i in range(n)]

for i in range(n):
	a = int(input())
	for _ in range(a):
		x, y = map(int, input().split())
		g[i][x-1] = y

ans = 0
for s in range(2**n):
	ok = True
	for i in range(n):
		if (s>>i&1) == 1:
			for j in range(n):
				if g[i][j] != -1 and (s>>j&1) != g[i][j]:
					ok = False
	if ok:
		ans = max(ans, bin(s).count("1"))

print(ans)
n = int(input())
money = 1000
stock = 0
(*a,) = map(int, input().split())

for i in range(n - 1):
    if a[i] < a[i + 1]:
        stock += money // a[i]
        money = money % a[i]
    elif a[i] > a[i + 1]:
        money += stock * a[i]
        stock = 0
    else:
        pass
money += stock * a[-1]
print(money)

### FIXED CODE ###

x = int(input())
if 400 <= x <= 599:
    print(8)
elif 600 <= x <= 799:
    print(7)
elif 800 <= x <= 999:
    print(6)
elif 1000 <= x <= 1199:
    print(5)
elif 1200 <= x <= 1399:
    print(4)
elif 1400 <= x <= 1599:
    print(3)
elif 1600 <= x <= 1799:
    print(2)
else:
    print(1)
import numpy as np

n, k = map(int, input().split())
a = list(map(int, input().split()))
score = [0] * (n+1)

for i in range(k, n+1):
    score[i] = np.prod(a[i-k:i])

for i in range(k+1, n+1):
    print('Yes' if score[i-1] < score[i] else 'No')


### FIXED CODE ###

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

for i in range(k, n+1):
    if i == k:
        continue
    print('Yes' if a[i-k-1] < a[i-1] else 'No')
import numpy as np

def dfs(n,a,s):
  if n==0:
    return -1 if (a >= X).all()==False else s
  #print(a+A[n-1])
  x=dfs(n-1,a+A[n-1],s+C[n-1])
  y=dfs(n-1,a,s)
  return y if x==-1 else x if y==-1 else min(x,y)

N,M,X=map(int,input().split())
C=[]
A=[]
for i in range(N):
  c,*tmp=map(int,input().split())
  A.append(np.array(tmp))
  C.append(c)
#print(A)
print(dfs(N,np.array([0]*M),0))



### FIXED CODE ###

import numpy as np

def dfs(n,a,s):
  if n==0:
    return -1 if (a >= X).all()==False else s
  #print(a+A[n-1])
  x=dfs(n-1,a+A[n-1],s+C[n-1])
  y=dfs(n-1,a,s)
  return y if x==-1 else x if y==-1 else min(x,y)

N,M,X=map(int,input().split())
C=[]
A=[]
for i in range(N):
  c,*tmp=map(int,input().split())
  A.append(np.array(tmp))
  C.append(c)
#print(A)
print(dfs(N,np.array([0]*M),0))
inport numpy as np
n, k, x, y = map(int, input().split('\n'))
basic = np.min(k * x, n * x)
plus = np.max((n - k) * y, 0)
print(basic + plus)

### FIXED CODE ###

n, k, x, y = [int(input()) for i in range(4)]
basic = min(k * x, n * x)
plus = max((n - k) * y, 0)
print(basic + plus)
from functools import lru_cache

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

count = 0

@lru_cache(maxsize=1000)
def dfs(x, y):
    global count
    if x >= N or y >= N:
        return
    
    if (A[x]+A[y]) == y-x:
        count += 1

    if x+1 >= N and y+1 >= N:
        return
        
    if y+1 >= N:
        dfs(x+1, x+2)
    else:
        dfs(x, y+1)


dfs(0, 1)
print(count)


### FIXED CODE ###

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

count = 0

def solve():
    from collections import Counter
    cc=Counter()
    ans=0
    for i,val in enumerate(A,1):
        if i-val>0:
            ans+=cc[i-val]
        cc[i+val]+=1
    print(ans)
    
def dfs(x, y):
    global count
    if x >= N or y >= N:
        return
    
    if (A[x]+A[y]) == y-x:
        count += 1

    if x+1 >= N and y+1 >= N:
        return
        
    if y+1 >= N:
        dfs(x+1, x+2)
    else:
        dfs(x, y+1)


#dfs(0, 1)
#print(count)
solve()
a = input()
if a[0] == "A":
    b = 0
    for i in range(1, len(a)):
        if a[i] == "C" and (1 < i < len(a) - 1):
            b += 1
        else:
            if a[i] != a[i].lower():
                print("WA")
                exit()
if b == 1:
    print("AC")
else:
    print("WA")

### FIXED CODE ###

a = input()
b = 0
if a[0] != "A":
    print("WA")
    exit()
for i in range(2,len(a)-1):
    if b == 0 and a[i] == "C":
        b = i
    elif b != 0 and [i] == "C":
        print("WA")
        exit()
if b == 0:
    print("WA")
    exit()
for i in range(len(a)):
    if i != 0 and i != b and a[i].isupper():
        print("WA")
        exit()
print("AC")
a, b, h = [input() for _ in range(3)]
print(int((a + b) * h / 2))


### FIXED CODE ###

a, b, h = [int(input()) for _ in range(3)]
print(int((a + b) * h / 2))
A, B, C = map(int, input().split())

if C >= A and C <= b:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

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

if C >= A and C <= B:
  print("Yes")
else:
  print("No")
k,s = map(int,input().split())
ans = 0

for x in range(min(k,s)+1):
    for y in range(min(k,s)+1):
        if 0 <= s - x - y <= min(k,s):
            ans += 1
    
print(ans)

### FIXED CODE ###

print(input().replace(","," "))
a=list(map(int,input().split()))
q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    for i in range(n):
        if a[i]==b:
            a[i]=c
    print(sum(a))

### FIXED CODE ###

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

count=[0]*(10**5+1)

for i in a:
    count[i]+=1

for i in range(q):
    b,c=map(int,input().split())
    if count[b]!=0:
        sum+=(c-b)*count[b]
        count[c]+=count[b]
        count[b]=0
    print(sum)
import math

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

gcd=math.gcd(A,B)

ANS=A*B/gcd

print(int(ANS))

### FIXED CODE ###

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

for i in range(max(A,B)):
    if A%(i+1)==0 and B%(i+1)==0:
        gcd=i+1

ANS=A*B/gcd

print(int(ANS))
if int(input())%2==0:
  print(N)
else:
  print(2*N)

### FIXED CODE ###

a = int(input())

if a%2==0:
  print(a)
else:
  print(2*a)
n,m=map(int,input().split())

par=[i for i in range(n)]

visited=[False]*n

def find(x):
  if par[x]==x:
    return par[x]
  else:
    par[x]=find(par[x])
    return par[x]


def find2(x):
  visited[x]=True
  if par[x]==x:
    return par[x]
  else:
    par[x]=find2(par[x])
    return par[x]

def union(x,y):
  fx=find(x)
  fy=find(y)
  if fx!=fy:
    par[fx]=fy

ans=-1

for i in range(m):
  x,y,z=map(int,input().split())
  union(x-1,y-1)

cnt=0

for i in range(n):
  if visited[i]==False:
    cnt+=1
    find2(i)


ans=min(cnt,len(set(par)))


print(ans)

### FIXED CODE ###

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

par=[i for i in range(n)]
size=[1]*n

def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
def union(a,b):
  x=find(a)
  y=find(b)
  if x!=y:
    if size[x]<size[y]:
      par[x]=par[y]
      size[y]+=size[x]
    else: 
      par[y]=par[x]
      size[x]+=size[y]
  else:
    return

for i in range(m):
  x,y,z=map(int,input().split())
  union(x-1,y-1)


ans={find(i) for i in range(n)}

print(len(ans))
N, X, M = map(int, input().split())
if X == 0:
    print(0)
    exit()
tx = X % M
tl = []
ts = set()
ttl = []
for i in range(N):
    tl.append(tx)
    ts.add(tx)
    tx = pow(tx, 2, M)
    if tx in ts:
        ttl = tl[tl.index(tx):]
        break
ans = sum(tl)
d, m = divmod(N-len(tl), len(ttl))
ans += sum(ttl)*d+sum(ttl[:m])
print(ans)


### FIXED CODE ###

N, X, M = map(int, input().split())
if X == 0:
    print(0)
    exit()
tx = X % M
tl = []
ts = set()
ttl = []
for i in range(N):
    tl.append(tx)
    ts.add(tx)
    tx = pow(tx, 2, M)
    if tx in ts:
        ttl = tl[tl.index(tx):]
        break
ans = sum(tl)
if len(ttl)>0:
    d, m = divmod(N-len(tl), len(ttl))
    ans += sum(ttl)*d+sum(ttl[:m])
print(ans)
s = int(input())
count = 0
for i in range(1000000):
  if x%2 == 0:
    x /=2
  else:
    x = 3*x+1
  
  if x==4:
    print(count+4)
  count +=1

### FIXED CODE ###

s = int(input())
ptn = []
count = 1
while True:
  ptn.append(s)
  if s%2 == 0:
    s /=2
  else:
    s = 3*s+1
  if s in ptn:
    print(count+1)
    exit()
  count +=1
n = int(input())  # nは入力回数
str_list = [input() for _ in range(n)]


a=0
b=0
c=0                
d=0                
                
for num in range(1, n)
    if str_list[num] == 'AC':
                a += 1
    elif str_list[num] == 'WA':
                b += 1
    elif str_list[num] == 'TLE':
                c +=1
    else str_list[num] == 'RE':
                d +=1
    	continue;

print('AC x'+ a)
print('WA x'+ b)
print('TLE x'+ c)
print('RE x'+ d)


### FIXED CODE ###

n = int(input())
str_list = [input() for _ in range(n)]


a=0
b=0
c=0                
d=0                
                
for i in range(n):
    if str_list[i] == 'AC':
    	a += 1
    elif str_list[i] == 'WA':
    	b += 1
    elif str_list[i] == 'TLE':
    	c +=1
    else :
    	d +=1

print('AC x '+ str(a))
print('WA x '+ str(b))
print('TLE x '+ str(c))
print('RE x '+ str(d))
import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    d = int(read())
    c = [int(i) for i in read().split()]
    s = [[int(i) for i in read().split()] for _ in range(d)]
    t = [int(read()) - 1 for _ in range(d)]
    m = int(read())
    query = [[int(i) - 1 for i in read().split()] for _ in range(m)]
    score = [0] * 26
    last = [[0] * 26 for _ in range(d)]
    for i in range(d):
        score[i] = s[i][t[i]]
        if i > 0:
            last[i] = last[i - 1].copy()
        last[i][t[i]] = i + 1
        for j in range(26):
            score[i] -= c[j] * (i + 1 - last[i][j])
    for di, qi in query:
        if di == 0:
            last[di][t[di]] = 0
        else:
            last[di][t[di]] = last[di - 1][t[di]]
        last[di][qi] = di + 1
        t[di] = qi
        for i in range(di, d):
            score[i] = s[i][t[i]]
            if i > 0:
                last[i] = last[i - 1].copy()
            last[i][t[i]] = i + 1
            for j in range(26):
                score[i] -= c[j] * (i + 1 - last[i][j])
        print(sum(score))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    d = int(read())
    c = [int(i) for i in read().split()]
    s = [[int(i) for i in read().split()] for _ in range(d)]
    t = [int(read()) - 1 for _ in range(d)]
    m = int(read())
    query = [[int(i) - 1 for i in read().split()] for _ in range(m)]
    score = 0
    last = [[0] * 26 for _ in range(d)]
    for i in range(d):
        score += s[i][t[i]]
        if i > 0:
            last[i] = last[i - 1].copy()
        last[i][t[i]] = i + 1
        for j in range(26):
            score -= c[j] * (i + 1 - last[i][j])
    for di, qi in query:
        hi = t[di]
        t[di] = qi
        score -= s[di][hi]
        score += s[di][qi]
        if di == 0:
            last[di][hi] = 0
        else:
            last[di][hi] = last[di - 1][hi]
        score -= c[hi] * (di + 1 - last[di][hi])
        score += c[qi] * (di + 1 - last[di][qi])
        last[di][qi] = di + 1
        for i in range(di + 1, d):
            score += c[hi] * (i + 1 - last[i][hi])
            if t[i] != hi:
                last[i][hi] = last[i - 1][hi]
                score -= c[hi] * (i + 1 - last[i][hi])
            else:
                break
        for i in range(di + 1, d):
            score += c[qi] * (i + 1 - last[i][qi])
            if t[i] != qi:
                last[i][qi] = last[i - 1][qi]
                score -= c[qi] * (i + 1 - last[i][qi])
            else:
                break
        print(score)


if __name__ == '__main__':
    main()
from fractions import gcd

def factrize(n):
    b = []
    while n % 2 == 0:
        if len(b) == 0 or b[-1] != f:
            b.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            if len(b) == 0 or b[-1] != f:
                b.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        b.append(n)
    return b

a, b = map(int, input().split())
d = gcd(a, b)
p = factrize(d)
print(len(p) + 1)


### FIXED CODE ###

from fractions import gcd

def factrize(n):
    b = []
    while n % 2 == 0:
        b.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            b.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        b.append(n)
    return b

a, b = map(int, input().split())
d = gcd(a, b)
p = factrize(d)
p_unique = set(p)
print(len(p_unique) + 1)
X, A = map(int, input.split())
print(0 if X < A else 0)

### FIXED CODE ###

X,A = map(int,input().split())
 
print(0 if X<A else 10)
#include <bits/stdc++.h>
using namespace std;
//unionfind
typedef pair<int, int> P;
const int MAX_N = 100010;
int m, n;
int par[MAX_N];    //親
int deapth[MAX_N]; //木の深さ
int cnt[MAX_N];
int num;

vector<int> vec[MAX_N];
//n要素で初期化
void init(int n)
{
    for (int i = 0; i < n; i++)
    {
        par[i] = i;
        deapth[i] = 0;
        cnt[i] = 1;
    }
}
//木の根を求める
int find(int x)
{
    if (par[x] == x)
    {
        return x;
    }
    else
    {
        return par[x] = find(par[x]);
    }
}

//xとyの属する集合を併合
void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y)
        return;
    if (deapth[x] < deapth[y])
    {
        par[x] = y;
        cnt[y] += cnt[x];
    }
    else
    {
        par[y] = x;
        cnt[x] += cnt[y];
        if (deapth[x] == deapth[y])
            deapth[x]++;
    }
}

bool same(int x, int y)
{
    return find(x) == find(y);
}

int main()
{
    cin >> n >> m;
    init(MAX_N);
    vector<P> v;
    for (int i = 0; i < m; i++)
    {
        int x, y, z;
        cin >> x >> y >> z;
        if (z % 2 == 0)
        {
            unite(x, y);
        }
        else
        {
            v.push_back(P(x, y));
            v.push_back(P(y, x));
        }
    }
    for (int i = 0; i < v.size(); i++)
    {
        vec[find(v[i].first)].push_back(find(v[i].second));
    }
    vector<bool> fl(n + 1, false);
    vector<P> u;

    for (int i = 1; i <= n; i++)
    {
        if (fl[find(i)])
            continue;
        fl[find(i)] = true;
        u.push_back(P(cnt[find(i)], find(i)));
    }

    sort(u.begin(), u.end(), greater<P>());

    vector<bool> f(n + 1, false);
    int ans = 0;
    for (int i = 0; i < u.size(); i++)
    {
        if (f[find(u[i].second)])
            continue;
        ans++;
        f[u[i].second] = true;
        for (int i = 0; i < vec[u[i].second].size(); i++)
        {
            int x = vec[u[i].second][i];
            f[find(x)] = true;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (!f[find(i)])
            ans++;
    }
    cout << ans << endl;
}


### FIXED CODE ###

class UnionFind:
    def __init__(self, max_size):
        self.parent = [i for i in range(max_size+1)]
        self.depth = [0 for _ in range(max_size+1)]
        self.cnt = [1 for i in range(max_size+1)]
    def find(self, x):
        if self.parent[x]==x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x]) 
            return self.parent[x]
    
    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        elif self.depth[x]<self.depth[y]:
            self.parent[x] = y
            self.cnt[y] += self.cnt[x]
        else:
            self.parent[y] = x
            self.cnt[x]+=self.cnt[y]
            if self.depth[x]==self.depth[y]:
                self.depth[x]+=1
    def same(self, x, y):
        return self.find(x)==self.find(y)
    def size(self,x):
        return self.cnt[self.find(x)]

n,m = map(int,input().split())
utree = UnionFind(n+10)
for _ in range(m):
    x,y,z = map(int,input().split())
    utree.unite(x,y)
l = [utree.find(i) for i in range(1,n+1)]
print(len(set(l)))
N=int(input())
if N%2=0:
    ans=N
else:
    ans=N*2
print(ans)

### FIXED CODE ###

N=int(input())
if N%2==0:
    ans=N
else:
    ans=N*2
print(ans)
import numpy as np
import itertools
 
H, W, K = list(map(int, input().split())) 
c = [input().split() for l in range(H)]
b=[]
d=[]
for m in range(len(c)):
  for item in c[m]:
    item_mod = item.replace("."  , "0")
    item_mod = item_mod.replace("#" , "1")
    b.append(item_mod)
  d.append(b)
  b=[]

C_arr = np.array(d)
 
In = np.array(list(itertools.product([0,1] , repeat=H)))
Out = np.array(list(itertools.product([0,1] , repeat=W)))
 
ans = 0
for i in range(2**H):
  for j in range(2**W):
    In_matrix = np.diag(In[i])
    Out_matrix = np.diag(Out[j])
    
    In_C = np.dot(In_matrix , C_arr)
    In_C_Out = np.dot(In_C , Out_matrix)
    
    ICO = In_C_Out.flatten()
    ICO = ICO.tolist()
    
    if ICO.count(1) == K:
      ans += 1
      
print(ans)

### FIXED CODE ###

H, W, K = list(map(int, input().split()))
 
c = [list(input()) for i in range(H)]
 
cnt = 0
for i in range(2**H):
    for j in range(2**W):
        cnt_black = 0
        for k in range(H):
            if (i >> k) & 1:
                continue
            for l in range(W):
                if (j >> l) & 1:
                    continue
                if c[k][l] == '#':
                    cnt_black += 1
        if cnt_black == K:
            cnt += 1
 
print(cnt)
N = int(input())
S = input()
count = 0
for k in range(N):
    for j in range(k):
        if S[k] == S[j]:
            continue
        for i in range(j):
            if S[i] == S[j] or S[i] == S[k] or j-i == k-j:
                continue
            count+=1
print(count)

### FIXED CODE ###

import sys

N = input()

for N_char in N:
    if N_char == "7":
        print("Yes")
        sys.exit()
print("No")
n = int(input())
ans = 1
for i in range(1, n + 1):
  ans *= i
  if ans >= (10 ** 9 + 7):
    ans = ans - (10 ** 9 + 7)
print(p % (10 ** 9 + 7))

### FIXED CODE ###

n = int(input())
ans = 1
for i in range(1, n + 1):
  ans *= i
  ans = ans % (10 ** 9 + 7)
print(ans)
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
ans = []

ApB = []

for i in range(min(X, K)):
  for j in range(min(Y, K)):
      ApB.append(A[i] + B[j])

ApB.sort(reverse = True)

for i in range(min(Z, K)):
  for j in range(int(min(len(ApB), K) / (i + 1)):
    ans.append(C[i] + ApB[j])

ans.sort(reverse = True)

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

### FIXED CODE ###

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
ans = []

for i in range(min(X, K)):
  for j in range(min(Y, K)):
    if (i + 1) * (j + 1) > K:
      break
    for k in range(min(Z, K)):
      if (i + 1) * (j + 1) * (k + 1) > K:
        break
      ans.append(A[i] + B[j] + C[k])

ans.sort(reverse = True)

for i in range(K):
  print(ans[i])
n, m = map(int, input().split())
ab = sorted(set([tuple(map(int, input().split())) for _ in range(m)]))

c = []
flag = False
for i in ab:
    a, b = i[0], i[1]
    for i in c:
        if a in i or b in i:
            i.add(a)
            i.add(b)
            if len(i) == n:
                flag = True
            break
        else:
            c.append(set())
            c[-1].add(a)
            c[-1].add(b)
    if flag:
        break
if m == 0:
    print(1)
else:
    print(max(map(len, c)))

### FIXED CODE ###

class Union:
    def __init__(self, n):
        self.parents = [-1] * n
    
    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            return self.root(self.parents[x])
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

uni = Union(n)
for a, b in ab:
    a -= 1
    b -= 1
    uni.unite(a, b)
print(-min(uni.parents))
N = int(input())
S = list(input())
max = N - 1
for i in range(N-1):
  cnt = S[:i].count('W') + S[i+1:].count('E')
  if cnt < min:
    min = cnt
print(min)

### FIXED CODE ###

N = int(input())
S = list(input())
W = 0
E = S[1:].count('E')
Turn = []
Turn.append(E)

for i in range(1, N):
  if S[i] == 'E':
    E -= 1
  if S[i-1] == 'W':
    W += 1
  Turn.append(E+W)

print(min(Turn))
N, A, B = input().strip().split()
ans = 0
for i in range(1, N+1):
  if A <= sum(map(int, list(str(i)))) <= B:
    ans += i
print(ans)


### FIXED CODE ###

N, A, B = map(int, input().strip().split())
ans = 0
for i in range(1, N+1):
  if A <= sum(map(int, list(str(i)))) <= B:
    ans += i
print(ans)
import math
p = raw_input().split()
x = math.fabs(int(p[0]) - int(p[2]))
y = math.fabs(int(p[1]) - int(p[3]))
print '%.8f' % math.sqrt(x**2 + y**2)

### FIXED CODE ###

import math
p = raw_input().split()
x = math.fabs(float(p[0]) - float(p[2]))
y = math.fabs(float(p[1]) - float(p[3]))
print '%.8f' % math.sqrt(x**2 + y**2)
from collections import deque
k = int(input())
Q = deque(range(1, 10))
for _ in range(k):
  x = Q.popleft()
  y = x % 10
  z = 10*x + y
  if y != 0:
    Q += [z-1]
  Q += [z]
  if y != 9:
    Q += [z+1]
print(x)

### FIXED CODE ###

#
N, K = map(int,input().split())
N  %= K
min = N
for i in range(10**6):
    N = abs(N-K)
    if min > N:
        min = N
    if N == 0:
        min = 0
        break
print(min)
n = int(input())
action = []
for i in range(n):
    action.append(list(map(int,input().split())))

memo = []
for i in range(n):
    memo.append([-1]*3)

def dp(i, a):
    if i == 0:
        return action[0][a]
    elif memo[i][a] != -1:
        return memo[i][a]
    else:
        memo[i][a] = max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]
        return memo[i][a]

print(max([dp(n-1,a) for a in range(3)]))

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

n = int(input())
action = []
for i in range(n):
    action.append(list(map(int,input().split())))

memo = []
for i in range(n):
    memo.append([-1]*3)

def dp(i, a):
    if i == 0:
        return action[0][a]
    elif memo[i][a] != -1:
        return memo[i][a]
    else:
        memo[i][a] = max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]
        return memo[i][a]

print(max([dp(n-1,a) for a in range(3)]))