Harryxun/stf_run huggingface dataset:
import sys
input = sys.stdin.readline
mod = 10**9 + 7
n = int(input())
ab = [[int(x) for x in input().split()] for _ in range(n)]
from collections import defaultdict, Counter
import math
double_zero_cnt = 0
a_zero_cnt = 0
b_zero_cnt = 0
d = defaultdict(list) # [a, b] ngのそれぞれの個数
a_b = []
b_a = []
for a, b in ab:
    if a == 0 and b == 0:
        double_zero_cnt += 1
        continue
    elif a == 0:
        a_zero_cnt += 1
        continue
    elif b == 0:
        b_zero_cnt += 1
        continue
    g = math.gcd(a, b)
    a //= g
    b //= g
    if b < 0:
        b *= (-1)
        a *= (-1) # 必ずbは正
    a_b.append((a, b))
c = Counter(a_b)
for key in c.keys():
    a, b = key
    if a < 0:
        a *= (-1)
        b *= (-1)
    if d[(-b, a)] != []:
        continue
    if c[(-b, a)] != 0:
        d[(a, b)] = [c[(a, b)], c[(-b, a)]]
ans = 1
used_cnt = double_zero_cnt
for key in d.keys():
    if d[key] == []:
        continue
    x, y = d[key]
    used_cnt += (x + y)
    mul = (pow(2, x, mod) + pow(2, y, mod) - 1) % mod
    ans *= mul
    ans %= mod
if a_zero_cnt > 0 or b_zero_cnt > 0:
    ans *= (pow(2, a_zero_cnt, mod) + pow(2, b_zero_cnt, mod) - 1)
    ans %= mod
    used_cnt += a_zero_cnt + b_zero_cnt
ans *= pow(2, n - (used_cnt), mod)
ans %= mod
ans -= 1
ans += double_zero_cnt
ans %= mod
print(ans)







### FIXED CODE ###

import sys
input = sys.stdin.readline
mod = 10**9 + 7
n = int(input())
ab = [[int(x) for x in input().split()] for _ in range(n)]
from collections import defaultdict, Counter
import math
double_zero_cnt = 0
a_zero_cnt = 0
b_zero_cnt = 0
d = defaultdict(list) # [a, b] ngのそれぞれの個数
a_b = []
for a, b in ab:
    if a == 0 and b == 0: 
        double_zero_cnt += 1
        continue
    elif a == 0:
        a_zero_cnt += 1
        continue
    elif b == 0:
        b_zero_cnt += 1
        continue
    g = math.gcd(a, b)
    a //= g
    b //= g
    if b < 0:
        b *= (-1)
        a *= (-1) # 必ずbは正
    a_b.append((a, b))
c = Counter(a_b)
key_list = list(c.keys())
for key in key_list:
    a, b = key
    if a < 0:
        a_ = a*(-1)
        b_ = b*(-1)
    else:
        a_ = a
        b_ = b
    if d[(-b_, a_)] != []:
        continue
    if c[(-b_, a_)] != 0:
        d[(a, b)] = [c[(a, b)], c[(-b_, a_)]]
ans = 1
used_cnt = double_zero_cnt
for key in d.keys():
    if d[key] == []:
        continue
    x, y = d[key]
    used_cnt += (x + y)
    mul = (pow(2, x, mod) + pow(2, y, mod) - 1) % mod
    ans *= mul
    ans %= mod
if a_zero_cnt > 0 and b_zero_cnt > 0:
    ans *= (pow(2, a_zero_cnt, mod) + pow(2, b_zero_cnt, mod) - 1)
    ans %= mod
    used_cnt += a_zero_cnt + b_zero_cnt
elif a_zero_cnt > 0:
    ans *= pow(2, a_zero_cnt, mod)
    ans %= mod
    used_cnt += a_zero_cnt
elif b_zero_cnt > 0:
    ans *= pow(2, b_zero_cnt, mod)
    ans %= mod
    used_cnt += b_zero_cnt
ans *= pow(2, n - (used_cnt), mod)
ans %= mod
ans -= 1
ans += double_zero_cnt
ans %= mod
print(ans)
import itertools

import numpy as np


# input
a = input()
b = input()
c = input()


def judge_array(x, y):
    l = [None] * 2001
    for i in range(2001):
        s = x[i:]
        t = y[:2001 - i]
        l[i] = np.all(np.where((s == t) | (s == 0) | (t == 0), True, False))
    return l


def main():
    n = [len(a), len(b), len(c)]
    d = {chr(ord('a') + i - 1): i for i in range(1, 27)}
    d['?'] = 0
    abc = np.full((3, 2001), np.zeros(2001))
    for i in range(2000):
        if i < n[0]:
            abc[0][i] = d[a[i]]
        if i < n[1]:
            abc[1][i] = d[b[i]]
        if i < n[2]:
            abc[2][i] = d[c[i]]

    w = [[None] * 3, [None] * 3, [None] * 3]
    for i in range(3):
        for j in range(3):
            if i == j:
                continue
            w[i][j] = judge_array(abc[i], abc[j])
    
    l = itertools.permutations([0, 1, 2])
    ans = 6000
    for x, y, z in l:
        xy = w[x][y]
        xz = w[x][z]
        yz = w[y][z]
        for i in range(2001):
            for j in range(2001):
                if xy[i] and yz[j] and xz[min(2000, i + j)]:
                    v = max(n[x], i + n[y], i + j + n[z])
                    ans = min(ans, v)
                    break
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!python3

import itertools

import numpy as np


# input
a = input()
b = input()
c = input()


def judge_array(x, y):
    l = [None] * 2001
    for i in range(2001):
        s = x[i:]
        t = y[:2001 - i]
        l[i] = np.all(np.where((s == t) | (s == 0) | (t == 0), True, False))
    return l


def main():
    n = [len(a), len(b), len(c)]
    d = {chr(ord('a') + i - 1): i for i in range(1, 27)}
    d['?'] = 0
    abc = np.full((3, 2001), np.zeros(2001))
    for i in range(2000):
        if i < n[0]:
            abc[0][i] = d[a[i]]
        if i < n[1]:
            abc[1][i] = d[b[i]]
        if i < n[2]:
            abc[2][i] = d[c[i]]

    w = [[None] * 3, [None] * 3, [None] * 3]
    for i in range(3):
        for j in range(3):
            if i == j:
                continue
            w[i][j] = judge_array(abc[i], abc[j])
    
    l = itertools.permutations([0, 1, 2])
    ans = 6000
    for x, y, z in l:
        xy = w[x][y]
        xz = w[x][z]
        yz = w[y][z]
        for i in range(2001):
            for j in range(2001):
                if xy[i] and yz[j] and xz[min(2000, i + j)]:
                    v = max(n[x], i + n[y], i + j + n[z])
                    ans = min(ans, v)
                    break
    print(ans)


if __name__ == "__main__":
    main()
N = int(input())
L = [int(input()) for _ in range(N)]

ans = 0
for i in range(N):
  for j in range(i+1, N):
    for k in range(j+1, N):
      if L[i] != L[j] and L[j] != L[k] and L[i] != L[k]:
        if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[i] + L[k] > L[j]:
          ans += 1

print(ans)

### FIXED CODE ###

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

ans = 0
for i in range(N):
  for j in range(i+1, N):
    for k in range(j+1, N):
      if L[i] != L[j] and L[j] != L[k] and L[i] != L[k]:
        if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[i] + L[k] > L[j]:
          ans += 1

print(ans)
n = int(input()) - 1
a = list(input())
while n and a:
    a = [i for i in a if i in input()]
print(a)


### FIXED CODE ###

n = int(input())

cnt = [10000] * 26

for i in range(n):
    s = input()
    tmp = [0] * 26
    for c in s:
        tmp[ord(c) - ord('a')] += 1
    for j in range(26):
        cnt[j] = min(cnt[j], tmp[j])

a = ''
for i in range(26):
    if cnt[i]:
        a = a + chr(ord('a') + i) * cnt[i]
print(a)
def solve():
    N = int(input())
    words = ["a"]*N
    for i in range(N):
        words[i] = list(input())
    A_list = []
    B_list = []
    AB_list = [] 
    AB_count = 0
    for i in range(N):
        tag_A = tag_B = tag_AB = 0
        for j in range(len(words[i])):
            if words[i][j] == "A" and j == len(words[i])-1:
                tag_A = 1
                tag_AB = 0
            elif words[i][j] == "A":
                tag_AB = 1
            elif words[i][j] == "B" and tag_AB == 1:
                tag_AB = 0
                AB_count += 1
            elif words[i][j] == "B" and j == 0:
                tag_B = 1
                tag_AB = 0
            else:
                tag_AB = 0
        if tag_A == 1 and tag_B == 1:
            AB_list.append(i)
        elif tag_A == 1:
            A_list.append(i)
        elif tag_B == 1:
            B_list.append(i)
        #print(tag_A,tag_B,AB_count,A_list,B_list,AB_list)

    if len(AB_list) > 0 and len(A_list) > 0 and len(B_list) > 0:
        count = AB_count + len(AB_list) + min(len(A_list),len(B_list))
    elif len(AB_list) > 0 and len(A_list) == 0 and len(B_list) == 0:
        count = AB_count + len(AB_list) -1
    elif len(AB_list) > 0 and (len(A_list) == 0 or len(B_list) == 0):
        count = AB_count + len(AB_list)
    else:
        count = AB_count + min(len(A_list),len(B_list))

    print(count)


 solve()


### FIXED CODE ###

def solve():
    N = int(input())
    words = ["a"]*N
    for i in range(N):
        words[i] = list(input())
    A_list = []
    B_list = []
    AB_list = [] 
    AB_count = 0
    for i in range(N):
        tag_A = tag_B = tag_AB = 0
        for j in range(len(words[i])):
            if words[i][j] == "A" and j == len(words[i])-1:
                tag_A = 1
                tag_AB = 0
            elif words[i][j] == "A":
                tag_AB = 1
            elif words[i][j] == "B" and tag_AB == 1:
                tag_AB = 0
                AB_count += 1
            elif words[i][j] == "B" and j == 0:
                tag_B = 1
                tag_AB = 0
            else:
                tag_AB = 0
        if tag_A == 1 and tag_B == 1:
            AB_list.append(i)
        elif tag_A == 1:
            A_list.append(i)
        elif tag_B == 1:
            B_list.append(i)

    if len(AB_list) > 0 and len(A_list) > 0 and len(B_list) > 0:
        count = AB_count + len(AB_list) + min(len(A_list),len(B_list))
    elif len(AB_list) > 0 and len(A_list) == 0 and len(B_list) == 0:
        count = AB_count + len(AB_list) -1
    elif len(AB_list) > 0 and (len(A_list) == 0 or len(B_list) == 0):
        count = AB_count + len(AB_list)
    else:
        count = AB_count + min(len(A_list),len(B_list))

    print(count)


solve()
N,M=map(int,input().split())
store=[map(int,input().split()) for _ in range(N)]
store.sort(key=lambda x: x[0])
res=0
for i in range(len(store)):
  price=store[i][0]
  num=store[i][1]
  if M>num:
    res+=price*num
    M-=num
  else:
    res+=price*M
    break
print(res)

### FIXED CODE ###

N, M = map(int, input().split())
shop = []
for i in range(N):
    a, b = map(int, input().split())
    shop.append([a, b])
shop.sort(key=lambda x: x[0])

amount = 0
quantity = 0
for s in shop:
    if quantity + s[1] < M:
        amount += s[0] * s[1]
        quantity += s[1]
    else:
        amount += (M - quantity) * s[0]
        quantity = M
        break

print(amount)
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
 
for i in range(101):
    for j in range(101):
        res = []
        zero = []
        f = True
        for k in range(0,n):
            dx = ab[k][0]
            dy = ab[k][1]
            dh = ab[k][2]
            if dh ==0:
                zero.append([dx,dy])
            else:
                res.append(abs(i-dx)+abs(j-dy)+dh)
        if len(set(res)) == 1:
            for l in zero:
                if res[0] - (abs(i-l[0])+abs(f-l[1])) <=0:
                    pass
                else:
                    f = False
                    break
            if f:
                ansx =i
                ansy =j
                ansr = res[0]

print(str(ansx)+" "+str(ansy)+" "+str(ansr))

### FIXED CODE ###

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

for _ in range(0,n):
    if ab[_][2] !=0:
        x = ab[_][0]
        y = ab[_][1]
        h = ab[_][2]
        break

for i in range(101):
    for j in range(101):
        f = True
        l = abs(i-x)+abs(j-y)+h
        for k in range(0,n):
            dx = ab[k][0]
            dy = ab[k][1]
            dh = ab[k][2]
            if max(l-abs(i-dx)-abs(j-dy),0) ==dh:
                pass
            else:
                f = False
        if f:
            ansx =i
            ansy =j
            ansr = l
            break
print(str(ansx)+" "+str(ansy)+" "+str(ansr))
# -*- coding: utf-8 -*-
import fractions
 
N,X = map(int, input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
y=[]
 
i=0
while i < n:
    y.append(x[i+1]-x[i])
    i +=1
y.sort()
 
y=list(set(y))
m=len(y)
z=y[0]
i=0
while i < m:
    z=fractions.gcd(z,y[i])
    i+=1
 
print(z)

### FIXED CODE ###

# -*- coding: utf-8 -*-
 
tmp = input()
a=[int(x) for x in tmp.split()]

if a[0]*a[1] % 2 == 1:
    print('Yes')
else:
    print('No')
num = (int, input().split())
dice = {'N':(2, 6, 3, 4, 1, 5),'E':(4, 2, 1, 6, 5, 3),'W':(3, 2, 6, 1, 5, 4),'S':(5, 1, 3, 4, 6, 2)}
for alf in input():
    num = [num[i]for i in dice[alf-1]]
print(num[0])



### FIXED CODE ###

dice = {'N':(2, 6, 3, 4, 1, 5),'E':(4, 2, 1, 6, 5, 3),'W':(3, 2, 6, 1, 5, 4),'S':(5, 1, 3, 4, 6, 2)}
num = input().split()
for alf in input():
    num = [num[i-1]for i in dice[alf]]
print(num[0])
n, m = map(int, input().split())

mod = 10 ** 9 + 7


def Fib(n, memo={}):
    if n == 1:
        return 0
    elif n == 2:
        return 1
    elif n in memo:
        return memo[n] % mod
    else:
        memo[n] = Fib(n - 1, memo) + Fib(n - 2, memo)
        return memo[n] % mod


A = list(int(input()) for i in range(m))


if m > 0:
    ans = Fib(A[0] + 1) % mod
    for i in range(m - 1):
        ans *= Fib(A[i + 1] - A[i])
        ans %= mod
        if A[i] + 1 == A[i + 1]:
            print(0)
            exit()
    ans *= Fib(n - A[-1] + 1)
    ans %= mod
else:
    ans = Fib(n + 1) % mod
print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
A = list(int(input()) for i in range(m))

mod = 10 ** 9 + 7

def Fib(n):
    a, b = 0, 1
    if n == 1:
        return a
    elif n == 2:
        return b
    else:
        for i in range(n-2):
            a, b = b, a + b
        return b


if m > 0:
    ans = Fib(A[0] + 1) % mod
    for i in range(m - 1):
        if A[i] == A[i + 1]:
            continue
        ans *= Fib(A[i + 1] - A[i])
        ans %= mod
    ans *= Fib(n - A[-1] + 1)
    ans %= mod
else:
    ans = Fib(n + 2) % mod
print(ans)
numlist = list(map(int,input().split()))
if max(numlist) == 7 and min(numlist) == 5 and sum(sumlist) == 17:
  print('YES')
else:
  print('NO')

### FIXED CODE ###

numlist = list(map(int,input().split()))
if max(numlist) == 7 and min(numlist) == 5 and sum(numlist) == 17:
  print('YES')
else:
  print('NO')
s = raw_input()
n = int(s)
print(n ** 3)


### FIXED CODE ###

s = input()
n = int(s)
print(n ** 3)
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    A, B, C, K = [int(x) for x in input().strip().split()]
    if K <= A + B:
        print(min(K, A))
    else:
        print(A - (K - A - B)))
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    A, B, C, K = [int(x) for x in input().strip().split()]
    if K <= A + B:
        print(min(K, A))
    else:
        print(A - (K - A - B))
    
if __name__ == '__main__':
    main()
import math
n = int(input());
dp = []
def dfs(x, i) :
  dp[i] = dp[i-1] + i
  if dp[i] >= n : 
    return i
  return dfs(dp[i], i+1)

sz = int(math.sqrt(n)) + 10
dp = [0] * sz
ans = dfs(0, 1)
print(ans)

### FIXED CODE ###

import math
import sys
import resource
n = int(input());
dp = []
def dfs(x, i) :
  dp[i] = dp[i-1] + i
  # print(i, dp[i])
  if dp[i] >= n : 
    return i
  return dfs(dp[i], i+1)

sys.setrecursionlimit(100000)

sz = 100000
dp = [0] * sz
print(dfs(0, 1))
N = int(input())
A = [[(int(x),True) for x in input().split()] for _ in range(N)]

ans = 0
for k in range(N):
    for i in range(N):
        if i == k: continue
        for j in range(i+1,N):
            if j == k: continue
            Aikj = A[i][k][0] + A[k][j][0]
            if A[i][j][0] > Aikj:
                ans = -1
            if A[i][j][0] == Aikj:
                A[i][j][1] = False

if ans != -1:
    for i in range(N):
        for j in range(i+1,N):
            if A[i][j][1]:
                ans += A[i][j][0]
print(ans)

### FIXED CODE ###

def main():
    inf=float("inf")
    n=int(input())
    alst=[list(map(int,input().split())) for _ in range(n)]
 
    for i in range(n):
        alst[i][i]=inf
 
    sm=0
    token=0
 
    for i in range(n):
        for j in range(i+1,n):
            for k in range(n):
                if alst[i][k]+alst[k][j]>alst[i][j]:
                    continue
                elif alst[i][k]+alst[k][j]==alst[i][j]:
                    break
                else:
                    token=1
                    break
            else :
                sm+=alst[i][j]
    
    if token : sm=-1
 
    print(sm)
 
main()
def all_water(h_list):
  if len(h_list) == 0:
    return 0
  min_h = min(h_list)
  h_list = list(map(lambda x:x-minh, h_list))
  i = h_list.index(0)
  return min_h + all_water(h_list[:i]) + all_water(h_list[i+1:])

n = input()

height = list(map(int,input().split(" ")))

print(allwater(height))

### FIXED CODE ###

def all_water(h_list):
  if len(h_list) == 0:
    return 0
  min_h = min(h_list)
  new_list = [x - min_h for x in h_list]
  i = new_list.index(0)
  return min_h + all_water(new_list[:i]) + all_water(new_list[i+1:])

n = input()

height = list(map(int,input().split(" ")))

print(all_water(height))
dp=["","+"]
s=input()
su=0
for i in range(2**(len(s)-1)):
    val=""
    for j in range(len(s)-1):
        val+=s[j]
        val+=dp[bin(i)[j+2]]
    val+=s[len(s)-1]
    su+=eval(val)
print(su)

### FIXED CODE ###

dp=["","+"]
s=input()
su=0
for i in range(2**(len(s)-1)):
    val=""
    b=bin(i)[2:].zfill(len(s)-1)
    for j in range(len(s)-1):
        val+=s[j]+dp[int(b[j])]
    val+=s[len(s)-1]
    su+=eval(val)
print(su)
# -*- Coding: utf-8 -*-
N, X = map(int, input().split())
L = list(map(int,input().split()))

ans = 1
p = 0
p += L[ans]
while p <= X:
    p += L[ans]
    ans += 1

print(ans) 



### FIXED CODE ###

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

ans = 1 #位置0も1にカウントするから
p = 0 #今のポジション
for i in range(N):
    p += L[i]
    if p <= X:
         ans += 1
    else:
        break

print(ans)
n = int(input())
tli = [ int(it) for it in input().split() ]
ali = [ int(it) for it in input().split() ]
#print (tli,ali)

mav1 = max(tli)
mav2 = max(ali)
mav = mav1
#print (mav1,mav2)
if (mav1!=mav2):
  print (0)
else:
  mai1 = tli.index(mav)
  mai2 = n-1-list(reversed(ali)).index(mav)
  #print (mai1,mai2)
  if (mai2<mai1):
    print (0)
  else:
    s = 1
    tma = -1
    for i in range(0,mai1+1):
      if tli[i]>tma:
        tma = tli[i]
        #print ("lt",tma)
      else:
        s*=(tli[i])
        #print ("l")
    tma = -1
    for i in range(n-1,mai2-1,-1):
      if ali[i]>tma:
        tma = ali[i]
        #print ("rt",tma)
      else:
        s*=(ali[i])
        #print ("r")
    if (mai2-mai1>1):
      for i in range(mai2-mai1-1):
        s*=mav
  #print ( s )
  print ( s%(1000000007) )
      
    
        
    
 

### FIXED CODE ###

MOD = 1000000007
n = int(input())
tli = [ int(it) for it in input().split() ]
ali = [ int(it) for it in input().split() ]
#print (tli,ali)

mav1 = max(tli)
mav2 = max(ali)
mav = mav1
#print (mav1,mav2)
if (mav1!=mav2):
  print (0)
else:
  mai1 = tli.index(mav)
  mai2 = n-1-list(reversed(ali)).index(mav)
  #print (mai1,mai2)
  if (mai2<mai1):
    print (0)
  else:
    s = 1
    tma = -1
    for i in range(0,mai1+1):
      if tli[i]>tma:
        tma = tli[i]
        #print ("lt",tma)
      else:
        s*=(tli[i])
        s%=MOD
        #print ("l")
    tma = -1
    for i in range(n-1,mai2-1,-1):
      if ali[i]>tma:
        tma = ali[i]
        #print ("rt",tma)
      else:
        s*=(ali[i])
        s%=MOD
        #print ("r")
    if (mai2-mai1>1):
      for i in range(mai2-mai1-1):
        s*=mav
        s%=MOD
    print ( s%(1000000007) )
n,m = map(int,input().split())
l = []
for i in range(m):
    a,b = map(int,input().split())
    l.append(a)
    l.append(b)
    t = list(set(l))
for i in range(n):
    print(l.count(t[i]))

### FIXED CODE ###

l = []
n,m = map(int,input().split())
for i in range(m):
    a,b = map(int,input().split())
    l.append(a)
    l.append(b)
for i in range(1,n+1):
    print(l.count(i))
a,b = input().split()
 
print(min(a*int(b),b*int(a) ) )


### FIXED CODE ###

a,b=map(int,input().split())
s=sum(map(int,input().split()))
print("Yes" if s>=a else "No")
N=int(input())
T,A=map(int, input().split())
H=list(map(int, input().split()))
tmin = 10000000
for i in range(N):
  if tmin < abs(T - H[i] * 0.006):
    ans = i+1
    tmin = abs(T - H[i] * 0.006)
print(ans)
    

### FIXED CODE ###

N=int(input())
T,A=map(int, input().split())
H=list(map(int, input().split()))
tmin = 10000000
for i in range(N):
  if tmin > abs(A - (T - H[i] * 0.006)):
    ans = i+1
    tmin = abs(A - (T - H[i] * 0.006))
print(ans)
input = raw_input
#import numpy as np

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

values = [[] for i in range(M+1)]
for i in range(N):
    A, B = map(int, input().split())
    if M >= A:
        values[A].append(B)

#print(values)
out = 0
elms = []
for i in range(1, M+1):
    new_elms = sorted(values[i], reverse=True)[:M-i+1]
    elms += new_elms
    if len(elms) >= 1:
        max_val = max(elms)
        out += max_val
        elms.remove(max_val)

print(out)

### FIXED CODE ###

x, y = map(int, input().split())

l = [x+y, x-y, x*y]
print(max(l))
def f(y,x,c0):
  global A
  c=A[y][x]
  if c==" " or c!=c0:
    return 0
  else:
    A[y][x]=" "
    for i,j in [[0,-1],[0,1],[-1,0],[1,0]]:
      f(y+i,x+j,c0)
    return 1

while 1:
  H,W=map(int,raw_input().split())
  if H==W==0: break
  A=[[[] for _ in range(W+2)] for _ in range(H+2)]
  for i in range(H+2):
    if i==0 or i==H+1:
      for j in range(W+2): A[i][j]=" "
    else:
      s=" "+raw_input().strip()+" "
      for j in range(W+2): A[i][j]=s[j]
  for e in A: print e
  c=0
  for i in range(1,H+1):
    for j in range(1,W+1):
      c+=f(i,j,A[i][j])
  print c

### FIXED CODE ###

def f(y,x,a):
  M.append([y,x])
  while M:
    y,x=M.pop()
    if A[y][x]==a:
      A[y][x]=' '
      for i,j in [[0,-1],[-1,0],[0,1],[1,0]]: M.append([y+i,x+j])
  return 1

M=[]
while 1:
  H,W=map(int,raw_input().split())
  if H==W==0: break
  A=[list(' '*(W+2)) for _ in range(H+2)]
  for i in range(H): A[i+1][1:W+1]=list(raw_input())
  c=0
  for i in range(1,H+1):
    for j in range(1,W+1):
      a=A[i][j]
      if a!=' ': c+=f(i,j,a)
  print c
N = int(input())
S = input()
T = input()

S = list(S)
T = list(T)
A = [] 
for i in range(N):
    A.append(S[i])
    A.append(T[i])
print(''.join(A))

### FIXED CODE ###

N = int(input())
S,T = input().split()

S = list(S)
T = list(T)
A = []
for i in range(N):
    A.append(S[i])
    A.append(T[i])
print(''.join(A))
import math.pi from math

r =[int(i) for i in input().split()]


s = r * r *pi
l = 2 * r *pi

print("{0:.5f},{1:.5f}".format(s,l))

### FIXED CODE ###

import math
r = float(input())
 
s = r * r *math.pi
l = r *2 *math.pi
 
print("{0:.5f} {1:.5f}".format(s,l))
n, m = map(int, input().split())
vote = list(map(int, input().split()))

vote.sort(reverse=True)
popular = vote[0:m]
sum = sum(vote)

yes = True
print('sum=', sum, sum/(4*m))
print('list=', popular)

for win in popular:
    if win < sum / (4*m):
        print('No')
        yes = False
        break

print(yes)

if yes:
    print('Yes')

### FIXED CODE ###

x,y,z = map(int, input().split())

x1, y1, z1 = y, x, z
x2, y2, z2 = z1, y1, x1

print(x2, y2, z2)
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    acopy = a.copy()
    del acopy[i]
    c = collections.Counter(acopy)
    itm = c.values()
    ans = 0
    for j in itm:
        ans += j*(j-1)//2
    print(ans)


### FIXED CODE ###

import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
v = c.values()
s = 0
for i in v:
    s += (i*(i-1))//2

for i in range(n):
    d = c[a[i]]
    x = (d*(d-1))//2 if d > 1 else 0
    y = ((d-1)*(d-2))//2 if d > 2 else 0
    print(s-x+y)
import math
import string


def readints():
    return list(map(int, input().split()))


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


n, x = map(int, input().split())
l = list(map(int, input().split()))
#print(l)
ll = [0]
sum = 0
for i in range(n):
    sum += l[i]
    ll.append(sum)
#print(ll)

cnt = 0
for i in range(n+1):
    if ll[i] <= x:
        cnt += 1
print(cnt)


### FIXED CODE ###

x, a = map(int, input().split())
if x < a:
    print(0)
else:
    print(10)