Harryxun/stf_run huggingface dataset:
n = int(input())
x = [0]*(n+1)
y = [0]*(n+1)
for i in range(n):
  a = int(input())
  x[i+1] = [0]*a
  y[i+1] = [0]*a
  for j in range(a):
    x[i+1][j], y[i+1][j] = map(int, input().split())

t = []
l = []
ans = 0
flag = 0
f = 1
for i in range(n):
  t.append(i+1)
  t_ = [i+1]
  flag = 1
  while(flag == 1):
    flag = 0
    t__ = [z for z in t_]
    t_ = []
    for m in t__:
      for j, k in zip(x[m],y[m]):
        if k == 0:
          if j in t or j in t_:
            f = 0
            t = []
            l = []
            t_ = []
            break
          l.append(j)
        if k == 1:
          if j in l:
            f = 0
            t = []
            l = []
            t_ = []
            break
          if j not in t and j not in t_:
            t_.append(j)
            flag = 1
      if f == 0:
        flag = 0
        t_ = []
        break
    t.extend(t_)
  if f != 0:
    ans = max(ans,len(t))
  remain = list(set(range(1,n+1))-set(t)-set(l))
  if len(remain)>0:
    T = [z for z in t]
    L = [z for z in l]
    for u in remain:
      t.append(u)
      t_ = [u]
      flag = 1
      while(flag == 1):
        flag = 0
        t__ = [z for z in t_]
        t_ = []
        for m in t__:
          for j, k in zip(x[m],y[m]):
            if k == 0:
              if j in t or j in t_:
                f = 0
                t = []
                l = []
                t_ = []
                break
              l.append(j)
            if k == 1:
              if j in l:
                f = 0
                t = []
                l = []
                t_ = []
                break
              if j not in t and j not in t_:
                t_.append(j)
                flag = 1
          if f == 0:
            flag = 0
            t_ = []
            t = [z for z in T]
            l = [z for z in L]
            break
        t.extend(t_) 
      if f != 0:
        ans = max(ans,len(t))
        T = [z for z in t]
    	L = [z for z in l]
print(ans)

### FIXED CODE ###

n = int(input())
x = [0]*(n)
y = [0]*(n)
for i in range(n):
  a = int(input())
  x[i] = [0]*a
  y[i] = [0]*a
  for j in range(a):
    x[i][j], y[i][j] = map(int, input().split())

A = 0
for i in range(2**n):
  flag = 0
  ans = 0
  num = list(format(i, '0{}b'.format(n)))
  for j, k in enumerate(num):
    if k == "1":
      ans += 1
      for l, m in zip(x[j], y[j]):
        if num[l-1] != "{}".format(m):
          flag = 1
          break
    if flag == 1:
      break
  if flag == 0:
  	A = max(A,ans)
print(A)
import math
N,D = map(int,input().split(" "))
 
for _ in range(N):
  count=0
  p,q=map(int,input().split(" "))
  if (p**2 + q**2)**0.5 <=D**2:
    count+=1
print(count)

### FIXED CODE ###

X=int(input())

if X>=30:
  print("Yes")
else:
  print("No")
a, b, x = map(int, input().split())
v = a*a*b
if x*2 > v:
	print(math.atan((v/a*a)/a))
elif x*2 == v:
	print(0)
else:
	print(math.atan((x/a*a)/a))


### FIXED CODE ###

import math
a, b, x = map(int, input().split())
v = a*a*b
if x*2 > v:
	print(math.degrees(math.atan2((2*(b-(x/(a*a)))), a)))
elif x == v:
	print(0)
else:
	print(90 - math.degrees(math.atan2(((2*x)/(a*b)), b)))
A,B,C,D = map(int, input().split())
from math import gcd
cd = C*D//gcd(D,C)
f = lambda x: B//x - ((A-1)//x)
print(B - A + 1 - (f(C) + f(D) - f(cd)))

### FIXED CODE ###

A,B,C,D = map(int, input().split())
from fractions import gcd

cd = C*D//gcd(D,C)
f = lambda x: B//x - ((A-1)//x)
print(B - A + 1 - (f(C) + f(D) - f(cd)))
import collections
def main():

    N, K = map(int, input().split())
    if K == 1:
        if N == 1: return 1
        else: return 0

    tree = collections.defaultdict(list)
    for _ in range(N-1):
        a, b = map(int, input().split())
        tree[a].append(b)
        tree[b].append(a)
    mod = pow(10, 9) + 7

    v = inv_factorial(K-1, mod)
    invf = [v]
    for i in range(K-1, 0, -1):
        invf.append(*invf[-1] * i) % mod)
    invf = invf[::-1]

    f = [1]
    for i in range(1, K):
        f.append(f[-1]*i)

    ans = K
    cur = []
    visited = set([1])
    for b in tree[1]:
        cur.append(b)
        visited.add(b)
    l = len(cur)
    if l > K-1: return 0
    ans *= (f[K-1]*invf[K-1-l]) % mod
    ans %= mod

    while cur:
        temp = []
        for a in cur:
            l = len(tree[a])-1
            if l > K-2: return 0
            ans *= (f[K-2]*invf[K-2-l]) % mod
            ans %= mod
            for b in tree[a]:
                if b not in visited:
                    temp.append(b)
                    visited.add(b)
        cur = temp

    return ans


def quickpow(x, y, mod):
    if y == 0: return 1
    elif y == 1: return x
    elif y % 2 == 0: return pow(quickpow(x, y//2, mod), 2) % mod
    elif y % 2 == 1: return (pow(quickpow(x, y//2, mod), 2) * x) % mod

def factorial(x, mod):
    v = 1
    for i in range(2, x+1):
        v *= i
        v %= mod
    return v

def inv_factorial(x, mod):
    v = factorial(x, mod)
    return quickpow(v, mod-2, mod)


if __name__ == '__main__':
    print(main())

### FIXED CODE ###

import collections
def main():

    N, K = map(int, input().split())
    if K == 1:
        if N == 1: return 1
        else: return 0

    tree = collections.defaultdict(list)
    for _ in range(N-1):
        a, b = map(int, input().split())
        tree[a].append(b)
        tree[b].append(a)
    mod = pow(10, 9) + 7

    v = inv_factorial(K-1, mod)
    invf = [v]
    for i in range(K-1, 0, -1):
        invf.append((invf[-1] * i) % mod)
    invf = invf[::-1]

    f = [1]
    for i in range(1, K):
        f.append((f[-1]*i) % mod)

    ans = K
    cur = []
    visited = set([1])
    for b in tree[1]:
        cur.append(b)
        visited.add(b)
    l = len(cur)
    if l > K-1: return 0
    ans *= (f[K-1]*invf[K-1-l]) % mod
    ans %= mod

    while cur:
        temp = []
        for a in cur:
            l = len(tree[a])-1
            if l > K-2: return 0
            ans *= (f[K-2]*invf[K-2-l]) % mod
            ans %= mod
            for b in tree[a]:
                if b not in visited:
                    temp.append(b)
                    visited.add(b)
        cur = temp

    return ans


def quickpow(x, y, mod):
    if y == 0: return 1
    elif y == 1: return x
    elif y % 2 == 0: return pow(quickpow(x, y//2, mod), 2) % mod
    elif y % 2 == 1: return (pow(quickpow(x, y//2, mod), 2) * x) % mod

def factorial(x, mod):
    v = 1
    for i in range(2, x+1):
        v *= i
        v %= mod
    return v

def inv_factorial(x, mod):
    v = factorial(x, mod)
    return quickpow(v, mod-2, mod)


if __name__ == '__main__':
    print(main())
mount_count = input()
mount_heights = input()
mount_heights_list = mount_heights.split()
count = 0
max_height = int(mount_heights_list[0])
for mount_height in mount_heights_list:
    if max_height <= int(mount_height):
        max_height = mount_height
        count += 1
print(count)

### FIXED CODE ###

mount_count = input()
mount_heights = input()
mount_heights_list = mount_heights.split()
count = 0
max_height = int(mount_heights_list[0])
for mount_height in mount_heights_list:
    if max_height <= int(mount_height):
        max_height = int(mount_height)
        count += 1
print(count)
import math
inlist=input("").split(" ")
a=int(inlist[0])
b=int(inlist[1])
h=int(inlist[2])
m=int(inlist[3])
sita1=h*30+0.5*m
sita2=h*6
sita=sita1-sita2
d=a**2+b**2-2*a*b*math.cos(math.radius(sita))
e=int(math.sqrt(d))
print(e)

### FIXED CODE ###

import math
inlist=input("").split(" ")
a=int(inlist[0])
b=int(inlist[1])
h=int(inlist[2])
m=int(inlist[3])
sita1=h*30+0.5*m
sita2=m*6
sita=sita1-sita2
d=a**2+b**2-2*a*b*math.cos(math.radians(sita))
e=math.sqrt(d)
print(e)
N = int(input())
ad = [[] for _ in range(N)]
edge = []
for _ in range(N-1):
    a, b = map(int,input().split())
    a -= 1; b -= 1
    ad[a].append(b)
    ad[b].append(a)
    edge.append((a, b))

K = max(len(S) for S in ad)
d = dict()

def dfs(v=0, pv=-1, memo=-1):
    color = 0
    for nv in ad[v]:
        if nv == pv:
            continue
        if color == memo:
            color += 1
        d[(v, nv)] = color
        d[(nv, v)] = color
        dfs(nv, v, color)
        color += 1

dfs()

print(K)
for e in edge:
    print(d[e]+1)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

N = int(input())
ad = [[] for _ in range(N)]
edge = []
# 0からn-1の値をとる木構造を管理する。
for _ in range(N-1):
    a, b = map(int,input().split())
    a -= 1; b -= 1
    ad[a].append(b)
    ad[b].append(a)
    edge.append((a, b))

K = max(len(S) for S in ad)
d = dict()

def dfs(v=0, pv=-1, memo=-1):
    color = 0
    for nv in ad[v]:
        if nv == pv:
            continue
        if color == memo:
            color += 1
        d[(v, nv)] = color
        d[(nv, v)] = color
        dfs(nv, v, color)
        color += 1

dfs()

print(K)
for e in edge:
    print(d[e]+1)
a,b,x = map(int, input().split())
if x < (b*a**2)/2:
    c = 2*x / a**2
    print(90 - math.degrees(math.atan(c/a)))
else:
    x2 = x - b*a**2
    c = 2*x2 / a**2
    print(-math.degrees(math.atan(c/a)))

### FIXED CODE ###

import math
a,b,x = map(int, input().split())
if x < (b*a**2)/2:
    c = (2*x) / (a*b)
    print(90 - math.degrees(math.atan(c/b)))
else:
    x2 = x - b*a**2
    c = (2*x2) / (a*a)
    print(-math.degrees(math.atan(c/a)))
a,b,c,d=map(int,input().split())
print (a*b-(b*c+a*d-c*d))

### FIXED CODE ###

a,b=map(int,input().split())
c,d=map(int,input().split())
print ((a-c)*(b-d))
import numpy as np


def main():
    # H, W = [int(x) for x in input().split()]
    H, W = map(int, [int(x) for x in input().split()])
    board = [[0 for i in range(H)] for j in range(W)]

    """ #は1, .は0 """
    for i in range(H):
        X = input()
        for j in range(len(X)):
            if X[j] == "#":
                board[i][j] = 1

    num_board = np.array(board)
    height, width = num_board.shape[:2]
    count = 0
    while (np.sum(np.array(board)) != height*width):
        num_board_ans = board
        for i in range(height):
            for j in range(width):
                if board[i][j] == 1:
                    num_board_ans[i][j] = 1
                    a = max(i-1, 0)
                    num_board_ans[a][j] = 1
                    b = max(j-1, 0)
                    num_board_ans[i][b] = 1
                    c = min(i+1, height-1)
                    num_board_ans[c][j] = 1
                    d = min(j+1, width-1)
                    num_board_ans[i][d] = 1
        board = num_board_ans
        count += 1

    print(count)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque


def bfs(h, w, board, visited):
    queue = deque([])
    for i in range(h):
        for j in range(w):
            if board[i][j] == "#":
                queue.append([i, j])
                visited[i][j] = 0
    ans = 0
    while queue:
        y, x = queue.popleft()
        for i, j in ([1, 0], [0, 1], [-1, 0], [0, -1]):
            yn, xn = y+i, x+j
            if yn >= h or xn >= w or yn < 0 or xn < 0:
                continue
            if visited[yn][xn] == -1 and board[yn][xn] == ".":
                visited[yn][xn] = visited[y][x] + 1
                queue.append([yn, xn])
                ans = max(ans, visited[yn][xn])

    return ans


def main():
    h, w = map(int, input().split())
    board = [input() for _ in range(h)]
    visited = [[-1 for _ in range(w)] for _ in range(h)]
    print(bfs(h, w, board, visited))


if __name__ == "__main__":
    main()
N = int(input())
HPs = list(map(int, input().split()))

while len(HPs) > 1:
    HPs.sort()
    for i in len(HPs):
        HPs[i+1] = HPs[i+1] % HPs[0]
    HPs.remove(0)

print(HPs[0])

### FIXED CODE ###

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

while len(HPs) > 1:
    HPs.sort()
    for i in range(len(HPs)-1):
        HPs[i+1] = HPs[i+1] % HPs[0]
    while 0 in HPs:
        HPs.remove(0)

print(HPs[0])
N=int(input())
s=list(input().split())
t=s[5::-2]+s[0::2]
for i in range(N):
    print(t[i],end=" ")




### FIXED CODE ###

N=int(input())
s=list(input().split())
if N>=2:
    t=s[N::-2]+s[N%2::2]
    for i in range(N):
        print(t[i],end=" ")
else:
    print(s[0])
n, k = map(int, input().split())
a = list(map(int, input().split()))

a = [i - 1 for i in a]
l = []
used = [0 for _ in range(n)]
used[0] = 0

c = 0
flag = True
while 1:
    if flag:
        flag = False
    else:
        l.append(c)
    if used[c] == 1 and l:
        break
    used[c] = 1
    c = a[c]

if len(l)<k:
    end = l[-1]
    p = 0
    s = []
    for i in range(len(l)):
        if l[i] == end:
            s = l[i:-1]
            p = i
            break

    b = (k-p) % len(s)
    print(l[b] + 1)
else:
    print(l[k-1])

        

### FIXED CODE ###

n, k = map(int, input().split())
a = [i-1 for i in list(map(int, input().split()))]

l = []
used = [0 for _ in range(n)]

c = 0
flag = True
while 1:
    if not flag:
        l.append(c)
    if used[c] == 1 and l:
        break
    if not flag:
        used[c] = 1
    c = a[c]
    flag = False

p = 0
length = len(l)
b = []
for i in range(length):
    if l[i] == l[-1]:
        b = l[:i]
        l = l[i:-1]
        p = i
        break


if len(b) >= k:
    print(b[k - 1]+1)
else:
    print(l[(k - p - 1) % len(l)] + 1)
N=int(input())
s=list(map(int,input().split()))
t=sorted(s)
p=t[N//2]
q=t[N//2+1]
for i in range(N):
    if s[i]<=p:
        print(q)
    else:
        print(p)
        

### FIXED CODE ###

N=int(input())
s=list(map(int,input().split()))
t=sorted(s)
p=t[N//2-1]
q=t[N//2]
for i in range(N):
    if s[i]<=p:
        print(q)
    else:
        print(p)
N = int(input())
R = int(input())

if N < 10:
  N = 100 * (10 - N) 
  print(N)
  
if N > 10:
  N = R
  print(N)
  

### FIXED CODE ###

N, R = (int(x) for x in input().split())
 
if N < 10:
  N = R + 100 * (10 - N) 
  print(N)
  
else:
  N = R
  print(N)
N = int(input())
a = [int(input()) for i in range(N)]
a.sort(reverse=True)
amax = a[0]
for i in range(len(a)):
  if a[i]==amax:
    print(a[i+1])
  else:
    print(amax)

### FIXED CODE ###

N = int(input())
a = [int(input()) for i in range(N)]
amax = max(a)
amax2 = sorted(a)[-2]
for i in range(len(a)):
  if a[i]==amax:
    print(amax2)
  else:
    print(amax)
s = input()
t = input()
len_s = len(s)
len_t = len(t)
dp = [[0]*(len_t+1) for _ in range(len_s+1)]
# dp[i][j]はs[i],t[j]までで、最長の部分列の長さ
for i in range(len_s):
    for j in range(len_t):
        if s[i] == t[i]:
            dp[i+1][j+1] = max(dp[i][j]+1, dp[i+1][j], dp[i][j+1])

        dp[i+1][i+1] = max(dp[i+1][j+1], dp[i+1][j], dp[i][j+1])
#print(dp)
ans = ""
while len_t>0 and len_s>0:
    if dp[len_s][len_t] == dp[len_s-1][len_t]:
        len_s -= 1
    elif dp[len_s][len_t] == dp[len_s][len_t-1]:
        len_t -= 1
    else:
        ans += s[len_s-1]
        len_s -= 1
        len_t -= 1
print(ans[::-1])

### FIXED CODE ###

s = input()
t = input()
len_s = len(s)
len_t = len(t)
dp = [[0]*(len_t+1) for _ in range(len_s+1)]
# dp[i][j]はi、j文字目までのs[i],t[j]で、最長の部分列の長さ
for i in range(len_s):
    for j in range(len_t):
        if s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i][j]+1, dp[i+1][j], dp[i][j+1])

        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j], dp[i][j+1])
#print(dp)
ans = ""
while len_t > 0 and len_s > 0:
    if dp[len_s][len_t] == dp[len_s-1][len_t]:
        len_s -= 1
    elif dp[len_s][len_t] == dp[len_s][len_t-1]:
        len_t -= 1
    else:
        ans += s[len_s-1]
        len_s -= 1
        len_t -= 1
print(ans[::-1])
ary = input().split(" ")
a = ary[0]
b = ary[1]
c = ary[2]

if ( a == b and (a != c or b != c) ) :
elif ( a == c and ( a != b and c != b ) ) :
elif ( b == c and ( c != a or b != a ) :
  print("Yes") 
else :
  print("No")

### FIXED CODE ###


ary = input().split(" ")
a = ary[0]
b = ary[1]
c = ary[2]

if a == b and ( a != c or b != c )  :
  print("Yes") 
elif a == c and ( a != b or c != b ) :
  print("Yes") 
elif b == c and ( b != a or c != a ) :
  print("Yes") 
else :
  print("No")
from math imort*
m,n=input.split()
c=0
for i in range(int(m)):
  a,b=input.split()
  d=(int(a)**2)+(int(b)**2)
  if d>=int(n):
    c=c+1
print(c)

### FIXED CODE ###

n=int(input())
if n<30:
  print("No")
else:
  print("Yes")
line = input()
a, b, c, k = [int(n) for n in line.split()]
numbers = [a, b, c]
numbers.sort(reverse=True)
numbers[0] *= 2 ** k
print(sum(numbers))


### FIXED CODE ###

line = input()

a, b, c = [int(n) for n in line.split()]
k = int(input())

max_val = max(a, b, c)
max_val_mem = max_val

amax = False
bmax = False
cmax = False

for _ in range(k):
    max_val *= 2

if max_val_mem == a:
    amax = True
    print(str(max_val+ b+ c))
elif max_val_mem == b:
    bmax = True
    print(str(max_val+ a+ c))
elif max_val_mem == c:
    cmax = True
    print(str(max_val+ a+ b))
S = list(input())
K = int(input())

#print(link_S)
#S = S.append(S[len(S)-1])
i = 0
sum = 1
total_sum = 0
sum_ketu = 0
while(1):
    if i == len(S)-1:
        if (S[i] == S[0] and S[0] != S[1]) or (S[i] == S[0] and S[i-1] != S[i]):
            if sum % 2 == 1:
                sum += 1
                sum_ketu = -1
        break
    if S[i] == S[i+1]:
     #   print("i is", i)
     #   print("S[i] is", S[i], "S[i+1] is", S[i+1])
        sum += 1
     #   print(sum)
        i += 1
    else:
        total_sum += sum // 2
        sum = 1
        i += 1
        
total_sum += sum // 2
#print(sum_ketu)
#print(total_sum)
print(total_sum * K + sum_ketu)



### FIXED CODE ###

S = list(input())
K = int(input())

if len(S) == 1:
    print( K // 2)
    exit()

count = 1
i = 0
sum = 0
while(1):
    if S[i] == S[i+1]:
        count += 1
        i += 1
    else:
        sum += count//2
        count = 1
        i += 1
    if i == len(S)-1:
        break

sum += count//2 #最後のカウントの加算

#print("check1",sum)

#先頭の連続数をカウント
j = 0 # リストカウント
a = 1 # 連続数カウント
while(1):
    if S[j] == S[j+1]:
        a += 1
        j += 1
    else:
        break
    if j == len(S) -1:
        break
#print("check")

#末尾の連続数をカウント
m = len(S)-1 # リストカウント
b = 1 # 連続数カウント
while(1):
    if S[m] == S[m-1]:
        m -= 1
        b += 1
    else:
        break
    if m == 0:
        break

#print("a is",a)
#print("b is",b)
#print("sum is", sum)
if a == len(S): #１文字のみで文字列構成の場合
    print((len(S)* K)//2)
elif S[len(S)-1] == S[0]:
    print( sum * K + ((a+b)//2 - a//2 - b //2 ) * ( K -1))
else:
    print( sum * K)
input()
print(*sorted(input().split()))

### FIXED CODE ###

print(*sorted(input().split()))
# -*- coding: utf-8 -*-

A, B, C, D = int(raw_input())
E = A*B-C*D

if E >= 0:
    print A*B
else E < 0:
    print C*D



### FIXED CODE ###

# -*- coding: utf-8 -*-

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

if A*B >= C*D:
    print(A*B)
else:
    print(C*D)
import math

s = input()
k = math.log10(int(input()))
index_num = 0
pow_num = 5000000000000000
if k == 0:
  print(s[0])
  exit()
for i in s:
  new_index_num = index_num  + math.log10(int(i)) * pow_num
  if k > index_num and k <= new_index_num:
    print(i)
    break

### FIXED CODE ###

a, b = input().split()

print((int(a) - 1) * (int(b) - 1))
#! python3
# prime_number.py

import math

def is_prime_number(x):
    if x < 2: return False
    elif x == 2: return True
    elif x%2 == 0: return False

    sqrt_upper_bound = math.ceil(math.sqrt(x))
    for i in range(3, sqrt_upper_bound, 2):
        if num % i == 0:
            return False

    return True

n = int(input())
prime_num = 0
for i in range(n):
    x = int(input())
    if is_prime_number(x):
        prime_num += 1

print(prime_num)



### FIXED CODE ###

#! python3
# prime_number.py

import math

def is_prime_number(x):
    if x < 2: return False
    elif x == 2: return True
    elif x%2 == 0: return False

    sqrt_upper_bound = math.floor(math.sqrt(x))+1
    for i in range(3, sqrt_upper_bound, 2):
        if x % i == 0:
            return False

    return True

n = int(input())
prime_num = 0
for i in range(n):
    x = int(input())
    if is_prime_number(x):
        prime_num += 1

print(prime_num)
n, m = map(int,input().split())
li = [[] for i in range(m)]
for i in range(m):
    a, b = map(int,input().split())
    li[a-1].append(b-1)
    li[b-1].append(a-1)
sign = {0: 0}
step = {0: 0}
now = {0}

while len(now) > 0:
    next = set()
    for i in now:
        for j in li[i]:
            if not j in sign:
                sign[j] = i
                step[j] = step[i] + 1
                next.add(j)
    now.clear()
    now = next

print('Yes')
for i in range(n - 1):
    print(sign[i + 1] + 1)

### FIXED CODE ###

n, m = map(int,input().split())
li = [[] for i in range(n)]
for i in range(m):
    a, b = map(int,input().split())
    li[a-1].append(b-1)
    li[b-1].append(a-1)
sign = {0: 0}
step = {0: 1}
now = {0}
flg = False
while len(now) > 0:
    if flg:
        print('No')
        exit()
    flg = True
    next = set()
    for i in now:
        for j in li[i]:
            if not j in sign:
                sign[j] = i
                step[j] = step[i] + 1
                next.add(j)
                flg = False
    now.clear()
    now = next

print('Yes')
for i in range(n - 1):
    print(sign[i + 1] + 1)
import sys
def dfs(x, y, sym):
	tile[x][y] = "."
	for i in range(len(DX)):
		nx = x + DX[i]
		ny = y + DY[i]
		if (0<=nx and nx<N and 0<=ny and ny<M and tile[nx][ny] is sym):
			dfs(nx, ny, sym)

def solve():
	res = 0
	for i in range(N):
		for j in range(M):
			sym = tile[i][j]
			if tile[i][j] != ".":
				if tile[i][j] is sym:
					dfs(i, j, sym)
					res += 1
	print(res)

counter=0
DX = [-1,0,1,0]
DY = [0,-1,0,1]
sys.setrecursionlimit(10**7)
while True:
	line = input()
	if " " in line:
		nums = line.split(" ")
		N = int(nums[0])
		M = int(nums[1])
		tile = [[0 for i in range(N)] for j in range(M)]
	else:
		tile[counter-1] = list(line)
	if N is 0 and M is 0:
		break
	counter += 1
	if counter-1 is M:
		solve()
		counter = 0

### FIXED CODE ###

# -*- coding:utf-8 -*-
import sys
def dfs(x, y, sym):
	tile[x][y] = "."
	for i in range(len(DX)):
		nx = x + DX[i]
		ny = y + DY[i]
		if (0<=nx and nx<N and 0<=ny and ny<M and tile[nx][ny] is sym):
			dfs(nx, ny, sym)

def solve():
	res = 0
	for i in range(N):
		for j in range(M):
			sym = tile[i][j]
			if tile[i][j] != ".":
				if tile[i][j] is sym:
					dfs(i, j, sym)
					res += 1
	print(res)

counter=0
DX = [-1,0,1,0]
DY = [0,-1,0,1]
sys.setrecursionlimit(10**7)
while True:
	line = input()
	if " " in line:
		nums = line.split(" ")
		N = int(nums[0])
		M = int(nums[1])
		tile = [[0 for i in range(M)] for j in range(N)]
	else:
		tile[counter-1] = list(line)
	if N is 0 and M is 0:
		break
	counter += 1
	if counter-1 is N:
		solve()
		counter = 0
n=int(input())
S=[]
for i in range(n):
  s=list(input())
  S+=[s]
ANS=[]
for k in range(len(S[0])):
  if S[0][k] in S[1]:
    ANS+=[S[0][k]]
    S[1].remove(S[0][k])
for i in ANS:
  for k in range(2,n):
    if i in S[k]:
      S[k].remove(i)
    else:
      ANS.remove(i)      
ANS.sort()      
ans="".join(ANS)  
print(ans)

### FIXED CODE ###

import sys
n=int(input())
S=[]
for i in range(n):
  s=list(input())
  S+=[s]
ANS=[]
if n==1:
  ANS=S[0]
  ANS.sort()
  ans="".join(ANS) 
  print(ans)
  sys.exit()
for k in range(len(S[0])):
  if S[0][k] in S[1]:
    ANS+=[S[0][k]]
    S[1].remove(S[0][k])
rem=[]
for i in ANS:
  flag=0
  for k in range(2,n):
    if i in S[k]:
      S[k].remove(i)
    elif flag!=1:
      rem+=[i]
      flag=1
for i in rem:
  ANS.remove(i)
ANS.sort()      
ans="".join(ANS)  
print(ans)
def mm(N, A, x):
  S = 0
  for i in range(N):
    S += abs(A[i] - x)
  return S

N = int(input())
A = []
j = 0
for i in input().split():
  j += 1
  A.append(int(i)-j)
A.sort()
if N % 2 == 0:
  print(mm(N, A, A[N//2]))
else:
  print(min(mm(N, A, A[N//2]), mm(N, A, A[N//2 + 1])))

### FIXED CODE ###

def mm(N, A, x):
  S = 0
  for i in range(N):
    S += abs(A[i] - x)
  return S

N = int(input())
A = []
j = 0
for i in input().split():
  j += 1
  A.append(int(i)-j)
A.sort()
if N % 2 == 0:
  print(mm(N, A, A[N//2]))
elif N == 1:
  print(0)
else:
  print(min(mm(N, A, A[N//2]), mm(N, A, A[N//2 + 1])))