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

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

g = 1
grade = []
for i in range(n):
    g *= a[i]
    if i+1 > k:
        g /= a[i-k]
    grade.append(int(g))

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

### FIXED CODE ###

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

for i in range(n):
    if i+1 > k:
        if a[i-k] < a[i]:
            print('Yes')
        else:
            print('No')
### BUGGY CODE ###

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

res = 0
for i in range(N):
    for j in range(i+1, N):
        _i = i
        _j = j
        while True:
            if S[_i] == S[_j]:
                _i += 1
                _j += 1
                if _i == j or _j == N:
                    break
            else:
                break
        _i -= 1
        _j -= 1
        res = max(res, _i-i+1)

print(res)


### FIXED CODE ###

N = int(input())
S = input()
 
def zal(s):
    i = 1
    j = 0
    _N = len(s)
    Z = [0]*_N
    Z[0] = _N
    res = 0
    while i < _N:
        while i + j < _N and s[j] == s[i+j]:
            j += 1
        Z[i] = j
 
        if Z[i] <= i:
            res = max(res, Z[i])
 
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < _N and k + Z[k] < j:
            Z[i+k] = Z[k]
 
            if Z[i+k] <= i+k:
                res = max(res, Z[i+k])
 
            k += 1
        i += k
        j -= k
    return res
 
ans = 0
for i in range(N):
    _S = S[i:]
    res = zal(_S)
    ans = max(ans, res)
print(ans)
### BUGGY CODE ###

N, M = map(int, raw_input().split())
A = map(int, raw_input().split())

AX = [0]
s = 0
for a in A:
    s += a
    AX.append(s)

result = 0
for i in range(1, N+1):
    for j in range(i, N+1):
        if (AX[j] - AX[i-1]) % M == 0:
            result += 1
print(result)


### FIXED CODE ###

N, M = map(int, raw_input().split())
A = map(int, raw_input().split())

AX = []
s = 0
for a in A:
    s += a
    AX.append(s)

B = {}
B[0] = 1
for i in range(N):
    e = AX[i] % M
    if e not in B:
        B[e] = 1
    else:
        B[e] += 1

res = 0
for _,v in B.items():
    res += v * (v-1) / 2

print(res)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
def main():
   K = int(input())
   CNT = 0
   for i in range(1, K+1):
       for j in range(1, K+1):
           A = gcd(i, j)
           for k in range(1, K+1):
               CNT += gcd(A, k)
   print(CNT)

def gcd(p, q):
    if p%q == 0:
        return q
    return gcd(q, p%q)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import math
from functools import reduce
K = int(input())
CNT= 0
def gcd(*numbers):
    return reduce(math.gcd, numbers)
for i in range(1,K+1):
    for j in range(1,K+1):
        GCD = gcd(i,j)
        if GCD == 1:
            CNT += K
        else:
            for k in range(1, K+1):
                if gcd(GCD,k) != 1:
                    CNT += gcd(GCD,k)
                else:
                    CNT += 1
print(CNT)
### BUGGY CODE ###

N = int(input())
H = list(map(int, input().split(" ")))
M = 0
m = 0

for i in range(len(H) - 1):
    m = 0
    for j in range(i, len(H) - 1):
        if (H[j] >= H[j+1]):
            m = m + 1
        else:
            break
    M = max(M, m)
print(M)

### FIXED CODE ###

N = int(input())
H = list(map(int, input().split(" ")))
M = 0
i = 0

while i < (N - 1):
    m = 0
    j = i
    if (M > N - i):
        break
    while j < (N - 1):
        if H[j] >= H[j+1]:
            m = m + 1
            j = j + 1
        else:
            break
    M = max(M, m)
    i = j + 1

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

h, w = map(int, input().split())
map_list = []
max_value = h + w
value_list = []
for _ in range(h):
    map_list.append(list(input()))
    value_list.append([max_value] * w)
for y in range(h):
    for x in range(w):
        if map_list[y][x] == "#":
            value_list[y][x] = 0
for y in range(1, h):
    for x in range(w):
        value_list[y][x] = min(value_list[y-1][x]+1, value_list[y][x])
for x in range(1, w):
    for y in range(h):
        value_list[y][x] = min(value_list[y][x-1]+1, value_list[y][x])
for y in range(h-2, -1, -1):
    for x in range(w-1, -1, -1):
        value_list[y][x] = min(value_list[y+1][x]+1, value_list[y][x])
for x in range(w-2, -1, -1):
    for y in range(h-1, -1, -1):
        value_list[y][x] = min(value_list[y][x+1]+1, value_list[y][x])
print(max([max(v) for v in value_list]))

### FIXED CODE ###

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

H,W = map(int,input().split())
INF = 10**18
q = []

visited = [[True]*(W+2)]
visited += [[True] + [x == '#' for x in input().rstrip()] + [True] for _ in range(H)]
visited.append([True]*(W+2))
for i in range(1,H+1):
  for j in range(1,W+1):
    if visited[i][j]:
      q.append((i,j))

moves = [(0,1),(0,-1),(1,0),(-1,0)] #全方向調べる

ans = -1
while q:
  qq = []
  ans += 1
  for x,y in q:
    if not visited[x-1][y]:
      visited[x-1][y] = True
      qq.append((x-1,y))
    if not visited[x+1][y]:
      visited[x+1][y] = True
      qq.append((x+1,y))
    if not visited[x][y-1]:
      visited[x][y-1] = True
      qq.append((x,y-1))
    if not visited[x][y+1]:
      visited[x][y+1] = True
      qq.append((x,y+1))
  q = qq
  
print(ans)
### BUGGY CODE ###

import copy


def insertion(n, x):
    if not x:
        return True
    for i in range(n - 1, -1, -1):
        y = copy.copy(x)
        if y[i] == i + 1:
            y.pop(i)
            ope.insert(0, i + 1)
            if insertion(n - 1, y):
                return True
            else:
                ope.pop(0)
    return False


n = int(input())
b = list(map(int, input().split()))
ope = []
if insertion(n, b):
    for i in ope:
        print(i)
else:
    print(-1)


### FIXED CODE ###

import sys


n = int(input())
b = list(map(int, input().split()))
ope = []
i = n
while i > 0:
    flag = 0
    j = i
    while j > 0:
        if b[j - 1] == j:
            b.pop(j - 1)
            i -= 1
            ope.insert(0, j)
            flag = 1
            break
        j -= 1
    if flag == 0:
        print(-1)
        sys.exit()
for i in ope:
    print(i)
### BUGGY CODE ###

from heapq import heappop, heappush


def main():
    N, M, S = map(int, input().split())
    adj = [{} for _ in range(N)]
    amax = 0
    for _ in range(M):
        u, v, a, b = map(int, input().split())
        adj[u-1][v-1] = (a, b)
        adj[v-1][u-1] = (a, b)
        amax = max(amax, a)
    C = [0] * N
    D = [0] * N
    for i in range(N):
        C[i], D[i] = map(int, input().split())
    MAX = amax * N
    dp = [[float("inf")] * (MAX+1) for _ in range(N)]
    q = [(0, min(S, MAX), 0, -1)]
    ans = [None] * N
    remain = N
    while len(q) and remain:
        time, coin, cur, prev = heappop(q)
        if dp[cur][coin] <= time:
            continue
        if ans[cur] is None:
            ans[cur] = time
            remain -= 1
        dp[cur][coin] = time
        if coin < MAX:
            heappush(q, (time + D[cur], min(coin + C[cur], MAX), cur, cur))
        for nxt in adj[cur]:
            dcost, dtime = adj[cur][nxt]
            if nxt != prev and dcost <= coin:
                heappush(q, (time + dtime, coin - dcost, nxt, cur))
    for i in range(1, N):
        print(ans[i])


if __name__ == "__main__":
    main()


### FIXED CODE ###

from heapq import heappop, heappush


def main():
    N, M, S = map(int, input().split())
    adj = [{} for _ in range(N)]
    amax = 0
    for _ in range(M):
        u, v, a, b = map(int, input().split())
        adj[u-1][v-1] = (a, b)
        adj[v-1][u-1] = (a, b)
        amax = max(amax, a)
    C = [0] * N
    D = [0] * N
    for i in range(N):
        C[i], D[i] = map(int, input().split())
    MAX = amax * N
    dp = [[float("inf")] * (MAX+1) for _ in range(N)]
    q = [[0, min(S, MAX), 0, -1]]
    ans = [None] * N
    remain = N
    while len(q) and remain:
        time, coin, cur, prev = heappop(q)
        if dp[cur][coin] <= time:
            continue
        if ans[cur] is None:
            ans[cur] = time
            remain -= 1
        dp[cur][coin] = time
        if coin < MAX:
            heappush(q, [time + D[cur], min(coin + C[cur], MAX), cur, cur])
        for nxt in adj[cur]:
            dcost, dtime = adj[cur][nxt]
            if nxt != prev and dcost <= coin:
                heappush(q, [time + dtime, coin - dcost, nxt, cur])
    for i in range(1, N):
        print(ans[i])


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

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

### FIXED CODE ###

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

r, c, k = map(int, input().split())
rcv = [list(map(int, input().split())) for i in range(k)]

area = [[0] * (c+1) for i in range(r+1)]
for a, b, v in rcv:
    area[a-1][b-1] = v

# dp[i][j][k]: その行でiまで拾っており、
# j行k列目に到達時点の最大スコア
dp = [[[-1] * (c+1) for i in range(r+1)] for j in range(4)]
dp[0][0][0] = 0

for rr in range(r+1):
    for cc in range(c+1):
        for i in range(4):
            # 取って右
            if i+1<4 and cc<c and area[rr][cc]>0:
                dp[i+1][rr][cc+1] = max(dp[i+1][rr][cc+1],
                                        dp[i][rr][cc]+area[rr][cc])
            # 取って下
            if i+1<4 and rr<r and area[rr][cc]>0:
                dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc]+area[rr][cc])
            # 取らずに右
            if cc<c:
                dp[i][rr][cc+1] = max(dp[i][rr][cc+1],
                                      dp[i][rr][cc])
            # 取らずに下
            if rr<r:
                dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc])
# ans: r行c列目の最大値（iは問わず）
ans = max([dp[i][r][c] for i in range(4)])
print(ans)





### FIXED CODE ###

r, c, k = map(int, input().split())
rcv = [list(map(int, input().split())) for i in range(k)]

area = [[0] * (c+1) for i in range(r+1)]
for a, b, v in rcv:
    area[a-1][b-1] = v

# dp[i][j][k]: その行でiまで拾っており、
# j行k列目に到達時点の最大スコア
dp = [[[-1] * (c+1) for i in range(r+1)] for j in range(4)]
dp[0][0][0] = 0

for rr in range(r+1):
    for cc in range(c+1):
        for i in range(4):
            # 取って右
            if i+1<4 and cc<c and area[rr][cc]>0:
                dp[i+1][rr][cc+1] = max(dp[i+1][rr][cc+1],
                                        dp[i][rr][cc]+area[rr][cc])
            # 取って下
            if i+1<4 and rr<r and area[rr][cc]>0:
                dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc]+area[rr][cc])
            # 取らずに右
            if cc<c:
                dp[i][rr][cc+1] = max(dp[i][rr][cc+1],
                                      dp[i][rr][cc])
            # 取らずに下
            if rr<r:
                dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc])
# ans: r行c列目の最大値（iは問わず）
ans = max([dp[i][r][c] for i in range(4)])
print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
max_ans = 0
ans_op = []
if A[0] < 0 and A[-1] < 0:
    al = A.pop(-1)
    ar = A.pop(-1)
    tmp = al - ar
    ans_op.append([al, ar])
    A.append(tmp)
    N -= 1
elif A[0] > 0 and A[-1] > 0:
    al = A.pop(0)
    ar = A.pop(1)
    tmp = al - ar
    ans_op.append([al, ar])
    A.insert(0, tmp)
    N -= 1
for i in range(N-1):
    if A[-2] <= 0:
        al = A.pop(-1)
        ar = A.pop(-1)
        tmp = al - ar
        ans_op.append([al, ar])
        A.append(tmp)
    else:
        al = A.pop(0)
        ar = A.pop(-1)
        tmp = al - ar
        ans_op.append([al, ar])
        A.insert(0, tmp)

print(A[0])
for op in ans_op:
    print(op[0], op[1])


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
max_ans = 0
ans_op = []
if A[0] < 0 and A[-1] < 0:
    al = A.pop(-1)
    ar = A.pop(-1)
    tmp = al - ar
    ans_op.append([al, ar])
    A.append(tmp)
    N -= 1
elif A[0] > 0 and A[-1] > 0:
    al = A.pop(0)
    ar = A.pop(0)
    tmp = al - ar
    ans_op.append([al, ar])
    A.insert(0, tmp)
    N -= 1
tmp = A.pop(-1)
if N >= 2:
    tmpl = A.pop(0)
else:
    tmpl = 0
    
for i in range(N-2):
    if A[-1] <= 0:
        ar = A.pop(-1)
        ans_op.append([tmp, ar])
        tmp = tmp - ar
    else:
        ans_op.append([tmpl, tmp])
        tmpl = tmpl - tmp
        tmp = A.pop(-1)
        # A.insert(0, tmp)
ans_op.append([tmp, tmpl])
print(tmp-tmpl)
for op in ans_op:
    print(op[0], op[1])
### BUGGY CODE ###

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

result = []
for i in range(n-2):
    for j in range(i+1,n-1):
        tem = "".join(set(s[j+1:]))
        for k in range(len(tem)):
            result.append(s[i]+s[j]+tem[k])

ans = set(result)
print(len(ans))

### FIXED CODE ###

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

dp = [[0]*10 for _ in range(10)]

count = [0]*10

result = []

for i in range(n-2):
    if count[int(s[i])]==0:
        for j in range(i+1,n-1):
            if dp[int(s[i])][int(s[j])]==0:
                tem = "".join(set(s[j+1:]))
                for k in range(len(tem)):
                    result.append(s[i]+s[j]+tem[k])
                dp[int(s[i])][int(s[j])]=1
        count[int(s[i])]=1

ans = set(result)
print(len(ans))
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
diff_ls = []
old_x = 0

for i in a:
    diff = 0
    ls = a.copy()
    ls.remove(i)
    ls.append(0)
    for index, x in enumerate(ls):
        diff += abs(x - old_x)
        old_x = x
    diff_ls.append(diff)

print(*diff_ls, sep="\n")


### FIXED CODE ###

from collections import deque

n = int(input())
a = deque(map(int, input().split()))
a.appendleft(0)
a.append(0)

sum = sum([abs(a[i + 1] - a[i]) for i in range(len(a) - 1)])
ans = 0

for i in range(n):
    ans = sum
    ans = ans - abs(a[i + 1] - a[i]) - abs(a[i + 2] - a[i + 1]) + abs(a[i + 2] - a[i])
    print(ans)
### BUGGY CODE ###


def main():
#    with open("input.txt", "r") as f:
#        t = f.readlines()
#        N = int(t[0].split()[0])
#        K = int(t[0].split()[1])
#        h = t[1].split()
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
#    print(h)
#    print(len(h))
    dp = [10**9] * max(N,K)
    dp[0] = 0

    for i in range(N):
#        j = 0
        L = min(K, i)
        m = []
        for j in range(L+1):
            m.append(dp[i-j] + abs(h[i]-h[i-j]))
        dp[i] = min(m)
#        while j <= L:
#            #print(i)
#            if dp[i] > dp[i-j] + abs(h[i]-h[i-j]):
#                dp[i] = dp[i-j] + abs(h[i]-h[i-j])
#            j += 1
    print(dp[N-1])

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N, K  = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9] * N
    dp[0] = 0

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

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

from bisect import bisect
from time import time

st_time = time()
N = int(input())
src = list(map(int,input().split()))

cums = [0]
for a in src:
    cums.append(cums[-1] + a)

ans = cums[-1] * 999
c = bisect(cums, cums[-1]//2)
d = 1
while time() - st_time < 1.85:
    if abs(d) >= N: break
    if 2 <= c <= N-2:
        b1 = bisect(cums[:c], cums[c]//2)
        b2 = bisect(cums[c:], (cums[c]+cums[-1])//2) + c
        pq_cands = []
        for i in (b1,b1-1):
            if not 0 < i < c: continue
            p = cums[i]
            q = cums[c] - cums[i]
            pq_cands.append((p,q))
        rs_cands = []
        for i in (b2,b2-1):
            if not c < i < N: continue
            r = cums[i] - cums[c]
            s = cums[-1] - cums[i]
            rs_cands.append((r,s))
        for p,q in pq_cands:
            for r,s in rs_cands:
                mn = min(p,q,r,s)
                mx = max(p,q,r,s)
                ans = min(ans, mx-mn)
    c += d
    d = (abs(d)+1) * [1,-1][d%2]
print(ans)

### FIXED CODE ###

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

cums = [0]
for a in src:
    cums.append(cums[-1] + a)

ps = [None] * (N+1)
qs = [None] * (N+1)
rs = [None] * (N+1)
ss = [None] * (N+1)

l = 1
for r in range(2,N-1):
    p1 = cums[l]
    q1 = cums[r] - cums[l]
    d1 = abs(p1-q1)
    while l < r:
        p2 = cums[l+1]
        q2 = cums[r] - cums[l+1]
        d2 = abs(p2-q2)
        if d2 > d1: break
        l += 1
        p1,q1,d1 = p2,q2,d2
    ps[r] = p1
    qs[r] = q1

r = N-1
for l in range(N-2,1,-1):
    r1 = cums[r] - cums[l]
    s1 = cums[N] - cums[r]
    d1 = abs(r1-s1)
    while l < r:
        r2 = cums[r-1] - cums[l]
        s2 = cums[N] - cums[r-1]
        d2 = abs(r2-s2)
        if d2 > d1: break
        r -= 1
        r1,s1,d1 = r2,s2,d2
    rs[l] = r1
    ss[l] = s1

ans = cums[-1] * 999
for p,q,r,s in zip(ps,qs,rs,ss):
    if p is None: continue
    tmp = max(p,q,r,s) - min(p,q,r,s)
    ans = min(ans, tmp)
print(ans)
### BUGGY CODE ###

from scipy.misc import comb
n,m=map(int,input().split())
a=1
p=2
while m>1:
    if m%p:
        p+=1
        continue
    c=0
    while not m%p:
        m//=p
        c+=1
    a=a*comb(n+c-1,c,exact=1)%(10**9+7)
print(a)

### FIXED CODE ###

import math
import random
from scipy.misc import comb
class Prime:
    seed_primes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
    def is_prime(self,n):
        is_prime_common=self.is_prime_common(n)
        if is_prime_common is not None:return is_prime_common
        if n<2000000:return self.is_prime_brute_force(n)
        return self.is_prime_miller_rabin(n)
    def is_prime_common(self,n):
        if n==1:return False
        if n in Prime.seed_primes:return True
        if any(map(lambda x:n%x==0,self.seed_primes)):return False
    def is_prime_brute_force(self,n):
        for k in range(2,int(math.sqrt(n))+1):
            if n%k==0:return False
        return True
    def is_prime_miller_rabin(self,n):
        d=n-1
        while d&1==0:d>>=1
        witnesses=self.get_witnesses(n)
        for w in witnesses:
            y=pow(w,d,n)
            while d!=n-1and y!=1and y!=n-1:
                y=y*y%n
                d<<=1
            if y!=n-1and d&1==0:return False
        return True
    def get_witnesses(self,num):
        def _get_range(num):
            if num<2047:return 1
            if num<1373653:return 2
            if num<25326001:return 3
            if num<3215031751:return 4
            if num<2152302898747:return 5
            if num<3474749660383:return 6
            if num<341550071728321:return 7
            if num<3825123056546413051:return 9
            return 12
        return self.seed_primes[:_get_range(num)]
    def gcd(self,a,b):
        if a<b:return self.gcd(b,a)
        if b==0:return a
        while b:a,b=b,a%b
        return a
    @staticmethod
    def f(x,n,seed):
        p=Prime.seed_primes[seed%len(Prime.seed_primes)]
        return(p*x+seed)%n
    def find_factor(self,n,seed=1):
        if self.is_prime(n):return n
        x,y,d=2,2,1
        count=0
        while d==1:
            count+=1
            x=self.f(x,n,seed)
            y=self.f(self.f(y,n,seed),n,seed)
            d=self.gcd(abs(x-y),n)
        if d==n:
            return self.find_factor(n,seed+1)
        return self.find_factor(d)
    def find_factors(self,n):
        primes={}
        if self.is_prime(n):
            primes[n]=1
            return primes
        while n>1:
            factor=self.find_factor(n)
            primes.setdefault(factor,0)
            primes[factor]+=1
            n//=factor
        return primes
n,m=map(int,input().split())
a=1
for c in Prime().find_factors(m).values():
    a=a*comb(n+c-1,c,exact=1)%(10**9+7)
print(a)
### BUGGY CODE ###

def resolve():
    '''
    code here
    '''
    import collections
    import sys
    input = sys.stdin.readline

    H, W = [int(item) for item in input().split()]
    Ch, Cw = [int(item)-1 for item in input().split()]
    Dh, Dw = [int(item)-1 for item in input().split()]
    grid = [[item for item in input()] for _ in range(H)]
    max_num = 10**6
    fp = [[max_num for _ in range(W)] for _ in range(H)]
    
    que = collections.deque([[Ch, Cw, 0]])
    fp[Ch][Cw] = 0
    next_y_x = []
    for i in range(5):
        for j in range(5):
            next_y_x.append([-2 + i, -2 + j])
    next_y_x.remove([0,0])

    while que:
        temp = que.popleft()
        w_num = temp[2]

        for dy, dx in next_y_x:
            ny = temp[0] + dy
            nx = temp[1] + dx

            if 0 <= ny <= H-1 and 0 <= nx <= W-1:
                if abs(dy) + abs(dx) == 1:
                    if grid[ny][nx] == '.' and fp[ny][nx] > w_num:
                        que.appendleft([ny, nx, w_num])
                        fp[ny][nx] = w_num
                else:
                    nw = w_num +1
                    if grid[ny][nx] == '.' and fp[ny][nx] == max_num:
                        que.append([ny, nx, nw])
                        fp[ny][nx] = nw

    if fp[Dh][Dw] != max_num:
        print(fp[Dh][Dw])
    else:
        print(-1)

if __name__ == "__main__":
    resolve()


### FIXED CODE ###

def resolve():
    '''
    code here
    '''
    from collections import deque

    H, W = [int(item) for item in input().split()]
    Ch, Cw = [int(item)-1 for item in input().split()]
    Dh, Dw = [int(item)-1 for item in input().split()]
    grid = [input() for _ in range(H)]
    max_num = 10**6
    fp = [[max_num] * W for _ in range(H)]

    que = deque([[Ch, Cw, 0]])
    fp[Ch][Cw] = 0

    walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
    warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

    while que:
        y, x, w_num = que.popleft()

        for dy, dx in walk:
            ny = y + dy
            nx = x + dx

            if 0 <= ny <= H-1 and 0 <= nx <= W-1 and grid[ny][nx] == '.' and fp[ny][nx] > w_num:
                que.appendleft([ny, nx, w_num])
                fp[ny][nx] = w_num

        for dy, dx in warp:
            ny = y + dy
            nx = x + dx
            nw = w_num +1

            if 0 <= ny <= H-1 and 0 <= nx <= W-1 and grid[ny][nx] == '.' and fp[ny][nx] > nw:
                que.append([ny, nx, nw])
                fp[ny][nx] = nw

    if fp[Dh][Dw] != max_num:
        print(fp[Dh][Dw])
    else:
        print(-1)

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

A, B, K = [int(i) for i in input().split()]

for i in range(K):
    if A > 0:
        A = A - 1
    elif B > 0:
        B = B - 1
    else:
        break

print('{} {}'.format(A,B))

### FIXED CODE ###

A, B, K = [int(i) for i in input().split()]

if K > A:
    K = K - A
    A = 0
    if K >= B:
        B = 0
    else:
        B = B - K
else:
    A = A - K

print('{} {}'.format(A,B))
### BUGGY CODE ###

n, m = input().split()
N = int(n)
M = int(m)


s = set([])
card = N
for i in range(M):
    l, r = input().split()
    L = int(l)
    R = int(r)

    for j in range(N):
        if L <= j+1 and j+1 <= R:
            pass
        else:
            s.add(j+1)

print(N - len(list(s)))


### FIXED CODE ###

n, m = input().split()
N = int(n)
M = int(m)

listL = []
listR = []
card = N
for i in range(M):
    l, r = input().split()
    L = int(l)
    R = int(r)

    listL.append(L)
    listR.append(R)

maxL = max(listL)
minR = min(listR)

if minR < maxL:
    result = 0
else:
    result = minR - maxL + 1
print(result)
### BUGGY CODE ###

s=input()
s= s[::-1]

S=[0,]
cnt=[0]*2019
cnt[0]=1
for i in range(len(s)):
    S.append((int(S[i]) + int(s[i]) * 10**i) % 2019)
    cnt[S[i+1]]+=1

ans=0
for i in cnt:
    ans += i*(i-1) //2

print(ans)

### FIXED CODE ###

s=input()
s= s[::-1]

S=[0,]
cnt=[0]*2019
cnt[0]=1
d=1
num=0
for i in range(len(s)):
    num += int(s[i])*d
    num %= 2019
    d *= 10
    d%= 2019
    # S.append((int(S[i]) + int(s[i]) * 10**i) % 2019)
    cnt[num]+=1

ans=0
for i in cnt:
    ans += i*(i-1) //2

print(ans)