Harryxun/stf_run huggingface dataset:
a = [int(i) for i in raw_input().split()]
b = [int(i) for i in raw_input().split()]
n = len(a)
c = [(a[i]/100.0,b[i]/100.0,(a[i]+b[i])/100.0,a[i]*1.0/(a[i]+b[i])) for i in range(n)]
c.sort(key=lambda item: item[3], reverse=True)
u = [0] * n
res = 1
for i in range(n):
    du = min(res / (c[i][2]), 1)
    u[i] = du
    res -= du * c[i][2]
    if res <=0:
        break
ans = 0
for i in range(n):
    ans += c[i][0] * u[i]

print ans


### FIXED CODE ###

a = [int(i) for i in raw_input().split()]
b = [int(i) for i in raw_input().split()]
c = [(a[i]/100.0,b[i]/100.0,(a[i]+b[i])/100.0,a[i]*1.0/(a[i]+b[i])) for i in range(len(a)) if a[i]+b[i]>0]
n = len(c)
c.sort(key=lambda item: item[3], reverse=True)
u = [0] * n
res = 1
for i in range(n):
    du = min(res / (c[i][2]), 1)
    u[i] = du
    res -= du * c[i][2]
    if res <=0:
        break
ans = 0
for i in range(n):
    ans += c[i][0] * u[i]

print ans
N = int(input())
S = input()
K = int(input())
for i in range(N):
    if(S[K] == S[i]):
        print(S[K],end="")
    else:
        print("*",end="")
print()    

### FIXED CODE ###

N = int(input())
S = input()
K = int(input())
for i in range(N):
    if(S[K-1] == S[i]):
        print(S[i],end="")
    else:
        print("*",end="")
print()
def partition(A,p=0, r=None):
    if r is None:
        r = len(A)-1
    x = A[r]
    i = p-1
    for j in range(p,r):
        while A[j] <= x:
            i += 1
            swap(A,i,j)
    swap(A,i+1,r)
    return i+1

if __name__ == "__main__:
    input()
    A = list(map(int, input().strip().split()))
    k = partition(A)
    B = list(map(str, A))
    B[k] = "[{}]".format(B[k])
    print(" ".join(B))

### FIXED CODE ###

def swap(A,i,j):
    A[i],A[j] = A[j],A[i]
    return A

def partition(A,p=0, r=None):
    if r is None:
        r = len(A)-1
    x = A[r]
    i = p-1
    for j in range(p,r):
        if A[j] <= x:
            i += 1
            swap(A,i,j)
    swap(A,i+1,r)
    return i+1

if __name__ == "__main__":
    input()
    A = list(map(int, input().strip().split()))
    k = partition(A)
    B = list(map(str, A))
    B[k] = "[{}]".format(B[k])
    print(" ".join(B))
n  = int(input())
x = n // 100
result = 0
if n % 100 < 5 * x && x < 1000000:
  result = 1
print(result)
  

### FIXED CODE ###

n  = int(input())
x = n // 100
result = 0
if n % 100 <= 5 * x and x <= 1000000:
  result = 1
print(result)
import sys
from itertools import accumulate
import operator as op
input = sys.stdin.readline

n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a = list(accumulate(A,op.add))
b = list(accumulate(B,op.add))
ans = 0
j = m-1
for i in range(n):
    if a[i]>k:
        break
    while b[j]>k-a[i]:
        j-=1
    ans=max(ans,i+j+2)
print(ans)


### FIXED CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)
a=int(input("a? >>"))
b=int(input("b? >>"))
ans="Even" if a*b%2==0 else "Odd"
print(ans)

### FIXED CODE ###

a,b=map(int,input().split())
ans="Even" if (a * b % 2) == 0 else "Odd"
print(ans)
from sys import stdin
import numpy as np
from operator import itemgetter

N = int(stdin.readline().rstrip().split()[0])
A = [int(x) for x in stdin.readline().rstrip().split()]

ans = "Yes"
L = []
for a in A:
    if a in L:
        continue

    if len(L)>=3:
        ans = "No"
        break
    L.append(a)

l1, l2, l3 = L
while ans=="Yes":
    sumL = l1%2 + l2%2 + l3%2
    if sumL!=0 and sumL!=2:
        ans = "No"
        break
    l1 = l1//2
    l2 = l2//2
    l3 = l3//2
    if l1+l2+l3==0:
        break
print(ans)


### FIXED CODE ###

from sys import stdin
import numpy as np
from operator import itemgetter

N = int(stdin.readline().rstrip().split()[0])
A = [int(x) for x in stdin.readline().rstrip().split()]

ans = "Yes"
L = []
L_cnt = {}
for a in A:
    if a in L:
        L_cnt[a]+=1
        continue

    if len(L)>=3:
        ans = "No"
        break
    L.append(a)
    L_cnt[a]=1

if len(L)==3:
    l1, l2, l3 = L
    if N%3!=0:
        ans="No"
    if not L_cnt[l1]==L_cnt[l2]==L_cnt[l3]:
        ans="No"
    while ans=="Yes":
        sumL = l1%2 + l2%2 + l3%2
        if sumL!=0 and sumL!=2:
            ans = "No"
            break
        l1 = l1//2
        l2 = l2//2
        l3 = l3//2
        if l1+l2+l3==0:
            break
    print(ans)
elif len(L)==2:
    if N%3!=0:
        ans="No"
    if L_cnt[0]!=N//3:
        ans="No"
    if L[0]!=0 and L[1]!=0:
        ans="No"
    print(ans)
else:
    if sum(L)!=0:
        ans="No"
    print(ans)
import queue

q = queue.Queue()
N, M = map(int, input().split())

ans = [-1 for i in range(N+1)]
path = [[] for i in range(N+1)]

for i in range(M):
  A, B = map(int, input().split())
  path[A].append(B)
  path[B].append(A)
q.put(1)
COUNTER = 0
while not q.empty() :
  now = q.get()
  for p in path[now]:
    if ans[p]==-1:
      ans[p]=now
      q.put(p)
      #print(COUNTER, now,p)
      COUNTER+=1
      
print("Yes")
for i in ans[2:]:
  print(i)


### FIXED CODE ###

x = input()[-1]
 
if x in ["2","4","5","7","9"]:
  print("hon")
elif x in ["0","1","6","8"]:
  print("pon")
else:
  print("bon")
A, B, C = input().split()
print(A, B, C)

### FIXED CODE ###

A, B, C = input().split(",")
print(A, B, C)
import numpy as np
import math

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

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

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

# 1 <= N <= 10^5
# 2 <= M <= 10^9
# 1 <= A <= 10^9

S = []
total = 0
S.append(0)
for i in range(N):
    total = (total + A[i]) % M
    S.append(total)

oS = sorted(S)

count = 0

# print(oS)

cur_val = 0
number = 0
for i in range(0, N+1):
    if oS[i] == cur_val:
        number += 1
    if oS[i] > cur_val or i == N:
        if number >= 2:
            count += int(nCr(number, 2))
        # print(cur_val, number)
        number = 1
        cur_val = oS[i]

print(count)


### FIXED CODE ###

import numpy as np
import math

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

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

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

# 1 <= N <= 10^5
# 2 <= M <= 10^9
# 1 <= A <= 10^9

S = []
total = 0
S.append(0)
for i in range(N):
    total = (total + A[i]) % M
    S.append(total)

oS = sorted(S)

count = 0

# print(oS)

cur_val = 0
number = 0
for i in range(0, N+1):
    if oS[i] == cur_val:
        number += 1
    if oS[i] > cur_val or i == N:
        if number >= 2:
            count += int(number * (number - 1) / 2)
        # print(cur_val, number)
        number = 1
        cur_val = oS[i]

print(count)
N,K=[int(i) for i in input().split()]
h = [int(i) for i in input().split()]
smy = 0

for i in h:
  if !(h<K):
    smy+=1:
print(smy)

### FIXED CODE ###

N,K=[int(i) for i in input().split()]
h = [int(i) for i in input().split()]
smy = 0
 
for i in h:
  if not(i<K):
    smy+=1
print(smy)
a = list(int,input().split())
a.sort()
print(10*a[2]+a[1]+a[0])

### FIXED CODE ###

a = list(map(int,input().split()))
a.sort()
print(10*a[2]+a[1]+a[0])
while 1:
    x=[ int(i) for i in input()]
    if x==0:
        break
    print(sum(list(x)))

### FIXED CODE ###

while 1:
    x=[int(i) for i in input()]
    if sum(x)==0:
        break
    print(sum(x))
a = list(map(int,input().split()));
if a[0] == a[1]:
	print('Yes');
else a[0] > a[1]:
	printf('No');

### FIXED CODE ###

str1, str2 = [s for s in input().split()]
if str1 == str2:
    print('Yes')
else:
    print('No')
A, B = map(int, input().split())
S = input()

if S[A] = "-" and S.count("-") == 1:
  print("Yes")
else:
  print("No")


### FIXED CODE ###

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

if S[A] == "-" and S.count("-") == 1:
  print("Yes")
else:
  print("No")
from collections import deque

dis_x = [1, 0, -1, 0]
dis_y = [0, 1, 0, -1]

goal_h, goal_w = map(int, input().split())

s = []
for _ in range(goal_h):
    line = input()
    s.append(list("#{}#".format(line)))

s = [list("#" * (goal_w + 2))] + s + [list("#" * (goal_w + 2))]

dist = [ [0] * (goal_w + 2) for _ in range(goal_w+2)]

que = deque([(1, 1)])

while que:
    h, w = que.popleft()

    for i in range(4):
        dx, dy = dis_x[i], dis_y[i]
        if s[h+dy][w+dx] == '.' and  dist[h+dy][w+dx] == 0:
            dist[h+dy][w+dx] = dist[h][w]+1
            que.append((h+dy, w+dx))

opt = dist[goal_h][goal_w]

not_wall_count = 0
for i in range(1, goal_h+1):
    for j in range(1, goal_w+1):
        if s[i][j] == '.':
            not_wall_count += 1

if dist[goal_h][goal_w] == 0:
    print(-1)
else:
    print(not_wall_count - opt - 1)

### FIXED CODE ###

from collections import deque
H, W = map(int, input().split())
S = [input() for i in range(H)]
C = sum(s.count('.') for s in S)

dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
que = deque([(0, 0, 0)])
used = {(0, 0)}

res = None
while que:
    s, t, cost = que.popleft()
    if s == H-1 and t == W-1:
        res = cost
        break
    for di, dj in dd:
        ni = s + di; nj = t + dj
        if (not 0 <= ni < H) or (not 0 <= nj < W) or S[ni][nj] == '#' or (ni, nj) in used:
            continue
        used.add((ni, nj))
        que.append((ni, nj, cost + 1))
if res:
    print(C - 1 - res)
else:
    print(-1)
import sys
import numpy
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

def input():
    return sys.stdin.readline().rstrip('\n')

N = int(input())

# めちゃくちゃ遅くて TLE
#V = [[0]*N for _ in range(N)]

V = numpy.zeros((N,N), dtype=numpy.int8)

for i in range(N-1):
    u,v,w = list(map(int, input().split()))
    V[u-1][v-1] = w

D = dijkstra(csr_matrix(V), directed=False, indices=0)
#print(D)

for d in D:
    if d % 2 == 0: #even
        print(0)
    else:
        print(1)


### FIXED CODE ###

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

import sys
#import numpy
#from collections import deque
sys.setrecursionlimit(10**5)

def input():
    return sys.stdin.readline().rstrip('\n')

N = int(input())

childsof = [[] for _ in range(N+1)]

for _ in range(N-1):
    u,v,w = list(map(int, input().split()))
    childsof[u].append((v,w))
    childsof[v].append((u,w))

distances = [-1]*(N+1)
distances[1] = 0

def dfs(i):
    childs = childsof[i]

    for c in childs:
        j = c[0]
        if distances[j] == -1:
            distances[j] = distances[i] + c[1]
            dfs(j)

dfs(1)

for d in distances[1:]:
    if d % 2 == 0: #even
        print(0)
    else:
        print(1)
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,M,X,Y = inpl()
X = max(inpl(),X)
Y = min(inpl(),Y)
if X < Y:
    print("No War")
else:
    print("War")


### FIXED CODE ###

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,M,X,Y = inpl()
X = max(max(inpl()),X)
Y = min(min(inpl()),Y)
if X < Y:
    print("No War")
else:
    print("War")
S =raw_input()
print (S-2)*180

### FIXED CODE ###

S =int(raw_input())
print (S-2)*180
A1 = int(input())
A2 = int(input())
A3 = int(input())

if A1 + A2 + A3 >= 22:
  print('bust')
else:
  print('win')

### FIXED CODE ###

A1, A2, A3 = map(int,input().split())

if A1 + A2 + A3 >= 22:
  print('bust')
else:
  print('win')
H, W, K = map(int, input().split())

cake = [list(input().split()) for _ in range(H)]
ans = [[0] * W for _ in range(H)]

id = 1
sign = 0

for i in range(H):
    for j in range(W):
        if cake[i][j] == '#':
            ans[i][sign:j+1] = [id] * (j+1-sign)
            sign = j+1
            id += 1
            #print(ans[i])
        elif j == W-1:
            ans[i][sign:j+1] = [id-1] * (j+1-sign)
    sign = 0

for i in range(H):
    for j in range(W):
        print('{} '.format(ans[i][j]), end='')
    print()

### FIXED CODE ###

H, W, K = map(int, input().split())

cake = [list(input()) for _ in range(H)]
ans = [[0] * W for _ in range(H)]

id = 1
sign = 0
nothing = 0

for i in range(H):
    if cake[i].count('#') == 0:
        nothing += 1
        if i == H-1:
            for j in range(W):
                for d in range(nothing):
                    ans[i-d][j] = ans[i-nothing][j]
        continue
    for j in range(W):
        if cake[i][j] == '#':
            ans[i][sign:j+1] = [id] * (j+1-sign)
            sign = j+1
            id += 1
        elif j == W-1:
            ans[i][sign:j+1] = [id-1] * (j+1-sign)
    if nothing != 0:
        for j in range(W):
            for d in range(1,nothing+1):
                ans[i-d][j] = ans[i][j]
    sign = 0
    nothing = 0

for i in range(H):
    for j in range(W):
        print('{} '.format(ans[i][j]), end='')
    print()
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X = INT()
# ans = 0
# for b in range(1, 1000):
#     for p in range(2, 1000):
#         tmp = b ^ p
#         # print(tmp)
#         if tmp <= X:
#             ans = max(ans, tmp)
#             # print(tmp)
#         else:
#             break
# print(ans)
def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

x = X
r = []
for i in range(2, x + 1):
    c = 2
    while i ** c <= x:
        r.append(i ** c)
        c += 1
ans = sorted(r)[-1]
print(ans)



exit()


for x in range(X, 0, -1):
    prime = prime_decomposition(x)
    c = Counter(prime)
    # print(c.values())
    value = c.values()
    # print(v)
    print(c)
    for v in value:
        d = v
    if len(c) == 1 and d >= 2:
        print(x)
        exit()
    elif x == 1:
        print(x)
        exit()
    



### FIXED CODE ###

x=int(input())
m=int(x**0.5)
r=[1]
for i in range(2,x+1):
        c=2
        while i**c<=x:
                r.append(i**c)
                c+=1
ans=sorted(r)[-1]
print(ans)
import numpy as np
N, M = map(int, input().split())
list_x = list(map(int, input().split()))
list_x.sort()
list_d = np.diff(list_x)
list_data = list_d.tolist()
if len(list_data) != 0:
    for _ in range(N-1):
        list_data.remove(max(list_data))
    print(sum(list_data))
else:
    print(0)


### FIXED CODE ###

import numpy as np
N, M = map(int, input().split())
list_x = list(map(int, input().split()))
list_x.sort()
list_d = np.diff(list_x)
list_data = list_d.tolist()
if len(list_data) != 0:
    if N >= 2:
        list_data.sort()
        del list_data[-(N-1):]
        print(sum(list_data))
    if N == 1:
        print(sum(list_data))
else:
    print(0)
S = input()

flag = True
for i in range(0, 11, 2):#len(S), 2):
    if len(S) % 2 == 0:
        if S[i] + S[i + 1] == 'hi':
            if i + 2 == len(S):
                break
            else:
                pass
    else:
        if S[i] + S[i + 1] == 'hi':
           pass
        if i + 1 == len(S):
            flag = False
            break
        else:
            flag = False
            break

if flag == True:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

S = input()

flag = True

if len(S) % 2 == 0:
    if S.find('hi') % 2 == 0:
        flag = True
    else:
        flag = False
else:
    flag = False


if flag == True:
    print('Yes')
else:
    print('No')
from math import ceil, sqrt
N = int(input())

for i in range(floor(sqrt(N)), 0, -1):
    if N % i == 0:
        print((N//i) + i - 2)
        break
    

### FIXED CODE ###

from math import ceil, sqrt
N = int(input())

for i in range(ceil(sqrt(N)), 0, -1):
    if N % i == 0:
        print((N//i) + i - 2)
        break
from fractions import gcd

def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

n=int(input())
a=list(map(int, input().split()))
A=lcm(a)
ans=0

for i in a:
    ans+=A/i

print(int(ans)%(10**9+7))


### FIXED CODE ###

from fractions import gcd

n=int(input())
a=list(map(int, input().split()))
mod=10**9+7
l=1
ans=0

for i in a:
    l=l*i//gcd(l,i)

for i in a:
    ans+=l//i

print(ans%mod)
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse= True)
B.sort(reverse= True)
C.sort(reverse= True)
LIS = []
for i in range(X):
    INTB = 3000//(j+1)
    for j in range(min(INTB+1,Y)):
        INT = 3000//((i+1)*(j+1))
        for k in range(min(INT+1,Z)):
            SUM = A[i] + B[j] + C[k]
            LIS.append(SUM)
LIS.sort(reverse = True)
for i in range(K):
    print(LIS[i])
        

### FIXED CODE ###

X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse= True)
B.sort(reverse= True)
C.sort(reverse= True)
LIS = []
for i in range(X):
    INTB = 3000//(i+1)
    for j in range(min(INTB+1,Y)):
        INT = 3000//((i+1)*(j+1))
        for k in range(min(INT+1,Z)):
            SUM = A[i] + B[j] + C[k]
            LIS.append(SUM)
LIS.sort(reverse = True)
for i in range(K):
    print(LIS[i])
import numpy as np
H, W, D = map(int, input().split())
grid = np.array([[0, 0]] * (H * W))
for i in range(H):
    Ai = list(map(int, input().split()))
    for j in range(W):
        grid[Ai[j] - 1] = [i, j]
Q = int(input())
tasks = [list(map(int, input().split())) for _ in range(Q)]

accum = [[]] * D
for i in range(D):
    diff = (abs(np.diff(grid[i::D, 0])) + abs(np.diff(grid[i::D, 1])))
    accum[i] = [0] + list(np.cumsum(diff))

for q in range(Q):
    Li, Ri = tasks[q]
    res = (Li - 1) % D
    x = (Li - 1) // D
    y = (Ri - 1)// D
    print(accum[res][y] - accum[res][x])


### FIXED CODE ###

import numpy as np
H, W, D = map(int, input().split())
grid = np.array([[0, 0]] * (H * W))
for i in range(H):
    Ai = list(map(int, input().split()))
    for j in range(W):
        grid[Ai[j] - 1] = [i, j]
Q = int(input())
tasks = [list(map(int, input().split())) for _ in range(Q)]

accum = [0] * (H*W)
for i in range(H * W):
    if i >= D:
        accum[i] = accum[i - D] + abs(grid[i][0] - grid[i - D][0]) + abs(grid[i][1] - grid[i - D][1])

for q in range(Q):
    Li, Ri = tasks[q]
    print(accum[Ri - 1] - accum[Li - 1])
num_n = raw_input()
ele_n = raw_input()
num_m = raw_input()
ele_m = raw_input()
 
n = ele_n.split()
m = ele_m.split()

def solve(i, t):
   if t == 0:
      return 1
   if i >= num_n:
      return 0
   res = solve(i + 1, t) or solve(i + 1,t - n[i])
   return res

for t in m:
   if solve(0,m):
      print "yes"
   else:
      print "no"

### FIXED CODE ###

_ = int(input())
hoge = [int(x) for x in input().split()]
_ = int(input())

def exSearch(i, m):
    if m == 0:
        return True
    if i >= len(hoge) or m > sum(hoge):
        return False
    res = exSearch(i+1, m) or exSearch(i+1, m-hoge[i])
    return res

if __name__ == '__main__':
    
    for val in (int(x) for x in input().split()):
        if exSearch(0, val):
            print ('yes')
        else:
            print ('no')
while 1:
  h, w = map(int, input().split())
  if h == w == 0:
    break
  for i in  range(h):
    if i == 0 or i == h-1:
      print "#" * w
    else:
      print "#" + "."*(w - 2) + "#"
  print ""

### FIXED CODE ###

while 1:
  h, w = map(int, raw_input().split())
  if h == w == 0:
    break
  for i in  range(h):
    if i == 0 or i == h-1:
      print "#" * w
    else:
      print "#" + "." * (w - 2) + "#"
  print ""
while 1:
    W, H = list(map(int,input().split()))
    if W == 0:break

    C = [list(map(int, input().split())) for i in range(H) ]

    def work(x,y):
        ax = [-1, 0, 1, -1, 1, -1, 0, 1]
        ay = [-1, -1, -1, 0, 0, 1, 1, 1]

        if C[y][x] != 1:return False
        C[y][x] = -1 #mark

        for _ax in ax:
            for _ay in ay:
                if 0 <= _ax + x < W and 0 <= _ay + y < H:
                    work(_ax + x, _ay + y)
        return True

    cnt = 0
    for x in range(W):
        for y in range(H):
            cnt += work(x,y)
    print(cnt)

### FIXED CODE ###

while 1:
    W, H = list(map(int,input().split()))
    if W == 0:break

    C = [list(map(int, input().split())) for i in range(H) ]
    
    def work(x,y):
        ax = [-1, 0, 1, -1, 1, -1, 0, 1]
        ay = [-1, -1, -1, 0, 0, 1, 1, 1]

        if C[y][x] != 1:return False
        stack = [(x,y)]

        while len(stack) > 0:
            s = stack.pop(-1)
            C[s[1]][s[0]] = -1 #mark

            for _x in [s[0] + _x for _x in ax]:
                for _y in [s[1] + _y for _y in ay]:
                    if 0 <= _x < W and 0 <= _y < H and C[_y][_x] == 1:
                        stack.append((_x, _y))
        return True
#    def work(x,y):
#        ax = [-1, 0, 1, -1, 1, -1, 0, 1]
#        ay = [-1, -1, -1, 0, 0, 1, 1, 1]
#
#        if C[y][x] != 1:return False
#        C[y][x] = -1 #mark
#
#        for _ax in ax:
#            for _ay in ay:
#                if 0 <= _ax + x < W and 0 <= _ay + y < H:
#                    work(_ax + x, _ay + y)
#        return True

    cnt = 0
    for x in range(W):
        for y in range(H):
            cnt += work(x,y)
    print(cnt)
S = input()
k = S[::-1]
count = -1
realcount = 0
for i in k:
    count +=1
    if i!=S[count]:
        S.replace(S[count],i)
        realcount+=1
        real = realcount//2
print(real)

### FIXED CODE ###

S = input()
k = S[::-1]
count = -1
realcount = 0
for i in k:
    count +=1
    if i!=S[count]:
        S.replace(S[count],i)
        realcount+=1
    if realcount == 0:
        real = 0
    else:
        real = realcount//2
print(real)
def FindAns(A, b):
    ans = 0
    for a in A:
        ans += abs(a - b)
    return ans

n = int(input())
A = list(map(int, input().split()))
for i in range(n):
    A[i] -= i + 1

center = int(sum(A) / len(A))
ans = 100000000000000
for i in range(21):
    ans = min(ans, FindAns(center - 50))
print(ans)

### FIXED CODE ###

def BinSearch(A, hi, lo):
    b = (hi + lo) // 2
    tmp0 = FindAns(A, b - 1)
    tmp1 = FindAns(A, b)
    if hi == lo:
        tmp2 = FindAns(A, b + 1)
        return min(tmp0, tmp1, tmp2)
    if tmp0 < tmp1:
        return BinSearch(A, b - 1, lo)
    else:
        return BinSearch(A, hi, b + 1)
    
def FindAns(A, b):
    ans = 0
    for a in A:
        ans += abs(a - b)
    return ans

n = int(input())
A = list(map(int, input().split()))
for i in range(n):
    A[i] -= i + 1
    
hi = max(A)
lo = min(A)

print(BinSearch(A, hi, lo))
S = int(input())
h = S // 3600
m = S // 60
s = S % 60
print(h: m: s

### FIXED CODE ###

S = int(input())
h = S // 3600
m = S % 3600 // 60
s = S % 60
print(h, m, s, sep = ':')
n,b=list(input().split())

a=[input() for i in range(n)]

print(''.join(a))

### FIXED CODE ###

n, l = map(int, input().split())
a = [input() for i in range(n)]
a.sort()
 
print("".join(a))
n,k = [int(i) for i in input().split()]

steps = [int(i) for i in input().split()]
dp = [9999999] * n

dp[0] = 0

for i in range(1, n):
    start = max(0, i-k)
    dp[i] = min([dp[start+j] + abs(steps[i] - steps[start+j]) for j in range(i)])

print(dp[n - 1])

### FIXED CODE ###

import numpy as np
 
 
N, K = map(int, input().split())
inputs = np.array([int(i) for i in input().split()])
 
dp = np.zeros(N, dtype=int)
for i in range(1, N):
    start = max(0, i-K)
    dp[i] = (dp[start:i] + abs(inputs[i] - inputs[start:i])).min()
 
print(dp[-1])