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

import sys
input = sys.stdin.readline
import heapq

def main():
  h, w, k = map(int, input().split())
  x1, y1, x2, y2 = map(lambda x:int(x)-1, input().split())
  S = [input().rstrip() for _ in range(h)]
  dist = [[[float("inf")]*w  for i in range(h)] for _ in range(4)]
  que = []
  que.append((0, 0, x1, y1))
  dist[0][x1][y1] = 0

  while que:
    c, di, x, y = heapq.heappop(que)
    if dist[di][x][y] < c:
      continue
    l, r = c+1, -(-c//k)*k
    if di == 0:
      if x > 0 and S[x-1][y] == "." and dist[di][x-1][y] > l:
        dist[di][x-1][y] = l
        heapq.heappush(que, (l, di, x-1, y))
    elif di == 1:
      if y > 0 and S[x][y-1] == "." and dist[di][x][y-1] > l:
        dist[di][x][y-1] = l
        heapq.heappush(que, (l, di, x, y-1))
    elif di == 2:
      if x < h-1 and S[x+1][y] == "." and dist[di][x+1][y] > l:
        dist[di][x+1][y] = l
        heapq.heappush(que, (l, di, x+1, y))
    else:
      if y < w-1 and S[x][y+1] == "." and dist[di][x][y+1] > l:
        dist[di][x][y+1] = l
        heapq.heappush(que, (l, di, x, y+1))

    if di%2:
      if dist[0][x][y] > r:
        dist[0][x][y] = r
        heapq.heappush(que, (r, 0, x, y))
      if dist[2][x][y] > r:
        dist[2][x][y] = r
        heapq.heappush(que, (r, 2, x, y))

    else:
      if dist[1][x][y] > r:
        dist[1][x][y] = r
        heapq.heappush(que, (r, 1, x, y))
      if dist[3][x][y] > r:
        dist[3][x][y] = r
        heapq.heappush(que, (r, 3, x, y))
  t = min(dist[0][x2][y2], dist[1][x2][y2], dist[2][x2][y2], dist[3][x2][y2])
  if t == float("inf"):
    print(-1)
  else:
    ans = -(-t//k)
    print(ans)

if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import deque

def main():
  h, w, k = map(int, input().split())
  x1, y1, x2, y2 = map(lambda x:int(x)-1, input().split())
  v1 = x1*(w+1)+y1
  v2 = x2*(w+1)+y2
  C = "".join(input().rstrip()+"@" for _ in range(h))
  dist = [-1 if c=="@" else 10**10 for c in C]
  ans = 0
  que = deque()
  que.append(v1)
  dist[v1] = 0
  while que:
    v = que.popleft()
    if v == v2:
      print(dist[v2])
      exit()
    d = dist[v]+1
    for dr in (-(w+1), -1, w+1, 1):
      for i in range(1, k+1):
        nv = v+dr*i
        if 0 <= nv < h*(w+1):
          if dist[nv] > d:
            dist[nv] = d
            que.append(nv)
          elif dist[nv] == d:
            continue
          else:
            break
        else:
          break
  print(-1)
if __name__ == "__main__":
  main()
### BUGGY CODE ###

N = int(input())
a = list(map(int, input().split()))
flag = False

for i in range(len(a)):
  ta = a.pop(i)
  sum_xor = 0
  for _a in a:
    sum_xor = sum_xor ^ _a
  if sum_xor==ta:
    flag = True
    break
  a.append(ta)

if flag:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
flag = False

sum_xor = 0
for _a in a:
  sum_xor = sum_xor ^ _a

if sum_xor==0:
  print('Yes')
else:
  print('No')
### BUGGY CODE ###

n, m = map(int, input().split())
wars = {}
for i in range(m):
  a, b = map(int, input().split())
  if a in wars.keys():
    wars[a].append(b)
  else:
    wars[a] = [b]

cuts = 0
antis = []

for i in range(1, n):
  if i in wars.keys():
    antis.append(min(wars[i]))
  if i + 1 in antis:
    cuts += 1
    antis.clear()
    
print(cuts)


### FIXED CODE ###

n, m = map(int, input().split())
wars = {}
for i in range(m):
  a, b = map(int, input().split())
  if a in wars.keys():
    wars[a] = min(wars[a], b)
  else:
    wars[a] = b

cuts = 0
antis = 10**6

for i in range(1, n):
  if i in wars.keys():
    antis = min(antis, wars[i])
  if i + 1 == antis:
    cuts += 1
    antis = 10**6
    
print(cuts)
### BUGGY CODE ###

import sys
def input():
	return sys.stdin.buffer.readline()[:-1]

n, m, q = map(int, input().split())
g = [[0 for _ in range(m)] for _ in range(n)]
for _ in range(q):
	r, c, v = list(map(int, input().split()))
	g[r-1][c-1] = v

dp = [[[0 for _ in range(4)] for _ in range(m)] for _ in range(n)]
dp[0][0][1] = g[0][0]
for i in range(n):
	for j in range(m):
		if i > 0:
			for k in range(4):
				dp[i][j][0] = max(dp[i][j][0], dp[i-1][j][k])
		if j > 0:
			dp[i][j][0] = max(dp[i][j][0], dp[i][j-1][0])
			for k in range(1, 4):
				dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k])
		if g[i][j] > 0:
			if i > 0 and j == 0:
				dp[i][0][1] = max(dp[i][0][1], max(dp[i-1][0]) + g[i][j])
			elif j > 0:
				for k in range(1, 4):
					dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + g[i][j])
				if i > 0:
					dp[i][j][1] = max(dp[i][j][1], max(dp[i-1][j]) + g[i][j])

print(max(dp[n-1][m-1]))

### FIXED CODE ###

import sys
def input():
	return sys.stdin.buffer.readline()[:-1]

n, m, q = map(int, input().split())
g = [[0 for _ in range(m)] for _ in range(n)]
for _ in range(q):
	r, c, v = list(map(int, input().split()))
	g[r-1][c-1] = v

pre = [0 for _ in range(m)]
dp = [[0 for _ in range(4)] for _ in range(m)]
dp[0][1] = g[0][0]
for i in range(n):
	for j in range(m):
		dp[j][0] = max(dp[j][0], pre[j])
		if j > 0:
			dp[j][0] = max(dp[j][0], dp[j-1][0])
			for k in range(1, 4):
				dp[j][k] = max(dp[j][k], dp[j-1][k])
				dp[j][k] = max(dp[j][k], dp[j-1][k-1] + g[i][j])
			if i > 0:
				dp[j][1] = max(dp[j][1], pre[j] + g[i][j])
		else:
			dp[0][1] = max(dp[0][1], pre[0] + g[i][j])
	pre = [max(dp[j]) for j in range(m)]
	dp = [[0 for _ in range(4)] for _ in range(m)]

print(pre[-1])
### BUGGY CODE ###

import sys
from collections import deque
from collections import defaultdict
import math
input = sys.stdin.readline
sys.setrecursionlimit(20000000)
h,w = map(int,input().split())
s = []
for i in range(h):
        a = [i for i in input().rstrip()]
        s.append(a)
x = [[[0,0,0,0]for i in range(w)] for j in range(h)]
for i in range(h):
        for j in range(w):
                if s[i][j] == "." and 0<j and s[i][j-1] == ".":
                        x[i][j][0] = x[i][j-1][0] +1

for i in range(h):
        for j in range(w-1,-1,-1):
                if s[i][j] == "." and w-1>j and s[i][j+1] == ".":
                        x[i][j][1] = x[i][j+1][1] +1

for i in range(w):
        for j in range(h-1,-1,-1):
                if s[j][i] == "." and h-1>j and s[j+1][i] == ".":
                        x[j][i][2] = x[j+1][i][2] +1
ans = 0
for i in range(w):
        for j in range(h):
                if s[j][i] == "." and 0<j and s[j-1][i] == ".":
                        x[j][i][3] = x[j-1][i][3] +1
                if s[j][i] == ".":
                        ans = max(ans,sum(x[j][i])+1)                   
print(ans)

### FIXED CODE ###

import sys
from collections import deque
from collections import defaultdict
import math
input = sys.stdin.readline
sys.setrecursionlimit(20000000)
h,w = map(int,input().split())
s = []
for i in range(h):
        a = [i for i in input().rstrip()]
        s.append(a)
ans = [[1]*w for i in range(h)]
res = 0
for i in range(h):
        res = 0
        for j in range(w):
                if s[i][j] == "." and 0<j and s[i][j-1] == ".":
                        res = res +1
                if s[i][j] == ".":
                        ans[i][j] += res
                else:
                        res = 0

res = 0
for i in range(h):
        res = 0
        for j in range(w-1,-1,-1):
                if s[i][j] == "." and w-1>j and s[i][j+1] == ".":
                        res = res +1
                if s[i][j] == ".":
                        ans[i][j] += res
                else:
                        res = 0
res = 0
for i in range(w):
        res = 0
        for j in range(h-1,-1,-1):
                if s[j][i] == "." and h-1>j and s[j+1][i] == ".":
                        res = res+1
                if s[j][i] == ".":
                        ans[j][i] += res
                else:
                        res = 0
res = 0
for i in range(w):
        res = 0
        for j in range(h):
                if s[j][i] == "." and 0<j and s[j-1][i] == ".":
                        res = res +1
                if s[j][i] == ".":
                        ans[j][i] += res           
                else:
                        res = 0  
ans2 = 0
for i in range(h):
        for j in range(w):
                ans2 = max(ans2,ans[i][j])
print(ans2)
### BUGGY CODE ###

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

for i in range(n + 1):
    for j in range(m + 1):
        s = sum(a[:i]) + sum(b[:j])
        if k >= sum(a[:i]) + sum(b[:j]):
            ans = max(ans, i + j)
        else:
            break

print(ans)

### FIXED CODE ###

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

A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0

a = [0]
b = [0]

for i in range(n):
    a.append(a[i] + A[i])

for i in range(m):
    b.append(b[i] + B[i])

j = m

for i in range(n + 1):
    if a[i] > k:
        break
    while a[i] + b[j] > k:
        j -= 1
    else:
        ans = max(ans, i + j)
print(ans)
### BUGGY CODE ###

H,W=map(int,input().split())

A=[list(map(int,input().split())) for _ in range(H)]
B=[list(map(int,input().split())) for _ in range(H)]
num=0
for i in range(H):
  for j in range(W):
    num=max(num,abs(A[i][j]-B[i][j]))
num*=H+W
num+=1
    
#dp[i][j]=マス(i,j)における可能なポイントのリスト
dp=[[[False]*(num) for _ in range(W)] for _ in range(H)]
dp[0][0][0]=True

for i in range(W+H-1):
  I,J=0,0
  if i < H:
    I=i
    J=0
  else:
    I=H-1
    J=i-H+1
  while I>=0 and J<W:
    sa = abs(A[I][J] - B[I][J])
    for n in range(num):
      if not dp[I][J][n]:
        continue
      if I!=H-1:
        dp[I+1][J][n+sa]=True
        dp[I+1][J][abs(n-sa)]=True
      if J!=W-1:
        dp[I][J+1][n+sa]=True
        dp[I][J+1][abs(n-sa)]=True
    I-=1
    J+=1

sa = abs(A[H-1][W-1] - B[H-1][W-1])
ans=float("inf")
for n in range(num):
  if not dp[-1][-1][n]:
    continue
  ans = min(ans,abs(n-sa),n+sa)
print(ans)

### FIXED CODE ###

H,W=map(int,input().split())

A=[list(map(int,input().split())) for _ in range(H)]
B=[list(map(int,input().split())) for _ in range(H)]

#dp[i][j]=マス(i,j)における可能なポイントのリスト
dp=[[set() for _ in range(W)] for _ in range(H)]
dp[0][0].add(0)

for i in range(W+H-1):
  I,J=0,0
  if i < H:
    I=i
    J=0
  else:
    I=H-1
    J=i-H+1
  while I>=0 and J<W:
    sa = abs(A[I][J] - B[I][J])
    for point in dp[I][J]:
      if I!=H-1:
        dp[I+1][J].add(point+sa)
        dp[I+1][J].add(abs(point-sa))
      if J!=W-1:
        dp[I][J+1].add(point+sa)
        dp[I][J+1].add(abs(point-sa))
    I-=1
    J+=1

ans=dp[H-1][W-1]
sa = abs(A[H-1][W-1] - B[H-1][W-1])
res=float("inf")
for p in ans:
  res=min(res,abs(p+sa),abs(p-sa))
print(res)
### BUGGY CODE ###

from collections import Counter
H, W, M = [int(i) for i in input().split()]
g = [0] * M
h = [0] * M
w = [0] * M
for i in range(M):
    h[i], w[i] = [int(j) for j in input().split()]
    g[i] = [h[i],w[i]]

ch = Counter(h)
cw = Counter(w)

hi = [i for i in ch.keys() if ch[i] == max(ch.values())]
wi = [i for i in cw.keys() if cw[i] == max(cw.values())]

for i in hi:
    for j in wi:
        if [i,j] not in g:
            print(ch[i] + cw[j])
            exit()
print(ch[hi[0]] + cw[wi[0]] - 1)

### FIXED CODE ###

from collections import Counter
H, W, M = [int(i) for i in input().split()]
g = set()
h = [0] * M
w = [0] * M
for i in range(M):
    h[i], w[i] = [int(j) for j in input().split()]
    g.add((h[i],w[i]))

ch = Counter(h)
cw = Counter(w)

chm = max(ch.values())
cwm = max(cw.values())
hi = [i for i in ch.keys() if ch[i] == chm]
wi = [i for i in cw.keys() if cw[i] == cwm]

for i in hi:
    for j in wi:
        if (i,j) not in g:
            print(ch[i] + cw[j])
            exit()
print(ch[hi[0]] + cw[wi[0]] - 1)
### BUGGY CODE ###

from sys import stdin
from itertools import accumulate
from itertools import permutations

n = int(stdin.readline().rstrip())
li = [int(stdin.readline().rstrip()) for _ in range(n)]

lin = list(permutations(li))

ma = 0

for i in lin:
    i = list(i)
    lis = list(accumulate(i))[::-1]
    for i in lis:
        if i % 10 == 0:
            continue
        ma = max(ma,i)
print(ma)

### FIXED CODE ###

from sys import stdin
from itertools import accumulate

n = int(stdin.readline().rstrip())
li = [int(stdin.readline().rstrip()) for _ in range(n)]
li.sort()
lin = list(accumulate(li))
if lin[-1] %10 != 0:
    print(lin[-1])
    exit()
else:
    for i in li:
        if i % 10 == 0:
            continue
        print(lin[-1]-i)
        exit()
print(0)
### BUGGY CODE ###

n = int(input())
A = list(map(int,input().split()))
B = []
for a in A:
    B.append(a)
    B = B[::-1]
print(*B,sep=" ")


### FIXED CODE ###

n = int(input())
A = list(map(int,input().split()))
answer = A[1::2][::-1]+A[::2]
if n%2==1:
    answer=answer[::-1]
print(*answer)
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline
import numpy as np

def main():
    N,M = map(int,input().split())
    INF = 10**7
    k = []
    for _ in range(M):
        a,b = map(int,input().split())
        c = list(map(int,input().split()))
        bit = 0
        for i in c:
            bit += 2**(i-1)
        k.append((a,bit))
    dp = np.full((M+1,1<<N),INF, dtype=np.int64)
    dp[0][0] = 0
    for i in range(M):
        a,bit = k[i]
        for j in range(1<<N):
            dp[i+1][j] = min(dp[i][j],dp[i+1][j])
            dp[i+1][j|bit] = min(dp[i+1][j|bit],dp[i][j|bit],dp[i][j]+a)
    
    print(dp[-1][-1] if dp[-1][-1] != INF else -1)
if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

def main():
    N,M = map(int,input().split())
    INF = 10**7
    k = []
    for _ in range(M):
        a,b = map(int,input().split())
        c = list(map(int,input().split()))
        bit = 0
        for i in c:
            bit += 2**(i-1)
        k.append((a,bit))
    dp = [INF for _ in range(1<<N)]
    dp[0] = 0
    for i in range(M):
        a,bit = k[i]
        for j in range(1<<N):
            af = bit|j
            dp[af] = min(dp[af],dp[j]+a)
            
    print(dp[-1] if dp[-1] != INF else -1)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import math

MOD = 10**9+7


def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0


def modinv(a):
    g, x, y = xgcd(a, MOD)
    return x % MOD


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


def calc(h, w):
    h -= 1
    w -= 1
    return (fact[h+w]*modinv(fact[h]) % MOD)*modinv(fact[w]) % MOD


h, w, a, b = map(int, input().split())
if a <= h // 2:
    ans = 0
    for i in range(1, h - a + 1):
        ans += calc(i, b) * calc(h + 1 - i, w - b) % MOD
        if ans >= MOD:
            ans -= MOD
    print(ans)

else:
    ans = calc(h, w)
    for i in range(h-a+1, h + 1):
        ans -= calc(i, b) * calc(h + 1 - i, w - b) % MOD
        if ans < 0:
            ans += MOD
    print(ans)


### FIXED CODE ###

import math

MOD = 10**9+7


def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0


def modinv(a):
    g, x, y = xgcd(a, MOD)
    return x % MOD


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


def calc(h, w):
    h -= 1
    w -= 1
    return (fact[h+w]*modinv(fact[h]) % MOD)*modinv(fact[w]) % MOD


h, w, a, b = map(int, input().split())
if a >= h // 2:
    ans = 0
    for i in range(1, h - a + 1):
        ans += calc(i, b) * calc(h + 1 - i, w - b) % MOD
        if ans >= MOD:
            ans -= MOD
    print(ans)

else:
    ans = calc(h, w)
    for i in range(h-a+1, h + 1):
        ans -= calc(i, b) * calc(h + 1 - i, w - b) % MOD
        if ans < 0:
            ans += MOD
    print(ans)
### BUGGY CODE ###

import numpy as np
from scipy.sparse.csgraph import breadth_first_tree
from scipy.sparse import csr_matrix
N, M = map(int,input().split())
l = [[0]*(N) for _ in range(N)]
for i in range(M):
    A, B = map(int,input().split())
    l[A-1][B-1] = 1
    l[B-1][A-1] = 1

csr = csr_matrix(l)
Tcsr = breadth_first_tree(csr, 0, False)

if int(np.sum(Tcsr)) != N-1:
    print("No")
else:
    print("Yes")
    for i in range(1, N):
        print(np.dot(Tcsr.toarray().T.astype(int), np.arange(N)+1)[i])

### FIXED CODE ###

from scipy.sparse.csgraph import breadth_first_tree, breadth_first_order
from scipy.sparse import csr_matrix, coo_matrix
N, M = map(int,input().split())
A = []
B = []
for i in range(M):
    a, b = map(int,input().split())
    a -= 1
    b -= 1
    A.append(a)
    B.append(b)
D = [1] * M
csr = coo_matrix((D, (A, B)), (N, N)).tocsr()
Tcsr = breadth_first_order(csr, 0, False, True)
ans = []
for i in Tcsr[1][1:]+1:
    if i == -9998:
        print("No")
        quit()
    ans.append(i)
print("Yes")
for i in ans:
    print(i)
### BUGGY CODE ###

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

ans = 0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if x + y + z == S:
                ans += 1

print(ans)

### FIXED CODE ###

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

ans = 0
for x in range(K+1):
    for y in range(K+1):
            z = S - x - y
            if K >= S - x - y and z >= 0:
                ans += 1

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

def main():
  from collections import deque
  s,*c=open(0)
  h,w=map(int,s.split())
  c=''.join(t[:w]for t in c)
  f=[1]*h*w
  q=deque()
  for i in range(h*w):
    if c[i]=='#':
      q.append((i//w,i%w,0))
      f[i]=0
  while q:
    y,x,v=q.popleft()
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
      if h>i>=0<=j<w and'.'==c[i*w+j]*f[i*w+j]:
        f[i*w+j]=0
        q.append((i,j,v+1))
  print(v)
if __name__=='__main__':
  main()

### FIXED CODE ###

from collections import*
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=deque()
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            q.append((i,j,0))
ans=0
while q:
    y,x,v=q.popleft()
    ans=max(ans,v)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
        if h>i>=0 and w>j>=0 and c[i][j]=='.':
            c[i][j]='#'
            q.append((i,j,v+1))
print(ans)
### BUGGY CODE ###

N = int(input())
arr = list(map(int, input().split()))
tmp = [0]*(max(arr)+1)
for i in arr:
    tmp[i] += 1
ans = 0
for i in range(N):
    if tmp[arr[i]] >= 2:
        continue
    flg = True
    for k in range(1,int(arr[i]**0.5)+1):
        if arr[i] % k == 0:
            if tmp[k] != 0 and arr[i] != k:
                flg = False
                break
            if k != arr[i] // k:
                if tmp[arr[i] // k] != 0 and arr[i] // k != arr[i]:
                    flg = False
                    break
    if flg:
        ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
arr = list(map(int, input().split()))
arr.sort()
ma = max(arr)
check = [True]*(ma+1)
cnt = [0]*(ma+1)
for i in arr:
    cnt[i] += 1
ans = 0
for i in arr:
    if not check[i]:
        continue
    for k in range(i,ma+1,i):
        check[k] = False
    if cnt[i] <= 1:
        ans += 1
print(ans)
### BUGGY CODE ###

N = int(input())
T = []
L = []
for i in range(0,N):
    S = str(input())
    L.append(S)

T.append([L[0],1])  
for i in range(1,N):
    for j in range(0,len(T)):
        if L[i] == T[j][0]:
            T[j][1] += 1
            break
        elif j == len(T)-1:
            T.append([L[i],1])

Max = 0
for i in range(0,len(T)):
    if T[i][1] > Max:
        Max = T[i][1]

ans = []
for i in range(0,len(T)):
    if T[i][1] == Max:
        ans.append(T[i][0])

ans = sorted(ans)

for i in range(0,len(ans)):
    print(ans[i])

### FIXED CODE ###

N = int(input())
T = []
L = []
for i in range(0,N):
    S = str(input())
    L.append(S)

L = sorted(L)
k = 0
T.append([L[0],1])  
for i in range(1,N):
    for j in range(k,len(T)):
        if L[i] == T[j][0]:
            T[j][1] += 1
        else:
            k = j + 1
            T.append([L[i],1])
            break

Max = 0
for i in range(0,len(T)):
    if T[i][1] > Max:
        Max = T[i][1]

ans = []
for i in range(0,len(T)):
    if T[i][1] == Max:
        ans.append(T[i][0])

ans = sorted(ans)

for i in range(0,len(ans)):
    print(ans[i])
### BUGGY CODE ###

n, y = list(map(int, input().split()))
ans = 0

for i in range(0, n+1):
    a1 = 10000 * i
    for j in range(0, n+1):
        a2 = 5000 * j
        for k in range(0, n+1):
            a3 = 1000 * k
            if a1 + a2 + a3  == y and i + j + k == n:
                print(i, j , k)
                ans += 1
                break
    if ans == 1:
        break
if ans == 0:
    print(-1, -1, -1)

### FIXED CODE ###

n, y = list(map(int, input().split()))
ans = 0

for i in range(n+1):
    a1 = 10000 * i
    for j in range(n+1-i):
        a2 = 5000 * j
        k = n- (i+j)
        a3 = k*1000
        if a1 + a2 + a3  == y and i + j + k == n:
            print(i, j , k)
            ans += 1
            exit(0)
    if ans == 1:
        break
if ans == 0:
    print(-1, -1, -1)
### BUGGY CODE ###

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

DP = [-1 for i in range(max(A)+1)]

A.sort()

for a in A:
  if DP[a] != 0:
    if DP[a] == 1:
      DP[a] = 0
      continue
    for i in range(2*a, max(A)+1, a):
      DP[i] = 0
    DP[a] = 1
  
    
ans = 0
for i in DP:
  if i == 1:
    ans += 1
    
print(ans)

### FIXED CODE ###

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

A.sort()
maxA = A[-1]
DP = [-1 for i in range(maxA+1)]
for a in A:
  if DP[a] != 0:
    if DP[a] == 1:
      DP[a] = 0
      continue
    for i in range(2*a, maxA+1, a):
      DP[i] = 0
    DP[a] = 1
  
    
ans = 0
for i in DP:
  if i == 1:
    ans += 1
    
print(ans)
### BUGGY CODE ###

s = input()

n = len(s)
mod = 10**9+7

dp = [[0]*13 for i in range(n+1)]
dp[0][0]=1

for i in range(n):
    if s[-1-i]=='?':
        p = [(x*10**i)%13 for x in range(0,10)]
    else:
        p = [(int(s[-1-i])*10**i)%13]
    for j in range(13):
        for x in p:
            dp[i+1][(j+x)%13] += dp[i][j]
    for j in range(13):
        dp[i+1][j]%=mod

print(dp[-1][5])


### FIXED CODE ###

s = input()

n = len(s)
mod = 10**9+7

dp = [[0]*13 for i in range(n+1)]
dp[0][0]=1

for i in range(n):
    if s[-1-i]=='?':
        p = [x*pow(10,i,13) for x in range(0,10)]
    else:
        p = [int(s[-1-i])*pow(10,i,13)]
    for j in range(13):
        for x in p:
            dp[i+1][(j+x)%13] += dp[i][j]
    for j in range(13):
        dp[i+1][j]%=mod

print(dp[-1][5])
### BUGGY CODE ###

n = int(input())
a = list(map(lambda x:format(int(x), '060b') , input().split()))
n1 = [0]*60
for i in a:
  for j in range(60):
    if i[59-j]=='1':
      n1[j] += 1
ans = 0
for i in range(60):
  ans += n1[i]*(n-n1[i])*2**i
  ans %= 10**9+7
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(60):
  tmp = sum([1 for j in a if (j>>i)&1])
  ans += tmp*(n-tmp)*(2**i)
  ans %= 10**9+7
print(ans)
### BUGGY CODE ###

N = int(input())

M = 0

for i in range(1, N+1):
    M += i

M = M - N

print(M)

### FIXED CODE ###

N = int(input())

M = 0

M = N * (N-1) // 2


print(int(M))
### BUGGY CODE ###

import numpy as np


def read_input(trans=int):
    return list(map(trans, input().split()))


N, K = read_input()
A = np.array(read_input(), dtype="int")
coordinate = np.arange(1, N+1)

for _ in range(K):
    B = np.zeros(N, dtype="int")
    for i in range(N):
        end = np.minimum(coordinate[i]+A[i], N)
        start = np.maximum(coordinate[i]-A[i], 1)

        B[start-1:end] += 1

    A = B

print(" ".join(map(str, A.tolist())))


### FIXED CODE ###

def read_input(trans=int):
    return list(map(trans, input().split()))


N, K = read_input()
A = read_input()
K = min(K, 41)

for _ in range(K):
    B = [0]*N
    for i in range(N):
        start = max(i-A[i], 0)
        end = min(i+A[i], N-1)

        B[start] += 1
        if end+1 < N:
            B[end+1] -= 1
    for i in range(1, N):
        B[i] += B[i-1]
    A = B.copy()


print(" ".join(map(str, A)))