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

N = int(input())
L = sorted(list(map(int,input().split())))
table = [[0 for _ in range(N)] for _ in range(N)]
ans = 0
for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      if L[i]+L[j]>L[k] and L[j]+L[k]>L[i] and L[k]+L[i]>L[j]:
        ans += 1
print(ans)

### FIXED CODE ###

import bisect 
N = int(input())
L = sorted(list(map(int,input().split())))
ans = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    idx = bisect.bisect(L,L[i]+L[j]-1)
    ans += idx-j-1
print(ans)
### BUGGY CODE ###

# coding: utf-8
from heapq import heapify, heappop, heappush
N, M = map(int, input().split())
AB = []
heapify(AB)
d = {}
for _ in range(N):
    a, b = list(map(int, input().split()))
    if a > M:
        continue
    if a not in d.keys():
        d[a] = [-b]
    else:
        d[a].append(-b)
ans = 0
ables = []
now = 1
while now <= M:
    if now in d.keys():
        for v in d[now]:
            heappush(ables, v)
    if len(ables) > 0:
        v = heappop(ables)
        ans += -1 * v
    now += 1
print(ans)

### FIXED CODE ###

# coding: utf-8
from heapq import heapify, heappop, heappush
N, M = map(int, input().split())
AB = []
heapify(AB)
d = {}
for _ in range(N):
    a, b = list(map(int, input().split()))
    if a > M:
        continue
    if a not in d.keys():
        d[a] = [-b]
    else:
        d[a].append(-b)
day = M - 1
ans = 0
ables = []
while day >= 0:
    now = M - day
    if now in d.keys():
        for v in d[now]:
            heappush(ables, v)
    if len(ables) > 0:
        v = heappop(ables)
        ans += -1 * v
    day -= 1
print(ans)
### BUGGY CODE ###

A, B, Q = map(int, input().split())
s = []
for _ in range(A):
    s.append(int(input()))
t = []
for _ in range(B):
    t.append(int(input()))
x = []
for _ in range(Q):
    x.append(int(input()))

def binsearch(threshold, lst):
    left, right = -1, len(lst)

    while right - left > 1:
        mid = (left + right) // 2
        if lst[mid] > threshold:
            right = mid
        else:
            left = mid
    return (left, right)

for q in x:
    ans = 10 ** 11
    for i in range(2):
        for j in range(2):
            a = binsearch(q, s)[i]
            b = binsearch(q, t)[j]
            #print(i, j, a, b)
            if 0 <= a <= A - 1 and 0 <= b <= B - 1:
                    #print(s[a], t[b], q)
                    ans = min(ans, abs(s[a] -t[b]) + min(abs(s[a]-q), abs(t[b]-q)))
    print(ans)

### FIXED CODE ###

A, B, Q = map(int, input().split())
s = []
for _ in range(A):
    s.append(int(input()))
t = []
for _ in range(B):
    t.append(int(input()))
x = []
for _ in range(Q):
    x.append(int(input()))

def binsearch(threshold, lst):
    left, right = -1, len(lst)

    while right - left > 1:
        mid = (left + right) // 2
        if lst[mid] > threshold:
            right = mid
        else:
            left = mid
    return (left, right)

for q in x:
    ans = 10 ** 11
    for i in range(2):
        for j in range(2):
            a = binsearch(q, s)[i]
            b = binsearch(q, t)[j]
            #print(i, j, a, b)
            if 0 <= a <= A - 1 and 0 <= b <= B - 1:
                    #print(s[a], t[b], q)
                    ans = min(ans, abs(s[a] -t[b]) + min(abs(s[a]-q), abs(t[b]-q)))
    print(ans)
### BUGGY CODE ###

#n=int(input())
#li=input().split()
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
import math

lis=[]
#N Q
li=list(map(int,input().split()))
S=input()
for i in range(li[1]):
    #l_i r_i
    lr=list(map(int,input().split()))
    lis.append(lr)
L=[0]*li[0]
for i in range(li[0]-1):
    if S[i:i+2]=="AC":
        L[i]+=1
for i in range(li[1]):
    ans=0
    ans=sum(L[lis[i][0]-1:lis[i][1]-1])
    print(ans)


### FIXED CODE ###

#n=int(input())
#li=input().split()
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math

lis=[]
#N Q
li=list(map(int,input().split()))
S=input()
for i in range(li[1]):
    #l_i r_i
    lr=list(map(int,input().split()))
    lis.append(lr)
L=[0]*(li[0])
for i in range(li[0]-1):
    L[i+1]+=L[i]
    if S[i:i+2]=="AC":
        L[i+1]+=1
for i in range(li[1]):
    print(L[lis[i][1]-1]-L[lis[i][0]-1])
### BUGGY CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
for k in range(len(P)):
    P[k] = (P[k] + 1 ) / 2
P = [sum(P[n:n + K]) for n in range(N - K + 1)]
print(max(P))

### FIXED CODE ###

def INT():
    return int(input())

def LI():
    return list(map(int, input().split()))

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

N, K = MI()
p = LI()

def E(x):
    return (x + 1) / 2

for i in range(N):
    p[i] = E(p[i])
    
ans = sum(p[:K])
E_K = ans

for i in range(N - K):
    E_K += p[i + K] - p[i]
    ans = max(ans, E_K)

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

import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def f(S, i):
    D = [-1] * len(S)
    P = [set() for _ in range(len(S))]

    Q = deque()
    Q.append(i)
    D[i] = 1

    while Q:
        v = Q.popleft()

        for w, s in enumerate(S[v]):
            if s == "0":
                continue

            if w in P[v]:
                continue
            
            if D[w] > 0 and D[w] < D[v] + 1:
                return -1

            P[w].add(v)
            D[w] = D[v] + 1
            Q.append(w)
    return D[v]


def main():
    N = int(input())
    S = [input().strip() for _ in range(N)]

    res = -1
    for i in range(N):
        r = f(S, i)
        res = max(res, r) 
    
    print(res)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def f(S, i):
    D = [-1] * len(S)
    P = [set() for _ in range(len(S))]
    
    Q = deque()
    Q.append(i)
    D[i] = 1

    while Q:
        v = Q.popleft()

        for w in S[v]:
            if w in P[v]:
                continue
            
            if D[w] > 0 and D[w] < D[v] + 1:
                return -1

            if D[w] < 0:
                Q.append(w)
            P[w].add(v)
            D[w] = D[v] + 1

    return D[v]


def main():
    N = int(input())
    S = [input().strip() for _ in range(N)]
    L = [set(j for j in range(N) if S[i][j] == "1") for i in range(N)]

    res = -1
    for i in range(N):
        r = f(L, i)
        res = max(res, r) 
    
    print(res)


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

N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
r=0
for i,aa in enumerate(A):
    for j,a in enumerate(aa[i+1:]):
        f=1
        j+=i+1
        for k in range(N):
            if k==i or k==j:
                continue
            if a>A[i][k]+A[k][j]:
                f=r=-1
                break
            if a==A[i][k]+A[k][j]:
                f=0
                break
        if f==1:
            r+=a
        elif f==-1:
            break
    if r<0:
        break
print(r)

### FIXED CODE ###

N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
r=0
for i,aa in enumerate(A):
    for j,a in enumerate(aa[i+1:]):
        f=1
        j+=i+1
        for k in range(N):
            if k==i or k==j:
                continue
            if a>A[i][k]+A[k][j]:
                f=r=-1
                break
            if a==A[i][k]+A[k][j]:
                f=0
                break
        if f==1:
            r+=a
        elif f==-1:
            break
    if r<0:
        break
print(r)
### BUGGY CODE ###

n, w = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(n)]
if w < items[0][0] :
    print(0)
    exit()
w_sum = 0
v_sum = 0
for i in range(n):
    w_sum += items[i][0]
    v_sum += items[i][1]
if w >= w_sum:
    print(v_sum)
    exit()
dp = {}
#for j in range(1,w+1):
for j in range(items[0][0],w+1):
    for i in range(1,n+1):
        if j-items[i-1][0] >= 0:
            if str(i-1)+":"+str(j) not in dp:
                dp[str(i - 1) + ":" + str(j)] = 0
            if str(i-1)+":"+str(j-items[i-1][0]) not in dp:
                dp[str(i - 1) + ":" + str(j - items[i - 1][0])] = 0
            dp[str(i)+":"+str(j)] = max(dp[str(i-1)+":"+str(j)],dp[str(i-1)+":"+str(j-items[i-1][0])]+items[i-1][1])
        else:
            if str(i-1)+":"+str(j) not in dp:
                dp[str(i - 1) + ":" + str(j)] = 0
            dp[str(i)+":"+str(j)] = dp[str(i-1)+":"+str(j)]
print(dp[str(n)+":"+str(w)])

### FIXED CODE ###

N,W=map(int,input().split())
dp=[[-1]*301 for i in range(N+1)]
dp[0][0]=0

for i in range(N):
    w,v=map(int,input().split())
    if i==0:
        base=w
    for i in range(N)[::-1]:
        for j in range(301)[::-1]:
            if dp[i][j]!=-1:
                dp[i+1][j+w-base]=max(dp[i][j]+v,dp[i+1][j+w-base])

ans=0
for index,item in enumerate(dp):
    if W-index*base+1<=0:
        break
    ans=max(max(item[:W-index*base+1]),ans)

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

a,b,x = map(int,input().split())
count=0
for i in range(a,b+1):
  if i%x == 0:
    count +=1
print(count)

### FIXED CODE ###

a,b,x = map(int,input().split())
print(b//x-(a-1)//x)
### BUGGY CODE ###

N=int(input())
ans=1
for i in range(1,N+1):
    ans=ans*i
print(ans%((10**9)+7))

### FIXED CODE ###

N=int(input())
ans=1
for i in range(1,N+1):
    ans=(ans*i)%((10**9)+7)
print(ans)
### BUGGY CODE ###

n=int(input())
s=input()
i=0
ans=0
while i<len(s):
  for j in range(i+1,len(s)):
    k=0
    while i+k<j and j+k<len(s):
      if s[i+k]==s[j+k]:
        k+=1
      else:
        break
    if ans<k:
      ans=k
  i+=1
print(ans)

### FIXED CODE ###

import sys
readline = sys.stdin.readline

N = int(readline())
S = readline().rstrip()

def zalgo(S):
  N = len(S)
  res = [0] * N
  res[0] = N
  i = 1
  j = 0
  while i < N:
    while i + j < N and S[j] == S[i + j]:
      j += 1
    res[i] = j
    if j == 0:
      i += 1
      continue
    k = 1
    while i + k < N and k + res[k] < j:
      res[i + k] = res[k]
      k += 1
    i += k
    j -= k
  return res

res = 0
for i in range(N):
  T = S[i:]
  lcp = zalgo(T)
  for j in range(len(T)):
    l = min(lcp[j],j)
    if res < l:
      res = l

print(res)
### BUGGY CODE ###

s = input()
iteration = int(input())
sousa_list = []
for i in range(0,iteration):
    sousa = input().split()
    sousa_list.append(sousa)

for c in range(0,iteration):
    if sousa_list[c][0] == "1":
        s = s[:: -1]
    else:
        if sousa_list[c][1] == "1":
            s = sousa_list[c][2] + s
        else:
            s = s + sousa_list[c][2]
print(s)

### FIXED CODE ###

from collections import deque
string = input()
s = deque(string)
iteration = int(input())
reverse = 1

for c in range(0,iteration):
    sousa = input().split()
    #操作１のとき
    if sousa[0] == "1":
        reverse = reverse*(-1)
    #操作２を行うとき
    elif sousa[1] == "1":
        if reverse == 1:
            s.appendleft(sousa[2])
        else:
            s.append(sousa[2])
    else:
        if reverse == 1:
            s.append(sousa[2])
        else:
            s.appendleft(sousa[2])

result = "".join(s)
if reverse == -1:
    result = result[::-1]


print(result)
### BUGGY CODE ###

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

result = []
for a in range(N+1):
  for b in range(N+1):
    for c in range(N+1):
      total = a * 10000 + b * 5000 + c * 1000
      if (total == Y) and (a + b + c == N):
        result.append([a, b, c])

if len(result) == 0:
  print("-1 -1 -1")
else:
  print(" ".join(map(str, result[0])))

### FIXED CODE ###

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

result = []
for a in range(N+1):
  for b in range(N+1):
    c = max(N - a - b, 0)
    total = a * 10000 + b * 5000 + c * 1000
    if (total == Y) and (a + b + c == N):
      result.append([a, b, c])

if len(result) == 0:
  print("-1 -1 -1")
else:
  print(" ".join(map(str, result[0])))
### BUGGY CODE ###

import math

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

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

a.sort(reverse=True)
max_comb = 0
for i in range(min(100, n-1)):
    comb_sum = 0
    for j in a:
        if j < a[i]:
            comb_sum = combinations_count(a[i], j)
            if comb_sum > max_comb:
                max_comb = comb_sum
                comb_n = a[i]
                comb_r = j

print(comb_n, comb_r)

### FIXED CODE ###

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

a.sort(reverse=True)

num = a[0]

target = a[0]/2

diff = 1000000000000

for i in a:
    if i == num:
        continue
    dif = abs(target-i)
    if dif < diff:
        diff = dif
        num_2 = i

print(num, num_2)
### BUGGY CODE ###

from itertools import product

H, W, K = map(int, input().split())
S = [[int(i) for i in input()] for _ in range(H)]

T = [t for t in zip(*S)]
if sum(map(sum, T)) <= K:
    print(0)
    quit()

ans = float("inf")
for P in product([0, 1], repeat=H - 1):
    cnt = sum(P)

    II = [[0]]
    for i, p in enumerate(P, 1):
        if p:
            II.append([])
        II[-1].append(i)

    A = [0] * len(II)
    for t in T:
        for i, I in enumerate(II):
            A[i] += sum(t[x] for x in I)

        if any(a > K for a in A):
            cnt += 1
            if cnt >= ans:
                break

            A = [sum(t[x] for x in I) for I in II]
            if any(a > K for a in A):
              cnt = 1 + ans
              break

    ans = min(ans, cnt)

print(ans)

### FIXED CODE ###

from itertools import product

H, W, K = map(int, input().split())
S = [[int(i) for i in input()] for _ in range(H)]

T = [t for t in zip(*S)]
if sum(map(sum, T)) <= K:
    print(0)
    quit()

ans = float("inf")
for P in product([0, 1], repeat=H - 1):
    cnt = sum(P)
    if cnt >= ans:
        continue

    II = [[0]]
    for i, p in enumerate(P, 1):
        if p:
            II.append([])
        II[-1].append(i)

    A = [0] * len(II)
    for t in T:
        for i, I in enumerate(II):
            A[i] += sum(t[x] for x in I)

        if any(a > K for a in A):
            cnt += 1
            if cnt >= ans:
                break

            A = [sum(t[x] for x in I) for I in II]
            if any(a > K for a in A):
              cnt = 1 + ans
              break

    ans = min(ans, cnt)

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

import math

#n = int(input())
l, r= [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
#s = [input() for i in range(n)]
#s = input()
#list = list(s)
#temp = [[0 for _ in range(13)] for _ in range(13)]

ans = 2019

for i in range(l,min(r,l+2019)) :
    for j in range(i+1,min(r+1,i+2020)) :
        a = i % 2019
        b = j % 2019
        ans = min(ans, (a * b) % 2019)

print(ans)

### FIXED CODE ###

import math

#n = int(input())
l, r= [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
#s = [input() for i in range(n)]
#s = input()
#list = list(s)
#temp = [[0 for _ in range(13)] for _ in range(13)]

ans = 2019

for i in range(l,min(r,l+2018)) :
    for j in range(i+1,min(r+1,i+2019)) :
        ans = min(ans, (i * j) % 2019)

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

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

res = 0
pair = []
for i in range(N):
    if A[A[i] - 1] - 1 == i and sorted([i, A[i] - 1]) not in pair:
        res += 1
        pair.append([i, A[i] - 1])

print(res)


### FIXED CODE ###

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

res = 0
for i in range(N):
    if A[A[i] - 1] - 1 == i:
        res += 1

print(res // 2)
### BUGGY CODE ###

#AGC023 A: 部分和は先頭からの

#AGC023 A
'''
問題
長さNの整数列Aがある
Nは1以上20000以下
Aiは-10**9以上10**9以下
Aの空でない連続する部分列であって，その総和が0であるものの個数は？

考察1
区間[i,j]を取り出して0になるかどうかを試す
これを0<=i<=j<=20000について繰り返す
計算時間はO(N**2)
つまりループ回数が10**10になる->大丈夫?
-> 大丈夫ではない。予想通りTLEになった

考察2
思いつかない...

解説を読んでやり直し
S0 = 0
S1 = A1
S2 = A1 + A2
...
Si = A1 + ... + Ai
とすると, 0<=p<q<=Nとなる(p,q)を選んでSq-Spを計算することによって任意の部分和を構成できる
Sq-Sp=0であればA_(p+1) + ... + Aqの部分和が0である
したがって0<=p<q<=Nとなる(p,q)に対してSp=Sqとなる(p,q)の組を数えればよい
このためにはS0,S1,...をソートして
Siをソートするところがボトルネックとなり, 計算量はO(NlogN)
'''

'''
#考察1は失敗
N = int(input())
A = list(map(int,input().split(' ')))

ans = 0

for i in range(N):
	for j in range(i,N):
		if sum(A[i:(j+1)]) == 0:
			ans += 1
		else:
			continue
			
print(ans)
'''

N = int(input())
A = list(map(int,input().split(' ')))
S = [0]
Scount = []
ans = 0

for i in range(N):
	#print(A[0:i+1])
	#S.append(sum(A[0:i+1])) <- これは遅くなるのでNG
	S.append(S[-1]+A[i])
	#print(S)

S = sorted(S)

for s in list(dict.fromkeys(S)):
	Scount.append(S.count(s))

for n in Scount:
	ans += (n*(n-1)/2)

print(int(ans))

### FIXED CODE ###

#AGC023 A: 部分和は先頭からの

#AGC023 A
'''
問題
長さNの整数列Aがある
Nは1以上20000以下
Aiは-10**9以上10**9以下
Aの空でない連続する部分列であって，その総和が0であるものの個数は？

考察1
区間[i,j]を取り出して0になるかどうかを試す
これを0<=i<=j<=20000について繰り返す
計算時間はO(N**2)
つまりループ回数が10**10になる->大丈夫?
-> 大丈夫ではない。予想通りTLEになった

考察2
思いつかない...

解説を読んでやり直し
S0 = 0
S1 = A1
S2 = A1 + A2
...
Si = A1 + ... + Ai
とすると, 0<=p<q<=Nとなる(p,q)を選んでSq-Spを計算することによって任意の部分和を構成できる
Sq-Sp=0であればA_(p+1) + ... + Aqの部分和が0である
したがって0<=p<q<=Nとなる(p,q)に対してSp=Sqとなる(p,q)の組を数えればよい
このためにはS0,S1,...をソートして
Siをソートするところがボトルネックとなり, 計算量はO(NlogN)
'''

'''
#考察1は失敗
N = int(input())
A = list(map(int,input().split(' ')))

ans = 0

for i in range(N):
	for j in range(i,N):
		if sum(A[i:(j+1)]) == 0:
			ans += 1
		else:
			continue
			
print(ans)
'''

N = int(input())
A = list(map(int,input().split(' ')))
S = [0]
Scount = [1]
ans = 0

for i in range(N):
	#print(A[0:i+1])
	#S.append(sum(A[0:i+1])) <- これは遅くなるのでNG
	S.append(S[-1]+A[i])
	#print(S)

S = sorted(S)

#for s in list(dict.fromkeys(S)):
	#Scount.append(S.count(s)) <- これも遅くなるのでNG
	
for i in range(N+1):
	if i==0:
		continue
	elif S[i]==S[i-1]:
		Scount[-1] += 1
	else:
		Scount.append(1)

for n in Scount:
	ans += (n*(n-1)/2)

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

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

d1 = [[0]*60 for _ in range(N+1)]
mod = 10**9+7

for i, n in enumerate(A, start=1):
    for j in range(60):
        d1[i][j] = d1[i-1][j]
        if n%2:
            d1[i][j] += 1
        n//=2

ans = 0
for i, n in enumerate(A, start=1):
    for j in range(60):
        a = d1[N][j]-d1[i][j] # 1
        b = N-a-i # 0

        if n%2:
            ans += b*(2**j)
        else:
            ans += a*(2**j)
        ans %= mod
        n//=2

print(ans)

### FIXED CODE ###

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

d1 = [[0]*60 for _ in range(N+1)]
mod = 10**9+7

for i, n in enumerate(A, start=1):
    for j in range(60):
        d1[i][j] = d1[i-1][j] + ((n>>j)&1)

ans = 0
for i, n in enumerate(A, start=1):
    for j in range(60):
        a = d1[N][j]-d1[i][j] # 1
        if (n>>j)&1:
            a = N-a-i # 0

        ans += a*(1<<j)
    ans %= mod

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

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

total = 1
for n in A:
    total *= n
if total <= 10 ** 18:
    print(total)
else:
    print(-1)

### FIXED CODE ###

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

if 0 in A:
    print(0)
else:
    ans = 1
    a = sorted(A, reverse=True)
    for i in a:
        ans *= i
        if ans > 10 ** 18:
            print(-1)
            break
    else:
        print(ans)
### BUGGY CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
vvv = na()
d = {}
for i in range(n):
    if vvv[i] not in d.keys():
        d[vvv[i]] = 1
    else:
        d[vvv[i]] += 1
if len(d.keys()) == 1:
    print(n // 2)
else:
    num1 = max(d, key=d.get)
    d.pop(num1)
    num2 = max(d, key=d.get)
    ct1 = 0
    ct2 = 0
    now1 = num1
    now2 = num2
    for i in range(n):
        if vvv[i] != now1:
            ct1 += 1
        if vvv[i] != now2:
            ct2 += 1
        now1, now2 = now2, now1
    print(min(ct1, ct2))

### FIXED CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
vvv = na()
even = vvv[::2]
odd = vvv[1::2]
d_even = {}
d_odd = {}
for i in range(n//2):
    if even[i] not in d_even.keys():
        d_even[even[i]] = 1
    else:
        d_even[even[i]] += 1

    if odd[i] not in d_odd.keys():
        d_odd[odd[i]] = 1
    else:
        d_odd[odd[i]] += 1

e_max = max(d_even, key=d_even.get)
o_max = max(d_odd, key=d_odd.get)
e1 = d_even[e_max]
o1 = d_odd[o_max]

if e_max == o_max:
    d_even[e_max] = 0
    d_odd[o_max] = 0

    e2 = max(d_even.values())
    o2 = max(d_odd.values())

    ans = n - max(e1 + o2, e2 + o1)

else:
    ans = n - e1 - o1

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

import math
K = int(input())
ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            s = math.gcd(a, b)
            ans += math.gcd(s, c)

print(ans)

### FIXED CODE ###

import math
K = int(input())
ans = 0

for a in range(1, K+1):
    for b in range(a, K+1):
        for c in range(b, K+1):
            s = math.gcd(a, b)
            t = math.gcd(s, c)
            if a == c:
                ans += t
            elif (a == b or b == c) and a != c:
                ans += 3*t
            else:
                ans += 6*t
print(ans)
### BUGGY CODE ###

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

n = int(input())
L = list(map(int, readline().split()))
cnt = 0

ls = list(itertools.combinations(L, 3))

for l in ls:
    if sum(l) > max(l)*2:
        cnt += 1

print(cnt)


### FIXED CODE ###

import bisect
import sys

input = sys.stdin.readline

n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0

for i in range(0, n-2):
    for j in range(i+1, n-1):
        cnt += bisect.bisect_left(l, l[i] + l[j]) - j-1

print(cnt)
### BUGGY CODE ###

def c_SpecialTrains(N, STATION):
    ans = []
    for i in range(N - 1):
        time = 0
        c, s, f = STATION[i]
        time += s + c  # 最初の駅では、開通後時間sに発車し、c秒かけて次の駅へ行く
        for j in range(i + 1, N - 1):
            c_next, s_next, f_next = STATION[j]
            while time > s_next:
                s_next += f_next  # s_next-timeが、その駅で待機しなければならない時間
            time += s_next - time + c_next  # c_next秒かけて次の駅へ行く
        ans.append(time)
    ans.append(0)  # N番目の駅からN番目の駅に行く時間は0とする
    return '\n'.join(map(str, ans))

N = int(input())
STATION = [[int(i) for i in input().split()] for j in range(N-1)]
print(c_SpecialTrains(N, STATION))

### FIXED CODE ###

def c_SpecialTrains(N, STATION):
    ans = []
    for i in range(N):
        t = 0  # 駅iからNまでにかかる時間
        for j in range(i, N - 1):
            c, s, f = STATION[j]
            if t < s:
                t = s  # まだ運行していないので、運行するまで待つ必要がある
            elif t % f == 0:
                # tがfで割り切れるなら、すぐに鉄道に乗ればよい
                # sはfで割り切れることが保証されているので、この条件式でよい
                pass
            else:
                t += f - (t % f)  # この分だけ駅で待つ必要がある
            t += c  # 次の駅までかかる時間
        ans.append(t)
    return '\n'.join(map(str, ans))

N = int(input())
STATION = [[int(i) for i in input().split()] for j in range(N-1)]
print(c_SpecialTrains(N, STATION))