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

def main():
    N,K = map( int, input().split())
    P = list(input().split())
    max_ex = 0
    
    for i in range(N-K+1):
        sum_ex = sum((float(P[j])+1)/2 for j in range(i,i+K))
        if sum_ex>max_ex:
            max_ex = sum_ex
    print(max_ex)
        

    
if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D
# CreatedDate:  2020-07-29 16:20:16 +0900
# LastModified: 2020-07-29 16:30:22 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from itertools import accumulate


def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    s = [(x+1)/2 for x in p]
#    print(s)
    s = list(accumulate(s))
    s.insert(0, 0)
    ans = 0
#    print(s)
    for i in range(n-k+1):
        ans = max(ans, s[i+k]-s[i])
    print(ans)



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

from collections import Counter
def main():
    n = int(input())
    ans = []
    for x in range(1, n):
        for y in range(1, n):
            for z in range(1, n):
                ans.append(x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x)
    counter = Counter(ans)
    for i in range(1, n+1):
        print(counter[i])
 
 
if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import Counter
import math
def main():
    n = int(input())
    ans = []
    for x in range(1, int(math.sqrt(n+1))+1):
        for y in range(1, int((math.sqrt(n+1)))+1):
            for z in range(1, int((math.sqrt(n+1)))+1):
                ans.append(x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x)
    counter = Counter(ans)
    for i in range(1, n+1):
        print(counter[i])
 
 
if __name__ == '__main__':
    main()
### BUGGY CODE ###

s = input()
ans = 0
mod = []
t = s[len(s)-1]
n = 1
for i in range(len(s)-1,-1,-1):
#     mod.append(int(s[i:])%2019)
    mod.append(int(t)%2019)
#     t = int(t) + (10**(len(s)-i-1))*int(s[i])
    t = int(t) + n*10*int(s[i-1])
    n = n*10%2019
for i in range(0,2019):
    ans += mod.count(i)*(mod.count(i)-1)/2
ans += mod.count(0)
print(int(ans))

### FIXED CODE ###

s = input()
ans = 0
mod = [0]*2019
t = s[len(s)-1]
n = 1
for i in range(len(s)-1,-1,-1):
#     mod.append(int(s[i:])%2019)
    mod[int(t)%2019] += 1
#     t = int(t) + (10**(len(s)-i-1))*int(s[i])
    t = int(t) + n*10*int(s[i-1])
    n = n*10%2019
for i in range(0,2019):
    ans += mod[i]*(mod[i]-1)/2
ans += mod[0]
print(int(ans))
### BUGGY CODE ###

n = int(input())
s = input()
memo = []
for i in range(10):
  for j in range(10):
    for k in range(10):
      memo.append(str(i) + str(j) + str(k))
ans = 0
for i in memo:
  x = 0
  for j in range(n):
    if i[x] == s[j]:
      x += 1
      if x == 3:
        break
  if x == 3:
    ans += 1
print(ans)

### FIXED CODE ###

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

num = [0,1,2,3,4,5,6,7,8,9]
memo = []
for i in num:
  for j in num:
    for k in num:
      memo.append(str(num[i]) + str(num[j]) + str(num[k]))

ans = 0

for i in memo:
  x = 0
  for j in range(n):
    if i[x] == s[j]:
      x += 1
      if x == 3:
        break
  if x == 3:
    ans += 1
    
print(ans)
### BUGGY CODE ###

from functools import cmp_to_key

def main():
  n, w = [int(e) for e in input().split()]
  d = [[int(e) for e in input().split()] for i in range(n)]
  d.sort(key = cmp_to_key(lambda x, y: y[1] / y[0] - x[1] / x[0]))
  t = {}
  t[w] = 0
  for i in range(n):
    keys = list(sorted(t.keys())) # sort しないと品物iを複数回ナップサックに詰める可能性がある
    tw, tv = d[i]
    for j in keys:
      nw = j - tw
      if nw < 0:
        continue
      nv = t[j] + tv
      if nw in t:
        if nv > t[nw]:
          for k in list(t.keys()):
            if k < nw and t[k] <= nv:
              del t[k]
          t[nw] = nv
      else:
        Flag = False
        for k in t:
          if nw < k and nv <= t[k]:
            Flag = True
            break
        if Flag:
          continue
        for k in list(t.keys()):
          if k < nw and t[k] <= nv:
            del t[k]
        t[nw] = nv
  print(max(t.values()))

main()

### FIXED CODE ###

n, w = [int(e) for e in input().split()]
d = [[int(e) for e in input().split()] for i in range(n)]
t = {}
t[w] = 0
for i in range(n):
  keys = list(sorted(t.keys()))
  tw, tv = d[i]
  for j in keys:
    nw = j - tw
    if nw < 0:
      continue
    nv = t[j] + tv
    if nw in t:
      if nv > t[nw]:
        t[nw] = nv
    else:
      t[nw] = nv
print(max(t.values()))
### BUGGY CODE ###

N,M=map(int,input().split())
A=[int(input()) for i in range(M)]
l=0
r=1
ans=0
for i in range(1,N+1):
    if i in A:
        ans=0
        l=r
        r=ans
    else:
        ans=l+r
        l=r
        r=ans
print(ans%(10**9+7))

### FIXED CODE ###

N,M=map(int,input().split())
B=[1]+[1]+[0]*(N-1)
for j in range(M):
    a=int(input())
    B[a]=-1
    if a==1:
        B[a]=0
i=2
while i<=N:
    if B[i]==-1:
        B[i]=0
    else:
        B[i] = (B[i - 1] + B[i - 2]) % (10 ** 9 + 7)
    i+=1
print(B[N])
### BUGGY CODE ###

N, H = map(int, input().split())
a_list = []
b_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
count = 0
a = max(a_list)
b_list.sort()
while True:
    if len(b_list) >= 1:
        if b_list[-1] >= a:
            b = b_list.pop(-1)
            H -= b
            count += 1
            if H <= 0:
                break
        else:
            H -= a
            count += 1
            if H <= 0:
                break
    else:
        H -= a
        count += 1
        if H <= 0:
            break
        
print(count)

### FIXED CODE ###

N, H = map(int, input().split())
a_list = []
b_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
count = 0
a = max(a_list)
b_list.sort()
while len(b_list) >= 1 and H >= 1:
    if b_list[-1] >= a:
        b = b_list.pop(-1)
        H -= b
        count += 1
    else:
        break
if H <= 0:
    print(count)
else:
    tmp = H // a if H % a == 0 else H //a + 1
    print(count + tmp)
### BUGGY CODE ###

S=input()
q=int(input())
for i in range(q):
    IN=input()
    if IN=="1":
        S=S[::-1]
    else:
        t,f,c=IN.split()
        if f=="1":
            S=c+S
        elif f=="2":
            S=S+c
print(S)

### FIXED CODE ###

S=input()
q=int(input())
RV=0
A="A"
for i in range(q):
    IN=input()
    if IN=="1":
        RV+=1
    else:
        t,f,c=IN.split()
        if RV%2==0:
            if f=="1":
                A=c+A               
            else:
                A=A+c
        else:
            if f=="1":
                A=A+c
            else:
                A=c+A
if RV%2==0:
    for i in range(len(A)):
        if A[i]=="A":
            print(A[:i]+S+A[i+1:])
else:
    A=A[::-1]
    for i in range(len(A)):
        if A[i]=="A":
            print(A[:i]+S[::-1]+A[i+1:])
### BUGGY CODE ###

import functools
from operator import mul


n = int(input())

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

product = 1

for num in nums:
    product *= num

if product > 1e18:
    product = -1

print(product)


### FIXED CODE ###

n = int(input())

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

product = 1

for num in nums:
    product *= num

    if product > 1e18:
        product = -1
        break

if 0 in nums:
    product = 0

print(product)
### BUGGY CODE ###

N=int(input())
D=[int(i) for i in input().split()]
M=int(input())
T=[int(i) for i in input().split()]
x=0
for i in range(M):
    if T[i] in D:
        D.remove(T[i])
    else:
        x+=1
if x==0:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

n = int(input())
*D, = map(int, input().split())
m = int(input())
*T, = map(int, input().split())
D.sort()
T.sort()
j = 0
for i in range(n):
    if j == m:
        break
    if D[i] == T[j]:
        j += 1
if j == m:
    print('YES')
else:
    print('NO')
### BUGGY CODE ###

#ALDS1_5-B Merge Sort
from collections import deque

def merge(A,B):
    ans = deque()
    count = 0
    while(True):
        if len(A)==0:
            if len(B)==0:
                break
            ans.append(B.popleft())
        elif len(B) == 0:
            ans.append(A.popleft())
        elif A[0] > B[0]:
            ans.append(B.popleft())
        else:
            ans.append(A.popleft())
        count+=1
    return (ans,count)

n = int(input())
S = [int(i) for i in input().split()]
div = deque([S])
mer = deque()
count = 0
while(len(div)>0):
    d = div.pop()
    if(len(d)>2):
        mid = len(d)//2
        div.appendleft(d[:mid])
        div.appendleft(d[mid:])
    elif(len(d)==2):
        if d[0] > d[1]:
            mer.appendleft(d[::-1])
        else:
            mer.appendleft(d)
        count+=2
    else:
        mer.appendleft(d)
        
while(len(mer)>1):
    A = deque(mer.popleft())
    B = deque(mer.popleft())
    ret = merge(A,B)
    mer.append(ret[0])
    count+=ret[1]
    
ans = ""
for i in ret[0]:
    ans += str(i) + " "
print(ans[:-1])
print(count)


### FIXED CODE ###

from collections import deque

def merge(A,B):
    ans = [0]*(len(A)+len(B))
    count=i=j=0
    A+=[10**9+1]
    B+=[10**9+1]
    for k in range(len(ans)):
        if A[i]<B[j]:
            ans[k]=A[i]
            i+=1
        else:
            ans[k]=B[j]
            j+=1
        count+=1
    return (ans,count)

n = int(input())
S = [int(i) for i in input().split()]
div = deque([S])
mer = deque()
count = 0
while(len(div)>0):
    d = div.popleft()
    if(len(d)>2):
        mid = len(d)//2
        div.append(d[:mid])
        div.append(d[mid:])
    elif(len(d)==2):
        if d[0] > d[1]:
            mer.append(d[::-1])
        else:
            mer.append(d)
        count+=2
    else:
        mer.append(d)
        
while(len(mer)>1):
    A = mer.pop()
    B = mer.pop()
    ret = merge(A,B)
    mer.appendleft(ret[0])
    count+=ret[1]
    
ans = ""
for i in ret[0]:
    ans += str(i) + " "
print(ans[:-1])
print(count)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from collections import deque

from sys import setrecursionlimit

setrecursionlimit(1000000)

INF = float("inf")
# Input#
# n = int(input())
n, m = map(int, input().split())
# a = list(map(int, input().split()))

d = deque()
d_tmp = deque()
x = [-1]
y = [-1]

for i in range(m):
    x_in, y_in = map(int, input().split())
    x.append(x_in)
    y.append(y_in)
    d.append((x_in, y_in))

memo = [-1] * (n + 1)
ans = -1


def dp(i):
    global ans
    if memo[i] == -1:
        ret = 0
        for x_in, y_in in d:
            if x_in == i:
                tmp = dp(y_in) + 1
                ret = max(tmp, ret)
        memo[i] = ret
        ans = max(ret, ans)
        return ret
    else:
        return memo[i]


for i, _ in d:
    if memo[i] == -1:
        dp(i)

print("{}".format(ans))


### FIXED CODE ###

# -*- coding: utf-8 -*-
from collections import deque

from sys import setrecursionlimit

setrecursionlimit(1000000)

INF = float("inf")
# Input#
# n = int(input())
n, m = map(int, input().split())
# a = list(map(int, input().split()))

d = deque()
d_tmp = deque()
x = [-1]
y = [[-1] for _ in range((n + 1))]

for _ in [0] * m:
    x_in, y_in = map(int, input().split())
    #    x.append(x_in)
    y[x_in].append(y_in)
    d.append((x_in, y_in))

memo = [-1] * (n + 1)
ans = -1


def dp(i):
    global ans
    if memo[i] == -1:
        ret = 0
        for x_in in y[i][1:]:
            tmp = dp(x_in) + 1
            if tmp > ret:
                ret = tmp
        memo[i] = ret
        if ret > ans:
            ans = ret
        return ret
    else:
        return memo[i]


for i, _ in d:
    if memo[i] == -1:
        dp(i)

print("{}".format(ans))
### BUGGY CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))
     
dp = [10 ** 9 for i in range(N + K)]
dp[0] = 0
for i in range(N):
    for j in range(1, K + 1):
        if i + j < N:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
        
print(dp[N - 1])

### FIXED CODE ###

# B - Frog2
import numpy as np

N, K = list(map(int, input().split()))
h = np.array(list(map(int, input().split()))+[0]*K)

dp = np.array([10**9]*(N+K))
dp[0] = 0

for i in range(N):
    dp[i+1:i+K+1] = np.minimum(dp[i+1:i+K+1], dp[i]+abs(h[i+1:i+K+1]-h[i]))
print(dp[N-1])
### BUGGY CODE ###

import itertools
import collections
                                                                          
N, Y = map(int, input().split())
for l in itertools.combinations_with_replacement([10000, 5000, 1000], N):
    if sum(l) == Y:
        c = collections.Counter(l)
        print("{} {} {}".format(c[10000], c[5000], c[1000]))
        break
else:
    print("-1 -1 -1")

### FIXED CODE ###

N, Y = map(int, input().split())
Y //= 1000
for nog in range(N + 1):
    for hig in range(N + 1 - nog):
        yuk = N - nog - hig
        if nog + hig * 5 + yuk * 10 == Y:
            print(yuk, hig, nog)
            break
    else:
        continue
    break
else:
    print("-1 -1 -1")
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from collections import deque
from bisect import bisect_left

def solve(N: int, A: "List[int]"):
    stack = [[]]

    for i in range(N):
        for st in stack:
            index = bisect_left(st,A[i])

            if not st or index == len(st):
                st.append(A[i])
                break
            else:
                continue
        else:
            stack.append([A[i]])
    
    print(len(stack))
    return



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

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from collections import deque
from bisect import bisect_left

def solve(N: int, A: "List[int]"):
    b = deque([A[0]])
    for a in A[1:]:
        if a <= b[0]:
            b.appendleft(a)
        else:
            idx = bisect_left(b, a)
            b[idx-1] = a
    print(len(b))
    return


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

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

a, b, k = [int(i) for i in input().split()]

for i in range(k):
  if a != 0:
    a -= 1
  elif b != 0:
    b -= 1
  else:
    break
    
print(a, b)

### FIXED CODE ###

a, b, k = [int(i) for i in input().split()]

if k > a+b:
  a = 0
  b = 0
elif k > a:
  b = a+b-k
  a = 0
else:
  a = a-k
  
print(a, b)
### BUGGY CODE ###

import heapq
n , m = map(int, input().split())
a = list(map(int,input().split()))
heapq.heapify(a)
for i in range(m):
    b , c = map(int, input().split())
    for j in range(b):
        if a[0]<c:
            heapq.heappushpop(a,c)
        else:
            break
print(sum(a))


### FIXED CODE ###

n , m = map(int, input().split())
a = list(map(int,input().split()))
a.sort()
bc=[]
for i in range(m):
    b , c = map(int, input().split())
    bc.append((b,c))
bc.sort(key = lambda x : x[1],reverse=True)

t=0
for i in range(m):
    b,c=bc[i]
    if t>=n:
        break
    if a[t]>=c:
        break
    for j in range(b):
        if a[t]<c:
            a[t]=c
            if t<n-1:
                t+=1
        else:
            break
print(sum(a))
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

ans = 0
for i in range(60):
    x = [(bool)(ai & 1 << i) for ai in a]
    sx = sum(x)
    count = sx * (n - sx)
    ans += count << i
    ans %= MOD

print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

ans = 0
for i in range(60):
    x = [(bool)(ai & 1 << i) for ai in a]
    sx = sum(x)
    count = sx * (n - sx)
    ans += count << i
    ans %= MOD

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

import sys
input = sys.stdin.readline
k, q = map(int, input().split())
d = list(map(int, input().split()))

query = []
for _ in range(q):
    query.append(list(map(int, input().split())))

for n, x, m in query:
    l = [d[i]%m for i in range(k)]
    n -= 1
    zero = l.count(0)
    count = n // k
    zero_total = zero*count
    rem = n % k
    total = sum(l)%m * count + x%m + sum(l[:rem])
    total //= m
    total += sum(l)//m * count
    zero_total += l[:rem].count(0)

    print(n-total-zero_total)


### FIXED CODE ###

import sys
input = sys.stdin.readline
k, q = map(int, input().split())
d = list(map(int, input().split()))
query = [None]*q
for i in range(q):
    query[i] = list(map(int, input().split()))

def answer_query(n, x, m):
    l = [m if i%m == 0 else i%m for i in d]
    count = n // k
    rem = n % k
    s = sum(l)
    total = s%m * count + x%m
    for i in range(rem):
        total += l[i]

    total //= m
    total += s//m * count

    print(n-total)


for n, x, m in query:
    answer_query(n-1, x, m)
### BUGGY CODE ###

n, k = map(int, input().split())
h = [int(i) for i in input().split()]
dp = [0]*n
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
  if i <= k:
    dp[i] = abs(h[0] - h[i])
  else:
    dp[i] = min(dp[i-j] + abs(h[i-j]-h[i])
    for j in range(1, k+1))
print(dp[-1])


### FIXED CODE ###

n, k = map(int, input().split())
h = [int(i) for i in input().split()]
dp = [0]*n
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
  if i <= k:
    dp[i] = abs(h[0] - h[i])
  else:
    dp[i] = min(dp[i-j] + abs(h[i-j]-h[i])
    for j in range(1, k+1))
print(dp[-1])
### BUGGY CODE ###

import math
 
s=list(map(int,input().split()))
t=list(map(int,input().split()))
a=0
t.sort(reverse=True)
if s[0]>=2:
  for i in range(s[1]):
    t[0]=math.floor(t[0]/2)
    if t[0]<t[1]:
      t.sort(reverse=True)
else:
  for j in range(s[1]):
    t[0]=math.floor(t[0]/2)
a=sum(t)
print(a)

### FIXED CODE ###

import math
 
s=list(map(int,input().split()))
t=list(map(int,input().split()))
a=0
b=0
c=0
d=s[1]
t.sort(reverse=True)
if s[0]==1:
  for i in range(s[1]):
    t[0]=math.floor(t[0]/2)
else:
  c=t[0]/2
  for j in range(s[1]):
    for l in range(s[0]):
      if d>0:
        if c<t[l]:
          t[l]=math.floor(t[l]/2)
          d=d-1
        else:
            t.sort(reverse=True)
            c=t[0]/2
            break
      else:
        break
e=sum(t)
print(e)
### BUGGY CODE ###

k = int(input())

que = [1,2,3,4,5,6,7,8,9]

for i in range(k):
    x = que[0]
    del que[0]
    mod = x%10
    if mod != 0:
        que.append(10*x+mod-1)
    que.append(10*x+mod)
    if mod != 9:
        que.append(10*x+mod+1)
print(x)

### FIXED CODE ###

from collections import deque
k = int(input())
q = deque(list(range(1, 10)))
for _ in range(k-1):
	d = q.popleft()
	if d%10 > 0:
		q.append(d*10 + d%10 - 1)
	q.append(d*10 + d%10)
	if d%10 < 9:
		q.append(d*10 + d%10 + 1)
print(q.popleft())
### BUGGY CODE ###

a,b,k=map(int,input().split())
d=[i for i in range(a,b+1)]
ans=[]
n=len(d)
if n>=2*k:
  for i in range(k):
    ans.append(d[i])
    ans.append(d[n-1-i])
elif k<=n<2*k:
  for i in range(k):
    ans.append(d[i])
  for j in range(n-k):
    ans.append(d[n-1-j])
elif n<k:
  for i in range(n):
    print(d[i])
  exit()
    
ans.sort()
for i in ans:
  print(i)

### FIXED CODE ###

a, b, k = map(int, input().split())

if b-a <= k:
  for i in range(a, b+1):
    print(i)
else:
  ans = []
  for i in range(a, a+k):
    if i not in ans:
      ans.append(i)
      print(i)
  for j in range(b-k+1, b+1):
    if j not in ans:
      print(j)
### BUGGY CODE ###

N = int(input())
T, A = map(int, input().split())
num = T + A
for _ in range(N-1):
  t, a = map(int, input().split())
  while True:
    if num%(t+a) == 0 and (num*t)//(t+a) >= T and (num*a)//(t+a) >= A:
      T = (num*t)//(t+a)
      A = (num*a)//(t+a)
      break
    num += num%(t+a)
print(num)


### FIXED CODE ###

import math

N = int(input())
x, y = map(int, input().split())
for _ in range(N-1):
  a, b = map(int, input().split())
  # n = max(math.ceil(x/a), math.ceil(y/b))
  na = nb = 0
  if x%a == 0:
    na = x//a
  else:
    na = x//a+1
  if y%b == 0:
    nb = y//b
  else:
    nb = y//b+1
  n = max(na, nb)
  x, y = n*a, n*b
print(x+y)
### BUGGY CODE ###

N = int(input())
S = list(input())
Q = int(input())
K = list(map(int,input().split()))
DP = [{"D":0,"M":0,"DM":0}]
C = []
for i in range(N):
    q = DP[i].copy()
    if S[i] == "D":
        q["D"] += 1
    elif S[i] == "M":
        q["M"] += 1
        q["DM"] += q["D"]
    elif S[i] == "C":
        C.append(i+1)
    DP.append(q)

for k in K:
    ans = 0
    for c in C:
        if c < k:
            ans += DP[c]["DM"]
        else:
            ans += DP[c]["DM"] - DP[c-k]["DM"] - DP[c-k]["D"]*(DP[c]["M"] - DP[c-k]["M"])
    print(ans)

### FIXED CODE ###

N = int(input())
S = list(input())
Q = int(input())
K = list(map(int,input().split()))
DP = [[0,0,0]]
C = []
for i in range(N):
    q = DP[i][:]
    if S[i] == "D":
        q[0] += 1
    elif S[i] == "M":
        q[1] += 1
        q[2] += q[0]
    elif S[i] == "C":
        C.append(i+1)
    DP.append(q)

for k in K:
    ans = 0
    for c in C:
        if c < k:
            ans += DP[c][2]
        else:
            ans += DP[c][2] - DP[c-k][2] - DP[c-k][0]*(DP[c][1] - DP[c-k][1])
    print(ans)
### BUGGY CODE ###

n,m = map(int,input().split())
a = n-m
ans = 0
if abs(a) > 1:
    ans = 0
elif abs(a) == 1:
    x = 1
    y = 1
    for i in range(1,n+1):
        x *= i % (10**9+7)
    for i in range(1,m+1):
        y *= i % (10**9+7)
    ans = x * y %(10**9+7)
else:
    x = 1
    y = 1
    for i in range(1,n+1):
        x *= i % (10**9+7)
    for i in range(1,m+1):
        y *= i % (10**9+7)
    ans = 2*x * y %(10**9+7)
print(ans)

### FIXED CODE ###

n,m = map(int,input().split())
a = n-m
ans = 0
if abs(a) > 1:
    ans = 0
elif abs(a) == 1:
    x = 1
    if a < 0:
        s = n
    else:
        s = m
    for i in range(1,s+1):
        x *= i 
        x %= (10**9+7)
    ans = x * x *(i+1) %(10**9+7)
else:
    x = 1
    for i in range(1,n+1):
        x *= i 
        x %= (10**9+7)
    ans = 2* x**2  %(10**9+7)
print(ans)
### BUGGY CODE ###

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

h, w = map(int, input().split())
a = [[j == "#" for j in input()] for _ in range(h)]

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

# スタート地点をqueueに追加
que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])

count = 0
while True:
    count += 1
    nque = deque()
    while que:
        y, x = que.popleft()
        for j in range(4):
            ny = y + dy[j]
            nx = x + dx[j]
            if nx < w and nx >= 0 and ny < h and ny >= 0 and not a[ny][nx]:
                a[ny][nx] = True
                nque.append((ny, nx))
    if nque:
        que = copy.copy(nque)
    else:
        break

print(count - 1)

### FIXED CODE ###

from collections import deque
h, w = map(int, input().split())
a = [[] for i in range(h)]
for i in range(h):
    a[i] = list(input())

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

que = deque()

white = h * w

# スタート地点をqueueに追加
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            que.append([i, j])
            white -= 1

count = 0
while 1:
    if white == 0:
        break
    count += 1
    loop = len(que)
    for i in range(loop):
        p = que.popleft()
        for j in range(4):
            ny = p[0] + dy[j]
            nx = p[1] + dx[j]
            if nx < w and nx >= 0 and ny < h and ny >= 0 and a[ny][nx] == ".":
                a[ny][nx] = "#"
                white -= 1
                que.append([ny, nx])


print(count)