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

n = int(input())
list =[int(input()) for i in range(n)]

for j in range(n):
    if list[j] == max(list):
        print(sorted(list)[-2])
    else:
        print(max(list))

### FIXED CODE ###

n = int(input())
list =[int(input()) for i in range(n)]
m = max(list)
s = sorted(list)[-2]
for i in range(n):
    if list[i] == m:
        print(s)
    else:
        print(m)
### BUGGY CODE ###

from bisect import bisect_left,bisect
import sys
 
N=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))
b=list(map(int,sys.stdin.readline().split()))
ans=0
for i in range(29):
  a_nex=list(map(lambda x:x%2**(i+1),a))
  b_nex=sorted(list(map(lambda x:x%2**(i+1),b)))
  l=0
  for k in a_nex:
    p=bisect_left(b_nex,2**i-k-0.1)
    q=bisect(b_nex,2*2**i-1-k)
    r=bisect_left(b_nex,3*2**i-k-0.1)
    l+=q-p+N-r
  if l%2==1:
    ans+=1<<i
print(ans)   
  


### FIXED CODE ###

N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
def f(i):
  res=0
  t=2**i
  a_nex=sorted([p%(2*t) for p in a])
  b_nex=sorted([p%(2*t) for p in b])
  l=0
  p=q=r=0
  for k in reversed(a_nex):
    while p<N and k+b_nex[p]<t:
      p+=1
    while q<N and k+b_nex[q]<2*t:
      q+=1
    while r<N and k+b_nex[r]<3*t:
      r+=1
    l+=q-p+N-r
  res=(l%2)<<i
  return res
for k in range(29):
  ans+=f(k)
print(ans)
### BUGGY CODE ###

n = int(input())

nums = [0]*n
m = n//6
for i in range(1,m+1):
  for j in range(i, m+1):
    if i**2 + j**2 + i*j >= n//2: break
    for k in range(j, m+1):
      t = i**2 + j**2 + k**2 + i*j + j*k + i*k
      if t <= n:
        if i == j and i == k: nums[t-1] += 1
        else: nums[t-1] += 3
        
print(*nums, sep="\n")

### FIXED CODE ###

from itertools import product
n = int(input())

nums = [0]*(n+1)
for i in product(range(1, int(n**0.5)+1),repeat=3):
  t = i[0]**2 + i[1]**2 + i[2]**2 + i[0]*i[1] + i[1]*i[2] + i[0]*i[2]
  if t <= n: nums[t] += 1

for i in range(1,n+1): print(nums[i])
### BUGGY CODE ###

N = int(input())
s = ["".join(sorted(list(input()))) for i in range(N)]

#出現文字列
dict = {}

ans = 0

for i in range(N):

    s_i = str(s[i])

    if s_i in dict:
        #組み合わせが増えるので
        dict[s_i]+= 1

        ans += dict[s_i]
        continue

    for j in range(i+1,N):
        dict[s_i] = 0

print(ans)


### FIXED CODE ###

N = int(input())
s = ["".join(sorted(input())) for i in range(N)]

#print(s)

#出現文字列
sdict = {}

for i in range(N):

    s_i = str(s[i])

    if s_i in sdict:
        #組み合わせが増えるので
        sdict[s_i]+= 1
        continue

    else:
        sdict[s_i] = 1

ans = 0
for i in sdict.values():
    ans += i*(i-1)//2
print(ans)
### BUGGY CODE ###

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

mod = 10**9 + 7

def choose(n, r):
    x = 1
    y = 1
    for i in range(1, r+1):
        x = (x * (n-i+1)) % mod
        y = (y * i) % mod
    return (x * pow(y, mod-2, mod)) % mod

ans = 0
for i in range(min(k+1,n+1)):
    ans = (ans + (choose(n, i) * choose(n-1, i)) % mod) % mod
print(ans)


### FIXED CODE ###

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

mod = 10**9 + 7
k = min(k, n-1)

def choose(n, r):
    x = 1
    y = 1
    for i in range(1, r+1):
        x = (x * (n-i+1)) % mod
        y = (y * i) % mod
    return (x * pow(y, mod-2, mod)) % mod

kaijo = [1]
for i in range(1,n+1): 
  kaijo.append(kaijo[i-1]*i % mod)

ans = 0
for i in range(k+1):
#    ans += (choose(n, min(i,n-i)) * choose(n-1, min(i,n-1-i))) % mod
    ans += kaijo[n] * pow(kaijo[i]*kaijo[n-i], mod-2,mod) * kaijo[n-1]*pow(kaijo[i]*kaijo[n-1-i],mod-2,mod)
    ans = ans % mod
print(ans % mod)
### BUGGY CODE ###

from heapq import heappop as hpop
from heapq import heappush as hpush

while True:
  n, m = map(int, input().split())
  
  if not n:
    break
  
  cost_edges = [[] for _ in range(m)]
  time_edges = [[] for _ in range(m)]

  for _ in range(n):
    a, b, c, t = map(int, input().split())
    cost_edges[a - 1].append((c, b - 1))
    cost_edges[b - 1].append((c, a - 1))
    time_edges[a - 1].append((t, b - 1))
    time_edges[b - 1].append((t, a - 1))
  
  k = int(input())

  for _ in range(k):
    start, goal, r = map(int ,input().split())
    start -= 1
    goal -= 1
    
    if r:
      edges = time_edges
    else:
      edges = cost_edges

    que = [(0, start)]
    visited = [False for _ in range(m)]
    
    while que:
      score, station = hpop(que)
      visited[station] = True
      
      if station == goal:
        print(score)
        break

      for c, to_station in edges[station]:
        if not visited[to_station]:
          hpush(que, (score + c, to_station))


### FIXED CODE ###

from heapq import heappop as hpop
from heapq import heappush as hpush

def main():
  
  while True:
    n, m = map(int, input().split())
    
    if not n:
      break
    
    cost_edges = [[] for _ in range(m)]
    time_edges = [[] for _ in range(m)]
  
    for _ in range(n):
      a, b, c, t = map(int, input().split())
      cost_edges[a - 1].append((c, b - 1))
      cost_edges[b - 1].append((c, a - 1))
      time_edges[a - 1].append((t, b - 1))
      time_edges[b - 1].append((t, a - 1))
    
    k = int(input())
  
    for _ in range(k):
      start, goal, r = map(int ,input().split())
      start -= 1
      goal -= 1
      
      if r:
        edges = time_edges
      else:
        edges = cost_edges
  
      que = [(0, start)]
      visited = [False for _ in range(m)]
      
      while True:
        score, station = hpop(que)
        visited[station] = True
        
        if station == goal:
          print(score)
          break
  
        for c, to_station in edges[station]:
          if not visited[to_station]:
            hpush(que, (score + c, to_station))

main()
### BUGGY CODE ###

n=int(input())
lis=list(map(int,input().split()))
num=(n*(n+1))//2
if sum(lis)%num!=0:
  print("NO")
  exit()
li=[lis[i]-lis[i-1]-sum(lis)//num for i in range(n)]
ans=0
for k in range(n):
  if -li[k]%n!=0:
    print("NO")
    exit()
  ans+=-li[k]//n
if ans == sum(lis)//num:print("YES")
else:print("NO")


### FIXED CODE ###

n=int(input())
lis=list(map(int,input().split()))
num=(n*(n+1))//2
ll=sum(lis)
if ll%num!=0:
  print("NO")
  exit()
ans=0
for i in range(n):
  if abs(lis[i]-lis[i-1]-ll//num)%n!=0:
    print("NO")
    exit()
  ans+=abs(lis[i]-lis[i-1]-ll//num)//n
if ans == ll//num:print("YES")
else:print("NO")
### BUGGY CODE ###

n, k = (int(x) for x in input().split())

while True:
  d = n - k
  if d < 0:
    d *= -1
  if d >= n:
    break
  else:
    n = d
print(n)

### FIXED CODE ###

n, k = (int(x) for x in input().split())

key = n % k


while True:
  d = key - k
  if d < 0:
    d *= -1
  if d >= key:
    break
  else:
    key = d
print(key)
### BUGGY CODE ###

n = int(input())
D = []
for i in range(n):
    x = int(input())
    if x in D:
        D.remove(x)
    else:
        D.append(x)
print(len(D))

### FIXED CODE ###

from collections import Counter
n = int(input())
A = Counter([int(input()) for i in range(n)]).most_common()
B = []

for i in range(len(A)):
    if A[i][1] % 2 == 1:
        B.append(A[i][1])
        
print(len(B))
### BUGGY CODE ###

a = input()
a = list(a)

s = 0
r = 1
cnt = 0
for l in range(len(a)):
    s = a[l]
    r =l
    while int(s)%2019 != 0 and r<=len(a)-2:
        #print(l,r)
        s +=a[r+1]
        if int(s)%2019 == 0:
            cnt +=1
        #print(s,cnt,l,r)   
        r += 1
    #r +=1
print(cnt)



### FIXED CODE ###

s = input()[::-1]

mod = 2019
ans = 0
d = 0
L = [0]
memo = [0]
for i in s:
    S =str(i)
    tmp = int(S)*pow(10,d,mod)%mod
    tmp = L[-1] + tmp
    L.append(tmp%mod)
    d +=1

from collections import Counter
L = Counter(L)

for v in L.values():
    ans +=v*(v-1)//2
print(ans)
### BUGGY CODE ###

H, W, K = map(int, input().split())
items = []

start = []
diff = float("inf")
p = []
prev = [[False] * W for _ in range(H)]
for i in range(H):
    items.append(list(input()))
    for j in range(W):
        s = items[i][j]
        if s == "S":
            start = [i, j]
            diff = min(diff, min(i, H - 1 - i, min(j, W - 1 - j)))
            p = [i, j]
            prev[i][j] = True

from collections import deque

que = deque([])

dx = [-1, 0, 0, 1]
dy = [0, 1, -1, 0]

for i in range(4):
    x = dx[i]
    y = dy[i]
    if 0 <= start[0] + y <= H - 1 and 0 <= start[1] + x <= W - 1:
        tmp = items[start[0] + y][start[1] + x]
        if tmp == ".":
            que.append((start[0] + y, start[1] + x))
k = K
while len(que) != 0:
    q = que.popleft()
    a = q[0]
    b = q[1]
    if abs(start[0] - a) + abs(start[1] - b) > K:
        continue

    prev[a][b] = True
    c = min(min(a, H - 1 - a), min(b, W - 1 - b))
    if c < diff:
        diff = c
        p = (a, b)

    for i in range(4):
        x = dx[i]
        y = dy[i]
        if 0 <= a + y <= H - 1 and 0 <= b + x <= W - 1:
            if prev[a + y][b + x]:
                continue
            tmp = items[a + y][b + x]
            if tmp == ".":
                que.append((a + y, b + x))
    k -= 1

ans = 1
if diff == 0:
    print(ans)
else:
    print(ans + (K - 1 + diff) // K)


### FIXED CODE ###

H, W, K = map(int, input().split())
items = []

start = []
diff = float("inf")
p = []
prev = [[False] * W for _ in range(H)]
for i in range(H):
    items.append(list(input()))
    for j in range(W):
        s = items[i][j]
        if s == "S":
            start = [i, j]
            diff = min(diff, min(i, H - 1 - i, min(j, W - 1 - j)))
            p = [i, j]
            prev[i][j] = True

from collections import deque

que = deque([])

dx = [-1, 0, 0, 1]
dy = [0, 1, -1, 0]

for i in range(4):
    x = dx[i]
    y = dy[i]
    if 0 <= start[0] + y <= H - 1 and 0 <= start[1] + x <= W - 1:
        tmp = items[start[0] + y][start[1] + x]
        if tmp == ".":
            que.append((start[0] + y, start[1] + x))
            prev[start[0] + y][start[1] + x] = True
k = K
while len(que) != 0:
    q = que.popleft()
    a = q[0]
    b = q[1]
    if abs(start[0] - a) + abs(start[1] - b) > K:
        continue
    c = min(min(a, H - 1 - a), min(b, W - 1 - b))
    if c < diff:
        diff = c
        p = (a, b)

    for i in range(4):
        x = dx[i]
        y = dy[i]
        if 0 <= a + y <= H - 1 and 0 <= b + x <= W - 1:
            if prev[a + y][b + x]:
                continue
            tmp = items[a + y][b + x]
            if tmp == ".":
                que.append((a + y, b + x))
                prev[a + y][b + x] = True

ans = 1
if diff == 0:
    print(ans)
else:
    print(ans + (K - 1 + diff) // K)
### BUGGY CODE ###

x = input()
n = int(input())
y = 0

for i in range(n):
    a = input()
    if a[0] == "1":
      x = x[::-1]
    else:
      a, b, c = a.split()
      a = int(a)
      b = int(b)

      if b == 2:
          x = x + c
      elif b == 1:
          x = x[::-1] + c
          x = x[::-1]

print(x)

### FIXED CODE ###

import collections

x = collections.deque(input())
n = int(input())
rev = False

for i in range(n):
    y = input().split()
    if len(y) == 1:
      rev = not rev
    elif rev:
      if int(y[1]) == 2:
          x.appendleft(y[2])
      else:
          x.append(y[2])
    else:
      if int(y[1]) == 2:
          x.append(y[2])
      else:
          x.appendleft(y[2])

if rev:
  x.reverse()

print("".join(x))
### BUGGY CODE ###

word_number, questions_number = map(int, input().split())
words = list(input())
questions = []
for question in range(questions_number):
    a,b = map(int, input().split())
    questions.append([a-1, b-1])

for i in range(len(questions)):
    counter = 0
    for j in range(questions[i][0], questions[i][1]):
        if words[j] == "A" and words[j+1] == "C":
            counter += 1
    print(counter)


### FIXED CODE ###

word_number, questions_number = map(int, input().split())
# words = list(input())
words = input()
questions = []
for question in range(questions_number):
    a,b = map(int, input().split())
    questions.append([a-1, b-1])

# 複数回の問題を2秒以内はきついので前処理する必要あり
# for i in range(len(questions)):
#     counter = 0
#     for j in range(questions[i][0], questions[i][1]):
#         # if words[j] == "A" and words[j+1] == "C":
#         if words[j: j+2] == "AC":
#             counter += 1
#     print(counter)

hasAC = [0] * word_number
for i in range(word_number-1):
    if words[i: i+2] == "AC":
        hasAC[i+1] = hasAC[i] + 1
    else:
        hasAC[i+1] = hasAC[i]

for i in range(questions_number):
    print(hasAC[questions[i][1]] - hasAC[questions[i][0]])
### BUGGY CODE ###

import sys
N,Q = [int(n) for n in input().split()]
S = "f" + str(input()) + "f"
# print(S)
t = [""]*Q
d = [""]*Q
for i in range(Q):
    t[i],d[i] = [str(n) for n in input().split()]

#左に落ちるやつで一番右のゴーレムのインデックスを探す
def leftbinarysearch():
    l = 0
    r = N + 1
    cnt = 0#デバグ用カウンタ
    while(l<r):
        m = (l+r)//2 + 1#探索範囲の中央値のIndexのゴーレムでシミュレーション
        cur = m#探す一つのゴーレムの現在地
        fall = False
        # print(l,r,m)
        for i in range(Q):
            if t[i] == S[cur]:
                if d[i] == "L":
                    cur-=1
                else:
                    cur+=1
            if(cur == 0):#左端に落ちるなら次はもっと右のやつを確かめる
                l = m
                fall = True
                break
            elif(cur == N+1):#右端に落ちるなら下の処理に飛ぶ
                break
        if not fall:#落ちなかったならそれより左端を探す
            r = m - 1
        cnt+=1
        # if(cnt == 10):print("loop", file=sys.stderr);break;
    return l

#→に落ちるやつを返す
def rightbinarysearch():
        l = 0
        r = N + 1
        cnt = 0
        while(l<r):
            m = (l+r)//2#探索範囲の中央値のIndexのゴーレムでシミュレーション
            cur = m#探す一つのゴーレムの現在地
            fall = False
            # print(l,r,m)
            for i in range(Q):
                if t[i] == S[cur]:
                    if d[i] == "L":
                        cur-=1
                    else:
                        cur+=1
                if(cur == N+1):#右端に落ちるなら次はもっと左のやつを確かめる
                    r = m
                    fall = True
                    break
                elif(cur == -1):#左端に落ちるなら下の処理まで飛ぶ
                    break
            if not fall:#落ちなかったならそれより右端を探す
                l = m + 1
            cnt+=1
            # if(cnt == 10):print("loop", file=sys.stderr);break;
        return l
# print(rightbinarysearch())
# print(leftbinarysearch())
print(rightbinarysearch()-leftbinarysearch()-1)


### FIXED CODE ###

n, q = [int(_) for _ in input().split()]
s = input()

Q = [(input().split()) for i in range(q)]
Q.reverse()
l = 0
r = n - 1
for t,d in Q:
    if s[l] == t and d == "L":
        l += 1
    elif l > 0 and s[l - 1] == t and d == "R":
        l -= 1
    if s[r] == t and d == "R":
        r -= 1
    elif r < n - 1 and s[r + 1] == t and d == "L":
        r += 1
    # print(r,l,r-l+1)
    if l > r:
        break
print(r - l + 1)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# 18:01 -> 18:36 (give up. TLE)
from collections import deque

dx = [0,1,0,-1]
dy = [1,0,-1,0]

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

A = []
black_deque = deque()

for i in range(H):
    A.append(list(input()))
    black_deque.extend([(i,j) for j in range(W) if A[i][j] == '#'])

for x,y in black_deque:
    A[x][y] = 0

while len(black_deque) != 0:
    x,y = black_deque.popleft()
    depth = A[x][y]
    tansaku = [(x+dx[k], y+dy[k]) for k in range(4)
        if 0 <= x+dx[k] < H and
           0 <= y+dy[k] < W and
           A[x+dx[k]][y+dy[k]] == '.'
    ]
    for new_x,new_y in tansaku:
        black_deque.append((new_x, new_y))
        A[new_x][new_y] = depth+1

print(depth)

### FIXED CODE ###

# -*- coding: utf-8 -*-
# 18:01 -> 18:36 (give up. TLE)
from collections import deque

dx = [0,1,0,-1]
dy = [1,0,-1,0]

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

A = []
black_deque = deque()

for i in range(H):
    A.append(list(input()))
    black_deque.extend([(i,j) for j in range(W) if A[i][j] == '#'])

if len(black_deque) == H*W:
    print(0)
    exit(0)

for x,y in black_deque:
    A[x][y] = 0

while len(black_deque) != 0:
    x,y = black_deque.popleft()
    depth = A[x][y]
    for k in range(4):
        new_x = x+dx[k]
        new_y = y+dy[k]
        if 0 <= new_x < H and \
           0 <= new_y < W and \
           A[new_x][new_y] == '.':
            black_deque.append((new_x, new_y))
            A[new_x][new_y] = depth+1

print(depth)
### BUGGY CODE ###

N, M = map(int, input().split())
p = [0] * M
S = [''] * M
for i in range(M):
    p_i, S[i] = input().split()
    p[i] = int(p_i)

penal_ct = 0
ac_count = 0
# prev_ac_num = -1

ac_list = [False] * N

for i in range(M):
    if (not ac_list[p[i] - 1]) and S[i] == 'AC': # ACかつ今までにACしてない
        ac_list[p[i] - 1] = True
        ac_count += 1
        if i == 0:
            continue
        for j in range(i)[::-1]:
            if S[j] == 'WA' and p[j] == p[i]:
                penal_ct += 1

    if all(ac_list):
        break



# for i in range(1, M)[::-1]:
#     if S[i] == 'AC' and p[i] != prev_ac_num:
#         prob_num = prev_ac_num = p[i]
#         ac_count += 1
#         for j in range(i)[::-1]:
#             if p[j] == prob_num and S[j] == 'WA':
#                 penal_ct += 1
print(ac_count, penal_ct) 


### FIXED CODE ###

N, M = map(int, input().split())
p = [0] * M
S = [''] * M
for i in range(M):
    p_i, S[i] = input().split()
    p[i] = int(p_i)




penal_ct = 0
ac_count = 0
# prev_ac_num = -1
ac_list = [False] * N
pos = 0

wa_count = [0] * N

for i in range(M):
    if S[i] == 'WA':
        wa_count[p[i] - 1] += 1
        # print(wa_count[p[i] - 1])
    elif (not ac_list[p[i] - 1]) and S[i] == 'AC': # ACかつ今までにACしてない
        ac_list[p[i] - 1] = True
        ac_count += 1
        if i == 0:
            continue
        penal_ct += wa_count[p[i] - 1]
        # for j in range(i)[::-1]:
        #     if S[j] == 'WA' and p[j] == p[i]:
        #         penal_ct += 1
    # if all(ac_list):
        # break
# print(wa_count)
print(ac_count, penal_ct)
### BUGGY CODE ###

n = int(input())
l = list(map(int,input().split()))
lone = [0]*60
for i in range(n):
  m = l[i]
  for j in range(59,-1,-1):
    if m >= 2**j:
      m = m -2**j
      lone[j] += 1
ans = 0
for i in range(60):
  ans += 2**i*lone[i]*(n-lone[i])
print(ans%(10**9+7))


### FIXED CODE ###

#O(nm) = O(60n)で解けるはず・・・！
n = int(input())
l = list(map(int,input().split()))
#2進数の桁の出現数をカウントする。
lone = [0]*60
for i in range(n):
  s = bin(l[i])[2:]
  for j in range(len(s)):
    lone[j] += int(s[-j-1])
ans = 0
for i in range(60):
  ans += (2**i*lone[i]*(n-lone[i]))%(10**9+7)
print(ans%(10**9+7))
### BUGGY CODE ###

N = int(input())
move = []
for i in range(N):
    X,L = map(int,input().split())
    move.append([X-L,X+L])
move.sort()

if N == 1:
    print(1)
else:    
    i = 1
    while(len(move) > i):
        if move[i-1][0] == move[i][0]:
            if move[i-1][1] >= move[i][1]:
                del move[i]
            else:
                del move[i-1]
        else:
            if move[i][1] <= move[i-1][1]:
                del move[i]
            else:
                i += 1
    
    if len(move) <= 2:
        print(len(move))
    else:
        i = 1
        while(len(move) > i+1):
            if move[i-1][1] >= move[i+1][0]:
                del move[i]
            else:
                i += 1
        print(len(move))

### FIXED CODE ###

N = int(input())
K = []
for i in range(N):
    X,L = map(int,input().split())
    K.append([X-L,X+L])

T = sorted(K,key=lambda x:x[1])
a = T[0][1]

c = 1
for i in range(1,N):
    if T[i][0] >= a:
        c += 1
        a = T[i][1]
print(c)
### BUGGY CODE ###

import math
from functools import reduce

a = int(input())
def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans =0
for n in range(a):
    for l in range(a):
        for m in range(a):
            ans += gcd(n+1,l+1,m+1)
print(ans)

### FIXED CODE ###

import math
a = int(input())
lis =[]
ans = 0
for x in range(1,a+1):
    for y in range(1, a+1):
        lis.append(math.gcd(x,y))
for z in range(1, a+1):
    for l in lis:
        ans += math.gcd(z,l)
print(ans)
### BUGGY CODE ###

import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))
S = sum(A)
ans = 1
C = []
for i in range(1,int(S**0.5+1)):
    if S%i == 0:
        C.append(i)
        C.append(S//i)
for c in C:
    B = np.array(A) % c
    B.sort()
    hoge = 0
    for i in range(N):
        hoge += B[i]
        if hoge <= K and hoge == -sum(B[i+1:]-c):
            ans = max(ans,c)
print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
S = sum(A)
ans = 1
C = []
for i in range(1,int(S**0.5+1)):
    if S%i == 0:
        C.append(i)
        C.append(S//i)
for c in C:
    B = []
    for i in A:
        B.append(i%c)
    B.sort()
    hoge = 0
    sum_b = sum(B)
    for i in range(N):
        hoge += B[i]
        sum_b -= B[i]
        if hoge <= K and hoge == c*(N-i-1)-sum_b:
            ans = max(ans,c)
print(ans)
### BUGGY CODE ###

from bisect import bisect_left

N = int(input())
L = sorted([int(i) for i in input().split()])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect_left(L[j+1:], L[i]+L[j])

print(ans)

### FIXED CODE ###

from bisect import bisect_left

N = int(input())
L = sorted([int(i) for i in input().split()])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect_left(L, L[i]+L[j]) - (j + 1)

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

def solve(s):
    dp = [0] * 2019
    dp[0] = 1
    r = 0
    for i in range(1, len(s) + 1):
        r += int(s[-i]) * (10 ** (i - 1))
        r %= 2019
        dp[r] += 1
    res = 0
    for r in range(2019):
        res += dp[r] * (dp[r] - 1) // 2
    return res


def main():
    s = input()
    res = solve(s)
    print(res)


def test():
    assert solve("1817181712114") == 3
    assert solve("14282668646") == 2
    assert solve("2119") == 0


if __name__ == "__main__":
    test()
    main()


### FIXED CODE ###

def solve(s):
    dp = [0] * 2019
    dp[0] = 1
    r = 0
    for i in range(1, len(s) + 1):
        r += int(s[-i]) * pow(10, i - 1, 2019)
        r %= 2019
        dp[r] += 1
    res = 0
    for r in range(2019):
        res += dp[r] * (dp[r] - 1) // 2
    return res


def main():
    s = input()
    res = solve(s)
    print(res)


def test():
    assert solve("1817181712114") == 3
    assert solve("14282668646") == 2
    assert solve("2119") == 0


if __name__ == "__main__":
    test()
    main()