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

from collections import Counter

n = int(input())

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

odds = []
evens = []

for i in range(n):
    if i % 2 == 0:
        evens.append(v[i])
    else:
        odds.append(v[i])

evens_c = Counter(evens).most_common()
odds_c = Counter(odds).most_common()

ans = n

fl = 0
for i in range(len(evens_c)):
    for j in range(len(odds_c)):
        try:
            if evens_c[i][0] != odds_c[j][0]:
                ans = min(ans, n - evens_c[i][1] - odds_c[j][1])
                fl = 1
        except:
            continue

if fl == 1:
    print(ans)
    exit()
print(n // 2)


### FIXED CODE ###

from collections import Counter

n = int(input())

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

odds = []
evens = []

for i in range(n):
    if i % 2 == 0:
        evens.append(v[i])
    else:
        odds.append(v[i])

evens_c = Counter(evens).most_common(2)
odds_c = Counter(odds).most_common(2)

if evens_c[0][0] != odds_c[0][0]:
    print(n - evens_c[0][1] - odds_c[0][1])
    exit()

if len(evens_c) == 1 or len(odds_c) == 1:
    print(n // 2)
    exit()

print(n - max(evens_c[0][1] + odds_c[1][1], evens_c[1][1] + odds_c[0][1]))
### BUGGY CODE ###

import sys
import os
sys.setrecursionlimit(100000)

prime = [2]
def gcd(x,y):
    if y <= 0:
        return x
    return gcd(y,x%y)
  
#P以下の素数のリストを作成
def makePrime(P):
    for x in range(3,P+1,2):
        for y in prime:
            if gcd(x,y) == 1:
                if y == max(prime):
                    prime.append(x)
                continue
            else:
                break
                
Q = int(input())
cnt = 0
L = [0 for _ in range(Q) ]
R = [0 for _ in range(Q) ]

for i in range(Q):
    l, r = map(int,input().split())
    L[i], R[i] = l, r
makePrime(max(R))

for i in range(Q):
    l, r = L[i], R[i]
    j = l
    while l <= j and j <= r:
        if j in prime and (j+1)//2 in prime:
            cnt += 1
        j += 1
    print(cnt)
    cnt = 0


### FIXED CODE ###

#Pはiが素数かどうかを表すlist
#素数でないと判明したらFalseに書き換える
P = [True]*100001
for i in range(2,100001):#2から始める
    if P[i]:
        for j in range(i+i,100000,i): #stepはi
            P[j] = False

#2017に似た数の個数をあらかじめ求める
#C[i]はi以下の2017に似た数の個数
C = [0 for _ in range(100002)]
#まずC[i]にiと(i+1)/2が2017likeであれば1を格納
for i in range(3,100000,2):
    if P[i] and P[(i+1)//2]:
        C[i] += 1
#C[i]はi<以下>の2017likeな数の個数なので，
#下から個数を足していく（累積和という）
for i in range(3,100000):
    C[i+1] += C[i]
Q = int(input())
for i in range(Q):
    l,r = map(int,input().split())
    print(C[r]-C[l-1])
### BUGGY CODE ###


import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def change_dict(string):
	dic = {}
	for ch in set(string):
		dic[ch] = string.count(ch)
	return dic

n = int(input())
st = []
for i in range(n):
	st.append(change_dict(input()))
ans = 0

lst = []
for i in st:
	if (st.count(i)>=2) and (not(i in lst)):
		ans += combinations_count(st.count(i),2)
		lst.append(i)

print(ans)





### FIXED CODE ###

n = int(input())
dic = {}
ans = 0
for i in range(n):
	tmp = list(input())
	sorted_str = "".join(sorted(tmp))
	if not(sorted_str in dic):
		dic[sorted_str] = 0
	else:
		dic[sorted_str] += 1
		ans += dic[sorted_str]

print(ans)
### BUGGY CODE ###

import math
A,B,N = map(int, input().split())

a = []
for i in range(N+1):
    ans = math.floor(A*i/B) - A*math.floor(i/B)
    a.append(ans)
print(max(a))


### FIXED CODE ###

import math
A,B,N = map(int, input().split())

# 0,1,2..B-1 毎の繰り返しとなる
# Nの範囲で、最大はB-1が最大となるので、 min(N, B-1)

x = min(N, B-1)
ans = math.floor(A*x/B) - A*math.floor(x/B)
print(ans)
### BUGGY CODE ###

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

from collections import deque

h, w = map(int, readline().split())
a = [input() for i in range(h)]
q = []
dist = [[True] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            q.append((i, j))
            dist[i][j] = False
cnt = -1
while q:
    cnt += 1
    qq = deque()
    for y, x in q:
        if x + 1 < w and dist[y][x + 1]:
            dist[y][x + 1] = False
            qq.append((y, x + 1))
        if x - 1 >= 0 and dist[y][x - 1]:
            dist[y][x - 1] = False
            qq.append((y, x - 1))
        if y + 1 < h and dist[y + 1][x]:
            dist[y + 1][x] = False
            qq.append((y + 1, x))
        if y - 1 >= 0 and dist[y - 1][x]:
            dist[y - 1][x] = False
            qq.append((y - 1, x))
    q = qq
print(cnt)


### FIXED CODE ###

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

h, w = map(int, readline().split())
a = [input() for i in range(h)]
q = []
dist = [[False] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            q.append((i, j))
            dist[i][j] = True
test = [(0, 1), (0, -1), (1, 0), (-1, 0)]
cnt = -1
while q:
    cnt += 1
    qq = []
    for y, x in q:
        for dy, dx in test:
            yy, xx = y + dy, x + dx
            if xx < 0 or yy < 0 or xx > w - 1 or yy > h - 1 or dist[yy][xx]:
                continue
            else:
                dist[yy][xx] = True
                qq.append((yy, xx))
    q = qq
print(cnt)
### BUGGY CODE ###

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

rs = 0
p = -1
r = []
d = 1
# i回目
if N > K:
  for i in range(K+1):
    r.append(d)
    d = A[d - 1]
else:
  for i in range(N+1):
    r.append(d)
    d = A[d - 1]
    for j in range(len(r)):
      if r[j] == d:
        rs = j
        p = i - j + 1
        break
if p == -1:
  print(r[-1])
else:
  print(r[rs+(K-rs)%p])

### FIXED CODE ###

import sys
readline = sys.stdin.readline

def main():
  N, K = map(int, readline().split())
  A = list(map(int, readline().split()))
 
  n = []
  for i in range(N):
    n.append(-1)
  s = 0
  c = -1
  d = A[1-1]
  r = [1]
  n[0] = 0
  for i in range(1, K+1):
    if n[d - 1] == -1:
      n[d - 1] = i
    else:
      s = n[d - 1]
      c = i - n[d - 1]
      break
    r.append(d)
    d = A[d - 1]
  if c == -1:
    print(r[-1])
  else:
    cr = r[s:s+c]
    k = (K - s)%c
    print(cr[k])
  exit()

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

import itertools
from sys import stdin
N=list(map(int,stdin.readline().strip().split()))[0]
st=list(stdin.readline().strip())
count=0
stt=list(set(st))
num=["0","1","2","3","4","5","6","7","8","9"]
num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    cnt = 0
    for i in range(N):
        if number[cnt]==st[i]:
            cnt+=1
            if cnt==3:
                count += 1
                break


print(count)

### FIXED CODE ###

def main():
  N = int(input())
  S = list(map(int,input()))
  ans = 0
  for i in range(10):
    for j in range(10):
      for k in range(10):
        flg = False
        flg2 = False
        for x in range(N):
          if flg2:
            break
          if not flg:
            if S[x] == i:
              flg = True
          else:
            if S[x] == j:
              flg2 = True
              if k in S[x+1:]:
                ans +=1
  print(ans)
main()
### BUGGY CODE ###

K,S=map(int,input().split())
sum=0
count=0
for i in range(K+1):
    sum+=i
    a=sum
    for j in range(K+1):
        sum+=j
        if sum==S: #X＝Sの場合
            count+=1
            #print(str(i)+" "+str(j))
            break
        if S-sum>=0 and S-sum<=K :
            count+=1
            #print(str(i)+" "+str(j))
        sum=a #jを足す前に戻す
    sum=0
print(count)            

### FIXED CODE ###

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

n,m = map(int,input().split())
a_list = list(map(int,input().split()))
for i in range(m):
    b,c = map(int,input().split())
    for i in range(b):
        a_list.append(c)
        
a_list.sort()
print(sum(a_list[::-1][0:n]))

### FIXED CODE ###

n,m = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = []
for i in range(m):
    b_list.append(list(map(int,input().split())))
    
    
b_list.sort(key=lambda x: x[1],reverse=True)
cnt = 0
for i in range(m):
    for j in range(b_list[i][0]):
        if cnt > n:
            break
        a_list.append(b_list[i][1])
        cnt += 1
    
a_list.sort()
print(sum(a_list[::-1][0:n]))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort(reverse=True)
f.sort()
z = list(zip(a,f))
ok = max(x*y for x,y in z)
ng = -1
while ok-ng>1:
  mid = (ok+ng)//2
  if sum(x-mid//y for x,y in z if x*y > mid) <= k:
    ok = mid
  else:
    ng = mid
print(ok)

### FIXED CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort(reverse=True)
f.sort()
z = list(zip(a,f))
ok = max(x*y for x,y in z)
ng = -1
while ok-ng>1:
  mid = (ok+ng)//2
  if sum(x-mid//y for x,y in z if x*y > mid) <= k:
    ok = mid
  else:
    ng = mid
print(ok)
### BUGGY CODE ###

from math import ceil


def log(s):
    # print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


def input_ints():
    return map(int, input().split())


def solve(goal, count, meta):
    if (goal <= 0):
        return count

    min_count = 999999999

    for m in meta:
        meta2 = list(meta)
        meta2.remove(m)
        c = solve(goal - m[3], count + m[0], meta2)
        if c < min_count:
            min_count = c

    for m in reversed(meta):
        if goal - m[0] * m[1] > 0:
            continue
        c = count + ceil(goal / m[1])
        if c < min_count:
            min_count = c
        break

    return min_count


def main():
    d, goal = tuple(input_ints())

    meta = list()
    for i in range(d):
        problems, bonus = tuple(input_ints())
        score = (i + 1) * 100
        meta.append((problems, score, bonus, score * problems + bonus))

    count = solve(goal, 0, meta)
    print(count)


main()


### FIXED CODE ###

from math import ceil


def log(s):
    # print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


def input_ints():
    return map(int, input().split())


cache = dict()


def solve(goal, count, meta):
    if (goal <= 0):
        return count

    s = frozenset([m[1] for m in meta])
    if s in cache:
        return cache[s]

    min_count = 999999999

    for m in meta:
        meta2 = list(meta)
        meta2.remove(m)
        c = solve(goal - m[3], count + m[0], meta2)
        if c < min_count:
            min_count = c

    for m in reversed(meta):
        if goal - m[0] * m[1] > 0:
            continue
        c = count + ceil(goal / m[1])
        if c < min_count:
            min_count = c
        break

    cache[s] = min_count

    return min_count


def main():
    d, goal = tuple(input_ints())

    meta = list()
    for i in range(d):
        problems, bonus = tuple(input_ints())
        score = (i + 1) * 100
        meta.append((problems, score, bonus, score * problems + bonus))

    count = solve(goal, 0, meta)
    print(count)


main()
### BUGGY CODE ###

N,K = map(int,input().split())
H = list(map(int,input().split()))
if K <= len(H):
  for i in range(K):
    H.pop(H.index(max(H)))
  print(sum(H))
else:
  print(0)

### FIXED CODE ###

N,K = map(int,input().split())
H = list(map(int,input().split()))
newH = sorted(H, reverse=True)
if K <= len(H):
  print(sum(newH[K:len(H)]))
else:
  print(0)
### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
?????§?????????
FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§????????????
????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨???
(108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????¨?????§????????????

???????????¨????????????????????? t ?????????????????? Rt (t=0,1,2,,,n???1)???
??\?????¨??????????????????????????§??????????????? Rj???Ri (????????????j>i ??¨??????) ????????§??????
?±??????????????????????
"""
import math

# ?????????
n = int(input().strip())
a = []
for i in range(n):
    a.append(int(input().strip()))
cnt = -1000000000
for j in range(1,n):
    for i in range(0,j):
        x = a[j] - a[i]
        if cnt < x:
            cnt = x
print(cnt)

### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
?????§?????????
FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§????????????
????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨???
(108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????¨?????§????????????

???????????¨????????????????????? t ?????????????????? Rt (t=0,1,2,,,n???1)???
??\?????¨??????????????????????????§??????????????? Rj???Ri (????????????j>i ??¨??????) ????????§??????
?±??????????????????????
"""
import math

# ?????????
cnt = -1000000000

n = int(input().strip())
min = int(input().strip())

for i in range(1,n):
    a =int(input().strip())
    x = a - min
    if cnt < x:
        cnt = x
    if min > a:
        min = a
print(cnt)
### BUGGY CODE ###

import collections

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

cnt_list = []

for i in range(N):
    if A[i] not in cnt_list:
        cnt_list.append(A[i])

c = collections.Counter(A)
values, counts = zip(*c.most_common())
counts = list(counts)
counts.reverse()

answer=0

if len(cnt_list) > K:
    for i in range(len(cnt_list)-K):
        answer += counts[i]
        
        
print(answer)


### FIXED CODE ###

import collections

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

cnt_list = []

c = collections.Counter(A)
values, counts = zip(*c.most_common())
counts = list(counts)
counts.reverse()

answer=0

if len(counts) > K:
    for i in range(len(counts)-K):
        answer += counts[i]
        
print(answer)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10**9)


def dfs(s, to, color, palette, i=0):
    seen[s] = 1
    for v in to[s]:
        if seen[v]:
            continue
        if s < v:
            color[sides.index([s, v])] = palette[i % len(palette)]
            i += 1
        dfs(v, to, color, palette, i)


N = int(input())
sides = [list(map(lambda x:int(x) - 1, input().split())) for _ in range(N - 1)]
to = [[] for _ in range(N)]
for a, b in sides:
    to[a].append(b)
    to[b].append(a)
colors_used = max(len(sub) for sub in to)
palette = [i for i in range(1, colors_used+1)]
seen = [0] * N
color = [0] * (N - 1)

dfs(0, to, color, palette)

print(colors_used)
print(*color, sep='\n')

### FIXED CODE ###

from collections import deque
import sys
sys.setrecursionlimit(10**9)


N = int(input())
to = [[] for _ in range(N)]
order = []

for _ in range(N - 1):
    a, b = list(map(lambda x:int(x) - 1, input().split()))
    to[a].append(b)
    to[b].append(a)
    order.append(b)


def solve():
    dist = [-1] * N
    # 頂点iに向かう辺をiとする
    color = [0] * N
    dist[0] = 0
    color[0] = 0
    que = deque([0])

    while que:
        v = que.popleft()
        used_color = [color[v]]
        next_color = 1
        for nv in to[v]:
            if dist[nv] == -1:
                dist[nv] = dist[v] + 1
                while next_color in used_color:
                    next_color += 1
                color[nv] = next_color
                used_color.append(next_color)
                que.append(nv)

    print(len(set(color[1:])))
    for i in range(N - 1):
        print(color[order[i]])


if __name__ == "__main__":
    solve()
### BUGGY CODE ###

n=int(input())
x=input()
f={0:0,1:1,2:1,3:2}
# for i in range(1,2**n):
#     popcount=format(i,'b').count('1')
#     f[i]=f[i%popcount]+1
for i in range(len(x)):
    if x[i]=='1':
        x_changed=x[:i]+'0'+x[i+1:]
    else:
        x_changed=x[:i]+'1'+x[i+1:]
    num_changed=int(x_changed,2)
    # print(x_changed,num_changed)
    add=[]
    tmp=num_changed
    while True:
        if tmp not in f:
            popcount=format(tmp,'b').count('1')
            add.append(tmp)
            tmp%=popcount
        else:
            break
    while len(add)>0:
        cnt=f[tmp]
        tmp=add.pop()
        f[tmp]=cnt+1
    print(f[num_changed])


### FIXED CODE ###

## 最初のmodをどうにか高速にやりたい → modの性質を使う
## xiのpopcount（1の数）はxのpopcount+1または-1
n=int(input())
x_str=input()
x_popcount=x_str.count('1')
dp=[0]*(x_popcount+1)
for i in range(1,x_popcount+1):
    popcount=format(i,'b').count('1')
    dp[i]=dp[i%popcount]+1
# print(dp)
# x=int(x_str,2)
if x_popcount>1:
    pows_minus=[pow(2,i,(x_popcount-1)) for i in range(n)]
    # x_minus=x%(x_popcount-1)
    x_minus=0
    for i in range(n):
        if x_str[i]=='1':
            x_minus+=pows_minus[n-1-i]
pows_plus=[pow(2,i,(x_popcount+1)) for i in range(n)]
# x_plus=x%(x_popcount+1)
x_plus=0
for i in range(n):
    if x_str[i]=='1':
        x_plus+=pows_plus[n-1-i]

for i in range(len(x_str)):
    ## xi=xi mod popcount(x)+-1
    xi=-1
    if x_str[i]=='1':
        if x_popcount>1: ## else: xi=-1
            xi=(x_minus-pows_minus[n-1-i])%(x_popcount-1)
    else:
        xi=(x_plus+pows_plus[n-1-i])%(x_popcount+1)
    if xi==-1:
        print(0)
    else:
        print(dp[xi]+1)
### BUGGY CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0

for i in range(1, N):
    A[i] = A[i - 1] + A[i]
    if A[i] > K:
        A = A[:i]
        break
A = [0] + A

for i in range(1, M):
    B[i] = B[i - 1] + B[i]
    if B[i] > K:
        B = B[:i]
        break
B = [0] + B

A_length = len(A)
B_length = len(B)

for i in range(A_length):
    j = 0
    while j < B_length:
        if A[i] + B[j] <= K:
            j += 1
        else:
            break
    ans = max(ans, i + (j - 1))
print(ans)


### FIXED CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0

for i in range(1, N):
    A[i] = A[i - 1] + A[i]
    if A[i] > K:
        A = A[:i]
        break
A = [0] + A
A = A[::-1]

for i in range(1, M):
    B[i] = B[i - 1] + B[i]
    if B[i] > K:
        B = B[:i]
        break
B = [0] + B

A_length = len(A)
B_length = len(B)

j = 0
for i in range(A_length):

    while j < B_length:
        if A[i] + B[j] <= K:
            j += 1
        else:
            break
    j -= 1

    ans = max(ans, A_length - (i + 1) + j)
print(ans)
### BUGGY CODE ###

import math
honsu,hp=map(int , input().split())
huru=[]
nageru=[]
for i in range(honsu):
  a,b=input().split()
  huru+=[int(a)]
  nageru+=[int(b)]
cou=0
for i in reversed(sorted(nageru)):
  if i>=max(huru):
  	hp-=i
  	cou+=1
  if hp<=0:
    break
if hp>0:
  cou+=math.ceil(hp/max(huru))
print(cou)

### FIXED CODE ###

from math import ceil
 
N, H = map(int, input().split())
a, b = [], []
 
for _ in range(N):
    a_i, b_i = map(int, input().split())
    a.append(a_i)
    b.append(b_i)
 
max_a = max(a)
b = sorted(b, reverse=True)
ans = float('inf')
th_po = 0
 
for i in range(N):
    th_po += b[i]
    
    if H >= th_po:
        ans_cand = i + 1 + ceil((H - th_po) / max_a)
    else:
        ans_cand = i + 1
    
    ans = min([ans, ans_cand])
 
print(ans)
### BUGGY CODE ###

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

res=0
for i in range(len(PN)):
  for j in range(i+1):
    if PN[i]>PN[j]:
      break
  else:
    res+=1
print(res)
  

### FIXED CODE ###

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

res=0
minim=PN[0]
for i in PN:
  minim=min(minim,i)
  if minim>=i:
    res+=1
print(res)
### BUGGY CODE ###

from collections import deque

N = int(input())
Ass = deque(deque(map(int, input().split())) for _ in range(N))

dp = [0 for _ in range(N)]
flag = True
while flag:
    flag = False
    for i, As in enumerate(Ass):
        if not As:
            continue
        t = As[0] - 1
        if Ass[t][0] == i + 1:
            Ass[t].popleft()
            As.popleft()
            dp[t] = dp[i] = max(dp[t], dp[i]) + 1
            flag = True
if any(Ass):
    print(-1)
else:
    print(max(dp))

### FIXED CODE ###

from collections import deque
 
N = int(input())
Ass = tuple(deque(map(int, input().split())) for _ in range(N))
 
dp = [0 for _ in range(N)]
Q = set(range(N))
ans = -1
while Q:
    ans += 1
    Q2 = Q.copy()
    Q.clear()
    for i in Q2:
        if not Ass[i]:
            continue
        t = Ass[i][0] - 1
        if not Ass[t]:
            continue
        if Ass[t][0] == i + 1:
            Q.add(i)
            Q.add(t)
    for i in Q:
        Ass[i].popleft()

if any(Ass):
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
N = int(input())
strings = []
for i in range(N):
    string = list(input())
    string.sort()
    strings.append(string)
strings.sort()
anagramNum = 0
for i in range(N-1):
    for j in range(i+1, N):
        if strings[j] == strings[i]: anagramNum += 1
print(anagramNum)

### FIXED CODE ###

# -*- coding: utf-8 -*-
N = int(input())
strings = []
for i in range(N):
    string = list(input())
    string.sort()
    strings.append(string)
strings.sort()
wordAnagramCou = 0
anagramCou = 0
for i in range(N-1):
    if strings[i+1] == strings[i]:
        wordAnagramCou += 1
    else:
        wordAnagramCou=0
    anagramCou += wordAnagramCou
print(anagramCou)
### BUGGY CODE ###

import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

def maxim(i,char):
    if i<0:
        return 0
    if d[i,char]!=-1:
        ##print('hi')
        ##print(i,char)
        return d[i,char]
    if char=='C':
        d[i,char]= max(c[i]+maxim(i-1,'B'),c[i]+maxim(i-1,'A'))
        return d[i,char]
    if char=='B':
        d[i,char]= max(b[i] + maxim(i - 1, 'A'), b[i] + maxim(i - 1, 'C'))
        return d[i,char]
    if char=='A':
        d[i,char]= max(a[i] + maxim(i - 1, 'B'), a[i] + maxim(i - 1, 'C'))
        return d[i,char]
n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    d=dict()
    for i in range(n):
        d[i,'A']=-1
        d[i,'B']=-1
        d[i,'C']=-1
    a.append(x)
    b.append(y)
    c.append(z)
print(max(maxim(n-1,'C'),maxim(n-1,'B'),maxim(n-1,'A')))




### FIXED CODE ###

import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    
    a.append(x)
    b.append(y)
    c.append(z)
li=[[-1 for i in range(3)]for j in range(n)]
li[0][0],li[0][1],li[0][2]=a[0],b[0],c[0]
for i in range(1,n):


        li[i][0] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])

        li[i][1] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])

        li[i][2] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
print(max(li[n-1]))
### BUGGY CODE ###

K, S = map(int, input().split())

ans = 0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if x+y+z == S:
                ans += 1

print(ans)


### FIXED CODE ###

K, S = map(int, input().split())

ans = 0
for x in range(K+1):
    for y in range(K+1):
        if S-x-y >= 0 and S-x-y <= K:
            ans += 1

print(ans)