Harryxun/stf_run huggingface dataset:
while(1):
    N, M = map(int, input().split())
    if N == 0 and M == 0:
        break
    H = [int(input()) for i in range(N)]
    HD = [0] * 1500 ** 2
    for i in range(N):
        for j in range(i + 1, N + 1):
            HD[sum(H[i:j])] += 1
    ans = 0
    W = [int(input()) for i in range(M)]
    for i in range(M):
        for j in range(i + 1, M + 1):
            ans += HD[sum(W[i:j])]
    print(ans)


### FIXED CODE ###

while(1):
    N, M = map(int, input().split())
    if N == 0 and M == 0:
        break
    H = [int(input()) for i in range(N)]
    HD = [0] * 1500 ** 2
    for i in range(N):
        tmp = 0
        for j in range(i, N):
            tmp += H[j]
            HD[tmp] += 1
    ans = 0
    W = [int(input()) for i in range(M)]
    for i in range(M):
        tmp = 0
        for j in range(i, M):
            tmp += W[j]
            ans += HD[tmp]
    print(ans)
A,B,K=map(int,input().split())
if A>=K:
  print(str(A-K)+" "+str(B))
else:
  t=K-A
 
  print("0"+" "+str(max(B-t,"0")))
A,B,K=map(int,input().split())
if A>=K:
  print(str(A-K)+" "+str(B))
else:
  t=K-A
 
  print("0"+" "+str(max(B-t,0)))

### FIXED CODE ###

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

if N<K:
  M=M-(K-N)
  N=0
else:
  N=N-K

if M<0:
  M=0
print(N,M)
A,B,C,D = map(int,input().split())

s = min(B-C,D-C)

if s <= 0:
    s = 0

print(s

### FIXED CODE ###

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

s = min(B,D)-max(A,C)

if s <= 0:
    s = 0

print(s)
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
h = Counter()
for x in a:
    h[x] += 1
f = True
for k, v in h.items():
    if n % 2 == 1 and k == 0:
        if v != 1:
            f = False
            break
    elif v != 2:
        f = False
        break
MOD = 1_000_000_007
def mpow(n, p, mod):
    r = 1
    while p > 0:
        if p & 1 == 1:
            r = r * n % mod
        n = n * n % mod
        p >>= 1
    return r
print(mpow(2, int(n / 2), MOD) if f else 0) 

### FIXED CODE ###

from collections import Counter

n = int(input())
a = list(map(int, input().split()))
h = Counter()
for x in a:
    h[x] += 1
f = True
for k, v in h.items():
    if n % 2 == 1 and k == 0:
        if v != 1:
            f = False
            break
    elif v != 2:
        f = False
        break
MOD = 1000000007
def mpow(n, p, mod):
    r = 1
    while p > 0:
        if p & 1 == 1:
            r = r * n % mod
        n = n * n % mod
        p >>= 1
    return r
print(mpow(2, int(n / 2), MOD) if f else 0)
def solve(n,l,pos):
    ans=0
    if(pos==n):
        return 0
    if(pos==n-1):
        return abs(l[-1]-l[-2])
    ans+=min(abs(l[pos-1]-l[pos])+solve(n,l,pos+1),abs(l[pos-1]-l[pos+1])+solve(n,l,pos+2))
    return ans
n=int(input())
l=list(map(int,input().split()))
print(solve(n,l,1))

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
def solve(n,l,pos):
    if(pos==n):
        return 0
    if(pos==n-1):
        return abs(l[-1]-l[-2])
    if(t[pos]!=-1):
        return t[pos]
    t[pos]=min(abs(l[pos-1]-l[pos])+solve(n,l,pos+1),abs(l[pos-1]-l[pos+1])+solve(n,l,pos+2))
    return t[pos]
n=int(input())
l=list(map(int,input().split()))
global t
t=[-1]*(n+1)
print(solve(n,l,1))
def col(i):
    for x in G[i]:
        if hist[x]==0:
            hist[x]=1
            col(x)
N,M = map(int,input().split())
G = {}
for _ in range(M):
    x,y,z = map(int,input().split())
    if x not in G:
        G[x]=[]
    G[x].append(y)
    if y not in G:
        G[y]=[]
    G[y].append(x)
cnt = N-len(G)
while G:
    hist = {i:0 for i in G.keys()}
    s = list(G.keys())[0]
    hist[s]=1
    col(s)
    for i in hist.keys():
        if hist[i]==1:
            del G[i]
    cnt += 1
print(cnt)


### FIXED CODE ###

def rt(i):
    while i!=G[i][0]:
        i = G[i][0]
    return i
N,M = map(int,input().split())
G = {i:[i,1] for i in range(1,N+1)}
for _ in range(M):
    X,Y,Z = map(int,input().split())
    rx = rt(X)
    ry = rt(Y)
    if rx!=ry:
        if G[rx][1]>=G[ry][1]:
            G[ry][0] = rx
            G[rx][1] += G[ry][1]
        else:
            G[rx][0] = ry
            G[ry][1] += G[rx][1]
cnt = 0
A = []
for i in range(1,N+1):
    A.append(rt(i))
A = list(set(A))
print(len(A))
import math

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

ans = B - A + 1

# A以上B以下の数でXの倍数の個数
def countX(X) :
    if X > B :
        return 0
    minX = math.ceil(A / X)
    maxX = math.floor(B / X)

    return maxX - minX + 1

# 最小公倍数
Z = int(C * D / math.gcd(C,D))

ans += -countX(C) - countX(D) + countX(Z)

print(ans)



### FIXED CODE ###

import math
import fractions

# A以上B以下の数でXの倍数の個数
def countX(X) :
    if X > B :
        return 0

    minX = (A - 1) // X
    maxX = B // X

    return maxX - minX

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

ans = B - A + 1

# 最小公倍数
Z = int(C * D / fractions.gcd(C,D))

ans -= countX(C)
ans -= countX(D)
ans += countX(Z)

print(int(ans))
s=input()

if s[3]==s[4] and s[5]==s[6];
	print("sはcoffeeと似ています")
	else
    print("sはcoffeeと似ていません")


### FIXED CODE ###

s = input()

if((s[2]==s[3]) and (s[4]==s[5])):
  	print("Yes")
else:
	print("No")
import math

def combinations_count(N, r):
    return math.factorial(N) // (math.factorial(N - r) * math.factorial(r))

# 整数の入力
N = int(input())
r = 2
 
print((combinations_count(N, r) * (10**(N-r)))  / (10**9 + 7))

### FIXED CODE ###

# 整数の入力
N = int(input())
 
print((10 ** N - 2* 9 ** N + 8 ** N) % (10 ** 9 + 7))
m = {'A':'T', 'T':'A', 'G':'C', 'C':'G'}
print(m[input())

### FIXED CODE ###

m = {'A':'T', 'T':'A', 'G':'C', 'C':'G'}
print(m[input()])
import itertools


def main():
    n, m, q = map(int, input().split())

    A, B, C, D = [], [], [], []
    for _ in range(q):
        a, b, c, d = map(int, input().split())
        A.append(a)
        B.append(b)
        C.append(c)
        D.append(d)
    ans = 0
    length = m+n-1
    for item in itertools.combinations(range(length), m-1):
        ptn = []
        num = 1
        p = 0
        for i in range(length):
            if i == item[p]:
                num += 1
                p += 1
                p = min(m-2, p)
                continue
            ptn.append(num)
        tmp = 0
        for k in range(q):
            if (ptn[B[k]-1] - ptn[A[k]-1]) == C[k]:
                tmp += D[k]
            else:
                tmp += 0

        ans = max(tmp, ans)
    return ans

print(main())


### FIXED CODE ###

import itertools


def main():
    n, m, q = map(int, input().split())

    A, B, C, D = [], [], [], []
    for _ in range(q):
        a, b, c, d = map(int, input().split())
        A.append(a)
        B.append(b)
        C.append(c)
        D.append(d)
    if m == 1:
        return sum(D)
    ans = 0
    length = m+n-1
    for item in itertools.combinations(range(length), m-1):
        ptn = []
        num = 1
        p = 0
        for i in range(length):
            if i == item[p]:
                num += 1
                p += 1
                p = min(m-2, p)
                continue
            ptn.append(num)
        tmp = 0
        for k in range(q):
            if (ptn[B[k]-1] - ptn[A[k]-1]) == C[k]:
                tmp += D[k]

        ans = max(tmp, ans)
    return ans

print(main())
from sys import stdin
input = stdin.readline

S = input()
n = len(S)

tot = 0

for i in range(2**(n-1)):
  f = S[0]
  for j in range(n-1):
       if ((i >> j) & 1):
        f += " "
       f += S[j+1]
  
  tot += sum(map(int, f.split(" ")))

print(tot)

### FIXED CODE ###

S = input()
n = len(S)

tot = 0

for i in range(2**(n-1)):
  f = S[0]
  for j in range(n-1):
       if ((i >> j) & 1):
        f += " "
       f += S[j+1]
  
  tot += sum(map(int, f.split(" ")))

print(tot)
i = list(map(int,input().split()))
w = i[0]
h = i[1]
x = i[2]
y = i[3]

m = (w*h)/2

if (2*x == w) and (2*y == h:)
  s = 1
else:
  s = 0
  

print("{:.9}".format(m));print(s)

### FIXED CODE ###

i = list(map(int,input().split()))
w = i[0]
h = i[1]
x = i[2]
y = i[3]

m = (w*h)/2

if (2*x == w) and (2*y == h):
  s = 1
else:
  s = 0
  

print("{:.9}".format(m));print(s)
import sys
from collections import Counter
from heapq import heapify, heappush, heappop

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))

    counterA = Counter(A)
    counterB = Counter(B)

    vecB = [(v, k) for k, v in counterB.items()]

    hq1 = [(-v, k) for k, v in counterA.items()]
    heapify(hq1)
    done = [False] * N
    done_list = []

    ans = [[] for _ in range(N)]

    for v, k in sorted(vecB, reverse=True):
        v_prev = v
        ok = True
        while v and ok:
            same_nv, same_nk = None, None
            while hq1 and v:
                nv, nk = heappop(hq1)
                if done[nk]:
                    done_list.append((-nv, nk))
                    continue
                elif k == nk:
                    same_nv, same_nk = nv, nk
                    continue
                nv *= -1
                if v < nv:
                    ans[nk].extend([k] * v)
                    heappush(hq1, (-(nv - v), nk))
                    v = 0
                else:
                    ans[nk].extend([k] * nv)
                    v = v - nv

            if same_nv is not None:
                heappush(hq1, (same_nv, same_nk))

            while done_list and v:
                nv, nk = done_list.pop()
                if v < nv:
                    ans[nk].extend([k] * v)
                    done_list.append((nv - v, nk))
                    v = 0
                else:
                    ans[nk].extend([k] * v)
                    v = v - nv

            if v == 0:
                done[k] = True

            if v == v_prev:
                ok = False
            v_prev = v
        if not ok:
            print('No')
            return

    print('Yes')
    res = []
    for vec in ans:
        res.extend(vec)
    print(*res)

    return


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from collections import Counter
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))

    counterA = Counter(A)
    counterB = Counter(B)

    for i in range(1, N + 1):
        if counterA[i] + counterB[i] > N:
            print('No')
            return

    C = [0] * (N + 1)
    D = [0] * (N + 1)
    for a in A:
        C[a] += 1
    for b in B:
        D[b] += 1

    C = list(accumulate(C))
    D = list(accumulate(D))

    x = max(C[i] - D[i - 1] for i in range(1, N + 1))

    ans = [0] * N
    for i in range(N):
        ans[i] = B[(i - x) % N]

    print('Yes')
    print(*ans)

    return


if __name__ == '__main__':
    main()
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)
if x*y*z < 1000000:
    ans = []
    for a in A:
        for b in B:
            for c in C:
                ans.append(a+b+c)
    ans.sort(reverse = True)
    for i in range(k):
        print(ans[i])
else:
    A.append(-1e20)
    B.append(-1e20)
    C.append(-1e20)
    cnt=0
    a = 0
    b = 0
    c = 0
    print(A[0]+B[0]+C[0])
    while(cnt<k-1):
        Adiv = A[0]-A[a+1]
        Bdiv = B[0]-B[b+1]
        Cdiv = C[0]-C[c+1]
        if(Adiv <= Bdiv and Adiv <= Cdiv):
            a+=1
            print(A[a]+B[0]+C[0])
        elif(Bdiv <= Adiv and Bdiv <= Cdiv):
            b+=1
            print(A[0]+B[b]+C[0])
        else:
            c+=1
            print(A[0]+B[0]+C[c])
        cnt+=1


### 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)
num = []
for a in A:
    for b in B:
        num.append(a+b)
num.sort(reverse = True)
num2 = []
for i in range(min(len(num),k)):
    for j in C:
        num2.append(num[i]+j)
num2.sort(reverse = True)
for i in range(k):
    print(num2[i])
b = input()
if b == A:
  print(T)
elif b == T:
  print(A)
elif b == C:
  print(G)
else:
  print(C)

### FIXED CODE ###

b = input()
if b == "A":
  print("T")
elif b == "T":
  print("A")
elif b == "C":
  print("G")
else:
  print("C")
n=int(input())
from math import gcd
from collections import defaultdict
abd=defaultdict(int)
mod=10**9+7
ab=[]
wzero=0
azero=0
bzero=0
for i in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        wzero+=1
        continue
    elif a==0 and b!=0:
        azero+=1
        continue
    elif a!=0 and b==0:
        bzero+=1
        continue
    x=gcd(a,b)
    a//=x
    b//=x
    ab.append((a,b))
    abd[(a,b)]+=1

kumid=defaultdict(int)
for i in range(len(ab)):
    a,b=ab[i]
    cnt=abd[(-b,a)]+abd[(b,-a)]
    kumid[cnt]+=1
maxkey=max(kumid.keys())
ans=1

for i in range(maxkey,1,-1):
    if kumid[i]!=0:
        j=kumid[i]
        kumid[j]-=i
        tmp=2**i+2**j-1
        ans*=(tmp%mod)
        ans%=mod
#print(kumid)
ans*=(kumid[1]+1)
ans%=mod
ans*=2**kumid[0]%mod
ans%=mod
ans*=(2**azero+2**bzero-1)%mod
ans%=mod
ans+=wzero
ans=(ans+mod-1)%mod
print(ans)

### FIXED CODE ###

from math import gcd
from collections import defaultdict

n=int(input())
abd=defaultdict(int)
mod=10**9+7
wzero=0
azero=0
bzero=0
for i in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        wzero+=1
    elif a==0 and b!=0:
        azero+=1
    elif a!=0 and b==0:
        bzero+=1
    else:
        g=gcd(a,b)
        a=a//g
        b=b//g
        abd[(a,b)]+=1

liskey=list(abd.keys())
ans=1
for k in liskey:
    if abd[k] != 0:
        a,b=k
        x=abd[(a,b)]+abd[(-a,-b)]
        y=abd[(-b,a)]+abd[(b,-a)]
        abd[(a,b)]=0
        abd[(-a,-b)]=0
        abd[(-b,a)]=0
        abd[(b,-a)]=0
        ans*=(2**x+2**y-1+mod)%mod
        ans%=mod

ans*=(2**azero+2**bzero-1)
ans%=mod
ans=(ans+wzero)%mod
ans=(ans+mod-1)%mod
print(ans)
if True:
    N, M = map(int, input().split())
    X = []
    for _ in range(M):
        a, b = map(int, input().split())
        X.append((a-1, b-1))

    X = X[::-1]
else:
    X = [(3, 4), (2, 3), (4, 5), (0, 1), (1, 2)]
    N = 6
    M = 5
    
P = [-1] * N
CT = [1] * N
def pr(i):
    if P[i] < 0:
        return i
    t = pr(P[i])
    P[i] = t
    return t

ANS = [0] * M
ans = N * (N-1) // 2
ANS[-1] = ans
for m in range(M-1):
    a, b = X[m]
    pa = pr(a)
    pb = pr(b)
    
    # print("0", m, a, b, P, CT)
    
    if pa != pb:
        ans -= CT[pa] * CT[pb]
        P[pa] = pb
        CT[pb] += CT[pa]

    # print("1", m, a, b, P, CT, ans)
        

    ANS[-m-2] = ans

for a in ANS:
    print(a)


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline

N, M = map(int, input().split())
X = []
for _ in range(M):
    a, b = map(int, input().split())
    X.append((a-1, b-1))
X = X[::-1]
    
P = [-1] * N
CT = [1] * N
def pr(i):
    if P[i] < 0:
        return i
    t = pr(P[i])
    P[i] = t
    return t

ANS = [0] * M
ans = N * (N-1) // 2
ANS[-1] = ans
for m in range(M-1):
    a, b = X[m]
    pa = pr(a)
    pb = pr(b)
    
    if pa != pb:
        ans -= CT[pa] * CT[pb]
        P[pa] = pb
        CT[pb] += CT[pa]

    ANS[-m-2] = ans

for a in ANS:
    print(a)
X, N = map(int, input().split())
p = list(map(int, input().split()))

not_in_p = list(range(1,101))
for pn in p:
    if pn in not_in_p:
        not_in_p.remove(pn)

diff_p = []
for not_in_pn in not_in_p:
    diff_p.append(abs(not_in_pn - X))
min_value_index =  [j for j, value in enumerate(diff_p) if value == min(diff_p)]

answer = 0
for index in min_value_index:
    if answer == 0:
        answer = not_in_p[index]
    elif answer > not_in_p[index]:
        answer = not_in_p[index]

print(answer)

### FIXED CODE ###

x = list(map(int, input().split()))
print(x.index(0) + 1)
from sys import exit
from random import randrange
MOD = 10**9+7
n, k = map(int, input().split())
b = list(map(int, input().split()))
a = []
if n == k:
	ans = 1
	for x in b:
		ans *= x
		ans %= MOD
	print(ans)
	exit()
for x in b:
	if x != 0:
		a.append(x)
if len(a) < k:
	print(0)
	exit()

a.sort(key=lambda x: -abs(x))
#print(a)
ans = 1
minus = 0
for i in range(k):
	ans *= a[i]
	ans %= MOD
	if a[i] < 0:
		minus += 1

if minus%2 == 0:
	print(ans)
	exit()

if len(a) == k:
	if len(a) < n:
		print(0)
		exit()

for i in range(k, len(a)):
	if a[i] < 0:
		minus += 1

if minus == len(a):
	if len(a) < n:
		print(0)
		exit()
	ans = 1
	for i in range(k):
		ans *= a[-i-1]
		ans %= MOD
	print(ans)
	exit()

for i in range(k-1, -1, -1):
	if a[i] * a[k] < 0:
		p, q = a[i], a[k]
		break
for i in range(k, len(a)):
	if a[k-1] * a[i] < 0:
		r, s = a[k-1], a[i]
		break
if abs(q*r) >= abs(p*s):
	ans *= pow(p, MOD-2, MOD)
	ans *= q
	print(ans%MOD)
else:
	ans *= pow(r, MOD-2, MOD)
	ans *= s
	print(ans%MOD)

### FIXED CODE ###

from sys import exit
from random import randrange
MOD = 10**9+7
n, k = map(int, input().split())
b = list(map(int, input().split()))
a = []
if n == k:
	ans = 1
	for x in b:
		ans *= x
		ans %= MOD
	print(ans)
	exit()
for x in b:
	if x != 0:
		a.append(x)
if len(a) < k:
	print(0)
	exit()

a.sort(key=lambda x: -abs(x))
#print(a)
ans = 1
minus = 0
for i in range(k):
	ans *= a[i]
	ans %= MOD
	if a[i] < 0:
		minus += 1

if minus%2 == 0:
	print(ans)
	exit()

if len(a) == k:
	if len(a) < n:
		print(0)
		exit()

for i in range(k, len(a)):
	if a[i] < 0:
		minus += 1

if minus == len(a):
	if len(a) < n:
		print(0)
		exit()
	ans = 1
	for i in range(k):
		ans *= a[-i-1]
		ans %= MOD
	print(ans)
	exit()

flg1 = False
for i in range(k-1, -1, -1):
	if a[i] * a[k] < 0:
		p, q = a[i], a[k]
		flg1 = True
		break

flg2 = False
for i in range(k, len(a)):
	if a[k-1] * a[i] < 0:
		r, s = a[k-1], a[i]
		flg2 = True
		break

if flg1 and flg2:
	if abs(q*r) >= abs(p*s):
		ans *= pow(p, MOD-2, MOD)
		ans *= q
		print(ans%MOD)
	else:
		ans *= pow(r, MOD-2, MOD)
		ans *= s
		print(ans%MOD)

elif flg1:
	ans *= pow(p, MOD-2, MOD)
	ans *= q
	print(ans%MOD)

elif flg2:
	ans *= pow(r, MOD-2, MOD)
	ans *= s
	print(ans%MOD)

else:
	print("コーナーケース多すぎん？")
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

sys.setrecursionlimit(10000)

class G(object):
    def __init__(self, i):
        self.paths = dict()

    def add(self, v, d):
        self.paths[v] = d

    def dist(self, g, s):
        if self is g:
            return s
        if g in self.paths:
            d = g.dist(g, s + self.paths[g])
            self.add(g, d)
            return d
        for k, v in self.paths.items():
            d = k.dist(g, s + v)
            if d >= 0:
                self.add(v, d)
                return d
        return -1

def main():
    (n, m) = tuple(map(int, input().split()))
    lrds = tuple(map(int, input().split()) for _ in range(m))

    g = dict()
    for lrd in lrds:
        (l, r, d) = lrd
        if l not in g:
            g[l] = G(l)
        if r not in g:
            g[r] = G(r)
        pd = g[l].dist(g[r], 0)
        if pd != -1 and pd != d or g[r].dist(g[l], 0) != -1:
            print('No')
            sys.exit()
        g[l].add(g[r], d)

    print('Yes')

if __name__ == '__main__':
    main()


### FIXED CODE ###

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

import sys

def main():
    n, m = map(int, sys.stdin.readline().split())
    lrds = ((map(int, line.split())) for line in sys.stdin.readlines())

    g = tuple([] for _ in range(n))
    x = [None] * n

    for l, r, d in lrds:
        l -= 1
        r -= 1
        g[l].append((r, d))
        g[r].append((l, -d))

    for i in range(n):
        if x[i] is not None:
            continue
        stack = [i]
        x[i] = 0
        while len(stack):
            v = stack.pop()
            for u, d in g[v]:
                if x[u] is None:
                    stack.append(u)
                    x[u] = x[v] + d

    for v in range(n):
        for u, d in g[v]:
            if x[v] + d != x[u]:
                print('No')
                sys.exit()

    print('Yes')

if __name__ == '__main__':
    main()
import math
A, B, H, M = map(int, input(), split())

H_degree = (30 * H) + (0.5 * M)
M_degree = 6 * M
diff = H_degree - M_degree
if diff > 180:
  diff = 360 - diff
else:
  diff = diff

length = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(diff)))

print(length)

### FIXED CODE ###

import math
A, B, H, M = map(int, input().split())
 
H_degree = (30 * H) + (0.5 * M)
M_degree = 6 * M
diff = abs(H_degree - M_degree)
if diff > 180:
  diff = 360 - diff
else:
  diff = diff
 
length = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(diff)))
 
print(length)
l_count = 0
r_count = sum([1 for c in S if c == "."])
count_if_contain_black = l_count+r_count
count_if_all_white = 0
for c in S:
    if c == "#":
        l_count += 1
        count_if_all_white += 1
    else:
        r_count -= 1
        
    count_if_contain_black = min(count_if_contain_black, l_count+r_count)

print(min(count_if_all_white, count_if_contain_black))

### FIXED CODE ###

N = int(input())
S = input()

count_if_all_white = 0
for c in S:
    if c == "#":
        count_if_all_white += 1

l_count = 0
r_count = sum([1 for c in S if c == "."])
count_if_contain_black = l_count+r_count
for c in S:
    if c == "#":
        l_count += 1
    else:
        r_count -= 1
        
    count_if_contain_black = min(count_if_contain_black, l_count+r_count)

print(min(count_if_all_white, count_if_contain_black))
S = list(input())
T = list(input())
for i in range(len(S)):
    if S[i] == T[0] or S[i] == '?':
        for j in range(len(T)):
            #print(T[j], S[i+j])
            if T[j] != S[i+j] and S[i+j] != '?':
                break
        else:
            for k in range(len(T)):
                S[i+k] = T[k]
            for k in range(len(S)):
                if S[k] == '?':
                    print('a',end="")
                else:
                    print(S[k],end="")
            print("")
            exit(0)
print("UNRESTORABLE")

### FIXED CODE ###

S = list(input())
T = list(input())
ans = []

for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j] == '?' or S[i+j] == T[j]:
            continue
        else:
            break
    else:
        tmp = str("".join(S[:i] + T + S[i+len(T):]).replace('?','a'))
        ans.append(tmp)
if len(ans) == 0:
    print("UNRESTORABLE")
else:
    ans.sort()
    print(ans[0])
import sys
sys.setrecursionlimit(100000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("$" * (2 + h)))
	for i in range(0, w) : array.append(list("$" + raw_input().replace(" ", "") + "$"))
	array.append(list("$" * (2 + h)))
	
	count = 0
	for i in range(1, h + 1):
		for j in range(1, w + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

def check(x, y):
	array[x][y] = "0"
	if array[x + 1][y] == "1" : check(x + 1, y)
	if array[x - 1][y] == "1" : check(x - 1, y)
	if array[x][y + 1] == "1" : check(x, y + 1)
	if array[x][y - 1] == "1" : check(x, y - 1)
	if array[x + 1][y + 1] == "1" : check(x + 1, y + 1)
	if array[x + 1][y - 1] == "1" : check(x + 1, y - 1)
	if array[x - 1][y + 1] == "1" : check(x - 1, y + 1)
	if array[x - 1][y - 1] == "1" : check(x - 1, y - 1)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	array = []
	array.append(list("0" * (2 + h)))
	for i in range(0, w) : array.append(list("0" + raw_input().replace(" ", "") + "0"))
	array.append(list("0" * (2 + h)))
	
	count = 0
	for i in range(1, w + 1):
		for j in range(1, h + 1):
			if array[i][j] == "1":
				check(i, j)
				count += 1
				
	print count