Harryxun/stf_run huggingface dataset:
import math
M = 256
while 1:
    N = int(raw_input())
    if N == 0: break
    H = 1
    l = map(int,raw_input().split())
    for S in range(16):
        for A in range(16):
            for C in range(16):
                R = S
                O = [0]*N
                for i in range(N):
                    R = (A*R+C)%M
                    O[i] = (l[i]+R)%M
                X = [O.count(i) for i in O]
                tmp = -sum(float(x)/N*math.log(float(x)/N) for x in X)
                if tmp < H:
                    H = tmp
                    ans = [S,A,C]
    print " ".join(map(str,ans))

### FIXED CODE ###

import math,itertools as it
M = 256
while 1:
    N = int(raw_input())
    if N == 0: break
    H = 1e10
    I = map(int,raw_input().split())
    for S,A,C in it.product(range(16),repeat=3):
        R = S
        O = [0]*M
        for i in I:
            R = (A*R+C)%M
            O[(i+R)%M] += 1
        tmp = -sum(1.0*x/N*math.log(1.0*x/N,2) for x in O if x > 0)
        if tmp < H:
            H = tmp
            ans = [S,A,C]
    print " ".join(map(str,ans))
import numpy as np
n = int(input())
b = 2*np.array([int(x) for x in input().split()])
A = np.eye(n)
for i in range(n-1):
    A[i, i+1] = 1
A[-1,0] = 1
print(' '.join(str(int(val)) for val in np.linalg.solve(A,b)))

### FIXED CODE ###

n = int(input())
bs = [int(x) for x in input().split()]
sign = 1
a_2 = bs[0]
for b in bs[1:]:
    a_2 += sign*b
    sign *= -1

ans = str(a_2) + ' '
for i in range(n-2):
    a_2 = 2*bs[i+1] - a_2
    ans += str(a_2) + ' '
ans = str(2*bs[i+2] - a_2) + ' ' + ans
print(ans)
t = [int(input()) for i in range(5)]
T = [(-(-i//10))*10 for i in t]
t_min = [i%10 for i in t]
t_min = min([i for i in t_min if i != 0])
print(sum(T) - 10 + t_min)

### FIXED CODE ###

t = [int(input()) for i in range(5)]
T = [(-(-i//10))*10 for i in t]
t_min = [i%10 for i in t]
t_min = min([i for i in t_min if i != 0]) if t_min != [0 for i in range(5)] else 10
print(sum(T) - 10 + t_min)
from collections import deque
S = deque(list(input().strip()))
Q = int(input().strip())
flag = 1
for i in range(Q):
  line = input().strip()
  if len(line) == 1:
    flag = 1 - flag
  else:
    _, F, C = line.strip().split()
    if flag:
      if int(F) == 1:
        S.appendleft(C)
      else:
        S.append(C)
    else:
      if int(F) == 1:
        S.append(C)
      else:
        S.appendleft(C)

if flag:
  print(''.join(S))
else:
  print(''.join(S[::-1]))
    

### FIXED CODE ###

print('Yes' if len(set(input().strip())) > 1 else 'No')
n,m=map(int,input().split())
lists=list(map(int,input().split()))
checklist=[]
count=0

for i in range(m):
    b,c=map(int,input().split())
    checklist.append((c,b))
checklist=sorted(checklist,reverse=True)
lists=sorted(lists)
uselist=[]
count=0

for i in checklist:
    for j in range(i[1]):
        uselist.append(i[0])
        count+=1
        if count==n:
            break
answer=0
for i in range(n):
    if lists[i]<uselist[i]:
        lists[i]=uselist[i]
    else:
        break
print(sum(lists))
      

### FIXED CODE ###

n,m=map(int,input().split())
lists=list(map(int,input().split()))
checklist=[]
count=0

for i in range(m):
    b,c=map(int,input().split())
    checklist.append((c,b))
checklist=sorted(checklist,reverse=True)
lists=sorted(lists)
uselist=[]
count=0

for i in checklist:
    for _ in range(i[1]):
        uselist.append(i[0])
    count+=i[1]

    if count>=n:
        break
answer=0
n=min(n,len(uselist))
for i in range(n):
    if lists[i]<uselist[i]:
            lists[i]=uselist[i]
    else:
        break
print(sum(lists))
n, k = map(int, input().split())
TO = [*map(lambda x: int(x)-1, input().split())]
C = [*map(int, input().split())]

# print(n,k)
# print(TO)
# print(C)

vis = [False]*(n+1)
def dfs(i, t):
    if vis[i]: return t
    vis[i] = True
    t.append(i)
    return dfs(TO[i], t)

INF = 1*((10**9)*5000 + 1)
score = -INF
for f in range(n):
    T = dfs(f, [])
    len_t = len(T)
    if len_t == 0: continue
    costs = [0] * (len_t)
    for i in range(len_t): costs[i] = C[T[i]]
    loops = k // len_t
    cost = sum(costs)
    # print(len_t, T, 'costs',costs, cost, loops)
    # if cost >= 0:
    #     k -= loops * len_t
    #     cost = cost * loops

    if cost >= 0:
        k -= loops * len_t
    else:
        pass

    peak_cost = -INF
    for i in range(len_t):
        sum_cost = 0
        for j in range(k):
            sum_cost += costs[(i+j)%len_t]
            peak_cost = max(peak_cost, sum_cost)
    # print(k,'peak_cost',peak_cost, cost)
    cost = max({cost, cost + peak_cost, cost*loops + peak_cost, peak_cost})
    # print('cost',cost)
    score = max(score, cost)
print(score)



### FIXED CODE ###

n, k = map(int, input().split())
P = [*map(lambda x: int(x)-1, input().split())]
C = [*map(int, input().split())]

INF = 10**18
max_score = -INF
for st in range(n):
    lc = 0 # lap count
    lap_sc = 0 # lap score
    nx = st
    while True:
        lc += 1
        lap_sc += C[nx]
        nx = P[nx]
        if nx == st: break

    sum_sc = 0
    kc = 0
    while True:
        kc += 1
        if k < kc: break

        sum_sc += C[nx]
        score = sum_sc + max(0, lap_sc) * ((k - kc) // lc)
        max_score = max(max_score, score)

        nx = P[nx]
        if nx == st: break

print(max_score)

# print('===')
# print(n,k)
# print(P)
# print(C,end='\n\n')
n = int(input())

if N <=999:
    print("ABC")
else:
    print("ABD")

### FIXED CODE ###

n = int(input())

if n <=999:
    print("ABC")
else:
    print("ABD")
N,K=map(int,input().split())
b=list(map(int,input().split()))
b.sort()
a=[]
for i in range(N):
    if b[i]<K:
        a.append(b[i])
N=len(a)
ans=0
#print(bin((1<<K)>>1))
C=[1]
n=1
for i in range(N):
    n=n|n<<a[i]
    n%=(1<<K)
    C.append(n)
#print(C)
    #print(bin(n))
P=N//2
n=C[P]
for x in range(P+1,N):
    n=n|n<<a[x]
    n%=(1<<K)
if n < (1<<K)>>a[P]:
    F=0
else:
    F=1
if F==0:
    for i in range(N):
        n=C[i]
        for j in range(i+1,N):
            n=n|n<<a[j]
            n%=(1<<K)
        if n < (1<<K)>>a[i]:
            ans+=1
        else:
            break
    print(ans)
else:
    ans=N//2
    P=N//2
    for i in range(P+1,N):
        n=C[i]
        for j in range(i+1,N):
            n=n|n<<a[j]
            n%=(1<<K)
        if n < (1<<K)>>a[i]:
            ans+=1
        else:
            break
    print(ans)


### FIXED CODE ###

N,K=map(int,input().split())
b=list(map(int,input().split()))
b.sort()
a=[]
for i in range(N):
    if b[i]<K:
        a.append(b[i])
N=len(a)
ans=0
#print(bin((1<<K)>>1))
C=[1]
n=1
for i in range(N):
    n=n|n<<a[i]
    n%=(1<<K)
    C.append(n)
#print(C)
    #print(bin(n))
if N<=10:
    for i in range(N):
        n=C[i]
        for j in range(i+1,N):
            n=n|n<<a[j]
            n%=(1<<K)
        if n < (1<<K)>>a[i]:
            ans+=1
        else:
            break
    print(ans)
else:
    a+=[10**9]
    H=N
    L=0
    
    while abs(H-L)>4:
        Mid=(H+L)//2
        #print(H,Mid,L)
        n=1
        for i in range(N):
            if i==Mid:
                continue
            else:
                n=n|n<<a[i]
                n%=(1<<K)
        if n >= (1<<K)>>a[Mid]:    
            H=Mid
        else:
            L=Mid
    #print(H,L)        
    for j in range(max(0,L-5),N):
        n=1
        for i in range(N):
            if i==j:
                continue
            else:
                n=n|n<<a[i]
                n%=(1<<K)
        if n >= (1<<K)>>a[j]: 
            print(j)
            exit()
    print(N)
import sys


def input():
    return sys.stdin.readline().strip()

def main():

    # i have too make index as weight and value as value
    import numpy as np
    N, W = map(int, input().split())

    dp = np.zeros(W + 1, int)

    for i in range(N):
        w, v = map(int, input().split())
        np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])
        # print(dp[:-w],dp[w:] )


    print(dp[-1])


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys


def input():
    return sys.stdin.readline().strip()

def main():

    # i have too make index as weight and value as value
    import numpy as np

    n, capacity = map(int, input().split())
    value_max = 10 ** 5
    dp = np.full(value_max + 1, capacity + 1)
    dp[0] = 0

    for i in range(n):
        w, v = map(int, input().split())
        np.minimum(dp[v:], dp[:-v] + w, out=dp[v:])

    print(np.where(dp <= capacity)[0][-1])


if __name__ == "__main__":
    main()
a,b,k=map(int,input().split())
d=set()
for i in range(k):
  d.add(a+i)
for i in range(k):
  d.add(b-i)
d.sort()
for i in d:
  print(d)

### FIXED CODE ###

a,b,k=map(int,input().split())
d=set()
f=min(b-a+1,k)
for i in range(f):
  d.add(a+i)
for i in range(f):
  d.add(b-i)
d=sorted(list(d))
for i in d:
  print(i)
a,b=input().split()
if int(a)>int(b):
  print(b*str(a))
else:
  print(a*str(b))

### FIXED CODE ###

a,b=input().split()
if int(a)>int(b):
  print(b*int(a))
else:
  print(a*int(b))
import heapq

n, m = map(int, input().split())
lis = []
for i in range(n + 1):
    lis.append([])

for i in range(n):
    a, b = map(int, input().split())
    if a <= m:
        lis[a].append(-b)

cnd = []
heapq.heapify(cnd)
res = 0

for j in range(1, m + 1):
    for e in lis[j]:
        heapq.heappush(cnd, e)
    if cnd:
        res += -heapq.heappop(cnd)
print(res)


### FIXED CODE ###

import heapq

n, m = map(int, input().split())
lis = []
for i in range(m + 1):
    lis.append([])

for i in range(n):
    a, b = map(int, input().split())
    if a <= m:
        lis[a].append(-b)

cnd = []
heapq.heapify(cnd)
res = 0

for j in range(1, m + 1):
    for e in lis[j]:
        heapq.heappush(cnd, e)
    if cnd:
        res += -heapq.heappop(cnd)
print(res)
i = input()
6 4 3
i1 = list(map(int, i.split() ) )
i2 = i1[0] - i1[1]
i3 = i1[2] - i2
		if i3 < 0:
 				print(0)
		else:
 				print(i3)


### FIXED CODE ###

i = input()
i1 = list(map(int, i.split() ) )
i2 = i1[0] - i1[1]
i3 = i1[2] - i2
if i3 < 0:
 print("0")
else:
 print(i3)
max=0
N=int(input())
K=int(input())
t=list(input().split())
s=[int(n) for n in t]
for i in range(N-K+1):
    x=0
    for j in range(K):
        x+=s[i+j]
    if max<x :
        max=x
print((max+K)/2)

### FIXED CODE ###

N, K = map(int,input().split())
t=list(input().split())
s=[int(n) for n in t]
max=x=sum(s[:K])
for i in range(N-K):
    x+=(s[K+i]-s[i])
    if max<x :
        max=x
print((max+K)/2)
import math

N = int(input().strip())
ar = list(map(int,input().strip().split()))

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

koubai = 1

for i in range(0,len(ar)):
    koubai = lcm(ar[i],koubai)

res = 0
koubai -= 1
for i in range(0,len(ar)):
    res += koubai % ar[i]
print(res)

### FIXED CODE ###

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)  # 再帰定義

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


N = int(input().strip())
ar = list(map(int,input().strip().split()))

koubai = 1

for i in range(0,len(ar)):
    koubai = lcm(ar[i],koubai)

res = 0
koubai -= 1
for i in range(0,len(ar)):
    res += koubai % ar[i]
print(res)
a, b = map(int, input().split())
 
if b == 0:
    return 1
else:
    inpu = 1
    while b > (a -1) * inpu + a:
        inpu +=1
    print(inpu + 1)

### FIXED CODE ###

a, b = map(int, input().split())
 
k = 1
ans = 0
 
if b == 1:
  print(0)
else:
  while k<b:
    k += a-1
    ans += 1
  print(ans)
n = int(input())
A = list(map(int, input().split()))
A.sort()
hst = [0] * (A[-1] + 1)
for a in A:
    hst[a] += 1

rec = []
squ = []
for a in list(set(A)):
    if hst[a] > 1:
        rec.append(a)
    if hst[a] >= 4:
        squ.append(a)

# print(rec)
# print(squ)

s = 0
if len(squ) != 0:
    s = squ[-1]**2

if len(rec) <= 1 and len(squ) < 1:
    print(0)
else:
    print(max(s, rec[-1]*rec[-2]))

### FIXED CODE ###

from collections import Counter
n = int(input())
A = list(map(int, input().split()))

C = Counter(A)

rec = []
squ = []

for a in A:
    if 2 <= C[a]:
        rec.append(a)
    if 4 <= C[a]:
        squ.append(a)
rec = list(set(rec))
squ = list(set(squ))
# print(rec)
# print(squ)

s = 0
if len(squ) != 0:
    s = max(squ)**2

if len(rec) < 2:
    print(s)
else:
    rec.sort(reverse=True)
    print(max(s, rec[0]*rec[1]))
import sys

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

graph = list(map(int, input().split()))
graph.insert(0, 0)

queue = [1]
now_pos = 1
start = 0

for i in range(K):
    if not graph[now_pos] in queue:
        queue.append(graph[now_pos])
        now_pos = graph[now_pos]

    # 循環した
    else:
        start = graph[now_pos]
        break

before = queue[:queue.index(start)]
roop = queue[queue.index(start):]

for i in range(len(roop)):
    if (K - len(before)) % len(roop) == i:
        print(roop[i])
        sys.exit()


### FIXED CODE ###

import sys
import time

N, K = map(int, input().split())
town_list = list(map(int, input().split()))

queue = {}

start = -1
count = 1

now_town = 1

for i in range(K):
    if town_list[now_town - 1] in queue:
        start = town_list[now_town - 1]
        break
    queue[town_list[now_town - 1]] = count
    now_town = town_list[now_town - 1]
    count += 1

if start == -1:
    print(now_town)
    sys.exit()

roop = len(queue) - (queue[start] - 1)
before_len = queue[start]

print(list(queue.keys())[(K - before_len) % roop + before_len - 1])
T = int(input())

for t in range(T):
    N, A, B, C, D = map(int, input().split())
    memo = {}

    def dist(n):
        if n == 0:
            return 0
        if n in memo:
            return memo[n]
        
        ret = min(
            D * n,
            D * abs(n - n//5*5) + C + dist(n//5),
            D * abs(n - (n+4)//5*5) + C + dist((n+4)//5),
            D * abs(n - n//3*3) + B + dist(n//3),
            D * abs(n - (n+2)//3*3) + B + dist((n+2)//3),
            D * abs(n - n//2*2) + A + dist(n//2),
            D * abs(n - (n+1)//2*2) + A + dist((n+1)//2)
        )

        memo[n] = ret
        return ret
    print(dist(N))

### FIXED CODE ###

T = int(input())

for t in range(T):
    N, A, B, C, D = map(int, input().split())
    memo = {}

    def dist(n):
        if n == 0:
            return 0
        if n == 1:
            return D
        if n in memo:
            return memo[n]
        
        ret = min(
            D * n,
            D * abs(n - n//5*5) + C + dist(n//5),
            D * abs(n - (n+4)//5*5) + C + dist((n+4)//5),
            D * abs(n - n//3*3) + B + dist(n//3),
            D * abs(n - (n+2)//3*3) + B + dist((n+2)//3),
            D * abs(n - n//2*2) + A + dist(n//2),
            D * abs(n - (n+1)//2*2) + A + dist((n+1)//2)
        )

        memo[n] = ret
        return ret
    print(dist(N))
x,k = map(int,input().split())

if 500*x >= k:
  print('YES')
  
  else:
    print('NO')
    
    

### FIXED CODE ###

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

if 500*X >= K:
  print('Yes')
  
else:
    print('No')
n,m,r=map(int,input().split())
r-=m*n
if r<0:print(0)
else:
 a=1
 for i in range(r):a*=(i+n)/-~i
 print(int(a+.1))


### FIXED CODE ###

n,m,r=map(int,input().split())
r-=m*n
if r<0:print(0)
else:
 d=1
 for i in range(r):d*=i+1
 u=1
 for i in range(r):u*=i+n
 print(u//d)
x^3

### FIXED CODE ###

x = input()
print(x**3)
n=int(input())
lis=list(map(int,input().split()))
count=1
if 0 in lis:
  print(0)
  exit()
for num in lis:
    count *= num
	if count > 10**18:
    	print(-1)
        exit()
print(count)


### FIXED CODE ###

n = int(input())
lis = list(map(int,input().split()))
ans = 1
if 0 in lis:
  print(0)
  exit()
for num in lis:
  ans *= num
  if ans > 10 ** 18:
    print(-1)
    exit()
print(ans)
import numpy as np

n,l=map(int,inut().split())
w_all=np.zeros(l+1,dtype=int)

for _ in range(n):
  w,v=map(int,input().split())
  w_all=np.maximum(w_all[w:],w_all[:-w]+v)
  
print(w_all[w])

### FIXED CODE ###

import numpy as np 

N, W = map(int, input().split())
w_all = np.zeros(W + 1, dtype=int)

for i in range(N):
  w, v = map(int, input().split())
  w_all[w:] = np.maximum(w_all[w:], w_all[:-w] + v)

print(w_all[W])
S=input()
hihihihi
if(len(S)%2==0):
  for i in range(len(S)//2):
    if(S[2*i]!="h" or S[2*i+1]!="i"):
      print("No")
      break
  else:
    print("Yes")
else:
  print("No")

### FIXED CODE ###

S=input()
if(len(S)%2==0):
  for i in range(len(S)//2):
    if(S[2*i]!="h" or S[2*i+1]!="i"):
      print("No")
      break
  else:
    print("Yes")
else:
  print("No")
import math
A, B, C, D = map(int, input().split())

## b = qa + r
#b = C
#a = D
#r = C%D
#while r != 0:
#    b = a
#    a = r
#    r = b%a
#gcd = a
gcd = math.gcd(C, D)
CDlcm = C*D//gcd

total = B-(A-1)
Cmuls = B//C - (A-1)//C
Dmuls = B//D - (A-1)//D
CDmuls = B//CDlcm - (A-1)//CDlcm
ans = total - Cmuls - Dmuls + CDmuls
print(ans)


### FIXED CODE ###

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

Cprimes = {}
Dprimes = {}

tmpC = C
d = 2
while tmpC > 1:
    if tmpC % d == 0:
        if d in Cprimes:
            Cprimes[d] += 1
        else:
            Cprimes[d] = 1
        tmpC //= d
    else:
        d += 1

tmpD = D
d = 2
while tmpD > 1:
    if tmpD % d == 0:
        if d in Dprimes:
            Dprimes[d] += 1
        else:
            Dprimes[d] = 1
        tmpD //= d
    else:
        d += 1

comPrimes = {}
for k in Cprimes:
    comPrimes[k] = Cprimes[k]
for k in Dprimes:
    if k in comPrimes:
        if comPrimes[k] < Dprimes[k]:
            comPrimes[k] = Dprimes[k]
    else:
        comPrimes[k] = Dprimes[k]

comVal = 1
for k in comPrimes:
    comVal *= k**comPrimes[k]

#print(Cprimes)
#print(Dprimes)
#print(comPrimes)
#print(comVal)

CdivNum = B//C - (A-1)//C
DdivNum = B//D - (A-1)//D
comDivNum = B//comVal - (A-1)//comVal
ans = B-(A-1)
ans -= CdivNum
ans -= DdivNum
ans += comDivNum

print(ans)
N=int(input())
L=list(map(int,input().split()))

ans=0
for i in range(N-2):
  a=L[i]
  for j in range(i+1,N-1):
    b=L[j]
    for k in range(j+1,N):
      c=L[k]
      if a<b+c and b<c+a and c<a+b:
        ans+=1
      else:
        break
        
print(ans)

### FIXED CODE ###

A,B=map(int,input().split())
if A<=2*B:
  print(0)
else:
  print(A-2*B)
= int(input())
p = list(map(int, input().split()))
cnt = 0
tmp = 2 * 10 ** 6
for i in range(n):
    if p[i] <= tmp:
        cnt += 1
        tmp = min(tmp, p[i])
print(cnt)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
cnt = 0
tmp = 2 * 10 ** 6
for i in range(n):
    if p[i] <= tmp:
        cnt += 1
        tmp = min(tmp, p[i])
print(cnt)
= int(input())
def f(x):
    if int(x) >N:
        return 0
    if x.count('3')>0 and x.count('5')>0 and x.count('7')>0:
        z = 1
    z=0
    z +=f(x+'3')
    z +=f(x+'5')
    z +=f(x+'7')
    return z
print(f('0'))

### FIXED CODE ###

N= int(input())
def f(x):
    z=0
    if int(x) >N:
        return 0
    if x.count('3')>0 and x.count('5')>0 and x.count('7')>0:
        z = 1
    z +=f(x+'3')
    z +=f(x+'5')
    z +=f(x+'7')
    return z
print(f('0'))
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
import math
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def comb(n,r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    n,k = map(int, input().split())
    redn = n-k
    modn = 10**9+7
    for i in range(1,k+1):
        ans = comb(redn+1,i)%modn
        ans *= comb(k-1,i-1)%modn
        print(ans)
        

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
import math
from copy import deepcopy

# If you use recursive call, uncomment this code
sys.setrecursionlimit(10**6)

def comb(n,r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    n,k = map(int, input().split())
    redn = n-k
    modn = 10**9+7
    for i in range(1,k+1):
        ans = comb(redn+1,i)*comb(k-1,i-1)%modn
        print(ans)
        

if __name__ == '__main__':
    main()
h1 = int(input())
m1 = int(input())
h2 = int(input())
m2 = int(input())
K = int(input())
print(m2 + h2*60 - m1 - h1*60 - K)


### FIXED CODE ###

h1,m1,h2,m2,k = map(int, input().split())
print(m2-m1+(h2-h1)*60-k)
import copy
 
H, W = map(int, input().split())
 
def fib(msLst, i, j):
    if i > 0:
        msLst[i - 1][j] = '#'
    if i < W - 1:
        msLst[i + 1][j] = '#'
    if j > 0:
        msLst[i][j - 1] = '#'
    if j < H - 1:
        msLst[i][j + 1] = '#'
 
ansCnt = 0
masLst = [['' for i in range(H)] for j in range(W)]
for i in range(W):
    tmp = input()
    for j in range(len(tmp)):
        masLst[i][j] = tmp[j]
 
loopBoean = True
 
while loopBoean:
    jloop = True
    tmp = 0
    msLst = copy.deepcopy(masLst)
    for i in range(W):
        for j in range(H):
            if masLst[i][j] == '#':
                fib(msLst, i, j)
            if masLst[i][j] == '.':
                if tmp == 0:
                    tmp = 1
            if msLst[i][j] != '#':
                jloop = False
    masLst = msLst
    if tmp == 1:
        ansCnt += tmp
 
    if jloop == True:
        loopBoean = False
 
print(ansCnt)

### FIXED CODE ###

from collections import deque

def bfs():
    while len(que) != 0:
        p = que.popleft()
        for i in range(4):
            nextX = p[0] + moveR[i]
            nextY = p[1] + moveC[i]
            if 0 <= nextX and nextX < H\
                and 0 <= nextY and nextY < W\
                and s[nextX][nextY] != '#'\
                and s[nextX][nextY] == '.':
                s[nextX][nextY] = s[p[0]][p[1]] + 1
                que.append([nextX, nextY])

H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
moveR = [0, 1, -1, 0]
moveC = [1, 0, 0, -1]

que = deque()
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            que.append([i, j])
            s[i][j] = 0
bfs()
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, s[i][j])
print(ans)
while True:
	calc = raw_input().split()
	ans = []
	while len(calc) != 0:
		if calc[0].isdigit():
			ans.append(calc.pop(0))
		else:
			mark = calc[0]
			if mark == "+":
				tmp = float(ans.pop()) + float(ans.pop())
			elif mark == "-":
				tmp = -float(ans.pop()) + float(ans.pop())
			elif mark == "*":
				tmp = float(ans.pop()) * float(ans.pop())
			elif mark == "/":
				tmp = float(ans.pop()) / float(ans.pop())
				tmp = 1 / tmp
			ans.append(tmp)
			calc.pop(0)
	print '%.6f' % ans[0]

### FIXED CODE ###

while True:
	try:
		stack = []
		for s in raw_input().split():
			if s in ('+', '-', '*', '/'):
				stack.append(eval('{2}{1}{0}'.format(stack.pop(), s, stack.pop())))
			else:
				stack.append(float(s))
		print '%.6f' % stack.pop()
	except EOFError:
		break