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

import sys
input = sys.stdin.readline

N,K=(int(i) for i in input().split())
h = [int(i) for i in input().split()]
c = [0]*N
for i in range(1,N):
    jumpmax = min(i,K)
    c[i] = min([abs(h[i]-h[i-j])+c[i-j] for j in range(1,jumpmax+1)])
print(c[N-1])

### FIXED CODE ###

N,K=(int(i) for i in input().split())
h = [int(i) for i in input().split()]
c = [0]*N
for i in range(1,N):
    jumpmax = min(i,K)
    c[i] = min([abs(h[i]-h[i-j])+c[i-j] for j in range(1,jumpmax+1)])
print(c[N-1])
### BUGGY CODE ###

from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

n,m,k = map(int,stdin.readline().rstrip().split())
mod = 998244353
wariate = 1
point = 0

def combination(n,r,mod=mod):
    r=min(r,n-r)
    up,down=1,1
    for i in range(r):
        up=up*(n-i)%mod
        down=down*(i+1)%mod
    return up*pow(down,mod-2,mod)%mod

for i in range(n-1,-1,-1):
    if i != n-1:
        wariate *= m-1
        wariate %= mod
    if i <= k:
        point += m*combination(n-1,i)*wariate%mod
print(point%mod)

### FIXED CODE ###

from sys import stdin
from sys import setrecursionlimit

setrecursionlimit(10 ** 7)

n,m,k = map(int,stdin.readline().rstrip().split())
mod = 998244353
wariate = 1
point = 0

def prepare(n, MOD=mod):
    facts = [1]*(n+1)
    for i in range(1, n+1):
        facts[i] = facts[i-1]*i%MOD
    invs = [1]*(n+1)
    invs[n] = pow(facts[n], MOD-2, MOD)
    for i in range(0, n)[::-1]:
        invs[i] = invs[i+1] * (i+1) % MOD
    return facts, invs
facts, invs = prepare(n, mod)
for i in range(n-1,-1,-1):
    now = m
    if i != n-1:
        wariate *= m-1
        wariate %= mod
    now *= wariate%mod

    now *= facts[n-1]*invs[n-1-i]*invs[i]
    if i <= k:
        point += now%mod

print(point%mod)
### BUGGY CODE ###

from collections import Counter
from functools import reduce
from operator import mul

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    b = Counter(a)
    return b
def modmul(a,b):
    return a * b % 1000000007
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0
def modinv(a, m):
    g, x, y = xgcd(a, m)
    return x % m

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print('1')
else:
    fac = prime_factorize(A[0]) | prime_factorize(A[1])
    for x in A[2:]:
        fac |= prime_factorize(x)
    ans = 0
    f = [pow(x[0],x[1],1000000007) for x in fac.items()]
    if len(f) > 0:
        lcm = reduce(modmul,f)
    else:
        lcm = 1
    for x in A:
        ans = (ans + (lcm * modinv(x,1000000007))) % 1000000007
    print(ans)

### FIXED CODE ###

from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print('1')
else:
    g = gcd(A[0],A[1])
    lcm = (A[0]*A[1]) // g
    for x in A[2:]:
        lcm = (lcm * x) // gcd(lcm,x)
    print(sum((lcm//x) for x in A)%1000000007)
### BUGGY CODE ###

H, W, A, B = map(int, input().split())
MOD = 10 ** 9 + 7


# modしながらコンビネーションを求める
def mod_cmb(n, r, mod):
    p, q = 1, 1
    for i in range(r):
        p = p * (n - i) % mod
        q = q * (i + 1) % mod
    return p * mod_inverse(q, mod) % mod


# modしたa^bを求める
def mod_pow(a, p, mod):
    if p == 0:
        return 1
    elif p % 2 == 1:
        return a * mod_pow(a, p - 1, mod)
    else:
        return (mod_pow(a, p // 2, mod) % mod) ** 2 % mod


# aで割りたいときはa^(p-2)をかければよい（pは素数かつmodで使うやつ）
def mod_inverse(a, mod):
    return mod_pow(a, (mod - 2), mod)


n1 = B + H - A - 1
r1 = H - A - 1
n2 = W + A - B - 2
r2 = A - 1
temp = mod_cmb(n1, r1, MOD) * mod_cmb(n2, r2, MOD) % MOD
ans = temp
for _ in range(1, W - B):
    temp = temp * (n1 + 1) * mod_inverse(n1 + 1 - r1, MOD) * (n2 - r2) * mod_inverse(n2, MOD) % MOD
    n1 += 1
    n2 -= 1
    ans = (ans + temp) % MOD

print(ans)

### FIXED CODE ###

H, W, A, B = map(int, input().split())
MOD = 10 ** 9 + 7
limit = 2 * 10 ** 5


# modしながらコンビネーションを求める
def mod_cmb(n, r, mod):
    x = fact[n] * fact_inverse[r] % mod
    x = x * fact_inverse[n - r] % mod
    return x


def d_cmb(n, r, mod):
    return mod_cmb(n + r - 1, r, mod)


# modしたa^bを求める
def mod_pow(a, p, mod):
    if p == 0:
        return 1
    elif p % 2 == 1:
        return a * mod_pow(a, p - 1, mod)
    else:
        return (mod_pow(a, p // 2, mod) % mod) ** 2 % mod


fact = [1] * (limit + 1)
fact_inverse = [1] * (limit + 1)

for i in range(1, limit + 1):
    fact[i] = fact[i - 1] * i % MOD

fact_inverse[limit] = mod_pow(fact[limit], MOD - 2, MOD)
for i in reversed(range(1, limit + 1)):
    fact_inverse[i - 1] = fact_inverse[i] * i % MOD

n1 = W
r1 = H - A - 1
n2 = 1
r2 = A - 1
ans = 0
for i in range(W - B):
    ans += d_cmb(n1 - i, r1, MOD) * d_cmb(n2 + i, r2, MOD)
    ans %= MOD

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

import numpy as np

K = input()
D = int(input())
L = len(K)
mod = 10 ** 9 + 7

dp = np.array([[[0] * 2 for _ in range(D)] for _ in range(L+1)])
dp[0][0][0] = 1

for i in range(L):
    nd = int(K[i])
    for j in range(D):
        for k in range(2):
            #lim = 9 if k == 1 else nd
            for d in range(10):
                nk = k
                if k == 0:
                    if d > nd:
                        continue
                    if d < nd:
                        nk = 1
                dp[i+1][(j+d) % D][nk] += dp[i][j][k]
                dp[i+1][(j+d) % D][nk] %= mod

ans = (dp[L][0][0]+dp[L][0][1]-1+mod) % mod

#for i in range(L+1):
#    print(dp[i])
print(ans)


### FIXED CODE ###

K = input()
D = int(input())
L = len(K)
mod = 10 ** 9 + 7

dp = [[[0] * 2 for _ in range(D)] for _ in range(L+1)]
dp[0][0][0] = 1

for i in range(L):
    nd = int(K[i])
    for j in range(D):
        for k in range(2):
            #lim = 9 if k == 1 else nd
            for d in range(10):
                nk = k
                if k == 0:
                    if d > nd:
                        continue
                    if d < nd:
                        nk = 1
                dp[i+1][(j+d) % D][nk] += dp[i][j][k]
                dp[i+1][(j+d) % D][nk] %= mod

ans = (dp[L][0][0]+dp[L][0][1]-1+mod) % mod

#for i in range(L+1):
#    print(dp[i])
print(ans)
### BUGGY CODE ###

r,g,b,n = list(map(int,input().split(" ")))
c = 0
rl = n//r + 1
bl = n//b + 1


for i in range(rl):
    for j in range(bl):
        if n-(i*r + b*j) >=0 and (n-(i*r + b*j)) % g == 0:
            c += 1
print(c)

### FIXED CODE ###

r,g,b,n = list(map(int,input().split(" ")))
c = 0
rl = n//r + 1
bl = n//b + 1


for i in range(rl):
    for j in range(bl):
        if n-(i*r + b*j) >=0 and (n-(i*r + b*j)) % g == 0:
            c += 1
print(c)
### BUGGY CODE ###

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

# N = 5*10**3
# S = "".join(["t" for n in range(N)])

dp = [{} for i in range(N+1)]

mx = 0

for i in range(N):
#   print(dp)
  for j in range(N):
    if i<j and S[i] == S[j]:
      dp[i+1][j+1] = 1

  for k in dp[i]:
    c_before = dp[i][k]
    if k<N and i+c_before<k and S[k]==S[i]:
      dp[i+1][k+1] = c_before+1
      mx = max(mx,c_before+1)

# print(dp)
print(mx)



### FIXED CODE ###

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

# N = 5*10**3
# S = "".join(["t" for n in range(N)])

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

mx = 0

for i in range(N):
#   print(dp)
  for k in range(N):
    if i<k and S[i] == S[k]:
      dp[i+1][k+1] = 1
    c_before = dp[i][k]
    if k<N and i+c_before<k and S[k]==S[i]:
      dp[i+1][k+1] = c_before+1
      mx = max(mx,c_before+1)

# print(dp)
print(mx)
### BUGGY CODE ###

import sys

input = sys.stdin.readline

def f(n):
    uvw = [list(map(int, input().split())) for _ in range(n - 1)]
    ans = [-1] * (n + 1)
    ans[uvw[0][0]] = True
    while uvw:
        nuvw = []
        for u, v, w in uvw:
            if ans[u] != -1:
                if w % 2:
                    ans[v] = not ans[u]
                else:
                    ans[v] = ans[u]
            elif ans[v] != -1:
                if w % 2:
                    ans[u] = not ans[v]
                else:
                    ans[u] = ans[v]
            else:
                nuvw.append([u, v, w])
        uvw = nuvw
    for x in ans[1:]:
        print(x * 1)

n = int(input())
f(n)


### FIXED CODE ###

n = int(input())
pea = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    w %= 2
    pea[u].append([v, w])
    pea[v].append([u, w])
ans = [-1] * (n + 1)
ans[1]=1
nodes=[1]
used=set()
used.add(1)
ansi=1
while nodes:
    nn=[]
    for i in nodes:
        ansi=ans[i]
        for u,w in pea[i]:
            if u in used:continue
            ans[u]=(ansi+w)%2
            used.add(u)
            nn+=[u]
    nodes=nn
for x in ans[1:]:
    print(x)
### BUGGY CODE ###

N = int(input())
X = str(input())
count = X.count("1")
num, nump, numm = 0, 0, 0
now, nowp, nowm = 1, 1, 1

if count == 0:
  for i in range(N):
    print("1")
    quit()
elif count == 1:
  while True:
    a = 1
  if X[-1] == "1":
    for i in range(N):
      if i != N - 1:
        print("2")
      else:
        print("1")
  else:
    for i in range(N):
      print("1")
  quit()
  

xx = [0] * N
x_plus = [0] * N
x_minus = [0] * N
for i in range(1, N + 1):
  if i != 1:
    now *= 2
    nowp *= 2
    
    now %= count
    nowp %= (count + 1)
    

    nowm *= 2
    nowm %= (count - 1)
  
  else:
    now %= count
    nowp %= (count + 1)
    nowm %= (count - 1) 
  xx[i - 1] = now
  x_plus[i - 1] = nowp
  x_minus[i - 1] = nowm
  if X[-i] == "1":
    num += now
    num %= count
    nump += nowp
    nump %= count + 1
    numm += nowm
    numm %= count - 1
    
#print(num, xx, x_plus, x_minus)    

nextn = [0] * N
#ans = [1] * N
for i in range(N):
    if X[i] == "0":
      a = nump + x_plus[N - 1 - i]
      b = count + 1
      #print(a, b)
      nextn[i] = a % b
    else:
      #if count == 2:
      #  nextn[i] = 0
      #else:
        a = numm - x_minus[N - 1 - i]
        b = count - 1
        nextn[i] = a % b
        
#print(nextn)    
for i in range(N):
  if nextn[i] == 0:
    print("1")
  else:
    nownow = nextn[i]
    ans = 1
    while nownow != 0:
      alpha = bin(nownow)[2:]
      beta = str(alpha).count("1")
      nownow %= beta
      ans += 1
    print(ans)







### FIXED CODE ###

N = int(input())
X = str(input())
count = X.count("1")
num, nump, numm = 0, 0, 0
now, nowp, nowm = 1, 1, 1

if count == 0:
  for i in range(N):
    print(1)
    quit()
elif count == 1:
  if X[-1] == "1":
    for i in range(N):
      if i != N - 1:
        print(2)
      else:
        print(0)
  else:
    for i in range(N):
      if i!= N - 1:
        if X[i] == "1":
          print(0)
        else:
          print(1)
      else:
        print(2)
  quit()
  

xx = [0] * N
x_plus = [0] * N
x_minus = [0] * N
for i in range(1, N + 1):
  if i != 1:
    now *= 2
    nowp *= 2
    
    now %= count
    nowp %= (count + 1)
    

    nowm *= 2
    nowm %= (count - 1)
  
  else:
    now %= count
    nowp %= (count + 1)
    nowm %= (count - 1) 
  xx[i - 1] = now
  x_plus[i - 1] = nowp
  x_minus[i - 1] = nowm
  if X[-i] == "1":
    num += now
    num %= count
    nump += nowp
    nump %= count + 1
    numm += nowm
    numm %= count - 1
    
#print(num, xx, x_plus, x_minus)    

nextn = [0] * N
#ans = [1] * N
for i in range(N):
    if X[i] == "0":
      a = nump + x_plus[N - 1 - i]
      b = count + 1
      #print(a, b)
      nextn[i] = a % b
    else:
      #if count == 2:
      #  nextn[i] = 0
      #else:
        a = numm - x_minus[N - 1 - i]
        b = count - 1
        nextn[i] = a % b
        
#print(nextn)    
for i in range(N):
  if nextn[i] == 0:
    print("1")
  else:
    nownow = nextn[i]
    ans = 1
    while nownow != 0:
      alpha = bin(nownow)[2:]
      beta = str(alpha).count("1")
      nownow %= beta
      ans += 1
    print(ans)
### BUGGY CODE ###

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

cad_sum = 0
for i in range(n-k+1):
    cad_p_list = p_list[i:i+k]
    cad_sum_child_list = []
    for cad_p in cad_p_list:
        cad_sum_child = (cad_p+1)/2
        cad_sum_child_list.append(cad_sum_child)

    cad_sum_child = sum(cad_sum_child_list)
    if  cad_sum_child > cad_sum:
        cad_sum = cad_sum_child

print(cad_sum)

### FIXED CODE ###

n, k = map(int, input().split())
p_list = list(map(lambda x: (float(x) + 1) / 2, input().split()))

S_i = [0]
for i in range(n):
    S_i.append(S_i[i] + p_list[i])    

# print(S_i)
result_max = 0
for j in range(k, n+1):
    cad_max = S_i[j] - S_i[j-k]
    result_max = max(cad_max, result_max)

print(result_max)
### BUGGY CODE ###

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

import itertools

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

p = list(itertools.product(range(1,N+1), repeat=3))

ans = 0
for pair in p:
    if (pair[0] + pair[1]) % K == 0 and (pair[1] + pair[2]) % K == 0 and (pair[2] + pair[0]) % K == 0:
        ans += 1

print(ans)

### FIXED CODE ###

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

# mod Kをうまく使ってaを全検索

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

num = [0] * K
# 元のNまでの数がmod Kの世界で何になるかを集計
for i in range(1,N+1):
    num[i%K] += 1

ans = 0
# a mod Kを決め打ちしてb mod Kとc mod Kを出す
for a in range(K):
    b = (K - a) % K
    c = (K - a) % K
    # つじつまが合ってるか確認
    if (b + c) % K == 0:
        # 予め集計してあるmod Kでの数を合計させる
        ans += num[a] * num[b] * num[c]
print(ans)
### BUGGY CODE ###

n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
keep=1
count=0
lis=[]
for i in range(n):
  count+=1
  if keep in lis:
    print(-1)
    break
  lis.append(keep)
  keep=a[keep-1]
  if keep==2:
    print(count)
    break

### FIXED CODE ###

n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
keep=1
count=0
ababa=0
for i in range(n):
  count+=1
  keep=a[keep-1]
  if keep==2:
    ababa=1
    print(count)
    break
if ababa==0:
  print(-1)
### BUGGY CODE ###

def m():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ans = []

    for a in A:
        if a in ans:
            ans.remove(a)
        else:
            ans.append(a)
    return len(ans)

print(m())


### FIXED CODE ###

def m():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    A.sort()
    tmp = -1
    cnt = 0
    ans = 0
    for i in range(N):
        if tmp == A[i]:
            cnt +=1
        else:
            if cnt % 2 == 0: pass
            else: ans +=1
            tmp = A[i]
            cnt = 1

    if cnt % 2 == 0: pass
    else: ans += 1
    return ans

print(m())
### BUGGY CODE ###

N, M, Q = map(int, input().split())
trains = []
for _ in range(M):
    L, R = map(int, input().split())
    trains.append((L, R))

mem = []
for right in range(1, N+1):
    total_contains = set()
    total_overlaps = set()

    for i, (trainL, trainR) in enumerate(trains):
        if trainR <= right:
            total_contains.add(i)

        if trainL < right:
            total_overlaps.add(i)

    mem.append((total_contains, total_overlaps))

res = []
for _ in range(Q):
    QL, QR = map(int, input().split())
    res.append((mem[QR-1][0], mem[QL-1][1]))

for r in res:
    result = len(r[0]) - len(r[0]&r[1])
    print(result)

### FIXED CODE ###

N, M, Q = map(int, input().split())
mem = [[0 for _ in range(N)] for _ in range(N)]

for _ in range(M):
    L, R = map(int, input().split())
    mem[L-1][R-1] += 1

for L in range(N):
    for R in range(1, N):
        mem[L][R] += mem[L][R-1]

for R in range(N):
    for L in range(1, N):
        mem[L][R] += mem[L-1][R]

res = []
for _ in range(Q):
    QL, QR = map(int, input().split())
    if QL == 1:
        r = mem[QR-1][QR-1]
    else:
        r = mem[QR-1][QR-1] - mem[QL-2][QR-1]
    res.append(r)

for r in res:
    print(r)
### BUGGY CODE ###

N, K = map(int,input().split())
pn = list(map(int,input().split()))
num = 0
for i in range(N-K+1): num = max(num,sum(pn[i:i+K]))
print(0.5*K + num*0.5)

### FIXED CODE ###

N, K = map(int,input().split())
pn = list(map(int,input().split()))
num = [0]*(N-K+1)
num[0] = sum(pn[0:K])
for n in range(1,N-K+1):
  num[n] = num[n-1] - pn[n-1] + pn[n+K-1]
print(0.5*(K + max(num)))
### BUGGY CODE ###

def num_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return len(divisors)

N = int(input())

S = 0
for i in range(1,N+1):
    S += i * num_divisors(i)
print(S)

### FIXED CODE ###

# ABC172_D
N = int(input())
ans = 0

for i in range(1,N+1):
	ans += ((N//i)*(i+(N//i)*i))/2

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

#!/usr/bin/env python3
import sys

def conv2num(c):
    if c == "A":
        return 1
    elif c == "D":
        return 2
    elif c == "B":
        return 3
    else:
        return 4

def solve(s: str):

    res = 0

    s = s.replace("BC","D")
    s = [ conv2num(c) for c in s ]
    i = 0
    endi = len(s) - 1
    while i < endi:
        if s[i] == 1 and s[i+1] == 2:
            ai = i
            for j in range(i-1,-1,-1):
                if s[j] == 1 and j >=0 :
                    ai = j 
                else:
                    break
            s[ai]   = 2
            s[ai+1] = 1
            res += 1

            st = ai+2
            ed = i +2
            if st != ed:
                for k in range(st,ed):
                    s[k] = 1
                    res += 1
        i += 1

    print(res)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

def conv2num(c):
    if c == "A":
        return 1
    elif c == "D":
        return 2
    elif c == "B":
        return 3
    else:
        return 4

def solve(s: str):

    res = 0
    s = s.replace("BC","D")
    s = [ conv2num(c) for c in s ]

    acnt = 0
    for i,c in enumerate(s):
        if c == 1:
            acnt += 1
        elif c == 2:
            res += acnt
        else:
            acnt = 0


    print(res)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

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

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

N=int(raw_input())

a_num = 0
b_num = 0

for i in xrange(N):
        ratio_a, ratio_b = map(int,raw_input().split())

        # 初期化
        if a_num == 0 or b_num == 0:
                a_num = ratio_a
                b_num = ratio_b
                continue

        # a:b = c:d
        # a/b == c/d などと分数で比較してしまうと0近似で値がなくなってしまうおそれがあるので
        # ad == bc の掛け算で検討する

        while ratio_a * b_num != ratio_b * a_num:
                if ratio_a * b_num < ratio_b * a_num:
                        b_num += 1
                if ratio_a * b_num > ratio_b * a_num:
                        a_num += 1

print a_num + b_num

### FIXED CODE ###

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

N=int(raw_input())

a_num = 1
b_num = 1

for i in xrange(N):
        ratio_a, ratio_b = map(int,raw_input().split())

        base_n = max( (a_num - 1) // ratio_a + 1 , (b_num - 1 ) // ratio_b + 1)

        a_num = ratio_a * base_n
        b_num = ratio_b * base_n

print int(a_num + b_num)
### BUGGY CODE ###

import bisect

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

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

ans = 10**20
for i in range(2, N-1):
    m = bisect.bisect(S[:i], S[:i][-1]//2)

    if m == 0:
        L = [S[:i][0], S[:i][-1]-S[:i][0]]
    else:
        L = [S[:i][m], S[:i][-1]-S[:i][m]]
        L2 = [S[:i][m-1], S[:i][-1]-S[:i][m-1]]

        if(abs(L[0]-L[1]) > abs(L2[0]-L2[1])): L = L2

    m = bisect.bisect(S[i:], (S[i:][-1]+S[:i][-1])//2)
    if m == 0:
        R = [S[i:][0]-S[:i][-1], S[i:][-1]-S[i:][0]]
    else:
        R = [S[i:][m]-S[:i][-1], S[i:][-1]-S[i:][m]]
        R2 = [S[i:][m-1]-S[:i][-1], S[i:][-1]-S[i:][m-1]]

        if(abs(R[0]-R[1]) > abs(R2[0]-R2[1])): R = R2

    #print(L, end="")
    #print(R)

    ans = min(ans, max(L[0],L[1],R[0],R[1]) - min(L[0],L[1],R[0],R[1]))

print(ans)



### FIXED CODE ###

import bisect

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

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

ans = 1e18
for i in range(2, N-1):
    # 左側 [0,i)
    left_sum = S[i-1]
    m = bisect.bisect(S, left_sum/2)

    L = [S[m], left_sum-S[m]]

    if m != 0:
        L2 = [S[m-1], left_sum - S[m-1]]
        if(abs(L[0]-L[1]) > abs(L2[0]-L2[1])): L = L2

    # 右側 [i,N)
    m = bisect.bisect(S, (S[-1]+left_sum)/2)
    R = [S[m]-left_sum, S[-1]-S[m]]

    if m != i:
        R2 = [S[m-1]-left_sum, S[-1]-S[m-1]]
        if(abs(R[0]-R[1]) > abs(R2[0]-R2[1])): R = R2


    ans = min(ans, max(L[0],L[1],R[0],R[1]) - min(L[0],L[1],R[0],R[1]))

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

N,K = (int(T) for T in input().split())
Next = [int(T)-1 for T in input().split()]
GetP = [int(T) for T in input().split()]
DispP = [0]*N
for TN in range(0,N):
    Now   = Next[TN]
    Point = GetP[Now]
    MAXP  = Point
    RoopC = 1
    RoopFlag = False
    for TK in range(1,K):
        Now = Next[Now]
        Point += GetP[Now]
        RoopC += 1
        if Now==TN and Point>=0:
            RoopFlag = True
            break
        elif Now==TN and Point<0:
            RoopFlag = False
            break
        if MAXP<Point:
            MAXP = Point
    if RoopFlag:
        Omit = K-RoopC*((K//RoopC)-1)
        Point *= (K//RoopC)-1
        MAXP = Point
        for TO in range(0,Omit):
            Now = Next[Now]
            Point += GetP[Now]
            if MAXP<Point:
                MAXP = Point
    DispP[TN] = MAXP
print(max(DispP))

### FIXED CODE ###

N,K = (int(T) for T in input().split())
Next = [int(T)-1 for T in input().split()]
GetP = [int(T) for T in input().split()]
DispP = [0]*N
for TN in range(0,N):
    Now   = Next[TN]
    Point = GetP[Now]
    MAXP  = Point
    RoopC = 1
    RoopFlag = False
    for TK in range(1,K):
        Now = Next[Now]
        Point += GetP[Now]
        RoopC += 1
        if Now==TN and Point>=0:
            RoopFlag = True
            break
        elif Now==TN and Point<0:
            RoopFlag = False
            break
        if MAXP<Point:
            MAXP = Point
            MInd = TK
    if RoopFlag:
        Omit = K-RoopC*(K//RoopC)
        PointO = 0
        MAXO = 0
        for TO in range(0,Omit):
            Now = Next[Now]
            PointO += GetP[Now]
            if MAXO<PointO:
                MAXO = PointO
        if Point*(K//RoopC)+MAXO>=Point*((K//RoopC)-1)+MAXP:
            DispP[TN] = Point*(K//RoopC)+MAXO
        else:
            DispP[TN] = Point*((K//RoopC)-1)+MAXP
    else:
        DispP[TN] = MAXP
print(max(DispP))
### BUGGY CODE ###

n = int(input())
anagrams = [sorted(input()) for i in range(n)]
cnt=0
for i in range(n):
    for j in range(i+1, n):
        if anagrams[i] == anagrams[j]:
            cnt+=1
print(cnt)

### FIXED CODE ###

n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]
from collections import defaultdict
d = defaultdict(list)
for i in range(n):
    d[anagrams[i]].append(i)
from scipy.misc import comb
cnt=0
for k, v in d.items():
    cnt+=comb(len(v), 2, exact=True)
print(cnt)
### BUGGY CODE ###

def main():
    a=input()
    b=input().split(" ")
    sum1=1
    for i in range(int(a)):
	    sum1=sum1*int(b[i])
    if sum1>1000000000000000000:
	    print("-1")
    else:
	    print(sum1)




main()	


### FIXED CODE ###

a=int(input())
b=input().split(" ")
sum1=1

if "0" in b:
	print("0")
else:
	for i in range(a):
		sum1=sum1*int(b[i])
		if sum1>10**18:
			sum1=-1
			break
	print(sum1)