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

N, X, Y = map(int, input().split())

result = []
for i in range(1, N+1):
    for j in range(i, N+1):
        if j<=X:
            result.append(j-i)
        elif (i<=X)&(X<j<=Y):
            if (j-i)<=(Y-j+1+X-i):
                result.append(j-i)
            else:
                result.append(Y+X-j-i+1)
        elif (i<=X)&(Y<=j):
            result.append(j-Y+1+X-i)
        elif (X<i)&(j<=Y):
            if (j-i)<=(Y-j+1+i-X):
                result.append(j-i)
            else:
                result.append(Y-j+1+i-X)
        elif (X<i)&(Y<j):
            if (j-i)<=(j-Y+1+i-X):
                result.append(j-i)
            else:
                result.append(j-Y+1+i-X)
        else:
            #print(i, j)
            pass
            
for i in range(N-1):
    print(result.count(i+1))

### FIXED CODE ###

from itertools import combinations
N, X, Y = map(int, input().split())

result = [0]*N
for i, j in combinations(range(1, N+1), 2):
    mins = min([j-i, abs(Y-j)+abs(X-i)+1])
    result[mins] += 1
    
for i in range(1, N):
    print(result[i])
### BUGGY CODE ###

# 考えると、隣り合う列は結局 2*H 回ずることになり、
# それぞれの列間について最適な沈め順を見つけると、
# その順序関係を崩さないように全体の順番も構築できる（トポロジカルソートみたいに）ので、
# 各列間の最適解を求めて総和をとればいい

from itertools import accumulate
inf = 2 * 10**9
H, W = map(int, input().split())
C = [input() for _ in range(H)]
C_T = list(zip(*C))
C_T = [[ord(c) for c in s] for s in C_T]
ans = 0
for C1, C2 in zip(C_T[:-1], C_T[1:]):
    # Z[i][j] := i 個ずれてて沈んでない方が j 個沈んでる状態の連結個数
    Z1 = []  # 左を押したとき（右が上にあるとき）
    Z2 = []  # 右を押したとき（左が上にあるとき）
    z1 = list(accumulate([int(c1==c2) for c1, c2 in zip(C1, C2)]))
    z1.reverse();  z1.append(0)
    Z1.append(z1)
    Z2.append([])
    for j in range(1, H+1):
        z1 = list(accumulate([int(c1==c2) for c1, c2 in zip(C1, C2[j:])]))
        z1.reverse();  z1.append(0);  Z1.append(z1)
        z2 = list(accumulate([int(c1==c2) for c1, c2 in zip(C1[j:], C2)]))
        z2.reverse();  z2.append(0);  Z2.append(z2)
    # dp[i][j] := 左を i 個、右を j 個沈めるまでの最小コスト  # 逆かも（どっちでもいい）
    dp = [[inf] * (H+2) for _ in range(H+2)]
    dp[0][0] = 0
    for j in range(H+1):
        for k in range(H+1):
            cost = dp[j][k] + (Z1[j-k][k] if j>=k else Z2[k-j][j])
            dp[j+1][k] = min(dp[j+1][k], cost)
            dp[j][k+1] = min(dp[j][k+1], cost)
    ans += dp[H][H]
print(ans)


### FIXED CODE ###

# 考えると、隣り合う列は結局 2*H 回ずることになり、
# それぞれの列間について最適な沈め順を見つけると、
# その順序関係を崩さないように全体の順番も構築できる（トポロジカルソートみたいに）ので、
# 各列間の最適解を求めて総和をとればいい

def accumulate_reverse(S1, S2):
    n = min(len(S1), len(S2))
    res = [0] * (n+1)
    c = 0
    for i in range(n):
        if S1[i] == S2[i]:
            c += 1
        res[n-i-1] = c
    return res

inf = 10**8
H, W = map(int, input().split())
C = [input() for _ in range(H)]
C_T = list(zip(*C))
C_T = ["".join(s) for s in C_T]
ans = 0
for C1, C2 in zip(C_T[:-1], C_T[1:]):
    # Z[i][j] := i 個ずれてて沈んでない方が j 個沈んでる状態の連結個数
    Z1 = []  # 左を押したとき（右が上にあるとき）
    Z2 = []  # 右を押したとき（左が上にあるとき）
    Z1.append(accumulate_reverse(C1, C2))
    for j in range(1, H+1):
        Z1.append(accumulate_reverse(C1, C2[j:]))
        Z2.append(accumulate_reverse(C1[j:], C2))
    Z1 += Z2[::-1]
    # dp[i][j] := 左を i 個、右を j 個沈めるまでの最小コスト  # 逆かも（どっちでもいい）
    dp = [[inf] * (H+2) for _ in range(H+2)]
    dp[0][0] = 0
    for j in range(H+1):
        for k in range(H+1):
            cost = dp[j][k] + Z1[j-k][min(j, k)]
            dp[j+1][k] = min(dp[j+1][k], cost)
            dp[j][k+1] = min(dp[j][k+1], cost)
    ans += dp[H][H]
print(ans)
### BUGGY CODE ###

S = input()

cnt = 0
while True:
  f0 = S.find("01")
  f1 = S.find("10")
  if f0 >= 0:
#    print ("01", f0, S[:f0], S[f0+2:])
    S = S[:f0] + S[f0+2:]
    cnt += 2
  elif f1 >= 0:
#    print ("10", f1, S[:f1], S[f1+2:])
    S = S[:f1] + S[f1+2:]
    cnt += 2
  else:
    break
print (cnt)
  

### FIXED CODE ###

S = input()

cnt = 0
stack = []
for s in S:
  if len(stack) > 0:
    if stack[-1] != s:
      stack.pop()
      cnt += 2
    else:
      stack.append(s)
  else:
    stack.append(s)
print (cnt)
### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

lis = []
lis2 = []

def sum(lis):
  s = 0
  for e in lis:
    s += e
  return s

while True:
  num = input()
  if num == 0:
    break
  else:
    lis = []
    lis2 = []
    for i in range(num):
      lis.append(input())
    for i in range(len(lis)):
      for j in range(i+1,len(lis)+1):
        lis2.append(sum(lis[i:j]))
    print max(lis2)

### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
  num = input()
  if num == 0:
    break
  lis = [0]*num
  for i in range(num):
    n = input()
    if i == 0:
      lis[0] = n
    else:
      lis[i] = max( lis[i-1] + n , n )
  print max(lis)
### BUGGY CODE ###

n,k = map(int,input().split())
parent = []
q = {}
for i in range(n):
    a,b = map(int,input().split())
    if a not in q.keys():
        parent.append(a)
        q[a] = 0
    q[a] += b
parent.sort()
cnt = 0
for p in parent:
    cnt += q[p]
    if cnt >= k:
        print(p)
        break


### FIXED CODE ###

import sys
input = sys.stdin.readline
n,k = map(int,input().split())
inf = 10**10
parent = [inf]*n
q = {}
for i in range(n):
    a,b = map(int,input().split())
    if a not in q.keys():
        parent[i] = a
        q[a] = 0
    q[a] += b
parent.sort()
cnt = 0
for p in parent:
    cnt += q[p]
    if cnt >= k:
        print(p)
        break
### BUGGY CODE ###

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

if blue == 0:
    print(0)
    exit()

if n <= blue:
    print(n)
    exit()

cnt = 0

while True:
    if n > blue:
        cnt += blue
        n -= blue
        if n <= red:
            break
        elif n > red:
            n -= red
    else:
        cnt += n
        break
print(cnt)

### FIXED CODE ###

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

if blue == 0:
    print(0)
    exit()

if n <= blue:
    print(n)
    exit()

if n <= blue + red:
    print(blue)
    exit()

q = n // (blue + red)
r = n % (blue + red)

cnt = q * blue

while True:
    if r >= blue:
        cnt += blue
        r -= blue
        if r <= red:
            break
        elif r > red:
            r -= red
    else:
        cnt += r
        break

print(cnt)
### BUGGY CODE ###

n=int(input())
arr=list(map(int,input().split()))
arr.sort()
if 1 in arr:
    if arr.count(1)>1:
        print(0)
        quit()
    else:
        print(1)
        quit()
d={}
ans=0
for i in arr:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
for i in range(n):
    x=arr[i]
    if d[x]==1:
        f=1
        for j in range(2,int(x**0.5)+1):
            y=x//j
            if (j in d and x%j==0) or ( y in d and x%(y)==0):
                f=0
                break
        if f==1:
             ans+=1
print(ans)

### FIXED CODE ###


import os
import sys
from io import BytesIO, IOBase


def main():
    n = int(input())
    arr = list(map(int, input().split()))
    arr.sort()
    ans = 0
    k=max(arr)
    d = [0]*(k+1)
    if arr[0] == 1:
        if n>1 and arr[1]==1:
            print(0)
            quit()
        else:
            print(1)
            quit()
    for i in range(n):
        d[arr[i]]+=1
    for i in range(n):
        x=arr[i]
        if d[x]==1:
            ans+=1
        for j in range(x,k+1,x):
            d[j]+=1
    print(ans)


# fast-io region

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


def input():
    return sys.stdin.readline().rstrip("\r\n")


def write(*args, end="\n"):
    for x in args[:-1]:
        sys.stdout.write(str(x) + " ")
    sys.stdout.write(str(args[-1]))
    sys.stdout.write(end)


def r_array():
    return [int(x) for x in input().split()]


def r_int():
    return int(input())


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

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

    ans = 0

    while 1:
        f = False
        for i in range(N):
            adv = B[i-1] + B[(i+1) % N]
            if A[i] <= B[i] - adv:
                f = True
                ans += 1
                B[i] -= adv
        if not f:
            break

    if A != B:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    p_c()


### FIXED CODE ###

def p_c():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    l = [-1] * N

    for i in range(N):
        l[i] = B[i - 1] + B[(i + 1) % N]

    ans = 0

    while 1:
        f = False
        for i in range(N):
            if A[i] <= B[i] - l[i]:
                f = True
                n = (B[i] - A[i]) // l[i]
                ans += n
                B[i] -= n * l[i]
                l[i - 1] -= n * l[i]
                l[(i + 1) % N] -= n * l[i]
        if not f:
            break

    if A != B:
        print(-1)
    else:
        print(ans)


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

n, m = map(int, input().split())
a = []
for _ in range(m):
  a.append(int(input()))
  
dp = [0]*(n+1)
dp[0] = 1

for i in range(1, n+1):
  if i in a:
    dp[i] = 0
    continue
  dp[i] = dp[i-1]
  if i > 1:
    dp[i] = dp[i-1] + dp[i-2]

mod = 1000000007
print(dp[-1]%mod)

### FIXED CODE ###

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

safe = [True] * (n + 1)
for _ in range(m):
  safe[int(input())] = False
dp = [0] * (n + 1)

dp[0] = 1
if safe[1]:
  dp[1] = 1

for i in range(2, n + 1):
  if safe[i - 1]:
    dp[i] += dp[i - 1]
  if safe[i - 2]:
    dp[i] += dp[i - 2]
  dp[i] %= 1000000007
 
print(dp.pop())
### BUGGY CODE ###

import numpy as np
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def main():
  H, W = map(int, input().split())
  G = [list(input()) for _ in range(H)]
  black = [[True]*W for _ in range(H)]
  que = []
  ans = 0
  for i in range(H):
    for j in range(W):
      if G[i][j] == '#':
        que.append([i,j])
        black[i][j] = False
  while que:
    qq = []
    ans += 1
    for nh, nw in que:
      if nw+1<=W-1 and black[nh][nw+1] == True:
        qq.append([nh,nw+1])
        black[nh][nw+1] = False
      if  0<=nw-1 and black[nh][nw-1] == True:
        qq.append([nh,nw-1])
        black[nh][nw-1] = False
      if nh+1<=H-1 and black[nh+1][nw] == True:
        qq.append([nh+1,nw])
        black[nh+1][nw] = False
      if 0<=nh-1 and black[nh-1][nw] == True:
        qq.append([nh-1,nw])
        black[nh-1][nw] = False
    que = qq
  print(ans-1)

if __name__ == "__main__":
  main()

### FIXED CODE ###

import copy
from collections import deque
def main():
  H, W = map(int, input().split())
  G = [['#' == x for x in input()] for _ in range(H)]
 
  black = deque([(i, j) for i in range(H) for j in range(W) if G[i][j]])
 
  ans = 0
  while True:
    ans += 1
    next_black = deque()
    while black:
      bi, bj = black.popleft()
      if bi > 0 and not G[bi - 1][bj]:
        G[bi - 1][bj] = True
        next_black.append((bi - 1, bj))
      if bj > 0 and not G[bi][bj - 1]:
        G[bi][bj - 1] = True
        next_black.append((bi, bj - 1))
      if bi < H - 1 and not G[bi + 1][bj]:
        G[bi + 1][bj] = True
        next_black.append((bi + 1, bj))
      if bj < W - 1 and not G[bi][bj + 1]:
        G[bi][bj + 1] = True
        next_black.append((bi, bj + 1))
    if next_black:
       black = copy.copy(next_black)
    else:
       break
  print(ans - 1)
  
if __name__ == "__main__":
  main()
### BUGGY CODE ###

N,M = map(int, input().split())
citys = [list(map(int,input().split()))+[i] for i in range(M)]

citys.sort(key=lambda x: (x[0],x[1]))
states = []
for s in range(N):
    temp = list(filter(lambda x:x[0]==s+1,citys))
    states += [city+[i+1] for i,city in enumerate(temp)]

states.sort(key=lambda x: x[2])

for city in states:
    print(str(city[0]).zfill(6)+str(city[3]).zfill(6))

### FIXED CODE ###

N,M = map(int, input().split())
citys = [list(map(int,input().split()))+[i] for i in range(M)]

citys.sort(key = lambda x:x[1])
nums = [0]*(N+1)
states = [None]*M

for p,y,i in citys:
    nums[p] += 1
    states[i] = [str(p), str(nums[p])]

for s in states:
    print(s[0].zfill(6)+s[1].zfill(6))
### BUGGY CODE ###

N = int(input())
S = input().strip()
cntmax = 0
for w in range(1,N//2+1):
    D = {}
    for i in range(N-w+1):
        a = S[i:i+w]
        if a not in D:
            D[a] = []
        D[a].append(i)
    for a in D:
        cur = D[a][0]
        cnt = 10**8
        for i in range(1,len(D[a])):
            cnt = min(cnt,D[a][i]-cur)
            cur = D[a][i]
        if 10**8>cnt>=w:
            cntmax=w
print(cntmax)

### FIXED CODE ###

N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N):
    X = S[:N-k]
    Y = S[k:]
    cur = 0
    cnt = 0
    for i in range(N-k):
        if X[i]!=Y[i]:
            cmax = max(cmax,min(cnt,k))
            cur = i
            cnt = 0
        else:
            cnt += 1
    cmax = max(cmax,min(cnt,k))
print(cmax)
### BUGGY CODE ###

from collections import Counter

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

left, right = S[:N], S[N:][::-1]
a, b = Counter(), Counter()

for i in range(2 ** N):
    t = u = v = w = ""
    for j in range(N):
        if (i >> j) & 1:
            t += left[j]
            u += right[j]
        else:
            v += left[j]
            w += right[j]
    a[t, v] += 1
    b[u, w] += 1

print(sum(a[t] * b[t] for t in a.keys()))

### FIXED CODE ###

from collections import Counter

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

left, right = S[:N], S[N:][::-1]
a, b = Counter(), Counter()

for i in range(2 ** N):
    t = "".join(left[j] if (i >> j) & 1 else "" for j in range(N))
    u = "".join(right[j] if (i >> j) & 1 else "" for j in range(N))
    v = "".join("" if (i >> j) & 1 else left[j] for j in range(N))
    w = "".join("" if (i >> j) & 1 else right[j] for j in range(N))
    a[t, v] += 1
    b[u, w] += 1

print((sum(a[t] * b[t] for t in a.keys())))
### BUGGY CODE ###

import heapq
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort(reverse=True)
f.sort()
m = []
for i, j in zip(a, f):
    heapq.heappush(m, (-i*j, i, j))
for i in range(k):
    t = heapq.heappop(m)
    heapq.heappush(m, (-(t[1] - 1)*t[2], t[1]-1, t[2]))
    if min(m, key=lambda x:x[0]) == 0:
        print(0)
        break
else:
    print(-min(m, key=lambda x:x[0])[0])



### FIXED CODE ###

import math
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    f = list(map(int, input().split()))
    a.sort(reverse=True)
    f.sort()
    hi = a[0] * f[-1]
    lo = 0
    def caneat(m):
        t = 0
        for i, j in zip(a, f):
            if i * j > m:
                t += math.ceil((i*j - m)/j)
            if t > k:
                return False
        return True
    while hi != lo:
        m = (hi + lo) // 2
        if caneat(m):
            hi = m
        else:
            lo = m + 1
    return hi
print(main())
### BUGGY CODE ###

N,H = map(int,input().split())
Ma = 1
B = []
for i in range(N):
    a,b = map(int,input().split())
    B.append(b)
    if a > Ma:
        Ma = a
B.sort()
B.reverse()
C = 0
while H > 0:
    if B == []:
        C += int(-(-H//Ma))
        H = 0
    else:
        Mb = max(B)
        if Ma >= Mb:
            C += int(-(-H//Ma))
            H = 0
        else:
            C += 1
            H -= Mb
            B.remove(Mb)
print(C)

### FIXED CODE ###

N,H = map(int,input().split())
Ma = 1
B = []
for i in range(N):
    a,b = map(int,input().split())
    B.append(b)
    if a > Ma:
        Ma = a
B.sort()
B.reverse()
i = 0
Mb = B[0]
while Mb > Ma and H > 0:
  i += 1
  H -= Mb
  if i == N:
    Mb = 0
  else:
    Mb = B[i]
if H <= 0:
  print(i)
else:
  print(i+int(-(-H//Ma)))
### BUGGY CODE ###

n,m = map(int,input().split())
money = sorted([list(map(int,input().split())) for _ in range(n)], key = lambda x: x[1], reverse = True)

dic = {}
ans = 0
for s in money:
    if s[0] <= m:
        if s[0] not in dic:
            dic[s[0]] = s[1]
            ans += s[1]
        else:
            for i in range(1,m-s[0]+1):
                if s[0]+i not in dic:
                    dic[s[0]+i] = s[1]
                    ans += s[1]
                    break
print(ans)

### FIXED CODE ###

import heapq
from collections import defaultdict
n,m = map(int,input().split())
dct = defaultdict(list)

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

h = []
ans = 0

for i in range(1,m+1):
    if dct[i]:
        for item in dct[i]:
            heapq.heappush(h, item)
    if h:
        ans += heapq.heappop(h)
print(-ans)
### BUGGY CODE ###

def main():
    H, N = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    dp = [10**12 for i in range(H+1)]  # dp[i] := 体力をi減らすときの魔力の最小値
    dp[0] = 0
    for h in range(H):
        for damage, cost in AB:
            next_index = min(h + damage, H)
            dp[next_index] = min(dp[next_index], dp[h] + cost)
    print(dp[H])


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    H, N = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    dp = [[(10**8) for i in range(H + 1)] for j in range(N+1)]
    for i in range(N+1):
        dp[i][0] = 0

    for i in range(1, N + 1):
        for h in range(H + 1):
            dp[i][h] = min(dp[i][max(h - AB[i - 1][0], 0)] +
                           AB[i - 1][1], dp[i - 1][h])
    print(dp[N][H])


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

from collections import Counter

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

ttl = sum(A)
cnt = Counter(A)

Q = int(input())
for _ in range(Q):
    b, c = map(int, input().split())
    
    if b in cnt:
        occ = cnt.pop(b)
        ttl = ttl - b * occ
        cnt = cnt + Counter({c: occ})
        ttl = ttl + c * occ
    
    print(ttl)

### FIXED CODE ###

from collections import defaultdict

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

cnt = defaultdict(int)
for a in A:
    cnt[a] += 1
ttl = sum(A)

Q = int(input())
for _ in range(Q):
    b, c = map(int, input().split())
    
    if b in cnt:
        occ = cnt.pop(b)
        cnt[c] += occ
        ttl = ttl - b * occ + c * occ
    
    print(ttl)
### BUGGY CODE ###

from collections import deque
n, q = map(int, input().split())
g = [[] for i in range(n)]
k = []
for i in range(n-1):
  a,b = map(int, input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)
for i in range(q):
  a,b = map(int, input().split())
  k.append([a-1,b])
m = [-1]*n
m[0] = 0
q = deque()
q.append(0)
while len(q):
  d = q.popleft()
  for i in g[d]:
    if m[i] == -1:
      m[i] = m[d]+1
      q.append(i)
kyori = [[] for i in range(max(m)+1)]
for i,j in enumerate(m):
  kyori[j].append(i)
ans= [0]*n
for i,j in k:
  t = m[i]
  ans[i]+=j
  for r in range(t+1,len(kyori)):
    for z in kyori[r]:
      ans[z]+=j
print(' '.join(map(str,ans)))

### FIXED CODE ###

from collections import deque
n, q = map(int, input().split())
g = [[] for i in range(n)]
k = []
for i in range(n-1):
  a,b = map(int, input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)
for i in range(q):
  a,b = map(int, input().split())
  k.append([a-1,b])
m = [-1]*n
m[0] = 0
m1 = [-1]*n
m1[0] = 0
q = deque()
q.append(0)
while len(q):
  d = q.popleft()
  for i in g[d]:
    if m[i] == -1:
      m[i] = m[d]+1
    if m1[i] == -1:
      m1[i] = d
      q.append(i)
kyori = [[] for i in range(max(m)+1)]
for i,j in enumerate(m):
  kyori[j].append(i)
ans= [0]*n
for i,j in k:
  ans[i]+=j
for i in kyori[1:]:
  for j in i:
    ans[j] = ans[j] + ans[m1[j]]
print(' '.join(map(str,ans)))
### BUGGY CODE ###

#!/usr/bin/env python3
h, w, m = map(int, input().split())
r = [0] * h
c = [0] * w
s = set()
for _ in range(m):
    x, y = map(lambda i: int(i) - 1, input().split())
    r[x] += 1
    c[y] += 1
    s.add((x, y))
R = max(r)
C = max(c)
ans = {(i, j)
       for i, p in enumerate(r) for j, q in enumerate(c) if p == R and q == C}
print(R + C - (len(ans - (ans & s)) == 0))


### FIXED CODE ###

#!/usr/bin/env python3
h, w, m = map(int, input().split())
r = [0] * (h + 1)
c = [0] * (w + 1)
s = []
for _ in range(m):
    x, y = map(int, input().split())
    r[x] += 1
    c[y] += 1
    s.append([x, y])
R = max(r)
nr = {i for i, x in enumerate(r) if x == R}
C = max(c)
nc = {i for i, x in enumerate(c) if x == C}
count = 0
for x, y in s:
    count += x in nr and y in nc
print(R + C - (len(nr) * len(nc) == count))
### BUGGY CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
max_a = max(a)
second_a = sorted(a)[-2]
[print(max_a) if a[i] != max_a or a.count(a[i]) > 1 else print(second_a) for i in range(len(a))]

### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
max_a = max(a)
second_a = sorted(a)[-2]
max_count = a.count(max_a) - 1
if max_count:
    [print(max_a) for _ in range(len(a))]
else:
    [print(max_a) if a[i] != max_a else print(second_a) for i in range(len(a))]
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
count = 0
flag = False
while flag == False:
    for ai in a:
        if ai % 2 == 0:
            ai = ai / 2
        else:
            flag = True
    
    if flag == True:
        break
    count += 1
print(count)

### FIXED CODE ###

import math
n = input()
a = list(map(int, input().split()))
ans = float("inf")
for i in a:
    ans = min(ans, len(bin(i)) - bin(i).rfind("1") - 1)
print(round(ans))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

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

    array = [0]*n
    before = 1
    for i in range(k):
        before *= A[k-1-i]
    for i in range(k,n):
        tmp = 1
        after = (before//A[i-k])*A[i]
        if before < after:
            print('Yes')
        else:
            print('No')
        before = after


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

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

    for i in range(k,n):
        if A[i-k]<A[i]:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()