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

def main():
  _map = map
  _range = range
  _len = len
  _max = max
  _input = input
  _int = int
  n, m = _map(_int, _input().split())
  d1 = {}
  for _ in _range(n):
    a, b = _map(_int, _input().split())
    if a in d1:
      d1[a].append(b)
    else:
      d1[a] = [b]
  result = 0
  d2 = {}
  maxb = -1
  for i in _range(1, m + 1):
    if i in d1:
      for j in d1[i]:
        if j not in d2:
          d2[j] = 1
        else:
          d2[j] += 1
        if j > maxb:
          maxb = j
    else:
      if _len(d2) == 0:
        continue
    result += maxb
    if d2[maxb] == 1:
      del d2[maxb]
      if _len(d2) == 0:
        maxb = -1
      else:
        maxb = _max(d2.keys())
    else:
      d2[maxb] -= 1
  print(result)
main()

### FIXED CODE ###

n, m = map(int, input().split())
d1 = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a in d1:
    d1[a].append(b)
  else:
    d1[a] = [b]
result = 0
d2 = {}
maxb = -1
for i in range(1, m + 1):
  if i in d1:
    for j in d1[i]:
      if j not in d2:
        d2[j] = 0
      d2[j] += 1
      if j > maxb:
        maxb = j
  else:
    if len(d2) == 0:
      continue
  result += maxb
  if d2[maxb] == 1:
    del d2[maxb]
    if len(d2) == 0:
      maxb = 0
    else:
      maxb = max(d2.keys())
  else:
    d2[maxb] -= 1
print(result)
### BUGGY CODE ###

import numpy as np

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

# インデックスはライフ 値はそれを以下にする最小MP
dp = [10**10 for i in range(H+1)]
# dp = [np.inf for i in range(H+1)]
dp[0] = 0

for i in range(1, H+1):
    # quietus_MP = np.inf
    for a, b in AB:
        # if i-a >= 0:
        dp[i] = min(dp[max(i-a, 0)] + b, dp[i])
        # 一回で倒せて一番MP使わない魔法
        # if a > i:
        #     quietus_MP = min(b, quietus_MP)
    # 一回で倒す場合
    # dp[i] = min(quietus_MP, dp[i])

print(dp[-1])

### FIXED CODE ###

import numpy as np

H, N = map(int, input().split())
AB = np.array([list(map(int, input().split())) for i in range(N)])
A = AB[:, 0]
B = AB[:, 1]

# インデックスはライフ 値はそれを以下にする最小MP
dp = np.array([10**10 for i in range(H+1)], dtype=int)
# dp = np.array([np.inf for i in range(H+1)], dtype=int)
dp[0] = 0

for i in range(1, H+1):
    # print(np.maximum(i-A, 0))
    dp[i] = min(dp[np.maximum(i-A, 0)] + B)

print(dp[-1])
### BUGGY CODE ###

N, M = map(int, input().split())
A = [int(a) for a in input().split()]
A = sorted(A)
for _ in range(M):
    A[-1] = int(A[-1] * 0.5)
    A = sorted(A)
print(sum(A))

### FIXED CODE ###

import heapq

N, M = map(int, input().split())
A = [int(a) for a in input().split()]
q = []
for a in A:
    heapq.heappush(q, -a)
    
for _ in range(M):
    tmp = -heapq.heappop(q)
    heapq.heappush(q, -(tmp//2))
print(-sum(q))
### BUGGY CODE ###

N = int(input())
D = list(map(int, input().split()))
c = [0]*(N + 1)
a = 0
ans = 1
mod = 998244353
 
for i, d in enumerate(D):
    if (i == 0) & (d != 0):
        print(0)
        a = 1
        break
    if (i != 0) & (d == 0):
        print(0)
        a = 1
        break
    c[d] += 1


if a == 0:
    for o in range(1, N):
        ans *= c[o]**c[o + 1]

    
    print(ans%mod)


### FIXED CODE ###

N = int(input())
D = list(map(int, input().split()))
c = [0]*(N + 1)
a = 0
ans = 1
temp = 0
pre = 1
mod = 998244353
c = 1

if D[0] != 0:
    print(0)
    a = 1

if a == 0:
    D = sorted(D)
    for i, d in enumerate(D):
        if i == 0:
            continue
        if d == 0:
            print(0)
            a = 1
            break
        if temp != d:
            if (d - temp) != 1:
                print(0)
                a = 1
                break
            ans *= pre ** c

            temp = d
            pre = c
            c = 1
        else:
            c += 1

        if i == N-1:
            ans *= pre ** c
    if a == 0:
        print(ans%mod)
### BUGGY CODE ###

from collections import deque

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

loop = deque([])
visited = set()
stack = deque([1])
loop_creating = False
last = 1

while True:
  if loop_creating and len(visited) == 0:
    break

  nex = a[last - 1]

  if nex in visited:
    visited.remove(nex)
    loop.append(nex)
    loop_creating = True
  elif nex in stack:
    visited.add(nex)
  else:
    stack.append(nex)

  last = nex

if k <= len(stack):
  print(stack[k])
elif k > len(stack):
  rem = k - len(stack)
  print(loop[rem % len(loop)])


### FIXED CODE ###

from collections import deque

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

loop = []
visited = set()
s = set([1])
loop_creating = False
last = 1

while True:
  if loop_creating and len(visited) == 0:
    break
  
  if k == len(s) - 1:
    print(last)
    exit(0)

  nex = a[last - 1]

  if nex in visited:
    visited.remove(nex)
    loop.append(nex)
    loop_creating = True
  elif nex in s:
    visited.add(nex)
  else:
    s.add(nex)

  last = nex

rem = k - len(s)
print(loop[rem % len(loop)])
### BUGGY CODE ###

import copy

N = int(input())

As = list(map(lambda i: int(i), input().split()))

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

for a in As:
    ns[a-1] += 1

def get_comb(arr):
    res = 0
    for a in arr:
        if a == 0:
            continue
        res += a*(a-1)/2
    return int(res)

# print(ns)
for a in As:
    tmp = copy.copy(ns)
    tmp[a-1] -= 1
    print(get_comb(tmp))
    

### FIXED CODE ###

import copy

N = int(input())

As = list(map(lambda i: int(i), input().split()))

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

for a in As:
    ns[a-1] += 1

def get_comb(arr):
    res = 0
    for a in arr:
        if a == 0:
            continue
        res += a*(a-1)/2
    return int(res)

ba = get_comb(ns)

for a in As:
    print(ba - get_comb([ns[a-1]]) + get_comb([ns[a-1]-1]))
### BUGGY CODE ###

def main():
  from collections import deque
  s,*c=open(0)
  h,w=map(int,s.split())
  c=''.join(t[:w]for t in c)
  f=[-1]*h*w
  q=deque()
  for i,d in enumerate(c):
    if d=='#':
      q.append(i)
      f[i]=0
  while q:
    y=q.popleft()
    v=f[y]
    if h*w>y+w and f[y+w]<0:
      q.append(y+w)
      f[y+w]=v+1
    if y>=w and f[y-w]<0:
      q.append(y-w)
      f[y-w]=v+1
    if w>y%w+1and f[y+1]<0:
      q.append(y+1)
      f[y+1]=v+1
    if y%w>0and f[y-1]<0:
      q.append(y-1)
      f[y-1]=v+1
  print(v)
if __name__=='__main__':
  main()

### FIXED CODE ###

from collections import*
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=deque()
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            q.append((i,j,0))
ans=0
while q:
    y,x,v=q.popleft()
    ans=max(ans,v)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
        if h>i>=0 and w>j>=0 and c[i][j]=='.':
            c[i][j]='#'
            q.append((i,j,v+1))
print(ans)
### BUGGY CODE ###

def main():
    n = int(input())
    a = list(map(int, input().split()))
    if n % 2 == 1:
        a1 = a[:int((n-1)/2)]
        a2 = a[int((n-1)/2):]
    else:
        a1 = a[:int(n/2)]
        a2 = a[int(n/2):]
    res1 = 1
    res2 = 1
    for i in a1:
        res1 *= i
    for i in a2:
        res2 *= i
    res = res1 * res2
    if res <= 10 ** 18:
        print(res)
    else:
        print(-1)
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_s = sorted(a)
    res = 1
    for i in a_s:
        res *= i
        if res == 0:
            print(0)
            break
        if res > 10 ** 18:
            print(-1)
            break
    if res > 0 and res <= 10 ** 18:
        print(res)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)
def ReadInput():
	return [int(i) for i in input().split(" ")]
(R, C) = ReadInput()
N = int(input())
VectorSet = set() 
Grid = defaultdict(list)
for i in range(N):
	(r, c, a) = ReadInput()
	Grid[("R", r)].append((("C", c), a))
	Grid[("C", c)].append((("R", r), a))
	VectorSet.add(("R", r))
	VectorSet.add(("C", c))
def iteration(vector):
	VectorSet.discard(vector)
	for (v, a) in Grid[vector]:
		temp = a - VectorCover[vector]
		if (v in VectorCover):
			if(temp != VectorCover[v]):
				print("No")
				exit()
		else:
			VectorCover[v] = temp
			iteration(v) 
while(len(VectorSet) != 0):
	vector = VectorSet.pop()
	VectorCover = dict() 
	VectorCover[vector] = 0
	iteration(vector)
	minR = min(a for (p, a) in VectorCover.items() if (p[0] == "R"))
	minC = min(a for (p, a) in VectorCover.items() if (p[0] == "C"))
	if (minR + minC < 0):
		print("No")
		exit()
print("Yes")

### FIXED CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

def ReadInput():
	return [int(i) for i in input().split(" ")]

(R, C) = ReadInput()
N = int(input())
VectorSet = set() 
Grid = defaultdict(list)
for i in range(N):
	(r, c, a) = ReadInput()
	Grid[("R", r)].append((("C", c), a))
	Grid[("C", c)].append((("R", r), a))
	VectorSet.add(("R", r))
	VectorSet.add(("C", c))

def iteration(vector):
	VectorSet.discard(vector)
	for (v, a) in Grid[vector]:
		temp = a - VectorCover[vector]
		if (v in VectorCover):
			if(temp != VectorCover[v]):
				print("No")
				exit()
		else:
			VectorCover[v] = temp
			iteration(v) 

while(len(VectorSet) != 0):
	vector = VectorSet.pop()
	VectorCover = dict() 
	VectorCover[vector] = 0
	iteration(vector)
	minR = min(a for (p, a) in VectorCover.items() if (p[0] == "R"))
	minC = min(a for (p, a) in VectorCover.items() if (p[0] == "C"))
	if (minR + minC < 0):
		print("No")
		exit()

print("Yes")
### BUGGY CODE ###

n, m, r = map(int,input().split())
rs = list(map(int, input().split()))
distance = [[float("inf")]*n for i in range(n)]
for i in range(n):
    distance[i][i] = 0
for i in range(m):
    a, b, c = list(map(int, input().split()))
    a, b = a-1, b-1
    distance[a][b] = c
    distance[b][a] = c

# 全点間最短距離を求める
for k in range(n):
    for i in range(n):
        for j in range(n):
            distance[i][j] = min(distance[i][j],distance[i][k] + distance[k][j])
# r個の並びを考える
from itertools import permutations
ans = float("inf")

for v in permutations(rs, len(rs)):
    dist_tmp = 0
    for i in range(r-1):
        dist_tmp += distance[v[i]-1][v[i+1]-1]
    ans = min(ans, dist_tmp)
print(ans)

### FIXED CODE ###

from scipy.sparse.csgraph import floyd_warshall

n, m, r = map(int,input().split())
rs = list(map(int, input().split()))
edge = [[0]*n for i in range(n)]
for i in range(m):
    a, b, c = list(map(int, input().split()))
    a, b = a-1, b-1
    edge[a][b] = c
    edge[b][a] = c
dist = floyd_warshall(edge, directed=False)

from itertools import permutations
ans = float("inf")
    
for v in permutations(rs, len(rs)):
    dist_tmp = 0
    for i in range(r-1):
        dist_tmp += dist[v[i]-1][v[i+1]-1]
    ans = min(ans, int(dist_tmp))
print(ans)
### BUGGY CODE ###

import queue

N,Q=map(int,input().split())
a=[0]*(N-1)
b=[0]*(N-1)
c=[0]*N#count
p=[0]*Q
x=[0]*Q

to=[[] for i in range(N)]

for i in range(N-1):
    a[i],b[i] =map(int,input().split())
    a[i]-=1
    b[i]-=1
    to[a[i]].append(b[i])
    to[b[i]].append(a[i])
    
    
for i in range(Q):
    p[i],x[i] =map(int,input().split())
    p[i]-=1
    c[p[i]]+=x[i]
    
q=queue.Queue()
q.put((0,-1))


while not q.empty():
    v,prev=q.get()
    for i in range(len(to[v])):
        v_next=to[v][i]
        if v_next!=prev:
            q.put((v_next,v))
            c[v_next]+=c[v]

        
print(' '.join(map(str, c)))

### FIXED CODE ###

import queue
import sys
input = sys.stdin.readline

N,Q=map(int,input().split())
c=[0]*N#count

to=[[] for i in range(N)]

for i in range(N-1):
    a,b =map(int,input().split())
    a-=1
    b-=1
    to[a].append(b)
    to[b].append(a)
    
    
for i in range(Q):
    p,x =map(int,input().split())
    p-=1
    c[p]+=x
    
q=queue.Queue()
q.put((0,-1))


while not q.empty():
    v,prev=q.get()
    for i in range(len(to[v])):
        v_next=to[v][i]
        if v_next!=prev:
            q.put((v_next,v))
            c[v_next]+=c[v]

        
print(' '.join(map(str, c)))
### BUGGY CODE ###

import collections

S=input()
S_int = int(S)
mods = [int(S[i:])%2019 for i in range(len(S))]
mods.append(0)
mods_count = collections.Counter(mods)
count = 0
for mod in mods_count:
  c = mods_count[mod]
  count += c*(c-1)//2
#print(mods)
#print(mods_count)
print(count)

### FIXED CODE ###

S=input()
dp = {0:1}

p=0
q=1

for i in range(len(S)-1,-1,-1):
  p += (int(S[i])*q)
  p = p%2019
  q *= 10
  q = q%2019
  if p not in dp:
    dp[p]=0
  dp[p]+=1

#print(dp)
c = 0
for v in dp:
  c += dp[v]*(dp[v]-1)//2
print(c)
### BUGGY CODE ###

import math


def eq_value(a, b, x):
    return math.floor(a * x / b) - a * math.floor(x / b)


A, B, n = map(int, input().split())
start, end = 0, n

maximum = 0
for i in range(n + 1):
    value = eq_value(A, B, i)
    if value > maximum:
        maximum = value

print(maximum)


### FIXED CODE ###

from sys import stdout, stdin
from queue import Queue
from collections import defaultdict
import math
a,b,n = map(int, stdin.readline().strip().split())
x = min(b - 1, n)
ans = math.floor(a * x / b) - a * math.floor(x / b)
stdout.writelines(str(ans) + '\n')
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import math

MOD = 10 ** 9 + 7

def main():
    N = int(input())
    S = input().strip()

    if S[0] == 'W' or S[-1] == 'W':
        print(0)
        return

    Sp = ''
    Dc = True
    Lcnt = 0
    Rcnt = 0
    Pattern = 1
    for Sc in S:
        Dc = not Dc if Sc == Sp else Dc
        Sp = Sc
        Pattern *= Lcnt - Rcnt if not Dc else 1
        Lcnt += 1 if Dc else 0
        Rcnt += 1 if not Dc else 0

    if Lcnt == Rcnt:
        Pattern *= math.factorial(N)
        Pattern = Pattern % MOD
        print(Pattern)
    else:
        print(0)

if __name__ == "__main__":
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-

MOD = 10 ** 9 + 7

N = int(input())
S = list(map(lambda x: int(x == "W"),input()))
if S[0] or S[-1]:
    print(0)
    exit(0)

Dc = 1
LRsub = 1
Pattern = 1
Sp = S[0]

for i in range(1,N*2):
    Sc = S[i]
    Dc = Dc if Sc != Sp else -Dc
    Sp = Sc
    if Dc < 0:
        Pattern = (Pattern * LRsub) % MOD
    LRsub += Dc

if LRsub == 0:
    for i in range(2,N+1):
        Pattern = (Pattern * i) % MOD
    print(Pattern)
else:
    print(0)
### BUGGY CODE ###

N = int(input())
L = list(map(int, input().split()))
O = sorted(L, reverse=True)
def X(n,j):
    C = sorted(L)
    L1 = 0
    L2 = N-1
    while L1 != L2:
        a = (L1+L2)//2
        if C[a] == n:
            nn = len(C[0:N-1-j])-len(C[0:a+1])
            if nn > 0:
                return nn
            else:
                return 0
        if L2 - L1 <= 1:
            if C[L1] > n:
                nn = len(C[0:N-1-j])-len(C[0:L1])
            else:
                nn = len(C[0:N-1-j])-len(C[0:L2])
            if nn > 0:
                return nn
            else:
                return 0
        elif C[a] < n:
            L1 = a
        else:
            L2 = a
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans += X((O[i]-O[j]),j)
print(ans)

### FIXED CODE ###

N = int(input())
L = list(map(int, input().split()))
C = sorted(L)
def X(n,j):
    L1 = j+1
    L2 = N-1
    while L1 != L2:
        a = (L1+L2)//2
        if C[a] == n:
            while C[a] == C[a-1]:
                a = a-1
            return len(C[j+1:a])
        elif L2 - L1 <= 1:
            if C[L2] < n:
                return len(C[j+1:L2+1])
            elif C[L1] < n <= C[L2]:
                return len(C[j+1:L2])
            while C[L1] == C[L1-1]:
                if j+1 <= L1-1:
                    L1 = L1-1
                else:
                    break
            if C[L1] > n:
                return len(C[j+1:L1])
            elif C[L1] == n:
                return len(C[j+1:L1])
        elif C[a] < n:
            L1 = a
        else:
            L2 = a
    if C[L1] < n:
        return 1
    else:
        return 0
ans = 0
# print(C)
for i in range(N-2):
    for j in range(i+1,N-1):
        # print(X((C[i]+C[j]),j))
        ans += X((C[i]+C[j]),j)
print(ans)
### BUGGY CODE ###

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

sal=sum(al)
res=10**9+1

for i in range(1,n):
    temp = al[:i]
    res = min(res,abs(sal/2-sum(temp)))

print(int(res*2))

### FIXED CODE ###

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

sal=sum(al)
res=10**9+1
temp=0
for i in range(0,n-1):
    temp += al[i]
    res = min(res,abs(sal/2-temp))
    if res <=0.5:
        break

print(int(res*2))
### BUGGY CODE ###

_ = input()
b = []
for i in [x for x in input().split()]:
    b.append(i)
    b.reverse()
else:
    print(" ".join(b))

### FIXED CODE ###

from collections import deque

n = int(input())
a = input().split()
b = deque()

for i in range(n):
    if i % 2 != n % 2:
        b.appendleft(a[i])
    else:
        b.append(a[i])
else:
    print(*b)
### BUGGY CODE ###

N, M = map(int, input().split())
MOD = 10 ** 9 + 7

a = [int(input()) for _ in range(M)]

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

for now in range(N):
    for next in range(now + 1, min(N + 1, now + 3)):
        if next not in a:
            dp[next] += dp[now]
            dp[next] = dp[next] % MOD

print(dp[N])


### FIXED CODE ###

N, M = map(int, input().split())
MOD = 10 ** 9 + 7

is_broken = [False for _ in range(N + 1)]
for _ in range(M):
    a = int(input())
    is_broken[a] = True

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

for i in range(1, N + 1):
    if is_broken[i]:
        continue
    if i == 1:
        dp[i] += dp[i - 1]
    else:
        dp[i] += dp[i - 1] + dp[i - 2]

    dp[i] = dp[i] % MOD

print(dp[N])
### BUGGY CODE ###

nn = '0' + input()
ans = 0
dp = [[0 for i in range(2)] for j in range(len(nn))]
dp[0][1] = 1

for i,c in enumerate(nn[1:]):
    cc = int(c)
    dp[i+1][0] = min(dp[i][0] + cc, dp[i][1] + 10 - cc)
    dp[i+1][1] = min(dp[i][0] + cc + 1, dp[i][1] + 10 - cc - (1 if i < len(nn) - 2 else 0))
print(min(dp[len(nn)-1]))
# print(dp)
 

### FIXED CODE ###

nn = '0' + input()
ans = 0
dp = [[0 for i in range(2)] for j in range(len(nn))]
dp[0][1] = 1

for i,c in enumerate(nn[1:]):
    cc = int(c)
    zero = dp[i][0] + cc
    one = dp[i][1] + 10 - cc
    dp[i+1][0] = min(zero, one)
    dp[i+1][1] = min(zero + 1, one - (1 if i < len(nn) - 2 else 0))
print(min(dp[len(nn)-1]))
# print(dp)
### 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

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

#ベルマンフォード N-1回
for _ in range(N):
	for a,b,c in fedge:
		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 fedge:
	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 ###

import sys

n,k = map(int,input().split())
a = list(map(int,input().split()))
dp = [sys.maxsize]*(n)
dp[0] = 0
for i in range(n):
  for j in range(i+1,k+i+1):
    if j<n:
      dp[j] = min(dp[j],dp[i]+abs(a[i]-a[j]))

print(dp[n-1])

 

### FIXED CODE ###

import sys

n,k = map(int,input().split())
a = list(map(int,input().split()))
dp = [sys.maxsize]*(n)
dp[0] = 0
for i in range(n):
  for j in range(i+1,k+i+1):
    if j<n:
      dp[j] = min(dp[j],dp[i]+abs(a[i]-a[j]))

print(dp[n-1])
### BUGGY CODE ###

X = input()
for i in range(10 ** 1000):
  p = X.find('ST')
  if p == -1:
    break
  X = X[:p] + X[p + 2:]
print(len(X))  

### FIXED CODE ###

X = input()
cnt = 0
res = 0
for i in X:
  if i == 'S':
    cnt += 1
  else:
    if cnt > 0:
      cnt -= 1
    else:
      res += 1
print(cnt + res)
### BUGGY CODE ###

num_all = int(input())
list = input().split(" ")


list_int = []
for j in list:
  list_int.append(int(j))

i = 1
while i <= num_all:
  data = list_int.count(i)
  #print(i)
  print(data)
  i = i+1

### FIXED CODE ###

n=int(input())
#l=list(map(int,input().split()))  #inputした数値列をintにしてlistを作成 けどなぜか使えない
list = input().split(" ")
list_int = []
for i in list:
  list_int.append(int(i)) 
k = [0]*n                         #大きさnのリスト
for i in list_int:
  k[i-1] = k[i-1]+1
for j in range(n):
  print(k[j])
### BUGGY CODE ###



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

ans=1
v=True
for i in arr:
    ans=ans*i

if ans>1000000000000000000:
    print(-1)
else:
    print(ans)
    


### FIXED CODE ###



n=int(input())
arr=list(map(int,input().split()))
arr.sort()
ans=1
v=True
for i in arr:
    ans=ans*i
    if ans==0:
        v=False
        print(0)
        break
        
    if ans>1000000000000000000:
        v=False
        print(-1)
        break

if v:
    print(ans)