Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

K,S=map(int, input().split())
data=[[x,y,z]for x in range(K+1)for y in range(K+1)for z in range(K+1) if x+y+z==S]
print(len(data))

### FIXED CODE ###

K,S=map(int, input().split())
count = 0
for x in range(K+1):
    for y in range(K+1):
        if 0<=S-x-y<=K:
            count=count+1
print(count)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
 
MOD = 1000000007  # type: int
 
def solve(S: str):
    total = 0
    for s in S:
        if s == '?':
            total += 1
    n = len(S)
    dp = [[0] * 4 for _ in range(n + 1)]
    cnt = 0
    for i in range(n):
        s = S[i]
        dp[i + 1][0] = dp[i][0]
        dp[i + 1][1] = dp[i][1]
        dp[i + 1][2] = dp[i][2]
        dp[i + 1][3] = dp[i][3]
        if s == '?':
            dp[i + 1][1] = dp[i][1] + 1
            dp[i + 1][2] = dp[i][2] * 3 + (dp[i][0] * int(3 ** cnt)) + (dp[i][1] * int(3 ** (cnt - 1)))
            dp[i + 1][3] = dp[i][3] + dp[i][2] * (3 ** (total - cnt - 1))
            cnt += 1
        elif s == 'A':
            dp[i + 1][0] = dp[i][0] + 1
        elif s == 'B':
            dp[i + 1][2] = dp[i][2] + (dp[i][0] * int(3 ** cnt)) + (dp[i][1] * int(3 ** (cnt - 1)))
        elif s == 'C':
            dp[i + 1][3] = dp[i][3] + dp[i][2] * (3 ** (total - cnt))
    #print(dp)
    ret = dp[n][3] % MOD
    print(ret)
    return
 
 
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)
 
if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(S: str):
    total = 0
    for s in S:
        if s == '?':
            total += 1
    tri = [1]
    for i in range(1, total + 1):
        tri.append(tri[i - 1] * 3 % MOD)
    n = len(S)
    dp = [[0] * 4 for _ in range(n + 1)]
    cnt = 0
    for i in range(n):
        s = S[i]
        #dp[i + 1][0] = dp[i][0]
        #dp[i + 1][1] = dp[i][1]
        #dp[i + 1][2] = dp[i][2]
        #dp[i + 1][3] = dp[i][3]
        if s == '?':
            dp[i + 1][0] = dp[i][0]
            dp[i + 1][1] = dp[i][1] + 1
            dp[i + 1][2] = (dp[i][2] * 3 + dp[i][0] * tri[cnt] + dp[i][1] * tri[cnt - 1]) % MOD
            dp[i + 1][3] = (dp[i][3] + dp[i][2] * tri[total - cnt - 1]) % MOD
            cnt += 1
        elif s == 'A':
            dp[i + 1][0] = dp[i][0] + 1
            dp[i + 1][1] = dp[i][1]
            dp[i + 1][2] = dp[i][2]
            dp[i + 1][3] = dp[i][3]
        elif s == 'B':
            dp[i + 1][0] = dp[i][0]
            dp[i + 1][1] = dp[i][1]
            dp[i + 1][2] = (dp[i][2] + dp[i][0] * tri[cnt] + dp[i][1] * tri[cnt - 1]) % MOD
            dp[i + 1][3] = dp[i][3]
        elif s == 'C':
            dp[i + 1][0] = dp[i][0]
            dp[i + 1][1] = dp[i][1]
            dp[i + 1][2] = dp[i][2]
            dp[i + 1][3] = (dp[i][3] + dp[i][2] * tri[total - cnt]) % MOD
    #print(dp)
    ret = dp[n][3] % MOD
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    a=list(map(int,input().split()))
    dp0=[1]*N
    dp1=[1]*N
    mask=(1<<K)-1
    for i in range(N-1):
        if a[i]<K:
            dp0[i+1]=(dp0[i]|(dp0[i]<<a[i]))&mask
        else:
            dp0[i+1]=dp0[i]
        if a[N-i-1]<K:
            dp1[N-i-2]=(dp1[N-i-1]|(dp1[N-i-1]<<a[N-i-1]))&mask
        else:
            dp1[N-i-2]=dp1[N-i-1]
    ans=0
    for i in range(N):
        if a[i]<K:
            mask2=((1<<a[i])-1)<<(K-a[i])
            for j in range(dp0[i].bit_length()):
                if (dp0[i]>>j)&1:
                    if (dp1[i]<<j)&mask2:
                        break
            else:
                ans+=1
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    a=list(map(int,input().split()))
    a.sort(reverse=1)
    dp0=[1]*N
    dp1=[1]*N
    mask=(1<<K)-1
    for i in range(N-1):
        if a[i]<K:
            dp0[i+1]=(dp0[i]|(dp0[i]<<a[i]))&mask
        else:
            dp0[i+1]=dp0[i]
        if a[N-i-1]<K:
            dp1[N-i-2]=(dp1[N-i-1]|(dp1[N-i-1]<<a[N-i-1]))&mask
        else:
            dp1[N-i-2]=dp1[N-i-1]
    ans=0
    def nibutan(ok,ng):
        while abs(ok-ng) > 1:
            mid = (ok + ng) // 2
            if solve(mid):
                ok = mid
            else:
                ng = mid
        return ok
    
    def solve(i):
        if a[i]<K:
            mask2=((1<<a[i])-1)<<(K-a[i])
            for j in range(dp0[i].bit_length()):
                if j>mask2.bit_length():
                    return True
                if (dp0[i]>>j)&1:
                    if dp1[i]&(mask2>>j):
                        return True
        else:
            return True
        return False
    
    res=nibutan(-1,N)
    print(N-1-res)
    


if __name__ == '__main__':
    main()
### BUGGY CODE ###

R,G,B,N=map(int,input().split())
counter=0

for r in range(N+1):
    for g in range(N+1):
        b=(N-r*R-g*G)/B
        if b.is_integer() and b>=0:
            counter += 1

print(counter)


### FIXED CODE ###

R,G,B,N=map(int,input().split())
counter=0
 
for r in range(N//R+1):
    for g in range((N-r*R)//G+1):
        b=(N-r*R-g*G)/B
        if b.is_integer() and b>=0:
            counter += 1
 
print(counter)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
H, W = map(int, input().split())
visited = [[True] * (W + 2)]
visited += [[True] + [x == '#' for x in input().rstrip()] + [True] for _ in range(H)]
visited.append([True] * (W + 2))

q = []
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if visited[i][j]:
            q.append((i, j))

ans = -1
while q:
    tmp = []
    ans += 1
    for h, w in q:
        if not visited[h - 1][w]:
            visited[h - 1][w] = True
            tmp.append((h - 1, w))
        if not visited[h + 1][w]:
            visited[h + 1][w] = True
            tmp.append((h + 1, w))
        if not visited[h][w - 1]:
            visited[h][w - 1] = True
            tmp.append((h, w - 1))
        if not visited[h][w + 1]:
            visited[h][w + 1] = True
            tmp.append((h, w + 1))
    q = tmp
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

H,W = map(int,input().split())
INF = 10**18
q = []

visited = [[True]*(W+2)]
visited += [[True] + [x == '#' for x in input().rstrip()] + [True] for _ in range(H)]
visited.append([True]*(W+2))
for i in range(1,H+1):
  for j in range(1,W+1):
    if visited[i][j]:
      q.append((i,j))

moves = [(0,1),(0,-1),(1,0),(-1,0)] #全方向調べる

ans = -1
while q:
  qq = []
  ans += 1
  for x,y in q:
    if not visited[x-1][y]:
      visited[x-1][y] = True
      qq.append((x-1,y))
    if not visited[x+1][y]:
      visited[x+1][y] = True
      qq.append((x+1,y))
    if not visited[x][y-1]:
      visited[x][y-1] = True
      qq.append((x,y-1))
    if not visited[x][y+1]:
      visited[x][y+1] = True
      qq.append((x,y+1))
  q = qq
  
print(ans)
### BUGGY CODE ###

H,W,M = map(int,input().split())
P = [0]*(H+1)
Q = [0]*(W+1)
A = []
for k in range(M):
  a,b = map(int,input().split())
  P[a] += 1
  Q[b] += 1
  A.append((a,b))
Pindex = [i for i, v in enumerate(P) if v == max(P)]
Qindex = [i for i, v in enumerate(Q) if v == max(Q)]
Pmax = P[Pindex[0]]
Qmax = Q[Qindex[0]]
ans = Pmax+Qmax-1
key = 0
for x in Pindex:
  for y in Qindex:
    if (x,y) not in A:
      ans += 1
      key = 1
      break
  if key == 1:
    break
print(ans)



### FIXED CODE ###

H,W,M = map(int,input().split())
P = [0]*(H+1)
Q = [0]*(W+1)
A = set()
for k in range(M):
    a,b = map(int,input().split())
    P[a] += 1
    Q[b] += 1
    A.add((a,b))
Pmax = max(P)
Qmax = max(Q)
Pindex = []
Qindex = []
for i in range(H+1):
    if P[i] == Pmax:
        Pindex.append(i)
for i in range(W+1):
    if Q[i] == Qmax:
        Qindex.append(i)
ans = Pmax+Qmax-1
key = 0
for x in Pindex:
  for y in Qindex:
    if (x,y) not in A:
      ans += 1
      key = 1
      break
  if key == 1:
    break
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import deque

N,M=[int(val) for val in input().split()]
a=deque()
b=deque()

for i in range(M):
  x,y = (int(val) for val in input().split())
  a.append(x)
  b.append(y)

cnt=0
for j in range(M):
    
    val_a=a.popleft()
    val_b=b.popleft()

    stack=deque([1])
    visited=deque()

    while len(stack) > 0:
        val=stack.pop()
        if visited.count(val)==0:
            visited.append(val)
        for i in range(len(a)):
            if a[i]==val:
                if b[i] != visited:
                    stack.append(b[i])
        for i in range(len(b)):
            if b[i]==val:
                if a[i] != visited:
                    stack.append(a[i]) 
                        
    if len(visited) < N:
        cnt+=1
    
    a.append(val_a)
    b.append(val_b)

print(cnt)


### FIXED CODE ###

n,m=[int(val) for val in input().split()]
matrix=[[int(val) for val in input().split()]for val in range(m)]
#print(n,m,matrix)
ee=[[val[0]-1, val[1]-1] for val in matrix]

cnt=0
k=0
for L in range(m):
    xx=[i for i in range(n)]
    for j in range(m):
        if j!=k:
            val1=xx[ee[j][1]]
            val2=xx[ee[j][0]]
            for i in range(len(xx)):
                if xx[i]==val1:
                    xx[i]=val2
#    print(xx)
    if len(set(xx))>1:
        cnt+=1
    k+=1
    
print(cnt)
### BUGGY CODE ###

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

count1 = 0
for i in range(N):
    for j in range(i + 1, N):
        # print(i, j)
        if A[i] > A[j]:
            # print(A[i], A[j])
            count1 += 1
# print(count1)

A2 = A + A[::]
count2 = 0
for i in range(N * 2):
    for j in range(i + 1, N * 2):
        # print(i, j)
        if A2[i] > A2[j]:
            # print(A[i], A[j])
            count2 += 1
# print(count2)

A3 = A + A[::] + A[::]
count3 = 0
for i in range(N * 3):
    for j in range(i + 1, N * 3):
        if A3[i] > A3[j]:
            count3 += 1
# print(count3)

diff1 = count2 - count1
diff2 = count3 - count2
diffx = diff2 - diff1

bn_last = diff1 + diffx * (K - 2)
# print(bn_last)
bn_sum = ((diff1 + bn_last) * (K - 1)) // 2
# print(bn_sum)
an_sum = count1 + bn_sum

if K == 1:
    print(count1)
elif K == 2:
    print(count2)
else:
    print(an_sum % ((10 ** 9) + 7))


### FIXED CODE ###

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

count1 = 0
for i in range(N):
    for j in range(i + 1, N):
        if A[i] > A[j]:
            count1 += 1

count2 = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            count2 += 1

# print(count1)
# print(count2)

ans = K * count1 + (count2 * K * (K - 1)) // 2
ans = ans % ((10 ** 9) + 7)
print(ans)
### BUGGY CODE ###

# 桁DP: 

S = input()
N = len(S)
mod = 10**9+7

# dp[前方からの桁数][13で割ったあまり] := 個数 
dp = [[0] * 13 for _ in range(N+1)]

dp[0][0] = 1

for i in range(N):
    if S[i] == '?':
        for j in range(10):
            for k in range(13):
                dp[i+1][(k * 10 + j) % 13] += dp[i][k] % mod
    else:
        for k in range(13):
            dp[i+1][(k * 10 + int(S[i])) % 13] += dp[i][k] % mod

print(dp[N][5] % mod)


### FIXED CODE ###

# 桁DP: 

S = input()
N = len(S)
mod = 10**9+7

# dp[前方からの桁数][13で割ったあまり] := 個数 
dp = [[0] * 13 for _ in range(N+1)]

dp[0][0] = 1

for i in range(N):
    if S[i] == '?':
        for j in range(10):
            for k in range(13):
                dp[i+1][(k * 10 + j) % 13] += dp[i][k] % mod
    else:
        for k in range(13):
            dp[i+1][(k * 10 + int(S[i])) % 13] += dp[i][k] % mod

print(dp[N][5] % mod)
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
ll = [0]*n
rl = [0]*n
lr = []

for i in range(n):
    ll[i] = s[:i + 1].count("AC")
    rl[i] = s[i:].count("AC")

for i in range(q):
    l, r = map(int, input().split())
    l = max(l - 1, 0)
    lr.append([l , r - 1]) 



for i in range(q):
    ans = rl[0] - ll[lr[i][0]] - rl[lr[i][1]]
    print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    n, q = map(int, input().split())
    s = input()
    t = [0]*(n + 1)

    for i in range(n):
        if s[i: i + 2] == "AC":
            t[i + 1] = t[i] + 1
        else:
            t[i + 1] = t[i]
    
    for i in range(q):
        l, r = map(int, input().split())
        print(t[r - 1] - t[l - 1])

main()
### BUGGY CODE ###

import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
ST = np.array(read().split(), dtype=np.int64)
S = ST[::2]
T = ST[1::2]

edge = np.zeros((N + 1, N + 1), dtype=np.int64)
edge[S, T] = 1
edge_sum = np.sum(edge, axis=1) # edge_sum[i] = iから出ている道の本数

dp = np.zeros(N + 1, dtype = np.float64) # dp[i]はiからNへの距離の期待値
dp[N - 1] = 1.0
# 道を塞がない場合
for i in range(N - 2, 0, - 1):
    dp[i] = 1 + (edge[i][i + 1:]*dp[i + 1:]).sum()/edge_sum[i]

E = dp[1]

for i in range(1, N - 1):
    if edge_sum[i] == 1:
        continue
        # iから出ている道の先にある部屋のうち、その部屋からNまでの距離の期待値が最も大きいものへ通ずる道を塞ぐ
    to = np.where(edge[i] == 1)[0]
    x = to[np.argmax(dp[to])] #iからxへの道を塞ぐ
    edge[i][x] = 0
    edge_sum[i] -= 1
    for j in range(i, 0, - 1):
        dp[j] = 1 + (edge[j][j + 1:]*dp[j + 1:]).sum()/edge_sum[j]
    edge[i][x] = 1
    edge_sum[i] += 1
    E = min(E, dp[1])
print(E)

### FIXED CODE ###

N, M = map(int, input().split())
edge_out = [[] for i in range(N)] #edge_out[i]はiから出ている道
edge_in = [[] for i in range(N + 1)] # edge_in[i]はiに行く道
for i in range(M):
    s, t = map(int, input().split())
    edge_out[s].append(t)
    edge_in[t].append(s)

edge_sum = [len(edge_out[i]) for i in range(N)] # edge_sum[i] = iから出ている道の本数

dp = [0.0]*(N + 1) # dp[i]はiからNへの距離の期待値
dp[N - 1] = 1.0
# 道を塞がない場合
for i in range(N - 2, 0, - 1):
    dp[i] = 1 + sum(dp[j] for j in edge_out[i])/edge_sum[i]
    
p_to_i = [0]*(N + 1) # p_to_i[i]は1から各iへ到達する確率
p_to_i[1] = 1
for i in range(2, N + 1):
    p_to_i[i] = sum(p_to_i[j]/edge_sum[j] for j in edge_in[i])


t = 0

for i in range(1, N - 1):
    if edge_sum[i] == 1:
        continue
        # iから出ている道の先にある部屋のうち、その部屋からNまでの距離の期待値が最も大きいものへ通ずる道を塞ぐ
    t = max(t, p_to_i[i]*(dp[i] - 1- ((dp[i] - 1)*edge_sum[i] - max(dp[j] for j in edge_out[i]))/(edge_sum[i] - 1)))
    
print(dp[1] - t)
### BUGGY CODE ###

n, m = map(int, input().split())
h = list(map(int, input().split()))
path = list(list(map(int, input().split())) for _ in range(m))

table = list([0]*(n+1) for _ in range(n))

for i in range(m):
    p = path[i]
    table[p[0]-1][p[1]] = h[p[1]-1]
    table[p[1]-1][p[0]] = h[p[0]-1]
    
for i in range(n):
    table[i][0] = h[i]

cnt = 0
for i in range(n):
    if table[i][0] > max(table[i][1:n+1]):
        cnt += 1

print(cnt)

### FIXED CODE ###

n, m = map(int, input().split())
h = list(map(int, input().split()))
path = list(list(map(int, input().split())) for _ in range(m))

table = [1]*n

for i in range(m):
    p = path[i]
    if h[p[0]-1] <= h[p[1]-1]:
        table[p[0]-1] = 0
    if h[p[0]-1] >= h[p[1]-1]:
        table[p[1]-1] = 0

        
cnt = 0
for i in table:
    if i == 1:
        cnt += 1
        
print(cnt)
### BUGGY CODE ###

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

T = [[0 for _ in range(N)] for _ in range(N)]

for i in range(N):
  for j in range(i + 1, N):
    if S[i] == S[j]:
      T[i][j] += T[i - 1][j - 1] + 1

answer = 0
for i in range(N):
  for j in range(N):
    if T[i][j] and j - i >= T[i][j]:
      answer = max(answer, T[i][j])
print(answer)


### FIXED CODE ###

import sys
input=sys.stdin.readline
N = int(input())
S = input()

T = [[0 for _ in range(N)] for _ in range(N)]

for i in range(N):
  for j in range(i + 1, N):
    if S[i] == S[j]:
      T[i][j] += T[i - 1][j - 1] + 1

answer = 0
for i in range(N):
  for j in range(N):
    if T[i][j] and j - i >= T[i][j]:
      answer = max(answer, T[i][j])
print(answer)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
pro = []
for i in range(N-1):
    redi = 0
    for j in range(i+1,N):
        redi += (A[i] * A[j])%(1000000007)
    pro.append(redi)
red = sum(pro)
res = red%(1000000007)
print(res)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
sumA = sum(A)%(1000000007)
sumA2 = (sumA * sumA)%(1000000007)
square = 0
for i in range(N):
    square +=  ( A[i]**2 ) % (1000000007)
    square = square % (1000000007)
buf = sumA2 - square
if buf < 0:
  buf = buf + (1000000007)
res = ( buf * ((1000000007+1)//2)) % 1000000007
print(int(res))
### BUGGY CODE ###

n = int(input())
s = [input() for i in range(n)]
ss = sorted(set(s))
l = []
for i in ss:
    l.append([i, s.count(i)])
l = sorted(l, key = lambda x:(-x[1],x[0]))
for i in l:
    if i[1]==l[0][1]:
        print(i[0])

### FIXED CODE ###

import collections
n = int(input())
l = []
s = collections.Counter([input() for i in range(n)])
mn = 0
for i in s.most_common():
    if i[1] >= mn:
        mn = i[1]
        l.append(i[0])
    else:
        break
for i in sorted(l):
        print(i)
### BUGGY CODE ###

#defnishitaradoudarou
def abc143c():
  n=int(input())
  l=list(map(int,input().split()))
  cnt=0
  for i in range(n):
    for j in range(i+1,n):
      for k in range(j+1,n):
        #print(i,j,k)
        a=l[i];b=l[j];c=l[k]
        if a<b+c and b<a+c and c<b+a:
          cnt+=1
  print(cnt)
abc143c()


### FIXED CODE ###

import bisect
 
n=int(input())
l=sorted(list(map(int,input().split())))
ans=0
 
for i in range(n):
  for j in range(i+1,n):
    temp=l[i]+l[j]
    ans+=(bisect.bisect_left(l,temp)-j-1)
print(ans)
### BUGGY CODE ###

import math
R,G,B,N = map(int,input().split())
cnt = 0
for i in range(math.ceil(N/G)+1):
	for j in range(math.ceil(N/R)+1):
			tmp = N - i * G - j * R
			if  tmp >=0 and tmp % B == 0:
				cnt += 1
print(cnt)

### FIXED CODE ###

import math
R,G,B,N = map(int,input().split())
cnt = 0
for i in range(math.ceil(N/G)+1):
	for j in range(math.ceil(N/R)+1):
			tmp = N - i * G - j * R
			if tmp < 0:
				break
			if tmp % B == 0:
				cnt += 1
print(cnt)
### BUGGY CODE ###

n=int(input())
A=list(map(int,input().split( )))
B=list(map(int,input().split( )))
count=0
flag=True
while flag:
    flag=False
    for i in range(-1,n-1):
        tmp=B[i]-B[i-1]-B[i+1]
        if tmp>=A[i]:
            B[i]=tmp
            count+=1
            flag=True
if A==B:
    print(count)
else:
    print(-1)


### FIXED CODE ###

n=int(input())
A=list(map(int,input().split( )))
B=list(map(int,input().split( )))
count=0
prv_count=-1#人の見て追加

#flag=True
while count!=prv_count:
    prv_count=count
    for i in range(-1,n-1):
        tonari=B[i-1]+B[i+1]
        tmp=(B[i]-A[i])//tonari
        if tmp>0:
            B[i]-=tonari*tmp
            count+=tmp
            #flag=True
if A==B:
    print(count)
else:
    print(-1)
### BUGGY CODE ###

import sys
import numpy as np
n = int(input())

dp = np.zeros((2, 3))

dp[0][0], dp[0][1], dp[0][2] = map(int, input().split())
if n == 1:
    print(int(np.max(dp[0])))
    sys.exit()
    
for _ in range(n-1):
    h = list(map(int, input().split()))
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[1][k] = max(dp[0][j] + h[k], dp[1][k])
    dp[0] = dp[1]
print(int(np.max(dp[1])))

### FIXED CODE ###

import sys
import numpy as np
n = int(input())

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

for i in range(n-1):
    a, b, c = list(map(int, input().split()))
    dp0, dp1, dp2 = dp
    dp[0] = max(dp1+a,dp2+a)
    dp[1] = max(dp0+b,dp2+b)
    dp[2] = max(dp0+c,dp1+c)
print(max(dp))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
if n == 1:
  print(1)
  exit()
  
chk = []
for i in range(n):
  a = int(input())
  chk.append((i,a))
  
from heapq import heapify,heappop,heappush
from bisect import bisect_left,insort_left
heapify(chk)
ans = 1

c = []
for j in range(n):
  i,a = heappop(chk)
  if j == 0:
    c.append((a,n-i))
  else:
    ind = bisect_left(c,(a,n-i))
    if ind == 0:
      ans += 1
      insort_left(c,(a,n-i))
    else:
      c[ind-1] = (a,n-i)
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
if n == 1:
  print(1)
  exit()
  
chk = []
for i in range(n):
  a = int(input())
  chk.append((i,a))
  
from bisect import bisect_left,insort_left
from collections import deque
ans = 1

c = deque([])
for j in chk:
  i,a = j
  if i == 0:
    c.append((a,n-i))
  else:
    ind = bisect_left(c,(a,n-i))
    if ind == 0:
      ans += 1
      c.appendleft((a,n-i))
    else:
      c[ind-1] = (a,n-i)
      
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    ans += a[i] ^ a[j]
    ans %= mod
print(ans)

### FIXED CODE ###

mod=10**9+7
def num2bi(x, k):
  #10進数xを2進数k桁(string)で出力
  out=format(x, '0'+str(k)+'b')
  return out

N=int(input())
A=list(map(int, input().split()))
ma=max(A)
keta=1
while ma>=2**keta:
  keta+=1
  
onekazu=[0 for i in range(keta)]
k=str(keta)
for i in range(N):
  temp=format(A[i], '0'+str(k)+'b')
  onekazu=[onekazu[j]+1 if temp[j]=='1' else onekazu[j] for j in range(keta)]
    
out=0
out=sum([(onekazu[i]*(N-onekazu[i])%mod)*(2**(keta-1-i))%mod for i in range(keta)])
out%=mod  
print(out)
### BUGGY CODE ###

N,M=map(int,input().split())
num=[0]*(N+1)
num[0]=1
num[1]=1

A=[]
for i in range(M):
    A.append(int(input()))

P=10**9+7

if 1 in A:
    num[1]=0

if N>=2:
    for i in range(2,N+1):
        num[i]=(num[i-1]+num[i-2])%P
        if i in A:
            num[i]=0

print(num[N])

### FIXED CODE ###

N,M=map(int,input().split())
num=[0]*(N+1)
num[0]=1
num[1]=1

A=[]
for i in range(M):
    A.append(int(input()))

P=10**9+7
index=0

if 1 in A:
    num[1]=0
    index+=1


if N>=2:
    for i in range(2,N+1):
        num[i]=(num[i-1]+num[i-2])%P
        if index<=M-1 and i==A[index]:
            num[i]=0
            index+=1

print(num[N])