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

n=int(input())
s=input()
a=[]
for i in s:
    if i=='W': a.append(1)
    else: a.append(-1)
a2=[-1*i for i in a]
#print(a,a2)
count=0
for i in range(len(a)):
    d=sum(a[i+1:])+sum(a2[:i])
    if count<d:count=d
    #print(sum(a[i+1:]),sum(a2[:i]),d)
print((n-1-count)//2)

### FIXED CODE ###

n=int(input())
s=input()
a=[]
for i in s:
    if i=='W': a.append(1)
    else: a.append(-1)
a2=[-1*i for i in a]
suma=[sum(a)-a[0]]
for i in range(len(a)-1):
    suma.append(-a[i+1]+suma[i])
suma2=[0]
for i in range(len(a2)-1):
    suma2.append(suma2[i]+a2[i])
#print(a,a2)
count=0
for i in range(len(a)):
    d=suma[i]+suma2[i]
    if count<d:count=d
    #print(sum(a[i+1:]),sum(a2[:i]),d)
print((n-1-count)//2)
### BUGGY CODE ###

import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
heapq.heapify(a)

for i in range(m):
    b, c = map(int, input().split())
    cnt = 0
    while 1:
        if a[0] < c and cnt < b:
            heapq.heappop(a)
            heapq.heappush(a, c)
            cnt += 1
        else:
            break

print(sum(a))

### FIXED CODE ###

import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
heapq.heapify(a)
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key = lambda x: x[1], reverse = True)

for i in range(m):
    if a[0] >= bc[i][1]:
        break
    else:
        cnt = 0
        while cnt < bc[i][0]:
            heapq.heapreplace(a, bc[i][1])
            cnt += 1

print(sum(a))
### BUGGY CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque

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

match_dict = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

A = list(map(int, input().split()))
queue = deque()
queue.append((0, ""))

ans = 0
while queue:
    c_num, c_str = queue.popleft()
    if c_num == N:
        ans = max(ans, int(c_str))
        continue
    if c_num > N:
        continue
    for num in A:
        match_num = match_dict[num]
        new_str = c_str + str(num)
        queue.append((c_num + match_num, new_str))

print(ans)

### FIXED CODE ###

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

match_dict = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

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

#桁数のMAX
dp = [-1] * (N+1)
dp[0] = 0

for a in A:
    for i in range(match_dict[a], N+1):
        if dp[i - match_dict[a]] >= 0:
            dp[i] = max(dp[i], dp[i - match_dict[a]] + 1)

ans = ''
A.sort(reverse=True)

i = N
while i:
    for a in A:
        if i - match_dict[a] >= 0 and dp[i - match_dict[a]] == dp[i] - 1:
            ans += str(a)
            i -= match_dict[a]
            break

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

# coding: utf-8
# Here your code !
list = []
for i in range(1000000000):
    list.append(0)
N = int(input())
for i in range(N):
    a = int(input())
    if list[a - 1] == 0:
        list[a-1] = 1
    else:
        list[a-1] = 0
print(list.count(1))

### FIXED CODE ###

N = int(input())
card = set()

for i in range(N):
    A = int(input())
    if A in card:
        card.remove(A)
    else:
        card.add(A)
print(len(card))
### BUGGY CODE ###

N, W = map(int, input().split())
items = [[0, 0]]
for _ in range(N):
    items.append(list(map(int, input().split())))

dp = [[float("inf") for _ in range(10 ** 5 + 1)] for _ in range(N + 1)]

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

for i in range(1, N + 1):
    for j in range(10 ** 5 + 1):
        if j - items[i][1] >= 0:
            dp[i][j] = min(dp[i - 1][j - items[i][1]] + items[i][0], dp[i - 1][j])
        else:
            dp[i][j] = dp[i - 1][j]

ans = 0
for i in range(N + 1):
    for j in range(10 ** 5 + 1):
        if dp[i][j] <= W:
            ans = max(ans, j)
print(ans)

### FIXED CODE ###

N, W = map(int, input().split())
items = [[0, 0]]
v_total = 0
for _ in range(N):
    w, v = map(int, input().split())
    items.append([w, v])
    v_total += v

dp = [[float("inf")] * (v_total + 1) for _ in range(N + 1)]

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

ans = 0
for i in range(1, N + 1):
    for j in range(v_total + 1):
        if j - items[i][1] >= 0:
            dp[i][j] = min(dp[i - 1][j - items[i][1]] + items[i][0], dp[i - 1][j])
        else:
            dp[i][j] = dp[i - 1][j]

        if i == N and dp[i][j] <= W:
            ans = max(ans, j)

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

from operator import itemgetter
import sys
input = sys.stdin.readline

N,M = map(int,input().split())
AB = [[int(i) for i in input().split()] for _ in range(N)]
AB.sort(key=itemgetter(0,1),reverse=True)

answer = 0
for j in range(M-1,-1,-1):
    maxB = 0
    index = -1
    for i in range(len(AB)-1,-1,-1):
        a,b = AB[i]
        if a + j <= M:
            if maxB < b:
                maxB = b
                index = i
            if i == 0:
                AB.pop(index)
                answer += maxB
        else:
            if index < 0:
                break
            else:
                AB.pop(index)
                answer += maxB
                break

print(answer)

### FIXED CODE ###

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

from heapq import heappush, heappushpop

N,M = map(int,input().split())
# task[締切][価値]
tasks = [[] for _ in range(M)] 
for _ in range(N):
    a,b = map(int,input().split())
    if a <= M:
        tasks[M-a].append(b)

# 受注したバイト
q = []
# 締切=dayとなる最大の価値をqに格納
for day in range(M):
    # その日締切のバイト
    for v in tasks[day]:
        # まだ今日は受注してない
        if len(q) < day+1:
            heappush(q,v)
        else:
            heappushpop(q,v)

answer = sum(q)
print(answer)
### BUGGY CODE ###

import sys
input=sys.stdin.readline

def main():
    X = input().strip()
    while 1:
        si = X.find("ST")
        if si == -1:
            break
        sc = 1
        for i in range(si-1,-1,-1):
            if X[i] != "S":
                break
            sc += 1
        tc = 1
        for i in range(si+2,len(X)):
            if X[i] != "T":
                break
            tc += 1
        c = min(sc,tc)
        X = X[:max(0,si-c+1)] + X[min(len(X),si+c+1):]
    print(len(X))

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input=sys.stdin.readline

def main():
    X = input().strip()
    A = []
    for c in X:
        if len(A) > 0 and A[-1] == "S" and c == "T":
            A.pop()
        else:
            A.append(c)
    print(len(A))

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

import math

N=int(input())
A=list(map(int,input().split()))
 
count=0
score=0
SUM=[0]
 
for i in range(N):
    SUM=SUM+[SUM[i]+A[i]]

    
SUM.sort()



for i in range(1,len(SUM)):
    if SUM[i]==SUM[i-1]:
        count=count+1
    else:
        if count!=0:
            score=score+math.factorial(count)
        count=0
        
if count!=0:
    score=score+math.factorial(count)

 
print(score)


### FIXED CODE ###

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

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

    
SUM.sort()



for i in range(1,N+1):
    if SUM[i]==SUM[i-1]:
        count=count+1
    else:
        if count!=0:
            score=score+count*(count+1)//2
        count=0
        
if count!=0:
    score=score+count*(count+1)//2

 
print(score)
### BUGGY CODE ###

S=input() + ' '
if len(S) <= 4:
  print(0)
elif len(S) == 5:
  if int(S[:-1]) % 2019 == 0:
    print(1)
  else:
    print(0)
else:
  count = 0
  for i in range(len(S)-5):
    for j in range(i+4, len(S)):
      s = int(S[i:j])
      if s % 2019 == 0:
        count += 1
  print(count)

### FIXED CODE ###

from collections import Counter

S=input()

rlist=[0]
for i in range(len(S)):
  rlist.append((rlist[-1]+int(S[-i-1])*pow(10,i,2019))%2019)
  
c = Counter(rlist)
c[0] -= 1

def nC2(n):
  return n*(n-1)//2
  
ans = c[0]
for k in c.keys():
  if c[k] >= 2:
    ans += nC2(c[k])
    
print(ans)
### BUGGY CODE ###

S = input()

c = {}
for i, j in enumerate(S):
    if j != "?":
        c[i] = j

T = [s if s != "?" else "9" for s in S]
T = int(''.join(T))

ans = 0
for i in range(T // 13 + 1):
    f = False
    s = '{0:0>{1}}'.format(i * 13 + 5, len(S))
    for k, v in c.items():
        if s[k] != v:
            f = True
            break
    if f is not True:
        ans += 1
print(ans % (10**9 + 7))

### FIXED CODE ###

S = input()
con = 10**9 + 7

T = [s if s != "?" else "0" for s in S]
T = int(''.join(T))
SS = T % 13

def get_mod(S):
    c = {}
    iii = 1
    for i in range(len(S)):
        if S[len(S) - i - 1] != "?":
            iii *= 10
            iii %= 13
            continue
        c[i] = {(j * iii) % 13: 1 for j in range(0, 10)}
        iii *= 10
        iii %= 13
    return c
c = get_mod(S)

def get_tdp(pdp):
    tdp = {i: 0 for i in range(13)}
    for r in v.keys():
        for _r, _v in pdp.items():
            tdp[(_r + r) % 13] += _v
    for i in range(13):
        tdp[i] %= con
    return tdp

pdp = {i: 0 for i in range(13)}
pdp[SS] += 1
for k, v in c.items():
    pdp = get_tdp(pdp)

ans = pdp[5]
print(ans)
### BUGGY CODE ###

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

t = [1]
for i in range(n):
    t.append(a[t[-1] -  1])

for i in range(n):
    for j in range(i + 1, n):
        if t[i] == t[j]:
            s = j - i
            break
    else:
        continue

    break

if k < i:
    print(t[k])
else:
    print(t[(k - i) % s + i])

### FIXED CODE ###

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

t = [1]
for i in range(n):
    t.append(a[t[-1] -  1])

t_sort = sorted(t)
for i in range(n):
    if t_sort[i] == t_sort[i + 1]:
        b = t_sort[i]
        break

count = 0
for i in range(n):
    if t[i] == b:
        if count == 0:
            count += 1
            s_first = i
        else:
            s_second = i
            break
s = s_second - s_first

for i in range(n - s + 1):
    if t[i] == t[i + s]:
        break

if k < i:
    print(t[k])
else:
    print(t[(k - i) % s + i])
### BUGGY CODE ###

N = int(input())
S = input()


count_r = S.count('R')
count_g = S.count('G')
count_b = S.count('B')

total = count_r * count_g * count_b


for gap in range(1, N//2+1):
    for i in range(N - 2):
        j = i + gap
        k = j + gap
        if k >= N:
            continue
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            total -= 1

print(total)


### FIXED CODE ###

N = int(input())
S = input()


total = S.count('R') * S.count('G') * S.count('B')


for gap in range(1, N//2+1):
    for i in range(N - 2 * gap):
        j = i + gap
        k = j + gap
        if k >= N:
            continue
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            total -= 1

print(total)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(65536)

N=int(input())
d=[-1 for _ in range(N+1)]
e=[[] for _ in range(N+1)]
for _ in range(N-1):
	a,b,c=map(int,input().split())
	e[a].append([b, c])
	e[b].append([a, c])
Q,K=map(int,input().split())
def bfs(now, dis):
	if d[now] != -1:
		return
	d[now] = dis
	for nxt, cos in e[now]:
		bfs(nxt, dis+cos)
bfs(K, 0)
for _ in range(Q):
	x,y=map(int,input().split())
	print(d[x]+d[y])


### FIXED CODE ###

import sys
sys.setrecursionlimit(1145141919)
N=int(input())
d=[-1 for _ in range(N+1)]
e=[[] for _ in range(N+1)]
for _ in range(N-1):
	a,b,c=map(int,input().split())
	e[a].append((b, c))
	e[b].append((a, c))
Q,K=map(int,input().split())
def dfs(now, dis):
	d[now] = dis
	for nxt,cos in e[now]:
		if d[nxt] == -1:
			dfs(nxt, dis+cos)
dfs(K, 0)
for _ in range(Q):
	x,y=map(int,input().split())
	print(d[x]+d[y])
### BUGGY CODE ###

primes = [0,0] + [1]*49999
for i in range(2, 223):
    if primes[i]:
        for j in range(i*i, 50001, i):
            primes[j] = 0
while True:
    n = int(input())
    if n == 0:
        break
    ans = 0
    mid = n // 2
    if primes[mid] and n%2 == 0:
        ans += 1
    left = [k for k, b in enumerate(primes[:mid]) if b]
    right = [k+mid+1 for k, b in enumerate(primes[mid+1:n]) if b]
    for i in right:
        for j in left:
            if i+j == n:
                ans += 1
                break
            if i+j > n:
                break
    print(ans)

### FIXED CODE ###

import bisect
primes = [0, 0] + [1] * 49999
for i in range(2, 224):
    if primes[i]:
        for j in range(i*i, 50001, i):
            primes[j] = 0
values = [i for i, k in enumerate(primes) if k]
while True:
    n = int(input())
    if n == 0:
        break
    I = bisect.bisect(values, n//2)
    print(len([1 for v in values[:I] if primes[n-v]]))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import deque
import copy

N,M,P=map(int, sys.stdin.readline().split())

al=[ [] for i in range(N+1) ]		#隣接リスト
rev_al=[ [] for i in range(N+1) ]	#reverse隣接リスト
#辺のリスト
edge=[]

for i in range(M):
	a,b,c=map(int, sys.stdin.readline().split())
	al[a].append(b)
	rev_al[b].append(a)
	edge.append((a,b,c-P))


#ゴールからBFS
q=deque()
q.append(N)
#訪問した頂点
Visit=[ 0 for _ in range(N+1) ]
while q:
	fro=q.popleft()
	Visit[fro]=1
	for to in rev_al[fro]:
		if Visit[to]==0:
			q.append(to)
			
Visit1=Visit

#スタートからBFS
q=deque()
q.append(1)
#訪問した頂点
Visit=[ 0 for _ in range(N+1) ]
while q:
	fro=q.popleft()
	Visit[fro]=1
	for to in al[fro]:
		if Visit[to]==0:
			q.append(to)

Visit2=Visit

#1からもNからも到達可能な頂点の集合
V=[]
for v1,v2 in zip(Visit1,Visit2):
	V.append(v1&v2)


D=[ float("-inf") for _ in range(N+1) ]	#頂点１からの距離 1-indexed
D[1]=0

#ベルマンフォード N-1回
for _ in range(N):
	for a,b,c in edge:
		if V[a]==1 and V[b]==1:
			D[b]=max( D[b],D[a]+c )

D1=copy.deepcopy(D)

#ベルマンフォード 追加1回で差分が出たら閉路検出
for a,b,c in edge:
	if V[a]==1 and V[b]==1:
		if D[b]!=max( D[b],D[a]+c ):
			print -1
			quit()
else:
	print max(D[N],0)


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import deque

N,M,P=map(int, sys.stdin.readline().split())

al=[ [] for i in range(N+1) ]		#隣接リスト
rev_al=[ [] for i in range(N+1) ]	#reverse隣接リスト
#辺のリスト
edge=[]

for i in range(M):
	a,b,c=map(int, sys.stdin.readline().split())
	al[a].append(b)
	rev_al[b].append(a)
	edge.append((a,b,c-P))


#ゴールからBFS
#訪問した頂点
Visit=[ 0 for _ in range(N+1) ]
q=deque()
q.append(N)
Visit[N]=1
while q:
	fro=q.popleft()
	for to in rev_al[fro]:
		if Visit[to]==0:
			Visit[to]=1
			q.append(to)
			
Visit1=Visit

#スタートからBFS
#訪問した頂点
Visit=[ 0 for _ in range(N+1) ]
q=deque()
q.append(1)
Visit[1]=1
while q:
	fro=q.popleft()
	for to in al[fro]:
		if Visit[to]==0:
			Visit[to]=1
			q.append(to)

Visit2=Visit

#1からもNからも到達可能な頂点の集合
V=[]
for v1,v2 in zip(Visit1,Visit2):
	V.append(v1&v2)

new_N=sum(V)

fedge=[]	#必要な要素だけをフィルターした辺集合
for a,b,c in edge:
	if V[a]==1 and V[b]==1:
		fedge.append((a,b,c))


D=[ float("-inf") ]*(N+1)	#頂点１からの距離 1-indexed
D[1]=0

#ベルマンフォード
for i in range(new_N):
	for a,b,c in fedge:
		if D[a]==float("-inf"): continue
		alt=D[a]+c
		if D[b]<alt:
			D[b]=alt
			if i==new_N-1:
				print -1
				quit()

print max(0,D[N])
### BUGGY CODE ###

#C問題
N, M = map(int, input().split())
N_list = []
for i in range (N):
    N_list.append(i+1)

L_list = []
R_list = []
for i in range(M):
    L, R = map(int, input().split())
    L_list.append(L)
    R_list.append(R)

N_list= [i for i in N_list if i >= max(L_list) and i<=min(R_list)]
print(len(N_list))

### FIXED CODE ###

#C問題
import numpy as np
N, M = map(int, input().split())
L_list = []
R_list = []
for i in range(M):
    L, R = map(int, input().split())
    L_list.append(L)
    R_list.append(R)
if min(R_list) - max(L_list) < 0:
    print(0)
else:
    print(min(R_list) - max(L_list)+1)
### BUGGY CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

index = defaultdict(list)

for i, s in enumerate(S):
    if s == "R":
        index["R"].append(i)
    elif s == "G":
        index["G"].append(i)
    else:
        index["B"].append(i)

G = sorted(index["G"])
R = sorted(index["R"])
B = sorted(index["B"])

count = 0
for r in R:
    for g in G:
        for b in B:
            s = min(r, g, b)
            l = max(r, g, b)
            if r != s and r != l:
                m = r
            if g != s and g != l:
                m = g
            if b != s and b != l:
                m = b
            if m - s != l - m:
                count += 1
            

print(count)

### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

R = []
G = []
B = []

for i in range(N):
    if S[i] == "R":
        R.append(i)
    elif S[i] == "G":
        G.append(i)
    else:
        B.append(i)

# print(R, G, B)

ans = len(R) * len(G) * len(B)

count = 0

for i in range(N):
    for j in range(N):
        if i < j:
            k = j + (j - i)
            if k < N:
                if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                    count += 1
print(ans - count)
### BUGGY CODE ###

import bisect as bi
import sys
from operator import itemgetter
input = sys.stdin.readline

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0] * m
for i in range(m):
    b[i] = list(map(int,input().split()))
a.sort()
#print(a)
b.sort(key=itemgetter(1),reverse=True)
for i in b:
    tmp = min(bi.bisect_left(a,i[1]),i[0])
    if tmp == 0:
        print(sum(a))
        sys.exit()
    for j in range(tmp):
        a[j] = i[1]
    a.sort()
#print(a)
print(sum(a))

### FIXED CODE ###

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

from operator import itemgetter

N,M = map(int,readline().split())
A = list(map(int,readline().split()))
m = map(int,read().split())
BC = list(zip(m,m))

BC.sort(key = itemgetter(1),reverse=True)

BC.append((N,-1))

change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break

A += change
A.sort()
answer = sum(A[-N:])
print(answer)
### BUGGY CODE ###

# encoding,utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import numpy as np

N,C = map(int,input().split())
tv_times = [[int(j) for j in input().split()] for i in range(N)]
# print(tv_times)
tv_times = np.array(tv_times)

tv_times = np.sort(tv_times,axis=0)

for i in range(N):
    for j in range(i,N):
        if tv_times[i,2] == tv_times[j,2]:
            if tv_times[i,0] == tv_times[j,1] or tv_times[i,1]==tv_times[j,0]:
                tv_times[i,0] = min(tv_times[i,0],tv_times[j,0])
                tv_times[i,1] = max(tv_times[i,1],tv_times[j,1])
                tv_times[j,0] = 0
                tv_times[j,1] = 0

max_end = -1
# print(tv_times)
for i in range(N):
    max_end = max(tv_times[i,1],max_end)

# print(tv_times)
# print(max_end)
count = [0 for i in range(max_end)]
for ni in range(N):
    for time in range(max(tv_times[ni,0]-1,0),tv_times[ni,1]):
        count[time] += 1

# print(count)
print(max(count))


### FIXED CODE ###

N,C = map(int,input().split())
tv_times = [[int(j) for j in input().split()] for i in range(N)]

channells = {}
for i in range(C+1):
    channells[i] = []
max_end = -1

for i in range(N):
    s,g,c = tv_times[i]
    max_end = max(max_end,g)
    channells[c] += [s,g]

tv_times = []
f = [0 for i in range(max_end+1)]
for cha in channells.keys():
    remove_list = []
    time = channells[cha]
    time.sort()
    for i in range(1,len(time)-1):
        if time[i] == time[i+1]:
            remove_list.append(time[i])
    time = list(set(time)-set(remove_list))
    time.sort()
    for i in range(len(time)//2):
        f[max(time[2*i]-1,0)] += 1
        f[time[2*i+1]] -= 1
ans = -1
for i in range(1,max_end+1):
    f[i] += f[i-1]
    if ans < f[i]:
        ans = f[i]

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

import sys


readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

s = ns()
slis = [int(s[-1*i:]) if i != 0 else 0  for i in range(len(s)+1)]
amari = [i % 2019 for i in slis]
ans = 0
for j in range(len(amari)-1):
    for k in range(j+1, len(amari)):
        if amari[j] == amari[k]:
            ans += 1
print(ans)

### FIXED CODE ###

import sys
from collections import defaultdict as de


readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

s = ns()
digit = 1
ans = 0
num = 0
amari = de(int)
amari[0] = 1
"""
大筋のやり方は
https://drken1215.hatenablog.com/entry/2020/04/29/171300
を参照。

「この下のfor文について」
1211400を考える。
1万の桁を考えるとき
digit = 10000
digit = 1924 mod 2019
11400 = 10000 + 1400 = 1924 + 1400 = ans mod 2019
つまり、ある桁までの2019のあまりはその一つ下の桁までのあまりと
その桁の数*桁のあまりを足したもののあまりである
"""

for i in s[::-1]:
    num = num + int(i) * digit
    num %= 2019
    digit *= 10
    digit %= 2019
    amari[num] += 1

for j in amari.values():
    ans += j*(j-1)//2

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

X,Y,A,B,C=map(int,input().split())
P=sorted(list(map(int,input().split())))
Q=sorted(list(map(int,input().split())))
R=sorted(list(map(int,input().split())))
P_=P[A-X:]
Q_=Q[B-Y:]
while P_[0]<R[-1] or Q_[0]<R[-1]:
    if P_[0]<Q_[0]:
        P_.pop(0)
        P_.append(R.pop(-1))
    else:
        Q_.pop(0)
        Q_.append(R.pop(-1))
    if len(R)==0:
        break
print(sum(P_)+sum(Q_))

### FIXED CODE ###

X,Y,A,B,C=map(int,input().split())
P=sorted(list(map(int,input().split())))
Q=sorted(list(map(int,input().split())))
R=sorted(list(map(int,input().split())))
S=sorted(P[A-X:]+Q[B-Y:])
ans=sum(S)
for i in range(min(len(R),len(S))):
    if S[i]<R[-1-i]:
        S[i]=R[-1-i]
    else:
        break
print(sum(S))
### BUGGY CODE ###

N = int(input())

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

ans = 1
for i in range(N):
    ans *= A[i]
if ans > 10 ** 18:
    ans = -1
print(ans)

### FIXED CODE ###

N = int(input())

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

ans = 1

if 0 in A:
    print(0)
else:
    for i in range(N):
        ans *= A[i]
        if ans > 10 ** 18:
            ans = -1
            break
    print(ans)