Harryxun/stf_run huggingface dataset:
#!/usr/bin/env python3
import sys
from pprint import pprint

INF = float('inf')

def solve(H: int, W: int, A: "List[str]"):
    #corner = [H + W] * 4
    #for i in range(H):
    #    for j in range(W):
    #        if A[i][j] == '#':
    #            corner[0] = min(corner[0], abs(i - 0) + abs(j - 0))
    #            corner[1] = min(corner[1], abs(i - 0) + abs(j - (W - 1)))
    #            corner[2] = min(corner[2], abs(i - (H - 1)) + abs(j - 0))
    #            corner[3] = min(corner[3], abs(i - (H - 1)) + abs(j - (W - 1)))

    count = [[INF] * (W + 2) for _ in range(H + 2)]
    for i in range(H):
        for j in range(W):
            if A[i][j] == '#':
                count[i + 1][j + 1] = 0
            else:
                count[i + 1][j + 1] = min(count[i][j + 1], count[i + 1][j]) + 1

    #pprint(count)
    ret = 0
    for i in range(H, 0, -1):
        for j in range(W, 0, -1):
            count[i][j] = min(count[i][j], min(count[i][j + 1], count[i + 1][j]) + 1)
            ret = max(ret, count[i][j])
    #pprint(count)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [ next(tokens) for _ in range(W) ]  # type: "List[str]"
    solve(H, W, A)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from pprint import pprint

def solve(H: int, W: int, A: "List[str]"):
    used = [[False] * W for _ in range(H)]
    dx = [1, 0, -1, 0]
    dy = [0, -1, 0, 1]
    s = set()
    for i in range(H):
        for j in range(W):
            if A[i][j] == '#':
                s.add((i, j))
                used[i][j] = True

    ret = 0
    while True:
        nex = set()
        for x, y in s:
            for j in range(4):
                tx = x + dx[j]
                ty = y + dy[j]
                if 0 <= tx < H and 0 <= ty < W and not used[tx][ty]:
                    nex.add((tx, ty))
                    used[tx][ty] = True
        if len(nex) < 1:
            break
        s = nex
        ret += 1

    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, A)

if __name__ == '__main__':
    main()
N, K = map(int, input().split())
S = str(input())
S[K] = S[K].lower()
print(S)

### FIXED CODE ###

N, K = map(int, input().split())
S = str(input())
ans = ""
for i in range(N):
  if i == K-1:
    ans += S[i].lower()
  else:
    ans += S[i]
print(ans)
def tenth(int a):
  if a % 10 == 0:
    return a
  else:
    a += 1

a = tenth(int(input()))
b = tenth(int(input()))
c = tenth(int(input()))
d = tenth(int(input()))
e = tenth(int(input()))

print(a + b + c + d + e)


### FIXED CODE ###

def tenth(a):
  temp = a
  while True:
    if temp % 10 == 0:
      return temp
    else:
      temp += 1

li = list()
ans = 0

for i in range(5):
  li.append(int(input()))
  ans += tenth(li[i])
  li[i] = tenth(li[i]) - li[i]
  
ans -= max(li)

print(ans)
def q(a,k):
 d[a]=k
 for b in t[a]:
  if'-1'!=b:q(b,k+1)
def n(a,k):
 h[a]=max(h[a],k)if a in h else k
 if'-1'!=p[a]:n(p[a],k+1)
t,p,s,d,h={},{},{},{},{}
for _ in[0]*int(input()):
 x,y,z=input().split()
 t[x]=set([y,z])-{-1}
 p[y]=p[z]=x
 s[y],s[z]=z,y
r=(set(t)-set(p)).pop()
p[r]=s[r]='-1'
q(r,0)
for i in t:
 if not t[i]:n(i,0)
for i in map(str,sorted(map(int,t))):
 print(f"node {i}: parent = {p[i]}, sibling = {s[i]}, degree = {len(t[i])}, depth = {d[i]}, height = {h[i]}, {'root'if d[i]==0else'internal node'if t[i]else'leaf'}")


### FIXED CODE ###

N=int(input())
t=[0]*N
r=set(range(N))
for _ in[0]*N:
 x,y,z=map(int,input().split())
 t[x]=[y,z]+[0]*5
 r-={y,z}
def f(i,p,s,d):
 if i<0:return-1
 k=t[i]
 l,r=k[:2]
 k[2:]=[p,s,(l!=-1)+(r!=-1),d,max(f(l,i,r,d+1),f(r,i,l,d+1))+1]
 return t[i][-1]
f(r.pop(),-1,-1,0)
for i in range(N):
 print('node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'.format(i,*t[i][2:],'root'if not t[i][5]else'internal node'if t[i][4]else'leaf'))
mod = 10 ** 9 + 7
x, y = map(int,  input().split())

def nCm_mod(A, B, mod):
    mul_one = 1
    mul_two = 1

    for i in range(B):
        mul_one *= A - i
        mul_two *= i + 1
        mul_one %= mod
        mul_two %= mod
    
    return (mul_one * pow(mul_two, mod-2, mod)) % mod

if (x + y) % 3 != 0 or n<0 or n>m:
    print(0)
else:
    n = (2 * y - x) // 3
    m = (2 * x - y) // 3

    comb_num = nCm_mod(n+m, min(n,m), mod)
    print(comb_num)
    

### FIXED CODE ###

mod = 10 ** 9 + 7
x, y = map(int,  input().split())

def nCm_mod(A, B, mod):
    mul_one = 1
    mul_two = 1

    for i in range(B):
        mul_one *= A - i
        mul_two *= i + 1
        mul_one %= mod
        mul_two %= mod
    
    return (mul_one * pow(mul_two, mod-2, mod)) % mod

n = (2 * y - x) // 3
m = (2 * x - y) // 3

if (x + y) % 3 != 0 or n < 0 or m < 0:
    print(0)
else:
    comb_num = nCm_mod(n+m, min(n,m), mod)
    print(comb_num)
n=int(input())
a=[]
for i in range(n):
  a.append(list(map(str,input())))
  
for j in range(1,n):
  if a[j][0]!=a[j-1][-1]:
    print("No")
    break
  elif j==n-1:
    print("Yes")
    break
  for l in range(j-1):
    if a[l]==a[j]:
      print("No")
      sys.exit()
    elif j==n-1 and l==j-2:
      print("Yes")
      sys.exit()
  


### FIXED CODE ###

import sys
n=int(input())
a=[]
for i in range(n):
  a.append(list(map(str,input())))
  
for j in range(1,n):
  if a[j][0]!=a[j-1][-1]:
    print("No")
    sys.exit()
  for l in range(j):
    if a[l]==a[j]:
      print("No")
      sys.exit()
  
print("Yes")
A,B = map(int,input().split)
X = A + B
Y = A - B
Z = A * B
if X > Y and X > Z : print(X)
if Y > Z and Y > X : print(Y)
if Z > X and Z > Y : print(Z)

### FIXED CODE ###

A,B = map(int,input().split())
X = A + B
Y = A - B
Z = A * B
if X >= Y and X >= Z:
     print(X)
elif Y >= Z and Y >= X:
     print(Y)
elif Z >= X and Z >= Y:
     print(Z)
# get the date as a string
s = input()

WEEKDAYS=['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
integer_day = WEEKDAYS[::-1].indexof(s) + 1
print(integer_day)

### FIXED CODE ###

# get the date as a string
s = input()

WEEKDAYS=['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
integer_day = WEEKDAYS[::-1].index(s) + 1
print(integer_day)
import sys
a,b,c,d= input()
for i in range(2**(len(op)-1)):
    op = ["+"]*3
    for j in range(len(op)-1):
        if (i >> j) & 1 == 1:
            op[j] = "-"
    if eval(a+op[0]+b+op[1]+c+op[2]+d) == 7:
        print(a+op[0]+b+op[1]+c+op[2]+d+'=7')
        sys.exit()

### FIXED CODE ###

import sys
a,b,c,d = input()

for i in range(2**3):
    l = ['+','+','+']
    for j in range(3):
        if (i>>j) & 1 == 1:
            l[j] = '-'
    if eval(a+l[0]+b+l[1]+c+l[2]+d) == 7:
        print(a+l[0]+b+l[1]+c+l[2]+d+'=7')
        sys.exit()
N, M = map(int, input().split())
l = list(map(int, input().split()))

if M == 1:
    print(0)
else:
    l.sort()
    l_dist =[]

    for i in range(1, M):
        l_dist.append(abs(l[i]-l[i-1]))

    l_dist.sort()

    for i in range(N-1):
       del l_dist[-1]

    print(sum(l_dist))

### FIXED CODE ###

N, M = map(int, input().split())
l = list(map(int, input().split()))

if (N>= M) or (M == 1):
    print(0)
else:
    l.sort()
    l_dist =[]

    for i in range(1, M):
        l_dist.append(abs(l[i]-l[i-1]))

    l_dist.sort()

    ans = sum(l_dist[:len(l_dist) - (N-1)])

    print(ans)
T, X = [int(n) for n in input().split()]

 print(T / X)

### FIXED CODE ###

T, X = [int(n) for n in input().split()]
print('{:.5f}'.format(T / X))
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_30 = [0]*30
b_30 = [0]*30
n_1 = 0
for i in range(n):
    n_i += 1 << i
    for j in range(30):
        a_30[j] +=  (a[i] & 2**j) >> j << i
        b_30[j] +=  (b[i] & 2**j) >> j << i



for k in range(n):
    x = 0
    check=True
    for j in range(30):
        a_temp  = a_30[j]
        a_30[j] = (a_temp >> 1) + ((a_temp & 1) << (n-1))
        if( (a_temp ^ b_30[j]) == n_1 ):
            x += (1 << j)
        elif( a_temp ^ b_30[j] != 0 ):
            check=False
    if(check):
        print('{} {}'.format(k, x))

### FIXED CODE ###

k , x = map(int, input().split())

if(k* 500 >= x):
    print('Yes')
else:
    print('No')
vimport sys


def main():
    N, M = map(int, input().split())
    s = M // N  # 答えはs以下
    m = M % N

    for i in range(s, 0, -1):
        if m % s == 0:
            print(s)
            sys.exit()
        else:
            s -= 1
            m += N


main()


### FIXED CODE ###

import sys


def main():
    N, M = map(int, input().split())
    s = M // N  # 答えはs以下
    m = M % N

    for i in range(s, 0, -1):
        if m % i == 0:
            print(i)
            sys.exit()
        else:
            m += N


main()
a.b = map(int,input().split())
if(a > b * 2):
    print(a-b * 2)
else:
    print(0)

### FIXED CODE ###

a,b = map(int,input().split())
if(a > b * 2):
    print(a-b * 2)
else:
    print(0)
# 初期入力
NN,K = (int(x) for x in input().split())

#K個の和、初項と修項
p =10**9 + 7
seq =[i for i in range(NN+1)] #0-Nまでの数列
ans =[0] *NN
st =[0]*NN
fi =[0]*NN
st[0] =sum(seq[  :K])
fi[0] =sum(seq[-K: ])
ans[0] =fi[0] -st[0] +1
for i in range(NN -K+1):
    st[i+1] =st[i] +seq[K+i]
    fi[i+1] =fi[i] +seq[-K-i-1]
    ans.append(fi[i+1] -st[i+1] +1)
print(sum(ans) %p)

### FIXED CODE ###

# 初期入力
NN,K = (int(x) for x in input().split())

#K個の和、初項と修項
p =10**9 + 7
seq =[i for i in range(NN+1)] #0-Nまでの数列
ans =[0] *(NN+1)
st =[0]*(NN+1)
fi =[0]*(NN+1)
st[0] =sum(seq[  :K])
fi[0] =sum(seq[-K: ])
ans[0] =fi[0] -st[0] +1
if NN==1 and K==1:
    print(3)
else:
    for i in range(NN -K+1):
        st[i+1] =st[i] +seq[K+i]
        fi[i+1] =fi[i] +seq[-K-i-1]
        ans[i+1] =(fi[i+1] -st[i+1] +1)
    print(sum(ans) %p)
a,b,c,d = list(map(int,input().split()))
cou = 0
if a is b:
  cou = cou + 1
elif b is c:
   cou = cou + 1
elif c is d:
   cou = cou + 1
else:
  print("Good")
if cou > 0:
  print("Bad")


### FIXED CODE ###

a = int(input())
b = a//1000
c = (a//100)%10
d = (a//10)%10
e = a%10
cou = 0
if b is c:
  cou = cou + 1
elif c is d:
   cou = cou + 1
elif d is e:
   cou = cou + 1
else:
  print("Good")
if cou > 0:
  print("Bad")
s = input()
m = 1000
for i in range(0,len(s)-2):
    m = min(abs(s[i]*100+s[i+1]*10+s[i+2]-753),m)
print(m)

### FIXED CODE ###

s = input()
m = 1000
for i in range(0,len(s)-2):
    m = min(abs(int(s[i])*100+int(s[i+1])*10+int(s[i+2])-753),m)
print(m)
k,x=input().split()
if 500 * k >= x:
  return "Yes"
else:
  return "No"

### FIXED CODE ###

k,x=(int(x) for x in input().split())
a = 500*k
if a >= x:
  print("Yes")
else:
  print("No")
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

min_value = 1000000000000
data = int(input())
ng_flag = False
divisors_array = make_divisors(data)
for i in range(0, len(divisors_array)):
    if(i % 2 == 0):
        if divisors_array[i] + divisors_array[i+1] < min_value:
            if i == 1:
                min_value = divisors_array[i] + divisors_array[i+1] - 1
            else:
                min_value = divisors_array[i] + divisors_array[i+1] - 2
print(min_value)

### FIXED CODE ###

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

min_value = 1000000000000
data = int(input())
ng_flag = False
divisors_array = make_divisors(data)

if len(divisors_array) % 2 == 1:
    divisors_array.append(divisors_array[len(divisors_array)-1])
for i in range(0, len(divisors_array)):
    if(i % 2 == 0):
        first = divisors_array[i] -1 
        second = divisors_array[i+1] -1 
        if first + second < min_value:
            if i == 1:
                min_value = first + second
            else:
                min_value = first + second
print(min_value)
import numpy as np
H,W,K = map(int,input().split())
c = [input().split() for l in range(H)]
 
c1 = c.count("#")
 
num = 0
while c1 > K:
  for i in range(H)
  for j in range(W)
  c = np.delete(c, i, j)
  num += 1
  
  print(num)

### FIXED CODE ###

H, W, K = list(map(int, input().split()))
 
c = [list(input()) for i in range(H)]
 
cnt = 0
for i in range(2**H):
    for j in range(2**W):
        cnt_black = 0
        for k in range(H):
            if (i >> k) & 1:
                continue
            for l in range(W):
                if (j >> l) & 1:
                    continue
                if c[k][l] == '#':
                    cnt_black += 1
        if cnt_black == K:
            cnt += 1
 
print(cnt)
import sys
input = sys.stdin.readline

n, m = [int(x) for x in input().split()]
ab = [[int(x) for x in input().split()] for _ in range(m)][::-1]

#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)

    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#初期化
#根なら-size,子なら親の頂点
par = [-1]*n

from math import factorial

def nCk(n, k, mod=1):
    if n < k:
        return 0
    k = min(k, n - k)
    numer = 1
    for x in range(n - k + 1, n + 1):
        numer = (numer * x) % mod
    denom = 1
    for x in range(1, k + 1):
        denom = (denom * x) % mod
    return numer * pow(denom, mod - 2, mod) % mod
convinience = [0]

for i in ab:
    a, b = i
    res = convinience[-1]
    a -= 1
    b -= 1
    if find(a) == find(b):
        convinience.append(res)
        continue
    if size(a) > 1:
        res -= nCk(size(a), 2)
    if size(b) > 1:
        res -= nCk(size(b), 2)
    unite(a, b)
    res += nCk(size(a), 2)
    convinience.append(res)

convinience = convinience[1::][::-1] + [0]

ans = [0]
for i in range(m):
    ans.append(convinience[i] - convinience[i + 1] + ans[-1])
for i in ans[1:]:
    print(i)

### FIXED CODE ###

import sys
input = sys.stdin.readline

n, m = [int(x) for x in input().split()]
ab = [[int(x) for x in input().split()] for _ in range(m)][::-1]

#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)

    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#初期化
#根なら-size,子なら親の頂点
par = [-1]*n

def cmb(n, k):
    return n * (n - 1) // 2
convinience = [0]

for i in ab:
    a, b = i
    res = convinience[-1]
    a -= 1
    b -= 1
    if find(a) == find(b):
        convinience.append(res)
        continue
    if size(a) > 1:
        res -= cmb(size(a), 2)
    if size(b) > 1:
        res -= cmb(size(b), 2)
    unite(a, b)
    res += cmb(size(a), 2)
    convinience.append(res)

convinience = convinience[1::][::-1] + [0]

ans = [0]
for i in range(m):
    ans.append(convinience[i] - convinience[i + 1] + ans[-1])
for i in ans[1:]:
    print(i)
import math

def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def ris(): return list(input())
def pli(a): return "".join(list(map(str, a)))


n, k = rli()
a = rli()
if(max(a) < k):
    print("IMPOSSIBLE")
else:
    g = a[0]
    for i in a[1:]:
        g = math.gcd(g, i)
    if(k % g == 0):
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")


### FIXED CODE ###

import fractions

def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def ris(): return list(input())
def pli(a): return "".join(list(map(str, a)))


n, k = rli()
a = rli()
if(max(a) < k):
    print("IMPOSSIBLE")
else:
    g = a[0]
    for i in a[1:]:
        g = fractions.gcd(g, i)
    if(k % g == 0):
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
n,k = map(int,inoput().split())
s = input()

print(s[:k-1]+lower.s[k]+s[k+1:])

### FIXED CODE ###

_, K = map(int, input().split())
S = input()
 
print(S[: K - 1] + S[K - 1].lower() + S[K:])
import bisect
import sys
S = input()
T = input()


# sが何番目に出てくるかの辞書をついくる
s_index = {}
for i in range(len(S)):
    if S[i] in s_index:
        s_index[S[i]].append(i + 1)
    else:
        s_index[S[i]] = [i+1]


current_s_index = 0
loop_count = 0
ans = 0
for t in T:
    if not t in s_index:
        print(-1)
        sys.exit()

    if current_s_index > s_index[t][-1]:
        current_s_index = s_index[t][0]
        loop_count += 1
    else:
        index = bisect.bisect(s_index[t], current_s_index)
        current_s_index = s_index[t][index]

print(current_s_index + loop_count * len(S))



### FIXED CODE ###

import bisect
import sys
S = input()
T = input()


# sが何番目に出てくるかの辞書をついくる
s_index = {}
for i in range(len(S)):
    if S[i] in s_index:
        s_index[S[i]].append(i + 1)
    else:
        s_index[S[i]] = [i+1]


current_s_index = 0
loop_count = 0
ans = 0
for t in T:
    if not t in s_index:
        print(-1)
        sys.exit()

    if current_s_index >= s_index[t][-1]:
        current_s_index = s_index[t][0]
        loop_count += 1
    else:
        index = bisect.bisect(s_index[t], current_s_index)
        current_s_index = s_index[t][index]

print(current_s_index + loop_count * len(S))
import sympy
Q = int(input())
l_r = [list(map(int, input().split())) for _ in range(Q)]

def like(x):
    if sympy.isprime(x) and sympy.isprime((x+1)//2):
        return True
    
    return False

x_list = [0] * (10 ** 5)
for i in range(1, 10**5, 2):
    if like(i):
        x_list[i] = 1

for i in range(Q):
    print(sum(x_list[l_r[i][0]: l_r[i][1]+1]))

### FIXED CODE ###

import math
import sys
sys.setrecursionlimit(10000000)
Q = int(input())
l_r = [list(map(int, input().split())) for _ in range(Q)]

prime = []
def isprime(n):
    if n in prime:
        return True
    if n <= 1:
        return False
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False
    
    return True


def like(x):
    if isprime(x) and isprime((x+1)//2):
        return True
    
    return False

x_dict = {1:0}
def count_like(x):
    if x in x_dict:
        return x_dict[x]
    x_dict[x] = count_like(x-1) + like(x)
    return x_dict[x]

for i in range(Q):
    print(count_like(l_r[i][1]) - count_like(l_r[i][0]) + int(like(l_r[i][0])))
import numpy as np

H, W = map(int, input().split())
field = []
for i in range(H):
    field.append(list(map(int, input().split())))

urdl = [(0,-1,0), (1,0,1), (0,1,2), (-1,0,3)]

move_records = []

if H != 1 or W != 1:
    for i in range(H):
        for j in range(W):
            if field[i][j] % 2 == 0:
                continue
            adj_values = np.array([10, 10, 10, 10])
            if not j == 0:
                adj_values[0] = field[i][j-1]
            if not j == W-1:
                adj_values[2] = field[i][j+1]
            if not i == 0:
                adj_values[3] = field[i-1][j]
            if not i == H-1:
                adj_values[1] = field[i+1][j]

            if sum(adj_values[adj_values != 10] % 2) == 0:
                
                h,w,k = urdl[np.where(adj_values != 10)[0][0]]
                field[i][j] -= 1
                field[i+h][j+w] += 1
                
            else:
                # import ipdb; ipdb.set_trace()
                for h,w,k in urdl:
                    if adj_values[k] == 10:
                        continue

                    if adj_values[k] % 2 != 0:
                        field[i][j] -= 1
                        field[i+h][j+w] += 1
                        break
            
            move_records.append([i+1,j+1,i+h+1,j+w+1])

M = len(move_records)
print(M)
for i in range(M):
    print('{} {} {} {}'.format(move_records[i][0],
                               move_records[i][1],
                               move_records[i][2],
                               move_records[i][3]))

### FIXED CODE ###

import numpy as np
H, W = map(int, input().split())
field = []
for i in range(H):
    field.append(list(map(int, input().split())))
rd = [(0,1,0), (1,0,1)]
move_records = []
if H != 1 or W != 1:
    for i in range(H):
        for j in range(W):
            if field[i][j] % 2 == 0:
                continue
            if i == H-1 and j == W-1:
                continue
            if i == H-1 and j == W-2:
                # import ipdb; ipdb.set_trace()
                if (field[H-1][W-1] + field[H-1][W-2]) % 2 != 0:
                    continue
                else:
                    field[H-1][W-2] -= 1
                    field[H-1][W-1] += 1
                    move_records.append([i+1,j+1,i+1,j+2])
            elif j != W-1:
                field[i][j] -= 1
                field[i][j+1] += 1
                move_records.append([i+1,j+1,i+1,j+2])
            else:
                field[i][j] -= 1
                field[i+1][j] += 1
                move_records.append([i+1,j+1,i+2,j+1])
M = len(move_records)
print(M)
for i in range(M):
    print('{} {} {} {}'.format(move_records[i][0],
                               move_records[i][1],
                               move_records[i][2],
                               move_records[i][3]))
N = int(input().split())
AN = list(map(int, input().split()))
 
print(sum(AN)-N)

### FIXED CODE ###


import fractions

n = int(input().strip())
an = list(map(int, input().strip().split(' ')))


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


temp = an[0]
for i in range(len(an)):
    temp = lcm(temp, an[i])

m = temp - 1

ret = 0
for a in an:
    ret += m % a

print(ret)
N = str(input())
Ds = str(input()).split(" ")
answer = 0

for di in range(len(Ds)):
  for dii in range(di):
    sum = Ds[di] + Ds[dii] 
    answer += sum

print answer

### FIXED CODE ###

N = str(input())
Ds = str(input()).split(" ")
answer = 0
 
for di in range(len(Ds)):
  for dii in range(di+1,len(Ds)):
    sum = int(Ds[di]) * int(Ds[dii])
    answer += sum
print(answer)
from collections import Counter
li=[]
d={}
for i in range(int(input()):
    p=input()
    if(p in d):
        d[p]+=1
    else:
    	d[p]=1  
if('AC' not in d):
    d['AC']=0
if('WA' not in d):
    d['WA']=0
if('TLE' not in d):
    d['TLE']=0
if('RE' not in d):
    d['RE']=0
print('AC','x',d['AC'] )
print('WA','x',d['WA'])
print('TLE','x',d['TLE'])
print('RE','x',d['RE'])

### FIXED CODE ###

import math
n=int(input())
d=n/1000
g=math.ceil(d)
print(g*1000-n)
n = int(input())

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

#mid = n//2 + n%2

ans = [0]*n
for i, a in enumerate(an[::-1]):

#    ta = [x for ii,x in enumerate(an[i:]) if i % (n-(ii+i)) == 0]
#    t = sum(ta)
#    print(ta,t,i,a)
#    ans[-i] = t%2

    ans[-i] = sum([x for ii, x in enumerate(an[i::i]) if i % (n-(ii+i)) == 0])%2

m = sum(ans)
print(m)

if m > 0:
    print(*[x for x in ans if x >0])

### FIXED CODE ###


n = int(input())

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

#mid = n//2 + n%2

#print(* range(10)[::2] )

ans = [0]*(n+1)

for _ in range(n):# 0 ... n-1
    i = n-_ # n ... 1

    ta = sum(ans[i::i])
    ans[i] = 0 if ta%2 == an[i-1] else 1

#    print(i, an[i-1::i])


m = sum(ans)
print(m)

if m > 0:
    print(*[i for i, x in enumerate(ans) if x >0])
a,b,c,x=map(int,[input()　for i in range(4)])

count=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if k*50+j*100+i*500==x:
                count+=1
                
print(count)

### FIXED CODE ###

a, b, c, x = map(int, [input() for i in range(4)])

count=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if k*50+j*100+i*500==x:
                count+=1
                
print(count)