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

from collections import deque
h, w = map(int, input().split())
maze = []
for _ in range(h):
    maze.append(list(input()))

def clear_maze(sx, sy, gx, gy, maze):
    INF = float('infinity')
    field_x_length = len(maze)
    field_y_length = len(maze[0])
    distance = [[INF for i in range(field_y_length)] for j in range(field_x_length)]

    def bfs():
        queue = deque([])
        queue.append((sx, sy))
        distance[sx][sy] = 0
        dx = [1, 0, -1, 0]
        dy = [0, 1, 0, -1]
        while queue:
            x, y = queue.pop()
            if x == gx and y == gy:
                break
            for i in range(0, 4):
                nx, ny = x + dx[i], y + dy[i]
                if (0 <= nx < field_x_length) and (0 <= ny < field_y_length):
                    if maze[nx][ny] != '#' and distance[nx][ny] == INF:
                        queue.appendleft((nx, ny))
                        distance[nx][ny] = distance[x][y] + 1
        return distance[gx][gy]
    return bfs()


pairs = []
for i in range(h):
    for j in range(w):
        if maze[i][j] == '.':
            pairs.append([i, j])

MAX = 0
for i in range(len(pairs)):
    sx, sy = pairs[i]
    for j in range(len(pairs)):
        gx, gy = pairs[j]
        r = clear_maze(sx, sy, gx, gy, maze)
        if r == float('infinity'):
            continue
        MAX = max(MAX, r)
print(MAX)

### FIXED CODE ###

from collections import deque
h, w = map(int, input().split())
maze = []
for _ in range(h):
    maze.append(list(input()))

def clear_maze(sx, sy, maze):
    INF = -float('infinity')
    field_x_length = len(maze)
    field_y_length = len(maze[0])
    distance = [[INF for i in range(field_y_length)] for j in range(field_x_length)]

    queue = deque([(sx, sy)])
    distance[sx][sy] = 0
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    while queue:
        x, y = queue.pop()
        # if x == gx and y == gy:
        #     break
        for i in range(0, 4):
            nx, ny = x + dx[i], y + dy[i]
            if (0 <= nx < field_x_length) and (0 <= ny < field_y_length):
                if maze[nx][ny] != '#' and distance[nx][ny] == INF:
                    queue.appendleft((nx, ny))
                    distance[nx][ny] = distance[x][y] + 1
    MAX = 0
    for row in range(field_x_length):
        for col in range(field_y_length):
            MAX = max(MAX, distance[row][col])
    return MAX
    # return distance[gx][gy]

pairs = []
for i in range(h):
    for j in range(w):
        if maze[i][j] == '.':
            pairs.append([i, j])

MAX = 0
for sx, sy in pairs:
    r = clear_maze(sx, sy, maze)
    MAX = max(MAX, r)
print(MAX)
### BUGGY CODE ###

MOD = 10**9+7
from math import factorial
h, w, a, b = list(map(int, input().split()))
num_path = 0

def get_path(n, r):
    return factorial(n)//(factorial(n-r)*factorial(r))

y, x = h-a, b+1
while(True):
    path_0 = get_path((y+x-2), min(x-1, y-1))
    path_1 = get_path((h-y+w-x), min(h-y, w-x))
    # print(y, x, path_0, path_1)
    num_path = (num_path + path_0*path_1)%MOD

    y -= 1
    x += 1
    if y == 0 or x > w:
        break
    
print(num_path)


### FIXED CODE ###

MOD = 10**9+7

h, w, a, b = list(map(int, input().split()))
ans = 0

facts = [1]
for i in range(1, h+w-1):
    facts.append((i*facts[i-1])%MOD)
# print(facts[:20])
    
def get_path(n, r):
    return (facts[n] * pow(facts[r], MOD-2, MOD)%MOD * pow(facts[n-r], MOD-2, MOD)%MOD) % MOD

y, x = h-a, b+1
while(True):
    path_0 = get_path(y+x-2, x-1)
    path_1 = get_path(h-y+w-x, w-x)
    # print(y, x, path_0, path_1)
    ans += (path_0*path_1)%MOD
    ans %= MOD

    y -= 1
    x += 1
    if y == 0 or x > w:
        break
    
print(ans)
### BUGGY CODE ###

import bisect

N,M = [int(x) for x in input().split()]

l = [[int(x) for x in input().split()] for _ in range(M)]



def do(l):
    

    count = 1

    l.sort()
    while True:
        l1 = [v1 for (v1,_) in l]
        l2 = [v2 for (_,v2) in l]
        l1.sort()
        l2.sort()

        nx = l2[0]

        for i in range(len(l)):
            #print(l)
            
            if l[i][0] >= nx:
                #print("i")
                #print(i)
                l = l[i:]
                #print(count)

                count+=1
                break
            if i >= len(l)-1:
                return count
        if l == []:
            return count



result = do(l)
print(result)

### FIXED CODE ###

import bisect

N,M = [int(x) for x in input().split()]

l = [[int(x) for x in input().split()] for _ in range(M)]



def do(l):

    count = 1

    l.sort()
    right = l[0][1]


    for i in range(len(l)):
        if l[i][0] >= right:
            right = l[i][1]
            count+=1
            continue
        if l[i][1] < right:
            right = l[i][1]
    return count

testl = [[x,x+1] for x in range(1)]

result = do(l)
print(result)
### BUGGY CODE ###

n,w=map(int,input().split())
W=[]
V=[]
for i in range(n):
  a,b=map(int,input().split())
  W.append(a)
  V.append(b)
DP=[[0]*(w+1) for j in range(n+1)]
for p in range(n):
  for q in range(w+1):
    if q<W[p]:
      DP[p+1][q]=DP[p][q]
    else:
      DP[p+1][q]=max(DP[p][q], DP[p][q-W[p]]+V[p])
print(DP[n][w])

### FIXED CODE ###

n,w=map(int,input().split())
W=[]
V=[]
for i in range(n):
  a,b=map(int,input().split())
  W.append(a)
  V.append(b)
DP=[[0]*(w+1) for j in range(n+1)]
for p in range(n):
  for q in range(w+1):
    if q<W[p]:
      DP[p+1][q]=DP[p][q]
    else:
      DP[p+1][q]=max(DP[p][q], DP[p][q-W[p]]+V[p])
print(DP[n][w])
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter
from bisect import bisect,bisect_left,insort

def solve(n, ppp):
    q = sorted(enumerate(ppp),key=itemgetter(1),reverse=True)
    le = [-1,-1,n,n]
    ans = 0
    for i, p in q:
        l_i = bisect(le,i)
        LL = le[l_i-2]
        LR = le[l_i-1]
        RL = le[l_i]
        RR = le[l_i+1]
        ans += p*((LR-LL)*(RL-i)+(RR-RL)*(i-LR))
        le = le[:l_i]+[i]+le[l_i:]
    return ans


n = int(readline())
ppp = list(map(int,readline().split()))
print(solve(n, ppp))

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from operator import itemgetter

n = int(readline())
ppp = list(map(int,readline().split()))

def BIT_add(i,x):
    while i <= n:
        tree[i] += x
        i += i&(-i)

def BIT_sum(i):
    s = 0
    while i:
        s += tree[i]
        i -= i&(-i)
    return s

def BIT_search(x):
    # 二分探索。和がx以上となる最小のインデックス(>= 1)を返す
      i = 0
      s = 0
      step = 1<<(n.bit_length()-1)
      while step:
          if i+step <= n and s + tree[i+step] < x:
              i += step
              s += tree[i]
          step >>= 1
      return i+1

q = sorted(enumerate(ppp,1),key=itemgetter(1),reverse=True)
tree = [0]*(n+1)

ans = 0
for i, p in q:
    L = BIT_sum(i) # 左にある既に書き込んだ数の個数
    BIT_add(i,1)
    R = n-p-L # 右にある既に書き込んだ数の個数
    LL = BIT_search(L-1) if L >= 2 else 0
    LR = BIT_search(L) if L >= 1 else 0
    RL = BIT_search(L+2) if R >= 1 else n+1
    RR = BIT_search(L+3) if R >= 2 else n+1
    ans += p*((LR-LL)*(RL-i)+(RR-RL)*(i-LR))
print(ans)
### BUGGY CODE ###

# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right
def inpl(): return list(map(int, input().split()))

S = input()
N = len(S)
while True:
    flag = False
    for i in range(1, len(S)-2):
        l = S[i-1]
        mid = S[i:i+2]
        r = S[i+2]
        if mid == "01" or mid == "10":
            if (l == "0" and r == "1") or (l == "1" and r == "0"):
                S = S[:i] + S[i+2:]
                flag = True
                break

    if flag:
        continue

    for i in range(0, len(S)-1):
        mid = S[i:i+2]
        if mid == "01" or mid == "10":
            S = S[:i] + S[i+2:]

    break
print(N-len(S))

### FIXED CODE ###

# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

# import math
# import numpy as np
# import copy
# from collections import defaultdict, Counter
# from itertools import product
# from bisect import bisect_left, bisect_right
def inpl(): return list(map(int, input().split()))

S = input()
N = len(S)
c0 = S.count("0")
c1 = S.count("1")

print(2*min(c0, c1))
### BUGGY CODE ###

n = int(input())
M = 1046527
a = [0 for i in range(M)]
for i in range(n):
    s = input().split(" ")
    num = 0
    p = 1
    for j in range(len(s[1])):
        if s[1][j] == "A":
            num += p * 1
        elif s[1][j] == "C":
            num += p * 2
        elif s[1][j] == "G":
            num += p * 3
        else:
            num += p * 4
        p *= 5
    h1 = num % M
    h2 = h1 + num % (M - 1)
    k = 0
    h = (h1 + k * h2) % M
    if s[0][0] == "i":
        while True:
            if a[h] == 0:
                a[h] = s[1]
                break
            elif a[h] == s[1]:
                break
            else:
                k += 1
    else:
        while True:
            if a[h] == s[1]:    
                print("yes")
                break
            elif a[h] == 0:
                print("no")
                break
            else:
                k += 1

### FIXED CODE ###

n = int(input())
dic = set()
for i in range(n):
    Cmd, Key = input().split(" ")
    if Cmd == "insert":
	    dic.add(Key)
    else:
        if Key in dic:
	        print("yes")
        else:
            print("no")
### BUGGY CODE ###

s = input()
K = int(input())

substringList = []
for i in range(len(s)):
    for j in range(i, len(s)):
        #print(i,j)
        substringList.append(s[i:j+1])
substringList = list(set(substringList))
print(sorted(substringList)[K-1])


### FIXED CODE ###

s = input()
K = int(input())

substringList = []
if(len(s) < 50):
    for i in range(len(s)):
            for j in range(i, len(s)):
                #print(i,j)
                if(s[i:j+1] in substringList):
                    pass
                else:
                    substringList.append(s[i:j+1])
else:
    for i in range(len(s)):
            for j in range(i, i+5):
                substringList.append(s[i:j+1])
#substringList = list(set(substringList))
print(sorted(list(set(substringList)))[K-1])
### BUGGY CODE ###

from copy import copy
from collections import defaultdict
N,P = map(int, input().split())
S = input()
d = [0] * 10000
prev = [0] * 10000
key_prev = set([0])

for i,s in enumerate(S):
    tmp = [0] * 10000
    key_tmp = set([0])
    amari = int(s)%P
    tmp[amari] += 1
    key_tmp.add(amari)
    
    for k in key_prev:
        tmp[(k*10+amari)%P] += prev[k]
        key_tmp.add((k*10+amari)%P)
    
    for k in key_tmp:
        d[k] += tmp[k]

    prev = copy(tmp)
    key_prev = copy(key_tmp)
print(d[0])

### FIXED CODE ###

from collections import defaultdict
N,P = map(int, input().split())
S = list(input()[::-1])
ans = 0
if P == 2:
    for i,s in enumerate(S):    
        if int(s) in [2,4,6,8,0]:
            ans += N - i
elif P == 5:
    for i,s in enumerate(S):    
        if int(s) in [0,5]:
            ans += N - i
else:
    d = defaultdict(int)
    cnt = 0
    d[0] = 1
    for i,s in enumerate(S):
        cnt = (cnt + pow(10,i,P)*int(s))%P
        d[cnt] += 1
    for k in d.keys():
        if d[k] > 1:
            ans += d[k]*(d[k]-1)//2 
print(ans)
### BUGGY CODE ###

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

ans = 0

for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      li = L[i]
      lj = L[j]
      lk = L[k]
      if ((li+lj)>lk)&((lj+lk)>li)&((li+lk)>lj):
        ans += 1
      else:
        continue
        
print(ans)

### FIXED CODE ###

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

import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N, M = map(int, input().split())
    l1, r1 = map(int, input().split())
    card = set(range(l1, r1 + 1))
    for _ in range(M - 1):
        l, r = map(int, input().split())
        card &= set(range(l, r + 1))

    print(len(card))


if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N, M = map(int, input().split())
    card = [0 for _ in range(N + 1)]

    for _ in range(M):
        l, r = map(int, input().split())
        l, r = l - 1, r - 1
        card[l] += 1
        card[r + 1] -= 1

    for i in range(N):
        card[i + 1] += card[i]

    # print(card)
    print(card.count(M))


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

#!/usr/bin/env python3
import sys
from math import log2

ROUND = 10 ** 100

def main():
    S = input()
    N = len(S)
    to = []
    for _ in range(int(log2(ROUND))):
        l = [0] * N
        to.append(l)
    
    for i in range(N):
        to[0][i] = i + 1 if S[i] == "R" else i - 1
    
    for i in range(1, int(log2(ROUND))):
        for j in range(N):
            to[i][j] = to[i - 1][to[i - 1][j]]

    a = []
    for i in range(int(log2(ROUND))):
        if ROUND>>i & 1:
            a.append(i)

    ans = [0] * N
    for j in range(N):
        ans[to[int(log2(ROUND)) - 1][j]] += 1

    L = [str(i) for i in ans]
    print(" ".join(L))
    return


if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin/env python3
import sys
from itertools import groupby

# RUN LENGTH ENCODING
def rfe_tupple(S: str):
    grouped = groupby(S)
    res = []
    for k, v in grouped:
        res.append((k, str(len(list(v)))))
    return res

def main():
    S = input()
    N = len(S)
    
    now = 0
    compressed = rfe_tupple(S)
    ans = [0] * N
    for lr, i in compressed:
        i = int(i)
        if lr == "R":
            now += i
            ans[now - 1] += i - i // 2
            ans[now] += i // 2
        else:
            ans[now - 1] += i // 2
            ans[now] += i - i // 2
            now += i
    
    L = [str(i) for i in ans]
    print(" ".join(L))
    return

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

s = input()
n = int(input())
status = True

for i in range(n):
	com = input().split()
	if len(com) == 1:
		status = not status
	else:
		s = com[2]*bool(((com[1]=='1')+status-1)) + s + com[2]*bool(((com[1]=='2')+status-1))
        
if not status:
	s = s[::-1]
print(s)

### FIXED CODE ###

from collections import deque

s = deque(input())
n = int(input())
status = True

for i in range(n):
	com = input().split()
	if com[0] == '1':
		status = not status
	elif int(com[1])+status == 2:
		s.appendleft(com[2])
	else:
		s.append(com[2])
        
if not status:
	s.reverse()
print("".join(s))
### BUGGY CODE ###

N = int(input().strip())
a = [list(map(int, input().split())) for i in range(N)]

for i in range(N):
    tmp=a[:i]+a[i+1:]
    print(max(tmp)[0])

### FIXED CODE ###

N = int(input().strip())
a = [int(input().strip()) for i in range(N)]

a_s=sorted(a,reverse=True)
mx=a_s[0]
for i, val in enumerate(a):
    if val!=mx:
        print(mx)
    else:
        print(a_s[1])
### BUGGY CODE ###

from fractions import gcd
from functools import reduce
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
R = 10**9+7

def lcm_base(a,b):
    return (a*b)//gcd(a,b)

n = inn()
a = inl()
#l = a[0]
#for i in range(1,n):
#    l = l*a[i]//gcd(l,a[i])
l = reduce(lcm_base,a,1)
sm = 0
for i in range(n):
    sm = (sm + l//a[i])%R
print(sm)


### FIXED CODE ###

from fractions import gcd
from functools import reduce
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
R = 10**9+7

def lcm_base(a,b):
    return (a*b)//gcd(a,b)

def inv(x):
    return pow(x,R-2,R)

n = inn()
a = inl()
#l = a[0]
#for i in range(1,n):
#    l = l*a[i]//gcd(l,a[i])
l = reduce(lcm_base,a,1)
sm = 0
for i in range(n):
    sm = (sm + inv(a[i]))%R
print((sm*l)%R)
### BUGGY CODE ###

N=int(input())
P=list(map(int,input().split()))
count=0
for i in range(1,N):
    new_P=P[0:i+1]
    m=min(new_P)
    if P[i]<=m:
        count+=1
print(count+1)


### FIXED CODE ###

N=int(input())
P=list(map(int,input().split()))
count=0
min=2*10**5
for i in range(N):
    if P[i]<=min:
        min=P[i]
        count+=1
print(count)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)

road_par = []
road_rank = []
rail_par = []
rail_rank = []
c1 = []
c2 = []

def init(par, rank, c, n):
    for i in range(n):
        par.append(i)
        rank.append(0)
        c.append(0)


def find(par,x):
    if par[x] == x:
        return x
    par[x] = find(par, par[x])
    return par[x]


def unite(par, rank, x, y):
    x = find(par, x); y = find(par, y)
    if x == y:
        return
    if rank[x] < rank[y]:
        par[x] = y
    elif rank[y] < rank[x]:
        par[y] = x
    else:
        par[y] = x
        rank[x] += 1


N, K, L = map(int, input().split())
init(road_par, road_rank, c1, N)
init(rail_par, rail_rank, c2, N)

for i in range(K):
    f, t = map(int, input().split())
    unite(road_par, road_rank, f-1, t-1)

for i in range(L):
    f,t = map(int, input().split())
    unite(rail_par, rail_rank, f-1, t-1)

for i in range(N):
    c1[find(road_par, i)] += 1
    c2[find(rail_par, i)] += 1

ans = [0 for i in range(N)]

for i in range(N):
    for j in range(N):
        if find(road_par, i) == find(road_par, j) and find(rail_par, i) == find(rail_par, j):
            ans[i] += 1

for i in range(N):
    print(ans[i], end=' ')
print('')

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

road_par = []
road_rank = []
rail_par = []
rail_rank = []
c1 = []
c2 = []

def init(par, rank, c, n):
    for i in range(n):
        par.append(i)
        rank.append(0)
        c.append(0)


def find(par,x):
    if par[x] == x:
        return x
    par[x] = find(par, par[x])
    return par[x]


def unite(par, rank, x, y):
    x = find(par, x); y = find(par, y)
    if x == y:
        return
    if rank[x] < rank[y]:
        par[x] = y
    elif rank[y] < rank[x]:
        par[y] = x
    else:
        par[y] = x
        rank[x] += 1


N, K, L = map(int, input().split())
init(road_par, road_rank, c1, N)
init(rail_par, rail_rank, c2, N)


for i in range(K):
    f, t = map(int, input().split())
    unite(road_par, road_rank, f-1, t-1)

for i in range(L):
    f,t = map(int, input().split())
    unite(rail_par, rail_rank, f-1, t-1)

for i in range(N):
    c1[find(road_par, i)] += 1
    c2[find(rail_par, i)] += 1

ans = [0 for i in range(N)]

"""
for i in range(N):
    for j in range(N):
        if find(road_par, i) == find(road_par, j) and find(rail_par, i) == find(rail_par, j):
            ans[i] += 1
"""
from collections import defaultdict
ans = defaultdict(int)
for i in range(N):
    ans[(find(road_par, i), find(rail_par, i))] += 1

for i in range(N):
    print(ans[(find(road_par, i), find(rail_par, i))], end=' ')
print('')
### BUGGY CODE ###

from bisect import bisect_left as bi
x,y,z,k=map(int,input().split())
a=sorted(list(map(int,input().split())))[::-1]
b=sorted(list(map(int,input().split())))[::-1]
c=sorted(list(map(int,input().split())))[::-1]
for i in sorted([j+i for j in c for i in sorted([i+j for i in a for j in b])[::-1][:k]])[::-1][:k]:
    print(i)

### FIXED CODE ###

x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
b=list(map(int,input().split()))
b.sort(reverse=True)
c=list(map(int,input().split()))
c.sort(reverse=True)
d=[i+j for i in a for j in b]
d.sort(reverse=True)
e=[i+j for i in c for j in d[:k]]
e.sort(reverse=True)
for i in range(k):
    print(e[i])
### BUGGY CODE ###

import collections as c
s = input()
r = [0]*len(s)
r[0] = int(s[-1])
for i in range(1,len(s)):
  r[i] = (int(s[-(1+i)])*10**i+ r[i-1]) % 2019

rc = c.Counter(r)
rl = list(rc.values())
sum = 0
for i in rl:
  sum += int(i*(i-1)/2)

if 0 in rc:
	sum+=1

print(sum)

### FIXED CODE ###

def main():
    s = list(map(int, list(input())))
    r = [0]*len(s)
    r[0] = int(s[-1])
    for i in range(1,len(s)):
        temp = s[-(1+i)]*pow(10,i,2019)
        r[i] = (temp+r[i-1])%2019

    ans = 0
    cts = [0]*2019
    for i in r:
        ans+=cts[i]
        cts[i]+=1
    
    ans+=cts[0]

    print(ans)

main()
### BUGGY CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
A = list(map(int,input().split()))
result = 1
for i in range(N):
    result = result * A[i]
if result > 10**18:
    print(-1)
else:
    print(result)

### FIXED CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
A = list(map(int,input().split()))
A.sort()
result = 1
for i in range(N):
    result = result * A[i]
    if result > 1e18:
        result = -1
        break
print(result)
### BUGGY CODE ###

l, r = map(int, input().split())
dp = []

for i in range(l, r):
    for j in range(i+1, r+1):
        dp.append(i * j % 2019)

dp.sort()
print(dp[0])



### FIXED CODE ###

import sys

l, r = map(int, input().split())
#dp = []
min = 1000000000000000000

if l <= 2019 < r:
    print(0)
    sys.exit()

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

        if min == 0:
            print(0)
            sys.exit()

#        dp.append(i * j % 2019)
#        dp.append(i * j % 18)

#dp.sort()
#print(dp[0])
print(min)
### BUGGY CODE ###

N = int(input())
ans = []
for i in range(N):
    A = int(input())
    if A not in ans:
        ans.append(A)
    else:
        ans.remove(A)
print(len(ans))


### FIXED CODE ###

N = int(input())
num = {}
for i in range(N):
    A = int(input())
    if A in num.keys():
        num[A] += 1
    else:
        num[A] = 1
ans = 0
for i, j in num.items():
    if j%2 == 1:
        ans += 1
print(ans)