Harryxun/stf_run huggingface dataset:
n,m=map(int,input().split())
k=[[int(i) for i in input().split()] for j in range(m)]
p=[int(i) for i in input().split()]
ans=chk=0
for i in range(2**n):
    l=[0]*m
    for j in range(n):
        if i&1: l[j]=1
        i=i>>1
    y=0
    for j in range(m):
        x=0
        for a in range(k[j][0]):
            if l[k[j][a+1]-1]==1: x+=1
        if x%2==p[j]%2: y+=1
    if y==m: ans+=1
print(ans)

### FIXED CODE ###

def sol():
    n,m=map(int,input().split())
    k=[]
    for i in range(m):
        l=[int(i) for i in input().split()]
        k.append([l[j]-1 for j in range(1,l[0]+1)])
    p=[int(i) for i in input().split()]
    ans=0
    #for i in range(2**10):
    for i in range(2**n):
        s=bin(i)[2:]
        s="0"*(n-len(s))+s
        s=s[::-1]
        for a,j in enumerate(k):
            chk=f=0
            for x in j:
                if s[x]=="1":
                    chk+=1
            if chk%2!=p[a]:
                f=1
                break
        if f==0:
            ans+=1
    print(ans)

if __name__=="__main__":
    sol()
n=int(input())
for _ in range(n):
	s=int(input())+int(input())
	print('overflow' iflen(str(s))>80 else s)

### FIXED CODE ###

n=int(input())
for _ in range(n):
	s=int(input())+int(input())
	print('overflow' if len(str(s))>80 else s)
#おかしの問題
n,m = map(int,input().split())
number = list(int(input().split()))
a = []
#ここから書きかえ
for i in range(n):
    for j in range(n-i):
            b=[]
            for k range(i+1):
                b.append(number[j+k-1])
            if sum(b)%m == 0:
                a.append(1)
            else:
                pass
print(len(a))

### FIXED CODE ###

n,m = map(int,input().split())
a = list(map(int,input().split()))
check = {};ios = [a[0]%m]*n
for i in range(n-1):
    ios[i+1] = (a[i+1] + ios[i])%m
    check[ios[i]] = 0
check[ios[n-1]] = 0
for i in range(len(ios)):
    check[ios[i]%m] += 1
ans = 0
for i in range(n):
    num = check[ios[i]];check[ios[i]] = 'finish'
    if num == 'finish':continue
    if ios[i] % m == 0:ans += num
    ans += (num * (num - 1))//2
print(ans)
N,K=map(int,input().split())
X=list(map(int,input().split()))
if X[0]>=0:
    b=X[K]
elif X[-1]<=0:
    b=X[-K]
elif 0 in X:
    a=0
    b=10**9
    for i in range(N):
        if X[i]==0:
            a=i
            break
    for j in range(max(0,K-1-a),min(K,N-a)):
        if b>X[a+j]-X[a+j-K+1]+min(abs(X[a+j]),abs(X[a+j-K+1])):
            b=X[a+j]-X[a+j-K+1]+min(abs(X[a+j]),abs(X[a+j-K+1]))
else:
    a=0
    b=10**9
    for i in range(N):
        if X[i]>0:
            a=i
            break
    for j in range(max(-1,K-a-1),min(K,N-a)):
        if b>X[a+j]-X[a+j-K+1]+min(abs(X[a+j]),abs(X[a+j-K+1])):
            b=X[a+j]-X[a+j-K+1]+min(abs(X[a+j]),abs(X[a+j-K+1]))
print(b)

### FIXED CODE ###

N,K=map(int,input().split())
X=list(map(int,input().split()))
if X[0]>=0:
    b=X[K-1]
elif X[-1]<=0:
    b=abs(X[-K])
elif 0 in X:
    a=0
    b=10**9
    for i in range(N):
        if X[i]==0:
            a=i
            break
    for j in range(max(0,K-1-a),min(K,N-a)):
        if b>X[a+j]-X[a+j-K+1]+min(abs(X[a+j]),abs(X[a+j-K+1])):
            b=X[a+j]-X[a+j-K+1]+min(abs(X[a+j]),abs(X[a+j-K+1]))
else:
    a=0
    b=10**9
    for i in range(N):
        if X[i]>0:
            a=i
            break
    for j in range(max(-1,K-a-1),min(K,N-a)):
        if b>X[a+j]-X[a+j-K+1]+min(abs(X[a+j]),abs(X[a+j-K+1])):
            b=X[a+j]-X[a+j-K+1]+min(abs(X[a+j]),abs(X[a+j-K+1]))
print(b)
N, T = map(int, input().split())
a = 9999
for _ in N:
    c, t = map(int, input().split())
    if t <= T:
        a = min(a, c)
if a == 9999:
    print('TLE')
else:
    print(a)


### FIXED CODE ###

N, T = map(int, input().split())
a = 9999
for _ in range(N):
    c, t = map(int, input().split())
    if t <= T:
        a = min(a, c)
if a == 9999:
    print('TLE')
else:
    print(a)
# -*- coding: utf-8 -*-


def main():
    """Function."""
    a, b, c, d = map(str, input().split())
    print(max(a*b, c*d))


if __name__ == "__main__":
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-


def main():
    """Function."""
    a, b, c, d = map(int, input().split())
    print(max(a*b, c*d))


if __name__ == "__main__":
    main()
n,m = map(int, input().split())

bridges = []
for i in range(m):
    bridges.append([int(x) for x in input().split()])

def root(par, a):
    while par[a] != -1:
       a = par[a]
    return a 

def unite(par, npar, depth, ra, rb):
    if depth[ra] >= depth[rb]:
        npar[ra] = npar[ra] + npar[rb]
        par[rb] = ra
        if depth[ra] == depth[rb]:
            depth[ra] += 1
    else:
        npar[rb] = npar[rb] + npar[ra]
        par[ra] = rb

par = [-1 for _ in range(n+1)]
npar = [1 for _ in range(n+1)]
depth = [1 for _ in range(n+1)]

ans = []
unconf = n*(n-1)//2
ans.append(unconf)

for x in reversed(bridges):
    a,b = x
    ra = root(par, ifpar, a)
    rb = root(par, ifpar, b)
    if ra != rb:
        tmp = npar[ra] * npar[rb]
        unite(par, ifpar, npar, depth, ra, rb)
        unconf -= tmp
    ans.append(unconf)

ans.reverse()
ans.pop(0)
for x in ans:
    print(x)

### FIXED CODE ###

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

bridges = []
for i in range(m):
    bridges.append([int(x) for x in input().split()])
'''
g = list(range(n+1))
ng = [1 for _ in range(n+1)]
gl = [[i] for i in range(n+1)]
ans = []
unconf = n*(n-1)//2
ans.append(unconf)


for x in reversed(bridges):
    a,b = x
    if g[a] != g[b]:
        tmp = ng[g[a]] * ng[g[b]]
        ng[g[a]] = ng[g[a]]+ng[g[b]]
        gl[g[a]] = gl[g[a]] + gl[g[b]]
        for y in gl[g[b]]:
            g[y] = g[a]
        unconf -= tmp
        ans.append(unconf)
    else:
        ans.append(unconf)


ans.reverse()
ans.pop(0)
for x in ans:
    print(x)
'''
def root(par, ifpar, a):
    while ifpar[a] != 1:
       a = par[a]
    return a 

def unite(cnt, par, ifpar, npar, depth, ra, rb):
    if depth[ra] >= depth[rb]:
        npar[ra] = npar[ra] + npar[rb]
        par[rb] = ra
        ifpar[rb] = 0
        if depth[ra] == depth[rb]:
            depth[ra] += 1
    else:
        npar[rb] = npar[rb] + npar[ra]
        par[ra] = rb
        ifpar[ra] = 0

par = list(range(n+1))
ifpar = [1 for _ in range(n+1)]
npar = [1 for _ in range(n+1)]
depth = [1 for _ in range(n+1)]

ans = []
unconf = n*(n-1)//2
ans.append(unconf)
cnt = 0

for x in reversed(bridges):
    a,b = x
    ra = root(par, ifpar, a)
    rb = root(par, ifpar, b)
    if ra != rb:
        tmp = npar[ra] * npar[rb]
        unite(cnt, par, ifpar, npar, depth, ra, rb)
        unconf -= tmp
    ans.append(unconf)
    cnt += 1

ans.reverse()
ans.pop(0)
for x in ans:
    print(x)
s, t = input()
a, b = map(int, input().split())
u = int(input())

if u == "red":
  print(int(s-1,t))
elif t == "blue":
  print(int(s, t-1))

### FIXED CODE ###

s, t = input().split()
a, b = map(int, input().split())
u = input()
 
if u == s:
  print(a-1,b)
elif u == t:
  print(a, b-1)
# coding:utf-8

import sys
from collections import defaultdict, deque


INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, k = LI()
    A = LI_()

    D = defaultdict(list)
    for i in range(1, n):
        D[A[i]].append(i)

    q = deque([(0, 0)])
    # 首都は必ず自己ループでなければならない
    global res
    res = 0 if A[0] == 0 else 1

    def DFS(v, par):
        global res
        h = 0
        for to in D[v]:
            # print('dfs {} -> {}'.format(v+1, to+1))
            # h: 葉からの距離の最大値
            h = max(h, DFS(to, v))
            
        # 根が首都ではなく，高さがk - 1の場合は首都につなぎ直す
        if h == k - 1 and par != 0:
            res += 1
            h = -1
        # print('Finish {} <- {}'.format(par+1, v+1))
        return h + 1

    DFS(0, 0)

    return res


print(main())


### FIXED CODE ###

# coding:utf-8

import sys
from collections import defaultdict

sys.setrecursionlimit(10**7)
INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, k = LI()
    A = LI_()

    D = defaultdict(list)
    for i in range(1, n):
        D[A[i]].append(i)

    # 首都は必ず自己ループでなければならない
    global res
    res = 0 if A[0] == 0 else 1

    def DFS(v, par):
        global res
        h = 0
        for to in D[v]:
            # print('dfs {} -> {}'.format(v+1, to+1))
            # h: 葉からの距離の最大値
            h = max(h, DFS(to, v))

        # 根が首都ではなく，高さがk - 1の場合は首都につなぎ直す
        if h == k - 1 and par != 0:
            res += 1
            h = -1
        # print('Finish {} <- {}'.format(par+1, v+1))
        return h + 1

    DFS(0, 0)

    return res


print(main())
n = int(input())
a = list(map(int, input().split()))
limit = 10 ** 18
if 0 in a:
    print(0)
    sys.exit()
else:
    ans = 1
    for i in range(n):
        ans *= a[i]
        if ans > limit:
            print(-1)
            sys.exit()
    print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
import sys
limit = 10 ** 18
if 0 in a:
    print(0)
    sys.exit()
else:
    ans = 1
    for i in range(n):
        ans *= a[i]
        if ans > limit:
            print(-1)
            sys.exit()
    print(ans)
import numpy as np

S = input()
N = len(S)
arr = np.zeros((N, N), dtype=np.int)
#for n, s in enumerate(S):
#    i = n
#    j = n + (1 if s == 'R' else -1)
#    arr[i, j] += 1
#mat = np.matrix(arr)
#print(*(np.ones(N, dtype=np.int) * (mat ** 10 ** 100)).tolist()[0])
print()


### FIXED CODE ###

import numpy as np
from scipy.sparse import csr_matrix

S = input()
N = len(S)
row = tuple(range(N))
col = [n + (1 if s == 'R' else -1) for n, s in enumerate(S)]
data = [1] * N
mat = csr_matrix((data, (row, col)), shape=(N, N))
print(*np.ones(N, dtype=np.int) * (mat ** 10 ** 100))
def max_minus_min(areas):
    # print("areas", areas)
    # return max(areas) - min(areas)
    return 999
 
def solve2(h, w):
    return 7, 7
    # area1 = h * (w // 2)
    # area2 = h * w - area1
    # return area1, area2
 
def solve(h, w):
    w_div_3 = w // 3;
    ans = 1e9
    for w2 in range(w_div_3, w_div_3 + 2):
        area1 = w2 * h
        
        tmp = max_minus_min([area1] + solve2(h, w - w2))

        # ans = min(ans, max_minus_min([area1] + solve2(h, w - w2)))
        # ans = min(ans, max_minus_min([area1] + solve2(w - w2, h)))
    return ans

H, W = map(int, input().split())
print(min(solve(H,W), solve(W,H)))


### FIXED CODE ###

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

# import array
# from bisect import *
# from collections import *
# import fractions
# import heapq 
# from itertools import *
# import math
# import re
# import string

def max_minus_min(areas):
    # print("areas", areas)
    return max(areas) - min(areas)

def solve2(h, w):
    area1 = h * (w // 2)
    area2 = h * w - area1
    return [area1, area2]

def solve(h, w):
    w_div_3 = w // 3;
    ans = 1e9
    for w2 in range(w_div_3, w_div_3 + 2):
        area1 = w2 * h
        ans = min(ans, max_minus_min([area1] + solve2(h, w - w2)))
        ans = min(ans, max_minus_min([area1] + solve2(w - w2, h)))
    return ans

H, W = map(int, raw_input().split())
print(min(solve(H,W), solve(W,H)))
w, h, x, y = [int(s) for s in input().split(" ")]

a = w * h

print("%d %d" % (a * 0.5, int(w // 2 == x and h // 2 == y))

### FIXED CODE ###

w, h, x, y = [int(s) for s in input().split(" ")]

a = w * h

print("%lf %d" % (a * 0.5, int(divmod(w, 2) == (x, 0) and divmod(h, 2) == (y, 0))))
n, d = mpa(int, input().split())
k = d * 2 + 1
if n % k == 0:
    print(n//k)
else:
    print(n//k + 1)

### FIXED CODE ###

n, d = map(int, input().split())
k = d * 2 + 1
if n % k == 0:
    print(n//k)
else:
    print(n//k + 1)
A, B, C = map(int,input().split())

a = A
b = b
count = 0
if a > b:
    print(0)

while b - a >= 0:
    if count == C:
        break
    b -= a
    count += 1

print(count)

### FIXED CODE ###

import math

A, B, C = map(int,input().split())

if B - A*C < 0:
    print(math.floor(B/A))
else:
    print(C)
n=int(input())
p=[int(input()) for i in range(n)]
print(int(sum(p)-(max(p)/2))


### FIXED CODE ###

n=int(input())
p=[int(input()) for i in range(n)]
print(int(sum(p)-(max(p)/2)))
from collections import Counter
code = input()
cnt = 0
for i in range(len(code) - 1):
  if c[i] == c[i + 1]:
    cnt += 1
    break
if cnt:
  print("Bad")
else:
  print("Good")
  

### FIXED CODE ###

from collections import Counter
code = input()
cnt = 0
for i in range(len(code) - 1):
  if code[i] == code[i + 1]:
    cnt += 1
    break
if cnt:
  print("Bad")
else:
  print("Good")
import numpy as np
N, M = [int(str) for str in input().strip().split()]
cakes = np.array([[int(str) for str in input().strip().split()] for i in range(N)])

def calc_score(choised_cakes):
    return sum([abs(sum(para)) for para in choised_cakes.T])

score_list = []
for i in range(3):
    sorted_cakes = cakes[np.argsort(cakes[:, i])]
    for j in range(min(100, N - M)):
        score_list.append(calc_score(sorted_cakes[j : M + j, :]))
        score_list.append(calc_score(sorted_cakes[::-1][j : M + j, :]))

print(max(score_list))

### FIXED CODE ###

import numpy as np
N, M = [int(str) for str in input().strip().split()]
cakes = np.array([[int(str) for str in input().strip().split()] for i in range(N)])

def calc_score(choised_cakes):
    return sum([abs(sum(para)) for para in choised_cakes.T])

signs_list = [[i, j, k] for i in (-1, 1) for j in (-1, 1) for k in (-1, 1)]

score_list = []
for signs in signs_list:
    sscores = np.dot(cakes, np.array(signs).T)
    sort_index = np.argsort(sscores)[::-1]
    sorted_cakes = cakes[sort_index]
    score_list.append(sum(np.dot(sorted_cakes[:M], np.array(signs).T)))

print(max(score_list))
import numpy as np
n = int(input())
a = list(map(int, input().split()))
a_max = max(a)
l = len(bin(a_max)) - 2
bits = np.zeros((l,2))
for num in a:
    for i, bit in enumerate(format(num, 'b').zfill(l)):
        if bit == '0':
            bits[i,0] += 1
        else:
            bits[i,1] += 1

sumation = 0
for i in range(l):
    sumation += bits[i,0] * bits[i, 1] * 2**(l-i-1)
print(int(sumation % (10**9+7)))
    

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a_max = max(a)
l = len(bin(a_max)) - 2
bits = [[0, 0] for _ in range(l)]
for num in a:
    for i, bit in enumerate(format(num, 'b').zfill(l)):
        if bit == '0':
            bits[i][0] += 1
        else:
            bits[i][1] += 1

sumation = 0
div = (10**9+7)
for i in range(l):
    sumation += (bits[i][0]) * (bits[i][1]) * (2**(l-i-1) % div)
print(int(sumation % (10**9+7)))
n = int(input())
p = list(map(int, input().split()))
count = 0
tmp = p[0]

for i in range(len(p)):
    target = p[i]
    flag = True
    if tmp < target:
        tmp = target
        continue
    for j in range(i):
        ccount += 1
        if p[i] > p[j]:
            flag = False
            break
    if flag:
        count += 1

print(count)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
ans = 0
min = p[0]

for i in range(len(p)):
    if p[i]<=min:
        min = p[i]
        ans += 1

print(ans)
n = int(input())
s = input()
S = ''
list = [A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z]*2

for i in range(len(s)):
  S += list[list.index('i') + n]
  
print(S)


### FIXED CODE ###

n = int(input())
s = input()
S = ''
list = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']*2
 
for i in s:
  S += list[list.index(i) + n]
  
print(S)
a, b, c = [int(s) for s in input().split()]

a, b = b, a
a, c = c, a

print(' '.join([a, b, c])

### FIXED CODE ###

a, b, c = input().split()
 
a, b = b, a
a, c = c, a
 
print(' '.join([a, b, c]))
n=int(input())
A=list(map(int,input().split())
a=1
for i in range(n):
  a*=A[i]
  if a>10**18
  print(-1)
  exit()

print(a)

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
x=1
A.sort()
if 0 in A:
  print(0)
  exit()

for i in range(n):
  x*=A[n-i-1]
  if x>10**18:
    print(-1)
    exit()
  else:
    continue

print(x)
s = input()
t = input()

len_s = len(s)
len_t = len(t)

ans = 1000
for i in range(len_s - len_t):
    cnt = 0
    l = []
    for j in range(len_t):
        if s[i + j] == t[j]:
            cnt += 1
        else:
            l.append(cnt)
            cnt = 0

    ans = min(ans, len_t - max(l))

print(ans)

### FIXED CODE ###

s = input()
t = input()

len_s = len(s)
len_t = len(t)

ans = 1000
max_cnt = 0
for i in range(len_s - len_t + 1):
    cnt = 0
    l = []
    for j in range(len_t):
        if s[i : i + len_t][j] == t[j]:
            cnt += 1
        if s[i : i + len_t][j] != t[j]:
            cnt += 0
    max_cnt = max(max_cnt, cnt)

ans = min(ans, len_t - max_cnt)

print(ans)
a, b = map(int, input().split())
if (a*b)%2 == 1:
  print "Odd"
else:
  print "Even"

### FIXED CODE ###

a, b = map(int, input().split())
if (a*b)%2 == 1:
  print ("Odd")
else:
  print ("Even")
n=int(input())
li=list(map(int,input().split()))
print(max(li)-min(li))

### FIXED CODE ###

n,x=map(int,input().split())
li=[]
for i in range(n):
    m=int(input())
    li.append(m)
x=x-sum(li)
print(n+x//min(li))
from collections import*
from heapq import*
def dijkstra(s):
  d=[inf]*n
  used=[True]*n
  d[s]=0
  used[s]=False
  edgelist=[]
  for e in edge[s]:
    heappush(edgelist,e)
  while len(edgelist):
    minedge=heappop(edgelist)
    if not used[minedge[1]]:
      continue
    v=minedge[1]
    d[v]=minedge[0]
    used[v]=False
    for e in edge[v]:
      if used[e[1]]:
        heappush(edgelist,(e[0]+d[v],e[1]))
  return d
inf=10**18
n,m,*t=map(int,open(0).read().split())
e=defaultdict(list)
s=[]
l=[]
f=False
for a,b,c in zip(t[::3],t[1::3],t[2::3]):
  if b<a:a,b=b,a
  if a<2:f=True
  x,y=a+-~n*c,b+-~n*c
  if b==n:l.append(y)
  e[a].append((1,x))
  e[y].append((0,b))
  e[x].append((0,y))
  s.extend([a,b,x,y])
if not f:
  print(-1)
  exit()
d={i:v for v,i in enumerate(sorted(set(s)))}
n=len(d)
edge=tuple([]for _ in range(n))
for i in e:
  edge[d[i]].extend([(c,d[j])for c,j in e[i]])
a=dijkstra(0)
a=min(a[d[i]]for i in l)
print([a,-1][a==inf])

### FIXED CODE ###

def main():
  from heapq import heappush,heappop,heapify
  inf=2**31-1
  n,m,*t=map(int,open(0).read().split())
  z=[]
  for a,b,c in zip(t[::3],t[1::3],t[2::3]):
    z.extend([a,b,a+n*c,b+n*c])
  z={i:v for v,i in enumerate(sorted(set(z)))}
  try:
    z[1]
  except:
    print(-1)
    exit()
  edge=[[]for _ in range(len(z))]
  d={}
  l=[]
  for a,b,c in zip(t[::3],t[1::3],t[2::3]):
    if b<a:a,b=b,a
    i,j,x,y=z[a],z[b],z[a+n*c],z[b+n*c]
    if b==n:
      l.append(y)
    edge[i].append((1,x))
    edge[j].append((1,y))
    edge[x].extend([(0,i),(0,y)])
    edge[y].extend([(0,j),(0,x)])
  used=[False]+[True]*~-len(z)
  d=[0]+[inf]*~-len(z)
  edgelist=edge[0]
  heapify(edgelist)
  while edgelist:
    m=heappop(edgelist)
    if not used[m[1]]:
      continue
    d[m[1]]=m[0]
    used[m[1]]=False
    for e in edge[m[1]]:
      if used[e[1]]:
        heappush(edgelist,(e[0]+m[0],e[1]))
  a=min([d[i]for i in l]or[inf])
  print([a,-1][a==inf])
if __name__=='__main__':
  main()
h, w, d = [ int(v) for v in input().split() ]
def manhattan(intuple1,intuple2):
	return abs(intuple1[2]-intuple2[2]) + abs(intuple1[1]-intuple2[1])

grid_list = [ None for i in range(w*h) ]
for i in range(h):
	num_list = [ int(v) for v in input().split() ]
	for j in range(w):
		grid_list[i*h+j] = (num_list[j],i,j)
grid_list = sorted(grid_list)


m = int(input())
for i in range(m):
	l, r = [ int(v) for v in input().split() ]
	score = 0
	left = grid_list[l-1]
	for j in range(l+d,r+d,d):
		right = grid_list[j-1]
		score += manhattan(left,right)
		left = right
	print(score)


### FIXED CODE ###

import sys
input = sys.stdin.readline

h, w, d = [ int(v) for v in input().split() ]
def manhattan(intuple1,intuple2):
	return abs(intuple1[2]-intuple2[2]) + abs(intuple1[1]-intuple2[1])

grid_list = [ None for i in range(w*h) ]
for i in range(h):
	num_list = [ int(v) for v in input().split() ]
	for j in range(w):
		grid_list[i*w+j] = (num_list[j],i,j)
grid_list = sorted(grid_list)

sum_list = []

for i in range(1,d+1):
	temp_list = []
	left = i
	s = 0
	for j in range(i,w*h+1,d):
		s +=  manhattan(grid_list[left-1],grid_list[j-1])
		temp_list.append(s)

		left = j
	sum_list.append(temp_list)

m = int(input())
for i in range(m):
	l, r = [ int(v) for v in input().split() ]
	print(sum_list[r%d-1][(r-1)//d]-sum_list[l%d-1][(l-1)//d])
a,b=map(int.input(),split())
if a-b＊2>=0:
  print(a-b＊2)
else:
   print('0')
  


### FIXED CODE ###

a,b=map(int,input().split())
if a-b*2<=0:
  
  print(0)
else:
  print(a-b*2)
N, K = map(int, input().split())
ans = 0

for i in range(1, N+1):
  if i < K:
    cnt = math.ceil(math.log2(K / i))
    ans += (1 / N) * (1 / 2)**cnt
  else:
    ans += 1 / N

print(ans)

### FIXED CODE ###

import math

N, K = map(int, input().split())
ans = 0

for i in range(1, N+1):
  if i < K:
    cnt = math.ceil(math.log2(K / i))
    ans += (1 / N) * (1 / 2)**cnt
  else:
    ans += 1 / N

print(ans)
if b == 'H':
    print(a)
elif a == b:
    print('H')
else:
    print('D')

### FIXED CODE ###

a, b = list(input().split())
if b == 'H':
    print(a)
elif a == b:
    print('H')
else:
    print('D')
n = int(input())
l = [1, 2, 4, 8, 16, 32, 64]
i = 0
while l[i] < n:
  i += 1
else:
  print(l[i])


### FIXED CODE ###

n = int(input())
l = [1, 2, 4, 8, 16, 32, 64, 128]
i = 0
while l[i] <= n:
  i += 1
else:
  print(l[i-1])
d,t,s = map(int, input().split())
print('Yes' if d <= t*s else 'No")


  
  


### FIXED CODE ###

d,t,s = map(int, input().split())
print('Yes' if d <= t*s else 'No')
import sys
input = sys.stdin.readline
from collections import deque

H, W = map(int, input().split())
S = [list(input().split()[0]) for _ in range(H)]

def bfs(S, H, W, start):
    INF = -1
    stack=deque([start])
    distance = [[INF]*W for _ in range(H)]
    distance[start[1]][start[0]] = 0
    while stack:
        x, y = stack.popleft()
        for i, j in [(1,0),(0,1),(-1,0),(0,-1)]:
            next_x = x + i
            next_y = y + j
            if not(0 <= next_x < W and 0 <= next_y < H):
                continue
            if S[next_y][next_x] != '#' and distance[next_y][next_x] == -1:
                stack.append([next_x, next_y])
                distance[next_y][next_x] = distance[y][x] + 1
    return max(map(max, s))

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != "#":
            ans = max(ans, bfs(S, H, W, (j, i)))

### FIXED CODE ###

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

H, W = map(int, input().split())
S = [list(input().split()[0]) for _ in range(H)]

def bfs(S, H, W, start):
    INF = -1
    stack=deque([start])
    distance = [[INF]*W for _ in range(H)]
    distance[start[1]][start[0]] = 0
    while stack:
        x, y = stack.popleft()
        for i, j in [(1,0),(0,1),(-1,0),(0,-1)]:
            next_x = x + i
            next_y = y + j
            if not(0 <= next_x < W and 0 <= next_y < H):
                continue
            if S[next_y][next_x] != '#' and distance[next_y][next_x] == -1:
                stack.append([next_x, next_y])
                distance[next_y][next_x] = distance[y][x] + 1
    return max(map(max, distance))

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != "#":
            ans = max(ans, bfs(S, H, W, (j, i)))
print(ans)