Harryxun/stf_run huggingface dataset:
#!/usr/bin/python

from sets import Set
import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N, M = map(lambda x: int(x), line.split(" ", 2))

        services_1 = Set([])
        services_n = []
        for i in xrange(M):
            a, b = map(lambda x: int(x), sys.stdin.readline().split(" ", 2))
            if a == 1:
                services_1.add(b)
            if b == N:
                services_n.append(a)

        if 1 in services_n:
            print("POSSIBLE")

        result = "IMPOSSIBLE"
        for service in services_n:
            if service == 1 or service in services_1:
                result = "POSSIBLE"
                break
        print result                

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

### FIXED CODE ###

#!/usr/bin/python

import sys

def main(argv):
    for line in sys.stdin:
        print("ABC{0}".format(int(line)))

if __name__ == "__main__":
    main(sys.argv)
N, M = list(map(int, input().split()))
a = []
for _ in range(M):
    a.append(int(input()))
a = list(set(a))
dif = [a[0]-1]
dif.extend([(a[i]-1)-(a[i-1]+1) for i in range(1,len(a))])
dif.extend([N-a[-1]-1])
max_dif = max(dif)
Fiblist = {-1:0,0:1,1:1,2:2}
for n in range(3,max_dif+1):
    Fiblist[n]=Fiblist[n-1]+Fiblist[n-2]
ans = 1
for part in dif:
    ans= ans*Fiblist[part]%1000000007
print(ans)

### FIXED CODE ###

N, M = list(map(int, input().split()))
a = []
for _ in range(M):
    a.append(int(input()))
a = sorted(list(set(a)))
if len(a)>0:
    dif = [a[0]-1]
    dif.extend([(a[i]-1)-(a[i-1]+1) for i in range(1,len(a))])
    dif.extend([N-a[-1]-1])
else:
    dif = [N]
max_dif = max(dif)
Fiblist = {-1:0,0:1,1:1,2:2}
for n in range(3,max_dif+1):
    Fiblist[n]=Fiblist[n-1]+Fiblist[n-2]
ans = 1
for part in dif:
    ans= ans*Fiblist[part]%1000000007
print(ans)
n, x, m = map(int,input().split())
ans = x
num = 0
l = [0]*(n//10)
lis = [-1]*m
l[0] = x
lis[x] = num
for i in range(1,n):
    x = (x*x)%m
    num += 1
    if lis[x]!=-1:
        a = (n-i)//(i-lis[x])
        b = (n-i)%(i-lis[x])
        ans += a * sum(l[lis[x]:i])
        break
    l[i] = x
    lis[x] = i
    ans += x
for i in range(lis[x],lis[x]+b):
    ans += l[i]
print(ans)

### FIXED CODE ###

n, x, m = map(int,input().split())
ans = x
num = 0
l = [0]*m
lis = [-1]*m
l[0] = x
lis[x] = num
for i in range(1,n):
    x = (x*x)%m
    num += 1
    if lis[x]!=-1:
        a = (n-i)//(i-lis[x])
        b = (n-i)%(i-lis[x])
        ans += a * sum(l[lis[x]:i])
        for j in range(lis[x],lis[x]+b):
            ans += l[j]
        break
    l[i] = x
    lis[x] = i
    ans += x
print(ans)
s = input()
sa = int(s[:2])
sb = int(s[3:])

if sa >= 1 and sa <= 12 and sb >= 1 and  sb <= 12:
    print('AMBIGUOUS')
    exit()
if sa > 12 and sb > 12:
    print('NA')
    exit()
if sa >= 1 and sa <= 12 and sb > 12:
    print('MMYY')
    exit()
if sa > 12 and sb >= 1 sb <= 12:
    print('YYMM')
    exit()


### FIXED CODE ###


s = input()
sa = int(s[:2])
sb = int(s[2:])

if sa >= 1 and sa <= 12 and sb >= 1 and  sb <= 12:
    print('AMBIGUOUS')
    exit()
else:
    if sa >= 1 and sa <= 12:
        print('MMYY')
        exit()
    if sb >= 1 and sb <= 12:
        print('YYMM')
        exit()

print('NA')
n, m = map(int, input().split())

dp = [[10**10 for _ in range(2**n)] for j in range(m)]
dp[0][0] = 0
a, b = map(int, input().split())
c = list(map(int, input().split()))
idx = 0
for cc in c:
  idx += 2**(cc-1)
for j in range(1, 2**n):
  if ~idx & j == 0:
    dp[0][j] = a

for i in range(1, m):
  a, b = map(int, input().split())
  c = list(map(int, input().split()))
  idx = 0
  for cc in c:
    idx += 2**(cc-1)
  for j in range(2**n):
    dp[i][j] = min(dp[i-1][j], dp[i-1][(j|idx)^idx]+a)

if dp[-1][-1] != 10**10:
  print(dp[-1][-1])
else:
  print(-1)

### FIXED CODE ###

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    return arr

a, b = map(int, input().split())
fa = factorization(a)
fb = factorization(b)

i = 0
j = 0
cnt = 1
while i < len(fa) and j < len(fb):
  if fa[i][0] == fb[j][0]:
    cnt += 1
    i += 1
    j += 1
  elif fa[i][0] < fb[j][0]:
    i += 1
  else:
    j += 1

print(cnt)
xxfrom collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    l=[]
    l = list(input().split())
    if l[0] == "1":
        x *= -1
    elif l[0] == "2":
        if (l[1] == "2" and x == -1) or  (l[1] == "1" and x == 1):
            S.appendleft(0, l[2])
        else:
            S.append(l[2])
if x == -1:
    S = S[::-1]
print(*S, sep="")

### FIXED CODE ###

from collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.appendleft(d)
        else:
            S.append(d)
if x == -1:
    S.reverse()
print(*S, sep="")
n=int(input())
boo=[0 for i in range(10**5+1)]
boo[100]=1
boo[101]=1
boo[102]=1
boo[103]=1
boo[104]=1
for i in range(100,n+1):
  if boo[i]==1:
    for j in range(6):
      boo[i+100+j]=1
if boo[n]:
  print(1)
else:
  print(0)

### FIXED CODE ###

n=int(input())
#下２桁を実現させる最小個数を考えよう
l=[0]
for i in range(1,100):
  num=i
  l.append((num-1)//5+1)
w=str(n)
if n<100:
  print(0)
else:
  num=int(w[-2]+w[-1])
  index=l[num]
  if n<index*100+num:
    print(0)
  else:
    print(1)
import sys


def popcount(x: int):
    return bin(x).count("1")


def main():
    N = int(sys.stdin.readline().rstrip())
    X = sys.stdin.readline().rstrip()

    Xdec = int(X, 2)

    # X がゼロなら終了
    if Xdec == 0:
        print(0)
        return

    # 1回目の演算用
    md = popcount(Xdec)
    md_p, md_m = md + 1, md - 1

    tmp_p = Xdec % md_p
    if md_m == 0:
        tmp_m = Xdec % md_m

    for i in range(0, N, 1):
        if X[i] == "1":  # 1->0
            if md_m == 0:
                print(0)
            x_m = pow(2, (N - 1 - i), md_m)
            tmp = (tmp_m - x_m) % md_m

        if X[i] == "0":  # 0->1
            x_p = pow(2, (N - 1 - i), md_p)
            tmp = (tmp_p + x_p) % md_p

        cnt = 1
        while tmp:

            tmp = tmp % popcount(tmp)
            cnt += 1

        print(cnt)


main()


### FIXED CODE ###

import sys


def popcount(x: int):
    return bin(x).count("1")


def main():
    N = int(sys.stdin.readline().rstrip())
    X = sys.stdin.readline().rstrip()

    Xdec = int(X, 2)

    # 1回目の演算用
    md = popcount(Xdec)
    md_p, md_m = md + 1, md - 1

    tmp_p = Xdec % md_p
    if md_m > 0:
        tmp_m = Xdec % md_m

    for i in range(0, N, 1):
        if X[i] == "1":  # 1->0
            if md_m == 0:
                print(0)
                continue
            x_m = pow(2, (N - 1 - i), md_m)
            tmp = (tmp_m - x_m) % md_m

        if X[i] == "0":  # 0->1
            x_p = pow(2, (N - 1 - i), md_p)
            tmp = (tmp_p + x_p) % md_p

        cnt = 1
        while tmp:

            tmp = tmp % popcount(tmp)
            cnt += 1

        print(cnt)


main()
s = input()
print(700　+ int(s.count('o'))*100)

### FIXED CODE ###

s=input()
print(700+int(s.count("o"))*100)
# encoding: utf-8
import math
N, M = map(int, input().split())

def distribute(pos, full, tmp):
    return memo[tmp][pos]

# define search range
p_max = int(M / 2) # M is prime if M has a factor p (> p_max)
ip_up = int(math.log2(p_max))

#### O(MlogM) below (if M has a very large prime factor)
M_tmp = M
ips = []
for p in range(2, p_max + 1):
    if M_tmp % p > 0: continue
    # how many times M_tmp can be divided
    p_tmp = p
    for i_p in range(ip_up + 1):
        if M_tmp % p_tmp > 0: break
        p_tmp = p_tmp * p
    # calculate later
    ips.append(i_p)
    # next
    M_tmp = M_tmp // (p_tmp // p)
    if M_tmp == 1: break
#### O(Mlog M) above

#### O(N) below
# create memo
## init
if len(ips) > 0: ip_max = max(ips)
else: ip_max = 0
memo = [[None] * N for i in range(ip_max + 1)] # max ip
for j in range(N): memo[0][j] = 1
for i in range(1, ip_max + 1): memo[i][N - 1] = 1
## fill
for i in range(1, ip_max + 1):
    sum_tmp = 0
    vals = list(memo[i - 1])[::-1]
    p_memo = memo[i]
    for j, val in enumerate(vals):
        sum_tmp += val
        p_memo[N - 1 - j] = sum_tmp
#### O(N) above
        
# calculate ans
ans = 1
for i_p in ips: ans = (ans * distribute(0, i_p, i_p)) % (10 ** 9 + 7)
    
print(ans)

### FIXED CODE ###

# encoding: utf-8
import math
N, M = map(int, input().split())

ips = []
M_tmp = M
for p in range(2, int(math.sqrt(M)) + 1):
    if M_tmp % p > 0: continue
    for i_p in range(1, 33):
        if M_tmp % (p ** (i_p + 1)) > 0: break
    ips.append(i_p)
    M_tmp = M_tmp // (p ** i_p)
    if M_tmp == 1: break
else:
    ips.append(1)

#### O(NlogM) below ?
# create memo
## init
if len(ips) > 0: ip_max = max(ips)
else: ip_max = 0
memo = [[None] * N for i in range(ip_max + 1)] # max ip
for j in range(N): memo[0][j] = 1
for i in range(1, ip_max + 1): memo[i][N - 1] = 1
## fill
for i in range(1, ip_max + 1):
    sum_tmp = 0
    vals = list(memo[i - 1])[::-1]
    ptr_memo = memo[i]
    for j, val in enumerate(vals):
        sum_tmp += val
        ptr_memo[N - 1 - j] = sum_tmp
#### O(NlogM) above ?
        
# calculate ans
ans = 1
for i_p in ips:
    ans = (ans * memo[i_p][0]) % (10 ** 9 + 7)

if M == 1: print(1)
elif ip_max < 1: print(N)
else: print(ans)
h,w = map(int, input().split())
listA = [input() for i in range(n)]
for i in range(n):
  print(listA[i-1]"\n"listA[i-1])


### FIXED CODE ###

h,w = map(int, input().split())
listA = [input() for i in range(h)]
for i in range(h):
  print(listA[i]+"\n"+listA[i])
N, K = list(map(int, input().split()))
S = input()
 
happy = 0
for i in range(N-1):
  if S[i] == S[i+1]:
    happy += 1
print(min([N-1, happy + 2 * K]))

### FIXED CODE ###

print(int(input()) ** 3)
a = set(map(chr, range(ord(a), ord(z) + 1)))
b = set(input())
print('None' if a==b else sorted(a-b)[0])


### FIXED CODE ###

s = input()
for i in range(ord('a'), ord('z')+1):
  if chr(i) not in s:
    print(chr(i))
    break
else:
  print('None')
n = int(input())
a = []
for _ in n:
  a.append(input())
print(len(set(a)))  

### FIXED CODE ###

n = int(input())
print(len(set(list([input() for _ in range(n)]))))
import sys
import pprint
sys.path.append('C:\\ARIHON')

from Kraskal import compute_mst_kruskal
import UnionFind
import array
import collections
from operator import itemgetter
 
Edge = collections.namedtuple("Edge", "start end weight")

def main():
    n = int(input())
    l = []
    for i in range(n):
        x,y = map(int,input().split())
        l.append((x,y,i))
    
    edges = []

    lxsort = sorted(l,key=itemgetter(0))
    for i in range(n-1):
        edges.append(Edge(lxsort[i][2],lxsort[i+1][2],lxsort[i+1][0]-lxsort[i][0]))
    
    lysort = sorted(l,key=itemgetter(1))
    for i in range(n-1):
        edges.append(Edge(lysort[i][2],lysort[i+1][2],lysort[i+1][1]-lysort[i][1]))
    
    mst = compute_mst_kruskal(n,edges)

    print(sum(edge.weight for edge in mst))
 
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
import pprint
sys.path.append('C:\\ARIHON')

# from Kraskal import compute_mst_kruskal
# import UnionFind
import array
import collections
from operator import itemgetter

class UnionFind(object):
 
    def __init__(self, number_of_nodes):  # 初期化
        self.par = array.array("L", range(number_of_nodes))
        self.rank = array.array("L", (0 for i in range(number_of_nodes)))
 
    def root(self, node):  # 根を求める
        if self.par[node] == node:
            return node
        else:
            r = self.root(self.par[node])
            self.par[node] = r  # 経路圧縮
            return r
 
    def in_the_same_set(self, node1, node2):  # 同じ集合に属するか
        return self.root(node1) == self.root(node2)
 
    def unite(self, node1, node2):  # 属する集合を併合
        x = self.root(node1)
        y = self.root(node2)
        if x == y:
            pass
        elif self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
 
 
# Kruskal法により最小全域木を求める
def compute_mst_kruskal(max_v, edges):
    edges.sort(key=lambda edge: edge.weight)
    uf = UnionFind(max_v)
    mst = []
    for edge in edges:
        if not uf.in_the_same_set(edge.start, edge.end):
            uf.unite(edge.start, edge.end)
            mst.append(edge)
    return mst
 
Edge = collections.namedtuple("Edge", "start end weight")

def main():
    n = int(input())
    l = []
    for i in range(n):
        x,y = map(int,input().split())
        l.append((x,y,i))
    
    edges = []

    lxsort = sorted(l,key=itemgetter(0))
    for i in range(n-1):
        edges.append(Edge(lxsort[i][2],lxsort[i+1][2],lxsort[i+1][0]-lxsort[i][0]))
    
    lysort = sorted(l,key=itemgetter(1))
    for i in range(n-1):
        edges.append(Edge(lysort[i][2],lysort[i+1][2],lysort[i+1][1]-lysort[i][1]))
    
    mst = compute_mst_kruskal(n,edges)

    print(sum(edge.weight for edge in mst))
 
if __name__ == '__main__':
    main()
import math
b = list(map(int,input().split()))
ans=0
check=0
i=0
A =0
C=b[1]
max = math.floor(b[2]/b[1])
if b[2]+1<10000:
    for i in range(b[2]+1):
        if b[2]-i <0:
            break
        check = math.floor((b[0]*(b[2]-i))/b[1]) - b[0]*math.floor((b[2]-i)/b[1])
        if check > ans:
            ans=check
else:
    for i in range(1,max+1):
        A=b[1]-1
        if A>0:
            check = math.floor((b[0]*A)/C) - b[0]*math.floor(A/C)
            if check > ans:
                ans=check
        b[1]+=b[1]
print(ans)

### FIXED CODE ###

import math
b = list(map(int,input().split()))
ans=0
check=0
if b[2]>b[1]-1:
    check = math.floor((b[0]*(b[1]-1))/b[1]) - b[0]*math.floor((b[1]-1)/b[1])
else:
    check = math.floor((b[0]*b[2])/b[1]) - b[0]*math.floor(b[2]/b[1])
if check>ans:
    ans=check
print(ans)
from collections import Counter
import bisect
n = int(input()) #リストの要素数
a = list(map(int, input().split())) #リストの要素
cnt = Counter(a) #aの要素数についての辞書
a.sort()#aを小さい順にソート
ans = 0
mx = 10 ** 6
p = [0] * (mx + 1)
for i in a:
    if p[a] == 0:
        for j in range(mx + 1):
            x = i * j
            if x > mx:
                break
            p[x] = 1 #pの中でaの要素iの倍数として表現できるものに１
        if cnt[a] == 1:
            ans += 1 #pの中で任意のiの倍数として表現できず、かつ１つのみ存在するものをカウント
print(ans)

### FIXED CODE ###

from collections import Counter
import bisect
n = int(input()) #リストの要素数
a = list(map(int, input().split())) #リストの要素
cnt = Counter(a) #aの要素数についての辞書
a.sort()#aを小さい順にソート
ans = 0
mx = 10 ** 6
p = [0] * (mx + 1)
for i in a:
    if p[i] == 0:
        for j in range(mx + 1):
            x = i * j
            if x > mx:
                break
            p[x] = 1 #pの中でaの要素iの倍数として表現できるものに１
        if cnt[i] == 1:
            ans += 1 #pの中で任意のiの倍数として表現できず、かつ１つのみ存在するものをカウント
print(ans)
a,b = map(int,input().split())
if a* b % 2 == 0:
    print("Even")
eles:
    print("Odd")

### FIXED CODE ###

a,b = map(int,input().split())
if a * b % 2 == 0:
    print("Even")
else:
    print("Odd")
A, B = map(int, input().split())
ls = [0]*(max(int(A**0.5)+1, int(B**0.5)+1)+1)
ans = 0
for i in range(1, max(int(A**0.5)+1, int(B**0.5)+1)):
  if A%i==0 and B%i==0:
    if ls[i]==0:
      ls[i]=1
    else:
      continue
    for n in range(2,int(i**0.5)+1):
      if i%n==0:
        break
    else:
      ans += 1
    j = A//i
    if B%j!=0:
      continue
    if ls[j]==0:
      ls[j] = 1
    else:
      continue
    for n in range(2,int(j**0.5)+1):
      if j%n==0:
        break
    else:
      ans += 1
print(ans)

### FIXED CODE ###

from collections import defaultdict
A, B = map(int, input().split())
ls = defaultdict(int)
ans = 0
for i in range(1, max(int(A**0.5)+1, int(B**0.5)+1)):
  if A%i==0 and B%i==0:
    if ls[i]==0:
      ls[i]=1
      for n in range(2,int(i**0.5)+1):
        if i%n==0:
          break
      else:
        ans += 1
  if A%i==0:
    j = A//i
    if B%j!=0:
      continue
  elif B%i==0:
    j = B//i
    if A%j!=0:
      continue
  else:
    continue
  if ls[j]==0:
    ls[j] = 1
  else:
    continue
  for n in range(2,int(j**0.5)+1):
    if j%n==0:
      break
  else:
    ans += 1
print(ans)
import math
a,b=map(int,input().split())
print(a*b//math.gcd(a,b))

### FIXED CODE ###

def euclidean(a,b):
    while True:
      r=a%b
      if r==0:
         return b
      a,b=b,r

a,b=map(int,input().split())
print(a*b//euclidean(a,b))
t,x = map(int(input()))
print(t/x)

### FIXED CODE ###

t,x = map(int,input().split())
print(t/x)
mod = 10**9+7
 
fact = [1,1]
finv = [1,1]
inv = [0,1]
 
for i in range(2,2*10**5+5):
    fact.append((fact[-1]*i)%mod)
    inv.append((inv[mod%i]*(mod-mod//i))%mod)
    finv.append((finv[-1]*inv[-1])%mod)
 
def nCr(n,r,mod):
      
    return fact[n]*finv[r]*finv[n-r]%mod

n = int(input())
e = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    e[a-1].append(b-1)
    e[b-1].append(a-1)

numl = [0]*n
resl = [0]*n
def dfs(x,pre):
    num = 0
    res = 1
    for nex in e[x]:
        if nex == pre:
            continue
        dfs(nex,x)
        num += numl[nex]
        res *= nCr(num,numl[nex],mod)*resl[nex]
        res %= mod
    numl[x] = num+1
    resl[x] = res
dfs(0,-1)

ans = [0]*n
ans[0] = resl[0]
def dfs2(x,pre):
    
    for nex in e[x]:
        if nex == pre:
            continue
        pres = [resl[x], numl[x], resl[nex], numl[nex]]
        resl[x] *= pow(nCr(numl[x]-1,numl[nex],mod)*resl[nex],mod-2,mod)
        resl[nex] %= mod
        numl[x] -= numl[nex]
        resl[nex] *=  nCr(numl[x]+numl[nex]-1,numl[x],mod)*resl[x]
        resl[nex] %= mod
        numl[nex] += numl[x]
        ans[nex] = resl[nex]
        dfs2(nex,x)
        resl[x], numl[x], resl[nex], numl[nex] = pres
dfs2(0,-1)
for i in ans:
    print(i)

### FIXED CODE ###


import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
mod = 10**9+7
 
fact = [1,1]
finv = [1,1]
inv = [0,1]
 
for i in range(2,2*10**5+5):
    fact.append((fact[-1]*i)%mod)
    inv.append((inv[mod%i]*(mod-mod//i))%mod)
    finv.append((finv[-1]*inv[-1])%mod)
 
def nCr(n,r,mod):
      
    return (fact[n]*finv[r])%mod*finv[n-r]%mod

n = int(input())
e = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    e[a-1].append(b-1)
    e[b-1].append(a-1)

numl = [0]*n
resl = [0]*n
def dfs(x,pre):
    num = 0
    res = 1
    for nex in e[x]:
        if nex == pre:
            continue
        dfs(nex,x)
        num += numl[nex]
        res *= nCr(num,numl[nex],mod)*resl[nex]
        res %= mod
    numl[x] = num+1
    resl[x] = res

    return 

dfs(0,-1)

ans = [0]*n
ans[0] = resl[0]
def dfs2(x,pre):
    
    for nex in e[x]:
        if nex == pre:
            continue
        pres = [resl[x], numl[x], resl[nex], numl[nex]]
        resl[x] *= pow(nCr(numl[x]-1,numl[nex],mod)*resl[nex],mod-2,mod)
        resl[x] %= mod
        numl[x] -= numl[nex]
        resl[nex] *=  nCr(numl[x]+numl[nex]-1,numl[x],mod)*resl[x]
        resl[nex] %= mod
        numl[nex] += numl[x]
        ans[nex] = resl[nex]
        dfs2(nex,x)
        resl[x], numl[x], resl[nex], numl[nex] = pres
    return
dfs2(0,-1)
for i in ans:
    print(i)
n=input()
list=list(map(int,input().split()))

if 0 in list:
  print(0)
else:
  prod=1
  for a in list:
    flg=True
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      flg=False
      break
if flg:
  print(prod)


### FIXED CODE ###

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

flg=True
if 0 in list:
  print(0)
  flg=False
else:
  prod=1
  for a in list:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      flg=False
      break
if flg:
  print(prod)
def binaryinsertion(A,x):
    left=0;right=len(A)-1
    while(True):
        center = math.floor((low + high) / 2)
        if(right == left):
            if(x[0]<A[left][0]):
                A.insert(left,x)
                break
            else :
                A.insert(left + 1,x)
                break
        else:
            if(x[0] < A[centre][0]) :
                right = centre - 1
            elif(A[centre][0] < x[0]) :
                left = centre + 1
            else : 
                A.insert(centre,x)
                break

[N,L] = [int(x) for x in input().split()]
A = [[int(x),int(i)] for i,x in enumerate(input().split())]
sweep = A[:L]
sweep = sorted(sweep)
ans = [str(sweep[0][0])]
for i in range(L,N) :
    sweep.remove(A[i-L])
    binaryinsertion(sweep,A[i])
    ans.append(str(sweep[0][0]))
print(" ".join(ans))

### 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])
#
K = int(input())
A = list(map(int, input().split()))

#
if A[-1]!=2:
    print(-1)
    exit()
if A[-2]!=2 and A[-2]!=3:
    print(-1)
    exit()

#
min_n = 2
max_n = 3
for i in A[::-1][1:]:
    a = (min_n - 1)//i
    b = max_n//i
    if a==b:
        print(-1)
        exit()

    if min_n%i==0:
        pass
    else:
        min_n = min_n + (i - min_n%i)
    max_n = max_n - max_n%i + i - 1
    #print(min_n, max_n)

#
print(min_n, max_n)


### FIXED CODE ###

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

#
if A[-1]!=2:
    print(-1)
    exit()
if K>1 and A[-2]!=2 and A[-2]!=3:
    print(-1)
    exit()

#
min_n = 2
max_n = 3
for i in A[::-1][1:]:
    a = (min_n - 1)//i
    b = max_n//i
    if a==b:
        print(-1)
        exit()

    if min_n%i==0:
        pass
    else:
        min_n = min_n + (i - min_n%i)
    max_n = max_n - max_n%i + i - 1
    #print(min_n, max_n)

#
print(min_n, max_n)