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

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
A = LIST()

a = [1]
r = -1
loc = 1


for i in range(N):
	loc = A[loc-1]
	#print(loc)
	if not loc in a:
		a.append(loc)
		#print(a)
	else:
		r = i+1
		loop_start = loc
		break

#print(a)
#print(r)
#print(loop_start)

for i in range(N):
	if a[i] == loop_start:
		l = i
		break

first = a[:l]
loop = a[l:]

#print(l, r)
#print(first)
#print(loop)


K += 1

if K <= len(first):
	print(a[K-1])
else:
	K -= len(first)
	K %= len(loop)
	print(loop[K-1])


### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
A = LIST()

a = [1]
r = -1
loc = 1
b = [0]*(N+1)
b[1] = 1


for i in range(N):
	loc = A[loc-1]
	#print(loc)
	if b[loc] == 0:
		a.append(loc)
		b[loc] = 1
		#print(a)
	else:
		r = i+1
		loop_start = loc
		break

#print(a)
#print(r)
#print(loop_start)

for i in range(N):
	if a[i] == loop_start:
		l = i
		break

first = a[:l]
loop = a[l:]

#print(l, r)
#print(first)
#print(loop)


K += 1

if K <= len(first):
	print(a[K-1])
else:
	K -= len(first)
	K %= len(loop)
	print(loop[K-1])
### BUGGY CODE ###

import sys
f = sys.stdin

def mix(a,b):
    return (min(a[0],b[0]),min(a[1],b[1]),max(a[2],b[2]),max(a[3],b[3]))

s = {}

n, d = map(int, f.readline().split())
for _ in range(n):
    x, y, b = map(int, f.readline().split())
    s[b] = mix(s[b],(x,y,x,y)) if b in s else (x,y,x,y)

max_size = 0
b = sorted(s.keys())
i = j = 0
while j < len(b) - 1:
    for k in range(j,-1,-1):
        if b[k] + d < b[j]:
            break
        i = k
    for k in range(i,len(b)):
        if b[i] + d < b[k]:
            break
        j = k
    
    xy = s[b[i]]
    for k in range(i + 1, j + 1):
        xy = mix(xy,s[b[k]])
    
    max_size = max(max_size,((xy[2] - xy[0]) * (xy[3] - xy[1])))
    j+=1
    
print(max_size)

### FIXED CODE ###

import math
def segmentTree(dat, f, sentinel):
        pad = 2 ** math.ceil(math.log(len(dat),2))
        dat = [0] * pad + dat + [sentinel] * (pad - len(dat))
        for i in range(pad - 1, 0, -1):
            dat[i] = f(dat[i * 2],dat[i * 2 + 1])
        return dat

def get_lr(b,d):
    l = r = 0
    while r < len(b):
        while b[l] + d < b[r]:
            l += 1
        for r in range(r,len(b)):
            if b[l] + d < b[r]:
                r -= 1
                break
        r += 1
        yield l,r
        l += 1
    
import sys
f = sys.stdin

_, d = map(int, f.readline().split())

xyb = []
for line in f:
    xyb.append(tuple(map(int, line.split())))
from operator import itemgetter
xyb.sort(key=itemgetter(2))

x = [xybi[0] for xybi in xyb]
y = [xybi[1] for xybi in xyb]
b = [xybi[2] for xybi in xyb]

xmax = segmentTree(x,max,sentinel = 0)
xmin = segmentTree(x,min,sentinel = 2000000)
ymax = segmentTree(y,max,sentinel = 0)
ymin = segmentTree(y,min,sentinel = 2000000)


pad = len(xmax) // 2
max_size = 0
def create_index(l,r):
    index = []
    ia = index.append
    while l < r:
        if r & 1:
            r -= 1
            ia(r)
        if l & 1:
            ia(l)
            l += 1
        l >>= 1
        r >>= 1
    return index

for l,r in get_lr(b,d):
    l += pad 
    r += pad
    index = create_index(l,r)

    now_xmax = max(xmax[i] for i in index)
    now_ymax = max(ymax[i] for i in index)
    if max_size < now_xmax * now_ymax:
        max_size = max(max_size,((now_xmax - min(xmin[i] for i in index)) * (now_ymax - min(ymin[i] for i in index))))
print(max_size)
### BUGGY CODE ###

class DLL:
    class Node:
        def __init__(self, x, y, z):
            self.v = x
            self.prv = y
            self.nxt = z

    def __init__(self):
        init = DLL.Node(None, None, None)
        init.prv = init
        init.nxt = init
        self.size = 0
        self.init = init

    def insert(self, x):
        i = self.init
        j = i.nxt
        k = DLL.Node(x, i, j)
        i.nxt = k
        j.prv = k
        self.size += 1

    def deleteFirst(self):
        if self.size > 1:
            i = self.init
            k = i.nxt
            j = k.nxt
            i.nxt = j
            j.prv = i
        else:
            i = self.init
            i.nxt = i
            i.prv = i

        self.size -= 1

    def deleteLast(self):
        if self.size > 1:
            i = self.init
            k = i.prv
            j = k.prv
            i.prv = j
            j.nxt = i
        else:
            i = self.init
            i.nxt = i
            i.prv = i

        self.size -= 1

    def delete(self, x):
        if self.size > 1:
            i = self.init
            k = i.nxt
            while 1:
                if k.v == x:
                    """
                    i = k.prv
                    j = k.nxt
                    i.nxt = j
                    j.prv = i
                    """
                    k.prv.nxt = k.nxt
                    k.nxt.prv = k.prv
                    self.size -= 1
                    break
                else:
                    if k.nxt == i:
                        break
                    else:
                        k = k.nxt
        else:
            i = self.init
            i.nxt = i
            i.prv = i

    def prt(self):
        f = self.init
        s = f.nxt
        l = f.prv
        while 1:
            if s != l:
                print(s.v, end=' ')
                s = s.nxt
            else:
                print(l.v)
                break

n = int(input())
L = DLL()

for i in range(n):
    com = input()
    if com == "deleteFirst":
        L.deleteFirst()
    elif com == "deleteLast":
        L.deleteLast()
    else:
        C = com.split()
        if C[0] == "insert":
            L.insert(int(C[1]))
        elif C[0] == "delete":
            L.delete(int(C[1]))
    #L.prt()
    
L.prt()



### FIXED CODE ###

from collections import deque

n = int(input())
L = deque()

for i in range(n):
    com = input()
    if com[0] == 'i':
        C = com.split()
        L.appendleft(int(C[1]))
    else:
        if com[6] == 'F':
            L.popleft()
        elif com[6] == 'L':
            L.pop()
        else:
            C = com.split()
            x = int(C[1])
            try:
                L.remove(x)
            except:
                pass

print(*L)
### BUGGY CODE ###

S = input()[::-1]

while len(S) > 0:
    if S[:5] == 'maerd':
        S = S[:5]
    elif S[:5] == 'esare':
        S = S[5:]
    elif S[:6] == 'resare':
        S = S[6:]
    elif S[:7] == 'remaerd':
        S = S[7:]
    else:
        print('NO')

if len(S) == 0:
    print('YES')


### FIXED CODE ###

s = input()
if s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","") == "":
    print("YES")
else:
    print("NO")
### BUGGY CODE ###

a, b = (int(_) for _ in input().split())  
res = 0
for x in range(a,-1,-1):
  if x + 2*a < b:
    break
  for y in range(a,-1,-1):
    if x + y + a < b:
      break
    for z in range(a,-1,-1):
      if x + y + z == b:
        res+=1

print(res)





### FIXED CODE ###

a, b = (int(i) for i in input().split())  
print(sum([min(2*a+i-b+1,b-i+1) for i in range(a+1) if min(2*a+i-b+1,b-i+1) > 0]))
### BUGGY CODE ###

n = int(input())
l = list(map(int,input().split()))
co = []
nl = sorted(l,reverse=True)
for i in range(1,n):
    for j in range(1,n):
        if i<j:
            co.append(nl[i]+nl[j])
sk = 0
g = 0
for i in range(n-1):
    a = nl[i]
    for j in co[sk:]:
        if a<j:
            g +=1
    sk += n-2-i
print(g)

### FIXED CODE ###

import bisect
n=int(input())
l=sorted(list(map(int,input().split())))
g=0
for ai in range(n-2):
    for bi in range(ai+1,n-1):
        g+=max(0,bisect.bisect_left(l,l[bi]+l[ai])-1-bi)
print(g)
### BUGGY CODE ###

n = int(input())
ta = [tuple(int(x) for x in input().split()) for _ in range(n)]

a = 0
b = 0
for x, y in ta:
    if x >= a and y >= b:
        a = x
        b = y
    else:
        temp = 2
        while x * temp < a or y * temp < b:
            temp += 1
        a = x * temp
        b = y * temp

print(a + b)


### FIXED CODE ###

n = int(input())
ta = [tuple(int(x) for x in input().split()) for _ in range(n)]

a = 0
b = 0
for x, y in ta:
    if x >= a and y >= b:
        a = x
        b = y
    else:
        temp = max(a // x, b // y)
        while x * temp < a or y * temp < b:
            temp += 1
        a = x * temp
        b = y * temp

print(a + b)
### BUGGY CODE ###

N=input()

lists = []
temp=[i for i in range(10)]

dic={0:1}

for i in N:
    new_dic={}
    if i == "?":
        for amari,count in list(dic.items()):
            amari*=10
            for num in temp:
                a = (amari + num) % 13
                if a in new_dic:
                    new_dic[a]+=count
                else:
                    new_dic[a]=count
    else:
        num=int(i)
        for amari,count in list(dic.items()):
            a = (amari*10 + num)%13
            if a in new_dic:
                new_dic[a]+=count
            else:
                new_dic[a]=count
    dic = new_dic

try:
    print(dic[5]%(10**9 + 7))
except:
    print(0)

### FIXED CODE ###


N=input()

lists = []
temp=[i for i in range(10)]

MOD=10**9+7

dic={0:1}

for i in N:
    new_dic={}
    hoge=list(dic.items())
    if i == "?":
        for amari,count in hoge:
            amari*=10
            for num in temp:
                a = (amari + num) % 13
                if a in new_dic:
                    new_dic[a]+=count
                else:
                    new_dic[a]=count
    else:
        num=int(i)
        for amari,count in hoge:
            a = (amari*10 + num)%13
            if a in new_dic:
                new_dic[a]+=count
            else:
                new_dic[a]=count
    for key in new_dic:
        new_dic[key] %= MOD
    dic = new_dic

try:
    print(dic[5])
except:
    print(0)
### BUGGY CODE ###

n = int(input())
a = [int(i) for i in input().split()]
for i in range(1, n+1):
    print(a.count(i))

### FIXED CODE ###

from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
cnt = Counter(a)
for i in range(1, n+1):
    print(cnt[i])
### BUGGY CODE ###

import itertools
from heapq import heapify, heappop, heappush, heappushpop

class PriorityQueue:
    def __init__(self, heap):
        '''
        heap ... list
        '''
        self.heap = heap
        heapify(self.heap)

    def push(self, item):
        heappush(self.heap, item)

    def pop(self):
        return heappop(self.heap)

    def pushpop(self, item):
        return heappushpop(self.heap, item)

    def __call__(self):
        return self.heap


heap = []  # ヒープといっても順序を工夫したただのリスト

q = PriorityQueue(heap) #ここでインスタンスを作ってます
n = int(input())
l = list(map(int, input().split()))
mod = 1000000007
for a,b in itertools.combinations(l, 2):
    q.push(((a % mod) * (b % mod)) % mod)
print(sum(heap) % mod)


### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
mod = 1000000007
q = sum(l)
ans = 0
for i in range(len(l)):
    q -= l[i]
    ans += l[i] * q % mod
print(ans % mod)
### BUGGY CODE ###

import bisect

s = list(input())
t = list(input())

# 辞書を作る
dictionary = {}

tt = t[:]
ss = dict(zip(list(range(len(s * 2))), s * 2))

while len(tt):
    _t = tt.pop(0)
    if _t in dictionary:
        continue
    indexes = [k for k, v in ss.items() if v == _t]
    if not len(indexes) > 0:
        print(-1)
        exit(0)
    for i in indexes:
        del ss[i]
    dictionary[_t] = indexes

result = 0
before = 0
sLen = len(s)
while len(t) > 0:
    _t = t.pop(0)
    next = dictionary[_t][bisect.bisect_left(dictionary[_t], before)] + 1
    result += next - before
    before = next
    if next >= sLen:
        before -= sLen

print(result)




### FIXED CODE ###

import bisect

s = list(input())
t = list(input())

# 辞書を作る
dictionary = {}

tt = t[:]
ss = dict(zip(list(range(len(s * 2))), s * 2))

for i in range(len(ss)):
    c = ss[i]
    if c not in dictionary:
        dictionary[c] = []
    dictionary[c].append(i)

result = 0
current_idx = 0
sLen = len(s)

for c in t:
    if c not in dictionary:
        print(-1)
        exit(0)
    indexes = dictionary[c]
    next = dictionary[c][bisect.bisect_left(indexes, current_idx)] + 1
    result += next - current_idx
    current_idx = next
    if next >= sLen:
        current_idx -= sLen

print(result)
### BUGGY CODE ###

N = int(input())
R = [int(input()) for _ in range(N)]

ret = R[1] - R[0]
for i in range(N - 1):
    tmp = max(R[i + 1:]) - R[i]
    if tmp > ret:
        ret = tmp
print(ret)

### FIXED CODE ###

N = int(input())
R = [int(input()) for _ in range(N)]

p_buy = R[0]
p_sale = R[1]
buy = R[1]
sale = None
for i in range(2, N):
    if p_sale < R[i]:
        p_sale = R[i]
    if buy > R[i]:
        if sale is None:
            sale = R[i]
        if p_sale - p_buy < sale - buy:
            p_sale, p_buy = sale, buy 
        sale, buy = None, R[i]
    else:
        if sale is None or sale < R[i]:
            sale = R[i]

p_gain = p_sale - p_buy
print(p_gain if sale is None else max(p_gain, sale - buy))
### BUGGY CODE ###

# coding: utf-8
# Your code here!
from functools import reduce
import collections
 
S = list(map(int,input().rstrip()))
N=len(S)
mod_list = [0]
for i in range(N):
    new = (mod_list[-1]+S[N-1-i]*10**i)%2019
    mod_list.append(new)
count = collections.Counter(mod_list)
#print(mod_list)
ans =0
for j in range(2019):
    n = count[j]
    ans+= n*(n-1)/2
print(int(ans))

### FIXED CODE ###

# coding: utf-8
# Your code here!
def main():
    from functools import reduce
    import collections
     
    S = list(map(int,input().rstrip()))
    N=len(S)
    mod_list = [0]
    for i in range(1,N+1):
        new1 =pow(10,i-1,2019)
        new = (new1*S[-i]+mod_list[-1])%2019
        #print(new)
        mod_list.append(new)
        
    count = collections.Counter(mod_list)
    ans =0
    for j in range(2019):
        n = count[j]
        ans+= n*(n-1)/2
    print(int(ans))
if __name__ == "__main__":
    main()
### BUGGY CODE ###


n = int(input())
s = str(input())

r = {}
b = {}
g = {}
for i in range(len(s)):
    if s[i] == 'R':
        r[i] = s[i]
    elif s[i] == 'B':
        b[i] = s[i]
    else:
        g[i] = s[i]

ans = len(r) * len(b) * len(g)

for i in r.keys():
    for j in b.keys():
        for k in g.keys():
            if abs(k -j) == abs(j -i) or abs(k-i) == abs(i-j) or abs(k-j) == abs(k-i) :
                ans -= 1


print(ans)

### FIXED CODE ###

import itertools
n = int(input())
s = str(input())
r = {}
b = {}
g = {}
for i in range(len(s)):
    if s[i] == 'R':
        r[i+1] = s[i]
    elif s[i] == 'B':
        b[i+1] = s[i]
    else:
        g[i+1] = s[i]
ans = len(r) * len(b) * len(g)
for i in r.keys():
    for j in b.keys():
        diff = abs(j-i)
        minb = min(i,j)-diff
        maxb = max(i,j)+diff
        if maxb in g.keys():
            ans -= 1
        if minb in g.keys():
            ans -= 1
        if((i+j)%2==0):
            if((i+j)//2 in g.keys()):
                ans -=1
print(ans)
### BUGGY CODE ###

from heapq import heappush, heappop, heappushpop
N = int(input())
*A, = map(int, input().split())

def update(v, que):
    p, q = que
    if v == p or v == q:
        return
    heappushpop(que, v)

memo = [None]*(2**N)
memo[0] = [(0, -1), (A[0], 0)]
ma = 0; ans = []
for i in range(1, 2**N):
    res = [(0, -1), (A[i], i)]
    for j in range(N):
        if (i >> j) & 1 == 0:
            continue
        p, q = memo[i ^ (1 << j)]
        update(p, res)
        update(q, res)
    p, q = memo[i] = res
    ma = max(ma, p[0] + q[0])
    ans.append(ma)
print(*ans, sep='\n')


### FIXED CODE ###

from heapq import heappush, heappop, heappushpop
N = int(input())
*A, = map(int, input().split())

def update(v, que):
    p, q = que
    if v == p or v == q:
        return
    heappushpop(que, v)

memo = [None]*(2**N)
memo[0] = [(0, -1), (A[0], 0)]
ma = 0; ans = []
for i in range(1, 2**N):
    res = [(0, -1), (A[i], i)]
    for j in range(N):
        if (i >> j) & 1 == 0:
            continue
        p, q = memo[i ^ (1 << j)]
        update(p, res)
        update(q, res)
    p, q = memo[i] = res
    ma = max(ma, p[0] + q[0])
    ans.append(ma)
print(*ans, sep='\n')
### BUGGY CODE ###

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

def solve(L):
    cnt = 0
    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            b = L[j]
            for k in range(j+1, N):
                cnt += a+b > L[k]
    return cnt
print(solve(L))

### FIXED CODE ###

from numba import njit
N = int(input())
L = list(map(int, input().split()))
L.sort()

@njit
def solve(L):
    cnt = 0
    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            b = L[j]
            for k in range(j+1, N):
                cnt += a+b > L[k]
    return cnt
print(solve(L))
### BUGGY CODE ###

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

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
a=1
if 0 in A:
	a=0
else:
	for i in A:
		a *= i
		if a > 10**18:
			a = -1
			break
print(a)
### BUGGY CODE ###

A, B = map(int, input().split())
l = max(len(bin(A)), len(bin(B)))
ans = A
for i in range(A+1, B+1):
    ans = i ^ ans
print(ans)

### FIXED CODE ###

def F(N):
    if ((N+1) // 2) % 2 == 0:
        bit = 0
    else:
        bit = 1
    if N % 2 == 0:
        return bit ^ N
    else:
        return bit

A, B = map(int, input().split())
ans = F(A-1) ^ F(B)
print(ans)
### BUGGY CODE ###

s = list(input())
q = int(input())

def rev(sts):
    for i in range(len(sts)//2):
        sts[i],sts[-i-1] = sts[-i-1],sts[i]


for i in range(q):
    ins = input().split()
    if(ins[0] == "1"):
        rev(s)
    else:
        if (ins[1] == "1"):
            s.insert(0, ins[2])
        else:
            s.append(ins[2])

for j in s:
    print(j, end="")
print()


### FIXED CODE ###

s = list(input())
q = int(input())

revs = 0
front = []
rear = []

for i in range(q):
    ins = input().split()
    if(ins[0] == "1"):
        revs += 1
    else:
        if (ins[1] == "1" and revs%2 == 0 or ins[1] =="2" and revs%2 == 1):
            front.extend(ins[2])
        else:
            rear.extend(ins[2])

if (revs % 2 == 0):
    for j in reversed(front):
        print(j, end="")
    for j in s:
        print(j, end="")
    for j in rear:
        print(j, end="")
else:
    for j in reversed(rear):
        print(j, end="")
    for j in reversed(s):
        print(j, end="")
    for j in front:
        print(j, end="")
print()
### BUGGY CODE ###

N,M = map(int,input().split())
one_to = []
to_N = []
for _ in range(M):
    a,b = map(int,input().split())
    if a == 1:
        one_to.append(b)
    if b == N:
        to_N.append(a)
ans = 0 
for i in one_to:
    if i in to_N:
        ans = 1
        break
if ans == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

### FIXED CODE ###

N,M = map(int,input().split())
ans = 0
dic = {str(i):0 for i in range(1,N)}
for _ in range(M):
    a,b = map(int,input().split())
    if a == 1:
        dic[str(b)] += 1
        if dic[str(b)] == 2:
            ans = 1
    if b == N:
        dic[str(a)] += 1
        if dic[str(a)] == 2:
            ans = 1
if ans == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')
### BUGGY CODE ###

n,s = map(int, input().split())
cnt = 0
for i in range(n+1):
    for j in range(n+1):
        for k in range(n+1):
            if s == i + j + k:
                cnt+=1
print(cnt)

### FIXED CODE ###

k,s = map(int, input().split())
cnt = 0
for i in range(k+1):
    for j in range(k+1):
        z = s - i - j
        if z >= 0 and z <= k:
            cnt+=1
print(cnt)
### BUGGY CODE ###

from collections import deque

N,K=map(int,input().split())
if N==1:print(K)
else:
  G=[[] for i in range(N+1)]
  #deg=[0]*(N+1)
  mod=10**9+7

  for i in range(N-1):
    a,b=map(int,input().split())
    G[a].append(b)
    G[b].append(a)
    #deg[a]+=1
    #deg[b]+=1

  #deg2 = sorted(enumerate(deg),key=lambda x:x[1])
  for i in range(1,N+1):
    if len(G[i])==1:break
  first = i
  #first = deg2[1][0]
  second = G[first][0]
  color = [1]*(N+1)
  color[first],color[second]=K,K-1

  def bfs(s):
      todo = deque([])
      todo.append(s)
      while 1:
        if len(todo)==0:break
        a = todo.popleft()
        if a != first: 
          acolor=K-1
        for b in G[a]:
          if G[b]==a:continue
          todo.append(b)
          if b != second:
            acolor -= 1
            color[b] = acolor

  bfs(first)
  total=1
  for i in range(1,N+1):
    total *= color[i]
  total %= mod
  print(total)

### FIXED CODE ###

from collections import deque

N,K=map(int,input().split())
mod = 10**9+7
G=[[] for _ in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)

def bfs(s):
    seen = [0]*N
    prev = [0]*N
    color = [0]*N
    todo = deque()
    seen[s]=1
    todo.append(s)
    color[s]=K
    while todo:
      a = todo.popleft()
      if a == start: count = K-1
      else: count = K-2
      for b in G[a]:
        if seen[b] == 0:
          seen[b] = 1
          todo.append(b)
          prev[b] = a
          color[b] = count %mod
          count -= 1
    return color
  
MAX,start = 0,-1
for i in range(N):
  if len(G[i])>MAX:
    MAX=len(G[i])
    start = i
    
color = bfs(start)
ans = 1
for i in range(N):
  ans *= color[i]
  ans %= mod
  
print(ans)
### BUGGY CODE ###

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

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

for i in range(1,N):
  dp[N-1-i]=dp[N-i]+abs(h[N-i-1]-h[N-i])
  for j in range(2,min(K+1,i+1)):
    dp[N-i-1]=min(dp[N-i-1+j]+abs(h[N-i-1]-h[N-1-i+j]),dp[N-i-1])
print(dp[0]) 

### FIXED CODE ###

import numpy as np
import sys
input = sys.stdin.readline
[N,K]=[int(x) for x in input().split()]
h=[int(x) for x in input().split()]
h=np.array(h)
dp=np.zeros(N,dtype=int)
 
for i in range(1,N):
  last=min(K,i)+N-i
  dp[N-i-1]=min(dp[N-i:last]+np.abs(h[N-i:last]-h[N-i-1]))
print(dp[0])
### BUGGY CODE ###

k = int(input())
ans = 1
num = 0
if not k%2:
    print(-1)
else:
    while True:
        num = num*10%k + 7%k
        if num%k == 0:
            print(ans)
            break
        ans += 1

### FIXED CODE ###

k = int(input())
num = 0
if not k%2:
    print(-1)
else:
    for i in range(k):
        num = (num*10+7)%k
        if num == 0:
            print(i+1)
            break
    else:
        print(-1)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
if 0 in a:
	ans = 0
else:
	for i in a:
		ans *= i
if(ans>10**18):
	print(-1)
else:
	print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
if 0 in a:
	ans = 0
else:
	for i in range(n-1,-1,-1):
		ans *= a[i]
		if(ans>10**18):
			break
if(ans>10**18):
	print(-1)
else:
	print(ans)