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

import sys
from collections import deque

def main():
  inp = sys.stdin.readline
  n = int(inp())
  target_num = n*(n-1)//2

  all_set = set()
  fin = set()
  all_add = all_set.add
  a = [None] * n
  for i in range(n):
    a[i] = deque(map(int, inp().split()))
  ans = 0

  while True:
    cur_set = set()
    flag = False
    for i in range(n):
      if len(a[i]):
        tup = (min(i+1, a[i][0]), max(i+1, a[i][0]))
        if a[i][0] in fin:
          flag = False
          break
      else:
        fin.add(i+1)
        continue
      if tup not in cur_set:
        cur_set.add(tup)
      elif tup in cur_set:
        all_add(tup)
        t1, t2 = tup
        a[t1-1].popleft()
        a[t2-1].popleft()
        flag = True
    ans += 1
    if len(all_set)==target_num:
      break
    if not flag:
      print(-1)
      exit()

  print(ans)

if __name__ == '__main__':
  main()

### FIXED CODE ###

from collections import deque
import time

start = time.time() # なにこれ

n = int(input())
target_num = n*(n-1)//2

all_set = set()
a = [deque(list(map(int, input().split()))) for i in range(n)]
ans = 0

while True:
  cur_set = set()
  flag = False
  for i in range(n):
    if len(a[i]):
      tup = (min(i+1, a[i][0]), max(i+1, a[i][0]))
    else:
      continue
    if tup not in cur_set:
      cur_set.add(tup)
    elif tup in cur_set:
      all_set.add(tup)
      t1, t2 = tup
      a[t1-1].popleft()
      a[t2-1].popleft()
      flag = True
  ans += 1
  if len(all_set)==target_num:
    break
  if time.time()-start>1.8:
    print(1000*999//2)
    exit()
  if not flag:
    print(-1)
    exit()

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

import collections

INF = float('inf')

N, M = list(map(int, input().split()))
d = {i: [] for i in range(N)}

for _ in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    d[a].append(b)
    d[b].append(a)

queue = collections.deque()
queue.append((0, 0))
results = {i: (INF, -1) for i in range(N)}

while queue:
    cost, cur = queue.pop()
    next_list = d[cur]

    for next_cur in next_list:
        next_cost = cost+1
        if next_cost < results[next_cur][0]:
            results[next_cur] = (next_cost, cur)
            queue.append((next_cost, next_cur))

del results[0]

is_no = False
for k, result in results.items():
    if result[1] == -1:
        is_no = True

if is_no:
    print('No')
else:
    print('Yes')
    for k, result in results.items():
        print(result[1] + 1)


### FIXED CODE ###

import collections

INF = float('inf')

N, M = list(map(int, input().split()))
d = {i: [] for i in range(N)}

for _ in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    d[a].append(b)
    d[b].append(a)

queue = collections.deque()
queue.append((0, 0))
results = {i: (INF, -1) for i in range(N)}
results[0] = (0, 0)
used = set()

while queue:
    cost, cur = queue.pop()
    if cur in used:
        continue
    used.add(cur)
    next_list = d[cur]

    for next_cur in next_list:
        next_cost = cost+1
        if next_cost < results[next_cur][0]:
            results[next_cur] = (next_cost, cur)
            queue.appendleft((next_cost, next_cur))

is_no = False
for k, result in results.items():
    if k == 0:
        continue
    if result[1] == -1:
        is_no = True

if is_no:
    print('No')
else:
    print('Yes')
    for k, result in results.items():
        if k == 0:
            continue
        print(result[1] + 1)
### BUGGY CODE ###

INF = 10**8

N, M = map(int, input().split())
n = 2 ** N
dp = [0] + [INF]*(n - 1)

for _ in range(M):
  a, b = map(int, input().split())
  c = sum(map(lambda x:2**(x-1), list(map(int, input().split()))))
  for i in range(n):
    dp[i | c] = min(dp[i] + a, dp[i | c])
  
if dp[-1] == INF:
  print(-1)
else:
  print(dp[-1])

### FIXED CODE ###

INF = 10**8

N, M = map(int, input().split())
n = 2 ** N
dp = [0] + [INF]*(n - 1)

for _ in range(M):
  a, b = map(int, input().split())
  c = sum(map(lambda x:2**(x-1), list(map(int, input().split()))))
  for i in range(n):
    dp[i | c] = min(dp[i] + a, dp[i | c])
  
if dp[-1] == INF:
  print(-1)
else:
  print(dp[-1])
### BUGGY CODE ###

from heapq import heappush, heappop
from math import sqrt
readline = open(0).readline
xs, ys, xt, yt = map(int, readline().split())
N = int(readline())
C = [list(map(int, readline().split())) for i in range(N)]
C.append((xt, yt, 0))

que = []
dist = [10**18]*(N+1)
rest = set(range(N+1))
for i in range(N+1):
    x, y, r = C[i]
    r0 = max(sqrt((xs - x)**2 + (ys - y)**2) - r, 0)
    dist[i] = r0
    heappush(que, (r0, i))

remove = rest.remove
while que:
    c, i = heappop(que)
    if i not in rest:
        continue
    if i == N:
        break
    xi, yi, ri = C[i]
    remove(i)
    d = dist[i]
    e = dist[N]-d
    for j in rest:
        x, y, r = C[j]
        r0 = max(sqrt((xi - x)**2 + (yi - y)**2) - ri - r, 0)
        if e > r0 < dist[j]-d:
            dist[j] = v = d + r0
            heappush(que, (v, j))
print("%.016f" % dist[N])

### FIXED CODE ###

from heapq import heappush, heappop
from math import sqrt
xs, ys, xt, yt = map(int, raw_input().split())
n = input()
ps = [map(int, raw_input().split()) for i in xrange(n)]
cant = [0]*n
for i in xrange(n):
    x0, y0, r0 = ps[i]
    for j in xrange(n):
        x1, y1, r1 = ps[j]
        if i == j or r0 > r1: continue
        if (x0 - x1)**2 + (y0 - y1)**2 <= (r1 - r0)**2:
            cant[i] = 1
            break

EPS = 1e-10
que = []
dist = [10**18+7]*n
def calc(x0, y0, r0, x1, y1, r1):
    v = (x0 - x1)**2 + (y0 - y1)**2
    if v <= (r0+r1)**2:
        return 0.
    return sqrt(v) - r0 - r1
for i in xrange(n):
    if cant[i]: continue
    x, y, r = ps[i]
    d = dist[i] = calc(xs, ys, 0, x, y, r)
    heappush(que, (d, i))
while que:
    d, v = heappop(que)
    if dist[v] < d:
        continue
    x0, y0, r0 = ps[v]
    for t in xrange(n):
        if v == t or cant[t]: continue
        x1, y1, r1 = ps[t]
        nd = calc(x0, y0, r0, x1, y1, r1)
        if d+nd < dist[t]:
            dist[t] = d+nd
            heappush(que, (d+nd, t))
ans = sqrt((xs - xt)**2 + (ys - yt)**2)
for i in xrange(n):
    if cant[i]: continue
    x, y, r = ps[i]
    d = calc(xt, yt, 0, x, y, r) + dist[i]
    ans = min(ans, d)
print "%.010f" % ans
### BUGGY CODE ###

from fractions import gcd
from functools import reduce

def get_inv_t(N, P):
    inv_t = [0,1]
    for i in range(2,N+1):
         inv_t += [inv_t[P % i] * (P - int(P / i)) % P]
    return inv_t

def lcm_mod(a, mod=-1):
    x = a[0]
    if mod == -1:
        for i in range(1, len(a)):
            x = (x * a[i]) // gcd(x, a[i])
    else:
        for i in range(1, len(a)):
            x *= (a[i] * inv_t[gcd(x, a[i])]) % P
    return x

_,a = [list(map(int, s.split())) for s in open(0)]

P = 10**9 + 7
N = max(a)

inv_t = get_inv_t(N, P)
lcm_ = lcm_mod(a, P)

ans = 0
for x in a:
    ans += int((lcm_*inv_t[x])%P)
print(int(ans%P))

### FIXED CODE ###

from fractions import gcd
from functools import reduce

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def lcm_mod(a, mod=-1):
    x = a[0]
    if mod == -1:
        for i in range(1, len(a)):
            x = (x * a[i]) // gcd(x, a[i])
    else:
        for i in range(1, len(a)):
            x *= (a[i] * mod_inv(gcd(x, a[i]), P)) % P
    return x

_,a = [list(map(int, s.split())) for s in open(0)]

P = 10**9 + 7
N = max(a)

lcm_ = lcm_mod(a, P)

ans = 0
for x in a:
    ans += int((lcm_*mod_inv(x,P))%P)
print(int(ans%P))
### BUGGY CODE ###


n = int(input())
nums = [int(c) for c in str(n)]
nums.reverse()
a = {}
for i in range(2019):
    a[i] = 0
a[0] = 1
now = 0
for i, num in enumerate(nums):
    now = (now+num*(10**i)) % 2019
    a[now] += 1
sum = 0
for i in range(2019):
    sum += a[i]*(a[i]-1)//2
print(sum)

### FIXED CODE ###

n = int(input())
nums = [int(c) for c in str(n)]
nums.reverse()
a = [0]*2019
a[0] = 1
now = 0
pow10 = [1]*len(nums)
for i, num in enumerate(nums):
    if i < len(nums)-1:
        pow10[i+1] = pow10[i]*10 % 2019
for i, num in enumerate(nums):
    now = (now+num*pow10[i]) % 2019
    a[now] += 1
sum = 0
for i in range(2019):
    sum += a[i]*(a[i]-1)//2
print(sum)
### BUGGY CODE ###

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

def expectation(N):
    exp = 0
    for i in range(1, N+1):
        exp += i/N
    return exp

Ps = []
s = 0
for p in P:
    s += p
    Ps.append(s)
    
cmax = Ps[K-1]
max_sp = 0

for ix in range(1, N-K+1):
    csum = Ps[ix+K-1] - Ps[ix-1]
    if cmax < csum:
        max_sp = ix
        cmax = csum

ans = 0
for ix in range(max_sp, max_sp+K):
    ans += expectation(P[ix])

print(ans)

### FIXED CODE ###

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

def expectation(N):
    # exp = 0
    # for i in range(1, N+1):
    #     exp += i/N
    # return exp
    return N/2+0.5

Ps = []
s = 0
for p in P:
    s += p
    Ps.append(s)
    
cmax = Ps[K-1]
max_sp = 0

for ix in range(1, N-K+1):
    csum = Ps[ix+K-1] - Ps[ix-1]
    if cmax < csum:
        max_sp = ix
        cmax = csum

ans = 0
for ix in range(max_sp, max_sp+K):
    ans += expectation(P[ix])

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

import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
bc=[list(map(int,input().split())) for i in range(m)]

# print(a)
tmp=[]
for i in range(m):
    for j in range(bc[i][0]):
        tmp.append(bc[i][1])

tmp.sort()
change=tmp[-n:]
change.reverse()
# print(tmp)
# print(change)

for i in range(len(change)):
    if change[i]>a[i]:
        a[i]=change[i]
    else:
        break
print(sum(a))

### FIXED CODE ###

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

# print(bc)
# print(a)
tmp=[]
count=0
for i in range(m):
    for j in range(bc[i][0]):
        if count==n:
            break
        tmp.append(bc[i][1])
        count+=1


change=tmp[:n]
# print(tmp)
# print(change)

for i in range(len(change)):
    if change[i]>a[i]:
        a[i]=change[i]
    else:
        break
print(sum(a))
### BUGGY CODE ###

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

b = 10**9+7
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        ans += a[i]*a[j]
        ans %= b
print(ans)

### FIXED CODE ###

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

b = 10**9+7
s = sum(a)
ans = 0
for i in range(n-1):
    s -= a[i]
    ans += a[i]*(s%b)
    ans %= b
print(ans)
### BUGGY CODE ###

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

#sys.setrecursionlimit(10**9)

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

import copy

def main():
	n=II()
	A=[]
	for _ in range(n):
		a=LI()
		A.append(a)

	for i in range(n):
		A[i][i]=10**10

	B=copy.deepcopy(A)

	for k in range(n):
		for i in range(n):
			for j in range(n):
				if i!=j:
					B[i][j]=min(B[i][j],B[i][k]+B[k][j])

	if A!=B:
		print(-1)
		exit(0)

	for k in range(n):
		for i in range(n):
			for j in range(n):
				if B[i][j]==B[i][k]+B[k][j]:
					A[i][j]=0

	ans=0

	for i in range(n):
		for j in range(i,n):
			if i!=j:
				ans+=A[i][j]

	print(ans)


if __name__ == "__main__":
	main()

### FIXED CODE ###

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

#sys.setrecursionlimit(10**9)

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

import copy

def main():
	n=II()
	A=[]
	for _ in range(n):
		a=LI()
		A.append(a)

	for i in range(n):
		A[i][i]=10**10

	B=copy.deepcopy(A)

	for k in range(n):
		for i in range(n):
			for j in range(n):
				if i!=j:
					B[i][j]=min(B[i][j],B[i][k]+B[k][j])

	if A!=B:
		print(-1)
		exit(0)

	for k in range(n):
		for i in range(n):
			for j in range(n):
				if B[i][j]==B[i][k]+B[k][j]:
					A[i][j]=0

	ans=0

	for i in range(n):
		for j in range(i,n):
			if i!=j:
				ans+=A[i][j]

	print(ans)


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


count = 0
N = int(input())
A = list(map(int, input().split()))
B =[x for x in range(1,N+1)]
C = list(zip(A, B))
D = [sorted(x) for x in C]
for i in range(N):
  if D.count(D[i]) == 2:
    count += 1
    
print(int(count/2))

### FIXED CODE ###

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

for i in range(N):
  if A[A[i]-1] == i + 1:
    count += 1

print(int(count / 2))
### BUGGY CODE ###

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

dp=[[0 for _ in range(N)] for _ in range(N)]
#dp[i][j]:i文字目とj文字目からの共通文字の最大長さ

for i in range(N):
  if S[i]==S[N-1]:
    dp[i][N-1]=1
    dp[N-1][i]=1

for i in reversed(range(N-1)):
  for j in reversed(range(N-1)):
    if S[i]==S[j]:
      dp[i][j]=dp[i+1][j+1]+1
      if min(i,j)+dp[i][j]-1>=max(i,j):
        dp[i][j]=max(i,j)-min(i,j)

A=[]
for i in range(N):
  for j in range(i):
    A.append(dp[i][j])

print(max(A))

### FIXED CODE ###

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

dp=[[0 for _ in range(i)] for i in range(N)]
#dp[i][j]:i文字目とj文字目からの共通文字の最大長さ(i>j)

for i in range(N-1):
  if S[i]==S[N-1]:
    dp[N-1][i]=1

for i in reversed(range(N-1)):
  for j in range(i):
    if S[i]==S[j]:
      dp[i][j]=dp[i+1][j+1]+1
      if j+dp[i][j]-1>=i:
        dp[i][j]=i-j

A=[]
for i in range(N):
  for j in range(i):
    A.append(dp[i][j])

print(max(A))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    l = list(map(int, input().split()))
    l.append(i)
    lst.append(l)
    i+=1

ll=sorted(lst)
for i in range(1,n+1):
    j=1
    for k in ll:
        if i == k[0]:
            k.append(str(i).rjust(6,'0') + str(j).rjust(6,'0'))
            j+=1
#ans
sss= sorted(ll, key=lambda x:x[2])
for ans in sss:
    print(ans[3])


### FIXED CODE ###

# -*- coding: utf-8 -*-
n,m = map(int, input().split())
i=0
lst = []
while i < m: 
    lst.append(list(map(int, input().split())) + [i])
    i+=1
lst = sorted(lst)
j=0
i=1
for k in lst:
    if i != k[0]:
        i=k[0]
        j=1
        k[1]=i*1000000+j
    else:
        j+=1
        k[1]=i*1000000+j

#ans
for ans in sorted(lst, key=lambda x:x[2]):
    print('{0:012d}'.format(ans[1]))
### BUGGY CODE ###

r,g,b,n = map(int,input().split())
c = 0
for i in range(3001):
  for j in range(3001):
    for k in range(3001):
      if i*r + j*g + k*b == n:
        c += 1
print(c)

### FIXED CODE ###

r,g,b,n = map(int,input().split())
c = 0
for i in range(n//r+1):
  for j in range((n-i*r)//g+1):
    k = (n-i*r-j*g)
    if k%b == 0 and k >= 0:
      c += 1
print(c)
### BUGGY CODE ###

n, m = map(int,input().split())

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

# i-1番目の展望台と繋がっているかどうか
r = [[0] * n for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    r[a-1][b-1] = 1
    r[b-1][a-1] = 1

cnt=0
for x, t in enumerate(r):
    if h[x] > max([i * j for (i, j) in zip(t, h)]):
        cnt += 1

print(cnt)

### FIXED CODE ###

n, m = map(int,input().split())

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

# 各展望台について(自分が一番高い1, 高くない時0)
t = [1] * n
for i in range(m):
    a, b = map(int, input().split())

    if h[a-1] <= h[b-1]:
        t[a-1] = 0

    if h[b-1] <= h[a-1]:
        t[b-1] = 0

print(sum(t))
### BUGGY CODE ###

#coding:utf-8
def main():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(m):
        b, c = map(int, input().split())
        cnt = 0
        A.sort()
        for j in range(b):
            if A[j] < c:
                cnt += 1
            else:
                break
        A[:cnt] = [c] * cnt
    print(sum(A))
if __name__ == "__main__":
    main()

### FIXED CODE ###

# coding: utf-8
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)
minus = 0
l = []
for i in range(M):
    b, c = map(int, input().split())
    l.append([b, c])
l.sort(key=lambda x: x[1], reverse=True)
A.sort(reverse=False)
idx = 0
i = 0
ans = 0
while i < N and idx < M:
    if l[idx][0] == 0:
        idx += 1
    if idx >= M:
        ans += A[i]
        i += 1
        continue
    if A[i] < l[idx][1]:
        ans += l[idx][1]
        l[idx][0] -= 1
        i += 1
    else:
        ans += A[i]
        i += 1
    # print("ans =", ans)
for j in range(i, N):
    ans += A[j]
print(ans)
### BUGGY CODE ###

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

import collections

counter = collections.Counter(a)

result = 0
for j in range(q):
  b,c = list(map(int,input().strip().split()))
  if c in counter:
    counter[c] += counter[b]
  else:
    counter[c] = counter[b]
  counter[b] = 0
  result = 0
  for i in counter:
    result += i * counter[i]
  print(result)

### FIXED CODE ###

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

import collections

result = sum(a)
counter = collections.Counter(a)

for j in range(q):
  b,c = list(map(int,input().strip().split()))
  if c in counter:
    counter[c] += counter[b]
  else:
    counter[c] = counter[b]
  result += (c-b) * counter[b]
  counter[b] = 0
  print(result)
### BUGGY CODE ###

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

    I = 0
    J = 0
    K = 0
    for a in A:
        if a == 1:
            I += 1
        elif a == 2:
            J += 1
        else:
            K += 1

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

    # def output(lst):
    #     for tmp in lst:
    #         print (tmp)

    for k in range(K + 1):
        for j in range(K + J + 1):
            for i in range(N + 1):
                if i == j == k == 0:
                    continue
                tmp = N
                if i > 0:
                    tmp += i * dp[k][j][i - 1]
                if j > 0 and i < N:
                    tmp += j * dp[k][j - 1][i + 1]
                if k > 0 and j < K + J:
                    tmp += k * dp[k - 1][j + 1][i]
                dp[k][j][i] = tmp / (i + j + k)

    print (dp[K][J][I])

    # output(dp)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = tuple(map(int, input().split()))

    I = A.count(1)
    J = A.count(2)
    K = A.count(3)
    # for a in A:
    #     if a == 1:
    #         I += 1
    #     elif a == 2:
    #         J += 1
    #     else:
    #         K += 1

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

    # def output(lst):
    #     for tmp in lst:
    #         print (tmp)

    for k in range(K + 1):
        for j in range(K + J + 1 - k):
            for i in range(N + 1 - k  - j):
                if i == j == k == 0:
                    continue
                tmp = N
                if i > 0:
                    tmp += i * dp[k][j][i - 1]
                if j > 0:
                    tmp += j * dp[k][j - 1][i + 1]
                if k > 0:
                    tmp += k * dp[k - 1][j + 1][i]
                dp[k][j][i] = tmp / (i + j + k)

    print (dp[K][J][I])

    # output(dp)

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

[N,L] = [int(x) for x in input().split()]
A = {}
ANS = [10**9+1]*N
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    if x in A : A[x] += [i]
    else : A[x] = [i]

for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            try :
                if ANS[j+k] == 10**9+1 : 
                    ANS[j+k] = i
                    count += 1
            except IndexError : continue
            if count == N : break
for i in ANS[L-1:-1] : print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

'''
Fuad Ashraful Mehmet
University of Asia Pacific,Bangladesh
Date:2nd june 2020
'''

def Solve():
    n=int(input())
    ar=[int(x) for x in input().split()]
    #print(ar)
    ans=1
    for x in ar:
        ans=ans*x
    print("-1" if ans>10**18 else ans)
Solve()

### FIXED CODE ###

'''
Fuad Ashraful Mehmet
University of Asia Pacific,Bangladesh
Date:2nd june 2020
'''

def Solve():
    n=int(input())
    ar=[int(x) for x in input().split()]
    if 0 in ar:
        print(0)
        exit()
    ans=1
    for x in ar:
        ans=ans*x
        if ans>10**18:
            print("-1")
            return
    print(ans)
Solve()
### BUGGY CODE ###

xy = input()
XY = xy.split()
X = int(XY[0])
Y = int(XY[1])

a = True
i = 1
while X * i <= X * Y:
    if (X * i) % Y != 0:
        print(X * i)
        a = False
        break
    else:
        i += 1
if a:
    print(-1)

### FIXED CODE ###

xy = input()
XY = xy.split()
X = int(XY[0])
Y = int(XY[1])

a = True
i = 1

if X < Y:
    print(X)
    a = False
elif X > Y and X % Y != 0:
    while X * i <= X * Y:
        if (X * i) % Y != 0:
            print(X * i)
            a = False
            break
        else:
            i += 1
if a:
    print(-1)
### BUGGY CODE ###

import sys, collections
range = xrange
input = raw_input

n, p = [int(x) for x in input().split()]
A = [ord(x) - 48 for x in input()]


if p == 2 or p == 5:
    ans = 0
    for i in range(n):
        if A[i]%p == 0:
            ans += i + 1
    print ans
    sys.exit()


DP = [0]*p
ans = 0
POW = 1
ind0 = 0
for a in reversed(A):
    DP[ind0] += 1
    DP = [DP[(a * POW + i) % p] for i in range(p)]
    #ind0 = (a * POW + ind0) % p
    ans += DP[ind0]
    POW = POW * 10 % p
print ans


### FIXED CODE ###

import sys, collections
range = xrange
input = raw_input

n, p = [int(x) for x in input().split()]
A = [ord(x) - 48 for x in input()]


if p == 2 or p == 5:
    ans = 0
    for i in range(n):
        if A[i]%p == 0:
            ans += i + 1
    print ans
    sys.exit()


DP = [0]*p
ans = 0
POW = 1
ind0 = 0
for a in reversed(A):
    DP[ind0] += 1
    #DP = [DP[(a * POW + i) % p] for i in range(p)]
    ind0 = (a * POW + ind0) % p
    ans += DP[ind0]
    POW = POW * 10 % p
print ans