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

import itertools

n=int(input())
ls=[]
k=[]
for i in range(n):
  ls.append(i+1)
  k.append(i+1)
k.pop(0)
k.append(1)

max=0
for l in ls:
  max+=l%k[l-1]
print(max)
  


### FIXED CODE ###

import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

n = inp()
print(int((n-1)*n//2))

# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.buffer.readline().rstrip()
def resolve():
    n = int(input())

    dp = [None] * (1 << n)
    dp[0] = 1
    now = [0]
    for _ in range(n):
        A = list(map(int, input().split()))
        next = []
        for i in range(n):
            if not A[i]:
                continue
            for U in now:
                if (U >> i) & 1:
                    continue
                nU = U | 1 << i
                if dp[nU] is None:
                    dp[nU] = dp[U]
                    next.append(nU)
                else:
                    dp[nU] += dp[U]
                    if dp[nU] >= MOD:
                        dp[nU] -= MOD
        now = next

    res = dp[-1]
    if res is None:
        res = 0
    print(res)
resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    popcount_to_state = [[] for _ in range(n + 1)]
    for U in range(1 << n):
        popcount_to_state[bin(U).count('1')].append(U)

    dp = [0] * (1 << n)
    dp[0] = 1
    for i in range(n):
        A = tuple(map(int, input().split()))
        for j in range(n):
            if not A[j]:
                continue
            for U in popcount_to_state[i]:
                if (U >> j) & 1:
                    continue
                nU = U | 1 << j
                dp[nU] += dp[U]
                if dp[nU] >= MOD:
                    dp[nU] -= MOD
    print(dp[-1])
resolve()
### BUGGY CODE ###

K = int(input())
AT = list(map(int,input().split()))

A=reversed(AT)
s = 2;b = 1;lis=[]
for i in A:
    ns = i
    if s > ns:
        while s > ns:
            ns += i
    s = ns
sn = s
for i in AT:
    sn = sn-sn%i

if sn!=2:
    print(-1)
    exit()
b = 1
AT.reverse()
for i in AT:
    b=b-b%i
    nb = i
    if b > nb:
        while b > nb:
            nb+= i
    b= (nb+i-1)
print(s,b)


### FIXED CODE ###

K = int(input())
AT = list(map(int,input().split()))

A=reversed(AT)
s = 2;b = 1;lis=[]
for i in A:
    ns = i
    if s > ns:
        ns +=(((s-ns)//i)*i)
        if s > ns:
            ns+=i
    s = ns
sn = s
for i in AT:
    sn = sn-sn%i

if sn!=2:
    print(-1)
    exit()
b = 1
AT.reverse()
for i in AT:
    b=b-b%i
    nb = i
    if b > nb:
        nb +=(((b-nb)//i)*i)
        if b > nb:
            nb+=i
    b= (nb+i-1)
print(s,b)
### BUGGY CODE ###

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

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
cnt = defaultdict(int)
for a in A:
    cnt[a] += 1
n = 1
while n <= 2 * A[0]:
    n *= 2
n //= 2
ans = 0
while n > 0:
    for a in A:
        if cnt[a] == 0:
            continue
        b = n - a
        if b > a:
            break
        c = 0
        if b == a and cnt[a] > 1:
            c = cnt[a] // 2
        elif b != a and cnt[b] > 0:
            c = min(cnt[a], cnt[b])
        cnt[a] -= c
        cnt[b] -= c
        ans += c
    n //= 2
print(ans)

### FIXED CODE ###

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

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
cnt = defaultdict(int)
for a in A:
    cnt[a] += 1
n = 1
while n <= 2 * A[0]:
    n *= 2
n //= 2
ans = 0
while n > 0:
    for a in A:
        if cnt[a] == 0:
            continue
        b = n - a
        if b < 0:
            continue
        if b > a:
            break
        c = 0
        if b == a and cnt[a] > 1:
            c = cnt[a] // 2
        elif b != a and cnt[b] > 0:
            c = min(cnt[a], cnt[b])
        cnt[a] -= c
        cnt[b] -= c
        ans += c
    n //= 2
print(ans)
### BUGGY CODE ###

h,w,m = map(int,input().split())
hw = [list(map(int,input().split())) for i in range(m)]
hb = [0 for i in range(h)]
wb = [0 for j in range(w)]
M = [[0 for i in range(w)] for j in range(h)]

for i in range(m):
    hb[hw[i][0]-1] += 1
    wb[hw[i][1]-1] += 1
    M[hw[i][0]-1][hw[i][1]-1] = -1

max_h = max(hb)
max_w = max(wb)
ans = max_h + max_w
count = hb.count(max_h) * wb.count(max_w)
for i in range(m):
    if hb[hw[i][0]-1] == max_h and wb[hw[i][1]-1] == max_w:
        count -= 1
if count <= 0:
    ans -= 1
print(ans)

### FIXED CODE ###

h,w,m = map(int,input().split())
hw = [list(map(int,input().split())) for i in range(m)]
hb = [0] * h
wb = [0] * w

for i in range(m):
    hb[hw[i][0]-1] += 1
    wb[hw[i][1]-1] += 1

max_h = max(hb)
max_w = max(wb)
ans = max_h + max_w
count = hb.count(max_h) * wb.count(max_w)
for i in range(m):
    if hb[hw[i][0]-1] == max_h and wb[hw[i][1]-1] == max_w:
        count -= 1
if count <= 0:
    ans -= 1
print(ans)
### BUGGY CODE ###


n, q = map(int, input().split())
s = input()
li_lr = list()

li_flg = [0] * len(s)

for i in range(q):
    li_lr.append(list(map(int, input().split())))


for idx, v in enumerate(s):
    if v == 'C':
        if idx != 0 and s[idx - 1] == 'A':
            li_flg[idx] = 1


for l in li_lr:
    li_w = li_flg[l[0] - 1: l[1]]
    if li_w[0] == 1:
        print(sum(li_w) - 1)
    else:
        print(sum(li_w))



### FIXED CODE ###

n, q = map(int, input().split())
s = input()
li_lr = list()

li_flg = [0] * len(s)

for i in range(q):
    li_lr.append(list(map(int, input().split())))


for idx, v in enumerate(s):
    if v == 'C' and idx != 0 and s[idx - 1] == 'A':
        li_flg[idx] = li_flg[idx - 1] + 1
    else:
        li_flg[idx] = li_flg[idx - 1]

for l in li_lr:
    print(li_flg[l[1] - 1] - li_flg[l[0] - 1])
### BUGGY CODE ###

from collections import deque

N = int(input())

neighbor = [[] for _ in range(N)]

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

# 黒を0、白を1、未着色を-1で表す
black_white = [0] + [-1]*(N-2) + [1]

# 点iを与えると、点iからの最短距離のリストを返す
def shortest_distance(home_point):
    shortest_distance_list = [-1]*N
    shortest_distance_list[home_point] = 0
    visited = [0]*N
    visited[home_point] = 1
    next_points = deque([home_point])

    while len(next_points) > 0:
        p = next_points.popleft()
        visited[p] = 1
        for idx in neighbor[p]:
            if visited[idx] == 0:
                shortest_distance_list[idx] = shortest_distance_list[p]+1
                if idx not in next_points:
                    next_points.append(idx)

    return shortest_distance_list

shortest_distance_from_Fennec = shortest_distance(0)
shortest_distance_from_Snuke = shortest_distance(N-1)

for idx in range(1,N-1):
    if shortest_distance_from_Fennec[idx] <= shortest_distance_from_Snuke[idx]:
        black_white[idx] = 0
    else:
        black_white[idx] = 1

print("Fennec" if black_white.count(0) > black_white.count(1) else "Snuke")


### FIXED CODE ###

from collections import deque

N = int(input())

neighbor = [[] for _ in range(N)]

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

# 黒を0、白を1、未着色を-1で表す
black_white = [0] + [-1]*(N-2) + [1]

# 点iを与えると、点iからの最短距離のリストを返す
def shortest_distance(home_point):
    shortest_distance_list = [-1]*N
    shortest_distance_list[home_point] = 0
    next_points = deque([home_point])

    while len(next_points) > 0:
        p = next_points.popleft()
        for idx in neighbor[p]:
            if shortest_distance_list[idx] == -1:
                shortest_distance_list[idx] = shortest_distance_list[p]+1
                next_points.append(idx)

    return shortest_distance_list

shortest_distance_from_Fennec = shortest_distance(0)
shortest_distance_from_Snuke = shortest_distance(N-1)

for idx in range(1,N-1):
    if shortest_distance_from_Fennec[idx] <= shortest_distance_from_Snuke[idx]:
        black_white[idx] = 0
    else:
        black_white[idx] = 1

print("Fennec" if black_white.count(0) > black_white.count(1) else "Snuke")
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
h,w = map(int,input().split())
l=['#'*(w+2)]+['#'+input().strip()+'#' for i in range(h)]+['#'*(w+2)]
dp = [[[0]*2 for i in range(w+2)] for i in range(h+2)]
cnt = 0
ans = 0

def dfsw(x,y,cnt):
  if l[x][y+1] == '.':
    cnt += 1
    dp[x][y][0] = dfsw(x,y+1,cnt)
    return dp[x][y][0]
  else:
    dp[x][y][0] = cnt
    return dp[x][y][0]

def dfsh(x,y,cnt):
  if l[x+1][y] == '.':
    cnt += 1
    dp[x][y][1] = dfsh(x+1,y,cnt)
    return dp[x][y][1]
  else:
    dp[x][y][1] = cnt
    return dp[x][y][1]

for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.':
      if dp[i][j][0] == 0:
        dfsw(i,j,1)
      if dp[i][j][1] == 0:
        dfsh(i,j,1)
      ans = max(ans, sum(dp[i][j]) - 1)
print(ans)

### FIXED CODE ###

import numpy as np
h,w = map(int,input().split())
ar = np.array([list(input()) for _ in range(h)]) == '.'
#print(ar)
l = np.zeros((h,w),dtype=int)
r = np.zeros((h,w),dtype=int)
u = np.zeros((h,w),dtype=int)
d = np.zeros((h,w),dtype=int)

for i in range(h):
  u[i] = (u[i-1]+1)*ar[i]
  #print(u)
  d[-i-1] = (d[-i]+1)*ar[-i-1]
  #print(d)
  
for j in range(w):
  l[:,j] = (l[:,j-1]+1)*ar[:,j]
  #print(l)
  r[:,-j-1] = (r[:,-j]+1)*ar[:,-j-1]
  #print(r)
print(np.max(u+d+l+r)-3)
### BUGGY CODE ###

N = int(input())
A = input().split()
X = [0] * (N // 2)
count = 0

num = 2 ** (len(A) - len(set(A)))



for a in A:
    k = A.count(str(a))
    if k == 2:
        count += 1
    else:
        pass

K = 2 ** (count/2)

if A.count('0') == 2:
    print(0)
elif K == num:
    print(int(K))
else:
    print(0)

### FIXED CODE ###

N = int(input())
o, h = N%2, N//2
arr = [0]*h
for a in map(int, input().split()):
    if a > 0:
        arr[a//2 - o] += 1
if all(c == 2 for c in arr):
    print((1 << h) % (10**9 + 7))
else:
    print(0)
### BUGGY CODE ###

import math


def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0  # 1は素数ではない
    x_sqrt = math.sqrt(x)  # 記憶させていちいち計算しない

    # エラトステネスのふるい
    for prime in primes:
        if prime == 0: continue  # 先に処理
        if prime > x_sqrt: break
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]


def twoprimes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0  # 1は素数ではない
    x_sqrt = math.sqrt(x)  # 記憶させていちいち計算しない

    # エラトステネスのふるい
    for prime in primes:
        if prime == 0: continue  # 先に処理
        if prime > x_sqrt: break
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime*2-1 for prime in primes if prime != 0]


q = int(input())
array = [[int(x) for x in input().split()] for x in range(q)]
primes_array = set(primes(10000))
twoprimes_array = set(twoprimes(10000))

for item in array:
    res = set(range(item[0], item[1]+1, 2)) & primes_array
    twores = set(range(item[0], item[1]+1, 2)) & twoprimes_array
    print(len(res & twores))

### FIXED CODE ###

import math
import bisect


def is_prime(x):
    if x < 2: return False # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数

    # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True


if __name__ == '__main__':
    q = int(input())
    array = [[int(x) for x in input().split()] for x in range(q)]
    nearby_2017 = [x for x in range(1, 100000, 2) if is_prime(x) and is_prime((x+1)/2)]
    for i, j in array:
        print(bisect.bisect_right(nearby_2017, j) - bisect.bisect_left(nearby_2017, i))
### BUGGY CODE ###

import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    def query(x):
        print(x)
        ret = input()
        if ret == "Vacant":
            sys.exit()
        return ret

    n = int(readline())

    l = 0
    r = n - 1

    ls = query(l)
    rs = query(r)

    while r - l > 1:
        mid = (l + r) // 2
        ms = query(mid)
        if (mid - l) % 2 == 0:
            if ls == ms:
                l = mid + 1
                ls = ms
            else:
                r = mid - 1
                rs = ms
        else:
            if ls == ms:
                r = mid - 1
                rs = ms
            else:
                l = mid + 1
                ls = ms
    query(l)
    query(r)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    def query(x):
        print(x)
        ret = input()
        if ret == "Vacant":
            sys.exit()
        return ret

    n = int(readline())

    l = 0
    r = n - 1

    op = {"Male": "Female", "Female": "Male"}

    ls = query(l)
    rs = query(r)

    while r - l > 1:
        mid = (l + r) // 2
        ms = query(mid)
        if (mid - l) % 2 == 0:
            if ls == ms:
                l = mid + 1
                ls = op[ms]
            else:
                r = mid - 1
                rs = op[ms]
        else:
            if ls == ms:
                r = mid - 1
                rs = op[ms]
            else:
                l = mid + 1
                ls = op[ms]
    query(l)
    query(r)


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

N,K,Q = (int(x) for x in input().split())
Win = ['No']*N
A = [0]*Q
for T in range(0,Q):
    A[T] = int(input())
    
for TT in range(0,N):
    if K-Q+A.count(TT+1)>0:
        Win[TT] = 'Yes'
print('\n'.join(Win))

### FIXED CODE ###

def Convert(N):
    if N>0: return 'Yes'
    else: return 'No'

N,K,Q = (int(x) for x in input().split())
Win = [K-Q]*N
for T in range(0,Q):
    Win[int(input())-1] += 1
print('\n'.join(list(map(Convert,Win))))
### BUGGY CODE ###

N,K,Q=map(int,input().split())
Q_list=[input() for i in range(Q)]  
#print(Q_list)
list_count=[]
for i in range(1,N+1):
  a=Q_list.count(str(i))
  list_count.append(a)
#print(list_count)

for j in range(0,N):
  y=list_count[j]
  d=K-Q+y
  if 0>=d:
    print("No")
  else:
    print("Yes")

### FIXED CODE ###

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

A=[K]*N
for i in range(Q):
  a=int(input())
  A[a-1] +=1
for i in range(len(A)):
  
  if A[i]-Q<=0:
    print("No")
  else:
    print("Yes")
### BUGGY CODE ###

N,K = map(int,input().split())
R,S,P  =  map(int,input().split())
s = input()
ans = 0
for i in range(K):
    if s[i] == 'r':
        ans += P
    elif s[i] == 's':
        ans += R
    else:
        ans += S
T = []
for i in range(K,N):
    if s[i] == 'r':
        if s[i-K] == 'r':
            if i-K in T:
                ans += P
            else:
                T.append(i)
        else:
             ans += P
    elif s[i] == 's':
        if s[i-K] == 's':
            if i-K in T:
                ans += R
            else:
                T.append(i)
        else:
             ans += R
    else:
        if s[i-K] == 'p':
            if i-K in T:
                ans += S
            else:
                T.append(i)
        else:
            ans += S
print(ans)


### FIXED CODE ###

N,K = map(int,input().split())
R,S,P  =  map(int,input().split())
t = input()
s = []
for i in range(N):
    s.append(t[i])
ans = 0
for i in range(K):
    if s[i] == 'r':
        ans += P
        s[i] = 'a'
    elif s[i] == 's':
        ans += R
        s[i] = 'b'
    else:
        ans += S
        s[i] = 'c'
T = []
for i in range(K,N):
    if s[i] == 'r':
        if s[i-K] != 'a':
            ans += P
            s[i] = 'a'
    elif s[i] == 's':
        if s[i-K] != 'b':
            ans += R
            s[i] = 'b'
    else:
        if s[i-K] != 'c':
            ans += S
            s[i] = 'c'
print(ans)
### BUGGY CODE ###


import sys
from collections import defaultdict
from collections import deque
import numpy as np
import heapq
from heapq import heappush, heappop
import itertools
import math
import copy


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

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

A = []
B = []
for _ in range(H):
    a = list(map(int, input().split()))
    A.append(a)

for _ in range(H):
    b = list(map(int, input().split()))
    B.append(b)

C = []
for i in range(H):
    cs = []
    for j in range(W):
        c = abs(A[i][j] - B[i][j])
        cs.append(c)

    C.append(cs)


def calc(arr):
    # print(arr)
    arr.sort(reverse=True)
    a = 0
    b = 0

    for i in range(len(arr)):
        if a > b:
            b += arr[i]
        else:
            a += arr[i]

    return abs(a-b)


def dfs(x, y, arr):
    # print(arr)
    arr.append(C[y][x])

    if x == W-1 and y == H-1:
        return calc(arr)

    xs = [0, 1]
    ys = [1, 0]

    mn = 10**4
    for i in range(2):
        if x+xs[i] <= W-1 and y+ys[i] <= H-1:
            arr2 = copy.copy(arr)
            a = dfs(x+xs[i], y+ys[i], arr2)

            if a < mn:
                mn = a

    return mn


ans = dfs(0, 0, [])
print(ans)


### FIXED CODE ###


import sys
from collections import defaultdict
from collections import deque
import numpy as np
import heapq
from heapq import heappush, heappop
import itertools
import math
import copy

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

A = []
B = []
for _ in range(H):
    a = list(map(int, input().split()))
    A.append(a)

for _ in range(H):
    b = list(map(int, input().split()))
    B.append(b)

C = []
for i in range(H):
    cs = []
    for j in range(W):
        c = abs(A[i][j] - B[i][j])
        cs.append(c)

    C.append(cs)


X = (H+W) * 80
L = X + X + 1

dp = [[0] * W for _ in range(H)]
dp[0][0] = np.zeros(L, np.bool)
d = C[0][0]
dp[0][0][X+d] = 1
dp[0][0][X-d] = 1

for r in range(H):
    for c in range(W):
        if r == 0 and c == 0:
            continue

        l = np.zeros(L, np.bool)
        d = C[r][c]

        if r != 0:
            l[d:] |= dp[r-1][c][:L-d]
            l[:L-d] |= dp[r-1][c][d:]

        if c != 0:
            l[d:] |= dp[r][c-1][:L-d]
            l[:L-d] |= dp[r][c-1][d:]

        dp[r][c] = l

dp = dp[-1][-1]
d = np.where(dp)[0] - X
ans = np.abs(d).min()
print(ans)
### BUGGY CODE ###

#大きな数の割り算は計算重いかも，for文内も掛け算の二分探索に

def main():
    import sys
    input = sys.stdin.readline

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

    #積がX未満になるものがK-1個以下になる最大のXを探す

    ng=10**18+1
    ok=-ng

    while ng-ok>1:
        X=(ok+ng)//2
        temp=0

        for i in range(N):
            if A[i]>0:
                #A[i]*A[j]がX未満となるjの個数を数える
                l=-1
                r=N
                while r-l>1:
                    med=(l+r)//2
                    if A[i]*A[med]<X:
                        l=med
                    else:
                        r=med
                temp+=r
                if r>i:
                    temp-=1

            elif A[i]<0:
                #A[i]*A[j]がX未満となるjの個数を数える
                l=-1
                r=N
                while r-l>1:
                    med=(l+r)//2
                    if A[i]*A[med]<X:
                        r=med
                    else:
                        l=med
                temp+=N-r
                if r<=i:
                    temp-=1

            else:
                if X>0:
                    temp+=N-1


        temp=temp//2

        if temp>=K:
            ng=X
        else:
            ok=X

    print(ok)


main()




### FIXED CODE ###

#場合分け尺取り


n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr)
nc=0
zc=0
pc=0
for i in range(n):
  if arr[i]<0:
    nc+=1
  elif arr[i]==0:
    zc+=1
  else:
    pc+=1
ncc=nc*pc
zcc=zc*(nc+pc)+(zc*(zc-1))//2
pcc=(nc*(nc-1))//2+(pc*(pc-1))//2
if k<=ncc:
  arr1=[]
  arr2=[]
  for i in range(n):
    if arr[i]<0:
      arr1.append(-arr[i])
    elif arr[i]>0:
      arr2.append(arr[i])
  arr1=arr1[::-1]
  c1=len(arr1)
  c2=len(arr2)
  l=0
  r=10**18+1
  k=ncc-k
  while r-l!=1:
    mid=(l+r)//2
    cnt=0
    pos=c2-1
    for i in range(c1):
      while pos!=-1:
        if arr2[pos]>mid//arr1[i]:
          pos-=1
        else:
          break        
      cnt+=pos+1
    if cnt>k:
      r=mid
    else:
      l=mid
  print(-r)
elif k<=(ncc+zcc):
  print(0)
else:
  arr1=[]
  arr2=[]
  for i in range(n):
    if arr[i]<0:
      arr1.append(-arr[i])
    elif arr[i]>0:
      arr2.append(arr[i])
  arr1=arr1[::-1]
  c1=len(arr1)
  c2=len(arr2)
  l=0
  r=10**18+1
  k-=(ncc+zcc)
  while r-l!=1:
    mid=(l+r)//2
    cnt1=0
    pos1=c1-1
    for i in range(c1):
      tmp=0
      while pos1!=-1:
        if arr1[pos1]>mid//arr1[i]:
          pos1-=1
        else:
          break
      tmp+=pos1+1
      if arr1[i]**2<mid:
        tmp-=1
      cnt1+=tmp
    cnt1=cnt1//2
    cnt2=0
    pos2=c2-1
    for i in range(c2):
      tmp=0
      while pos2!=-1:
        if arr2[pos2]>mid//arr2[i]:
          pos2-=1
        else:
          break
      tmp+=pos2+1
      if arr2[i]**2<mid:
        tmp-=1
      cnt2+=tmp
    cnt2=cnt2//2
    cnt=cnt1+cnt2
    if cnt>=k:
      r=mid
    else:
      l=mid
  print(r)
### BUGGY CODE ###

import numpy as np
n = int(input())
ary = [list(map(int,input().split())) for _ in range(n)]
ary = np.array(ary)
dp = np.zeros((n,3))
dp[0] = ary[0]
for i in range(n-1):
    for j in range(3):
        for k in range(3):
            if k == j:continue
            dp[i+1][k] = max(dp[i+1][k],dp[i][j] + ary[i+1][k])
print(int(max(dp[n-1])))

### FIXED CODE ###

nums = int(input())
ary = [0 for i in range(nums)]
for i in range(nums):
    ary[i] = list(map(int,input().split()))

dp = [0 for i in range(nums+1)]
for i in range(len(dp)):
    dp[i] = [0,0,0]

for i in range(nums):
    for x in range(3):
        for y in range(3):
            if x == y: continue
            check = dp[i][x] + ary[i][y]
            if check >= dp[i+1][y]:
                dp[i+1][y] = check

result= 0
for i in range(3):
    if result < dp[nums][i]:
        result = dp[nums][i]
print(result)