Harryxun/stf_run huggingface dataset:
#-*- coding:utf-8 -*-

#入力数値を分単位に変更
def convert_time(n):
    return (n/100)*60 + n%100

#コマーシャルの共通部分を返す
def kyotsu(cm1,cm2):
    result = []
    for i in range(len(cm2)/2):
        #cm2の各CMとかぶっている部分を取得
        for j in range(len(cm1)/2):
            st = max(cm2[i*2],cm1[j*2])
            ed = min(cm2[i*2+1],cm1[j*2+1])
            if ed - st > 0:
                result.append(st)
                result.append(ed)

    return result

#コマーシャルを見ずにテレビを見られる最長時間を求める
while 1:
    cond = [int(r) for r in raw_input().split(" ")]
    if cond[0]==cond[1]==cond[2]==0: #入力がすべて0なら終了
        break

    #開始時間、終了時間を算出
    start = convert_time(cond[1])
    end = convert_time(cond[2])

    cms = []
    #各チャンネルのコマーシャル時間を求める
    for i in range(cond[0]):
        n = int(raw_input()) #コマーシャル数
        input = [convert_time(int(r)) for r in raw_input().split(" ")]
        j=0
        cmstmp = []
        while j < n:
            st = input[2*j]
            ed = input[2*j+1]
            if not i:
                cms.append(st)
                cms.append(ed)
            else:
                cmstmp.append(st)
                cmstmp.append(ed)
            j += 1
        if i > 0:
            cms = kyotsu(cms,cmstmp)


    #cmsを利用してコマーシャルを見なくてすむ最大時間を出力
    cms = [start] + cms + [end]
    print max([cms[i*2+1]-cms[i*2] for i in range(len(cms)/2)])

### FIXED CODE ###

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

#入力数値を分単位に変更
def convert_time(n):
    return (n/100)*60 + n%100

#コマーシャルの共通部分を返す
def kyotsu(cm1,cm2):
    result = []
    for i in range(len(cm2)/2):
        #cm2の各CMとかぶっている部分を取得
        for j in range(len(cm1)/2):
            stt = max(cm2[i*2],cm1[j*2])
            edt = min(cm2[i*2+1],cm1[j*2+1])
            if edt - stt > 0:
                result.append(stt)
                result.append(edt)

    return result

#コマーシャルを見ずにテレビを見られる最長時間を求める
while 1:
    cond = [int(r) for r in raw_input().split()]
    if cond[0]==cond[1]==cond[2]==0: #入力がすべて0なら終了
        break

    #開始時間、終了時間を算出
    start = convert_time(cond[1])
    end = convert_time(cond[2])

    cms = []
    #各チャンネルのコマーシャル時間を求める
    for i in range(cond[0]):
        n = int(raw_input()) #コマーシャル数
        input = [convert_time(int(r)) for r in raw_input().split()]
        j=0
        cmstmp = []
        while j < n:
            st = input[2*j]
            ed = input[2*j+1]
            if not i:
                cms.append(st)
                cms.append(ed)
            else:
                cmstmp.append(st)
                cmstmp.append(ed)
            j += 1
        if i > 0:
            cms = kyotsu(cms,cmstmp)


    #cmsを利用してコマーシャルを見なくてすむ最大時間を出力
    cms = [start] + cms + [end]
    print max([cms[i*2+1]-cms[i*2] for i in range(len(cms)/2)])
x = [int(input()) for i range(5)]
k = int(input())

for i in range(4):
  for _ in range(1,5):
    if x[i] - x[_] > k:
      print(":(")
    exit()
else:
  print("Yey!")

### FIXED CODE ###

x = [int(input()) for i in range(5)]
k = int(input())

for i in range(4):
  for _ in range(1,5):
    if abs(x[i] - x[_]) > k:
      print(":(")
      exit()
print("Yay!")
A, B, C = map(int, input().split())

print(max(C-(A-B), 0)

### FIXED CODE ###

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

print(max(C-(A-B), 0))
N=int(input())
a_n=[]
a_n = input().split(" ")
a_n = x.split(" ")
count = 0

a_n.sort()
for i in range(N):
    if int(a_n[i])/400 < 8:
         a_n[i] = int(a_n[i])/400
    else:
        count += 1

num = len(set(a_n))

print(str(num)+" "+str(num+count))

### FIXED CODE ###

N=int(input())
a_n=[]
a2_n=[]
a_n = input().split(" ")
count = 0

for i in range(N):
    if int(a_n[i])/400 < 8:
         a2_n.append(int(a_n[i])//400)
    else:
        count += 1

n_min = len(set(a2_n))
n_max = n_min+count

print(max(1, n_min),n_max)
import math
K,A,B = map(int, input().split())
cookie = 0

if K < A + 1 or B - A <  A + 1 or B - A < 2:
    print(K + 1)

else:
    cookie = B
    K = K-A-1

    if K%2==0:
        cookie += (B-A)* math.floor(K/2)
        print(cookie)
    else:
        cookie += (B-A)*math.floor((K-1)/2)
        print(cookie + 1)


### FIXED CODE ###


A, B = map(int, input().split())
line = []
for k in range(0,A+1):
    line.append(k)
line = line[1::2]

if len(line) >= B:
    print("YES")
else:
    print("NO")
import sys
import math
import re

a = {"Sunny": "Cloudy", "Cloudy": "Rainy", "Rainy":"Sunny"}

print a[input()]


### FIXED CODE ###

import sys
import math
import re

a = {"Sunny": "Cloudy", "Cloudy": "Rainy", "Rainy":"Sunny"}

print(a[input()])
x=input("X:")
y=input("Y:")
z=x+y/2
print(z)

### FIXED CODE ###

number=input().split(" ")
x=int(number[0])
y=int(number[1])
z=x+y/2
print(int(z))
N = int(input())
A = list(map(int,input().split()))
rank = []

for i in range(1,N+1):
    rank.append(A.count(i))
    


for i in range(0,N+1):
    print(rank[i])
    


### FIXED CODE ###

R = input()

print( 2 * 3.141 * int(R) )
, b, c, d = map(int, input().split())

print(max(a*b, c*d))

### FIXED CODE ###

a, b, c, d = map(int, input().split())

print(max(a*b, c*d))
import math
while True:
	n = int(input())
	if n==0: break
	s = list(map(float, raw_input().split()))
	t = sum(s)
	a = t / n
	b = sum(map(lambda x: (x-a)**2, s))
	print(math.sqrt(b/n))

### FIXED CODE ###

import math
while True:
	n = int(input())
	if n==0: break
	s = list(map(float, input().split()))
	t = sum(s)
	a = t / n
	b = sum(map(lambda x: (x-a)**2, s))
	print(math.sqrt(b/n))
a=int(input())
b=int(input())
c=int(input())

if a-b=c-b:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

d=input().split()
a=int(d[0])
b=int(d[1])
c=int(d[2])



if b-a==c-b:
    print("YES")
else:
    print("NO")
N,M,P = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in [0]*M]

Ef = [{} for _ in [0]*N]
Eb = [{} for _ in [0]*N]

for a,b,c in ABC:
    Ef[a-1][b-1] = P-c
    Eb[b-1][a-1] = P-c

#pre process

d = [-1]*N
d[0] = 0
q = [0]
while q:
    i = q.pop()
    di = d[i]
    for j in Ef[i]:
        if d[j] != -1 : continue
        d[j] = di + 1
        q.append(j)

for i in range(N):
    if d[i] != -1: continue
    for j in Ef[i]:
        Eb[j].pop(i)
    Ef[i] = {}

d = [-1]*N
d[N-1] = 0
q = [N-1]
while q:
    i = q.pop()
    di = d[i]
    for j in Eb[i]:
        if d[j] != -1 : continue
        d[j] = di + 1
        q.append(j)

for i in range(N):
    if d[i] != -1: continue
    for j in Eb[i]:
        Ef[j].pop(i)
    Eb[i] = {}

#main process
ans = 0
d = [None]*N
d[0] = 0
for _ in [0]*N:
    done = [False]*N
    q = [0]
    while q:
        i = q.pop()
        if done[i]: continue
        done[i] = True
        di = d[i]
        for j,c in Ef[i].items():
            if d[j] == None:
                d[j] = di + c
            else:
                d[j] = min(d[j],di+c)
            if done[j]:continue
            q.append(j)

ans = d[-1]
check = d[:]

#check
for _ in [0]:
    done = [False]*N
    q = [0]
    while q:
        i = q.pop()
        if done[i]: continue
        done[i] = True
        di = d[i]
        for j,c in Ef[i].items():
            if d[j] == None:
                d[j] = di + c
            else:
                d[j] = min(d[j],di+c)
            if done[j]:continue
            q.append(j)

if check!=d: ans = -1/0
else: ans = -min(0,ans)

print(ans)

### FIXED CODE ###

def connect_dfs(N,E,start):
    connect = {start}
    q = [start]
    while q:
        i = q.pop()
        for j in E[i]:
            if j in connect:continue
            connect.add(j)
            q.append(j)
    return connect

def remove_Edge(N,Ef,Eb,start,goal):
    v = connect_dfs(N,Ef,start) & connect_dfs(N,Eb,goal)
    for i in range(N):
        if i in v:continue
        for j in Eb[i]:
            Ef[j].pop(i)

def Bellman_Ford(N,E,start,INFTY=10**18):
    def update(dist,N,E,start):
        done = [False]*N
        done[start] = True
        q = [start]
        d = dist[:]
        while q:
            i = q.pop()
            di = d[i]
            for j,c in E[i].items():
                d[j] = min(d[j],d[i]+c)
                if not done[j]:
                    q.append(j)
                    done[j] = True
        return d
    #
    d = [INFTY]*N
    d[start] = 0
    for _ in range(N-1):
        d = update(d,N,E,start)
    if d!=update(d,N,E,start): return None
    else: return d

N,M,P = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in [0]*M]

Ef = [{} for _ in [0]*N]
Eb = [{} for _ in [0]*N]
INFTY = 10**18
for a,b,c in ABC:
    Ef[a-1][b-1] = min(P-c,Ef[a-1].get(b-1,INFTY))
    Eb[b-1][a-1] = min(P-c,Eb[b-1].get(a-1,INFTY))
    
remove_Edge(N,Ef,Eb,0,N-1)
d = Bellman_Ford(N,Ef,0)

if d==None:ans=-1
else:ans = max(0,-d[-1])
print(ans)
N = int(input())
xy = [[0,0] for _ in range(N)]
for a in xy:
    a[0], a[1] = map(int, input().split())
x=a[0]
y=a[1]
import math
import numpy as np


def distance(x, y, i, j):
    d = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
    return d

da = np.zeros([N, N])
for i in range(N):
    for j in range(N):
        Da = distance(x, y, i, j)
        da[i][j] = Da
avg = da.sum() * math.factorial(N-1) / math.factorial(N)
print(avg)

### FIXED CODE ###

import math
N = int(input())
x = [0]*N
y = [0]*N
for i in range(N):
    x[i],y[i] = map(int,input().split())
at=[]
for i in range(N):
    for j in range(N):
        ea = math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)
        at.append(ea)
da = 0
for ag in at:
    da += ag
avg = da * math.factorial(N - 1) / math.factorial(N)
print(avg)
s=input()
t=s[::-1]
n=len(input())
if n%2==0:
    x=n//2
else:
    x=(n-1)//2
count=0
    for i in range(x):
        if s[i]!=t[i]:
            count+=1
print(count)

### FIXED CODE ###

s=input()
n=len(s)
cnt=0
if n%2==0:
  for i in range(n//2):
    if s[:n//2][::-1][i]!=s[n//2:n][i]:
      cnt+=1
  print(cnt)
else:
  for i in range(n//2):
    if s[:(n-1)//2][::-1][i]!=s[(n+1)//2:n][i]:
      cnt+=1
  print(cnt)
a=int(input())
b=int(input())
if(a<10 and b<10):
    print(a*b)
else:
    print(-1)

### FIXED CODE ###

a=list(map(int,input().split()))
if(a[0]<10 and a[1]<10):
    print(a[0]*a[1])
else:
    print(-1)
N = int(input())
ans = 0
for n in range(1,N+1):
    if len(str(n)) % 2 == 1:
    ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
ans = 0
for n in range(1,N+1):
    if len(str(n)) % 2 == 1:
        ans += 1
print(ans)
import numpy as np
n = int(input())
w = np.array(list(map(int, input().split())))
w_amount = w.cumsum()
w_reverse_amount = w[::-1].cumsum()[::-1]

res = abs(w_amount[0] - w_reverse_amount[0])
min_index = 0
for i in range(n):
  if(res => abs(w_amount[i] - w_reverse_amount[i])):
    res = abs(w_amount[i] - w_reverse_amount[i])
    min_index = i
print(i+1)

### FIXED CODE ###

import numpy as np
n = int(input())
w = np.array(list(map(int, input().split())))
w_amount = w.cumsum()
w_reverse_amount = w[::-1].cumsum()[::-1]
res = abs(w_amount[0] - w_reverse_amount[1])
min_index = 0
for i in range(n-1):
  if(res >= abs(w_amount[i] - w_reverse_amount[i+1])):
    res = abs(w_amount[i] - w_reverse_amount[i+1])
print(res)
import bisect

N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for i in range(M)]

A.sort()
BC.sort(key=lambda x: x[1],reverse=True) 
ans=0
for j in range(M):
    if A[0]>=BC[j][1] or len(A)==0:
        break
    else:
        b=BC[j][0]
        c=BC[j][1]
        R=bisect.bisect_left(A,c)
        n=len(A)
        if R>b:
            if b>=n:
                A=[]
                ans+=b*n
                break
            else:
                A[0:b]=[]
                ans+=b*c
        else:
            A[0:R]=[]
            ans+=R*c
        
print(sum(A)+ans)

### FIXED CODE ###

import bisect

N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for i in range(M)]

A.sort()
BC.sort(key=lambda x: x[1],reverse=True) 
ans=0
for j in range(M):
    if A[0]>=BC[j][1]:
        break
    else:
        b=BC[j][0]
        c=BC[j][1]
        R=bisect.bisect_left(A,c)
        n=len(A)
        if R>b:
            if n<=b:
                A=[]
                ans+=n*c
                break
            else:
                del A[0:b]
                ans+=b*c
        else:
            del A[0:R]
            ans+=R*c
    if len(A)==0:
        break        
print(sum(A)+ans)
N, K, X, Y = map(int, input().split())

AC=0

if N > K:
    for _ in range(K):
        AC += X
    
    for _ in range(N-K):
        AC += Y

    print(AC)

else:
    for _ in range(K):
        AC += X
        print(AC)

### FIXED CODE ###

N = int(input())
K = int(input())
X = int(input())
Y = int(input())

AC=0

for i in range(1,N+1):
    if i <= K:
        AC += X
    else:
        AC += Y

print(AC)
import sys

for line in sys.stdin:
    a, b = map(int, input().split())
    d = a * b
    if a < b:
        tmp = a
        a = b
        b = tmp

    c = a % b
    while(c != 0):
        a = b
        b = c
        c = a % b

    g = b
    l = d / g

    print(str(g)+" "+str(int(l)))

### FIXED CODE ###

import fileinput

for line in fileinput.input():
    tokens = list(map(int, line.strip().split()))
    a, b = tokens[0], tokens[1]
    d = a * b
    if a < b:
        tmp = a
        a = b
        b = tmp

    c = a % b
    while(c != 0):
        a = b
        b = c
        c = a % b

    g = b
    l = d / g

    print(str(g)+" "+str(int(l)))
a,b=map(int,input().split())
if 1<=a<=9 AND 1<=b<=9:
  print(a*b)
else:
  print("-1")


### FIXED CODE ###

a,b=map(int,input().split())
if 1<=a<=9 and 1<=b<=9:
  print(a*b)
else:
  print("-1")
n,k = map(int , input().split())
p = list(map(int , input()).split())
 
p1 = sorted(p)
 
temp = 0
for i in p[k] :
  temp += i
print(temp)

### FIXED CODE ###

n,k = map(int , input().split( ))
p = list(map(int , input().split( )))
 
p.sort()
 
temp = 0
for i in p[:k] :
  temp += i
print(temp)
n = int(input())
ns = list(range(1, n+1))
ns_ = ns[1:] + [ns[0]]

total = 0
for i in range(n):
    total += ns[i] % ns_[i]
print(total)

### FIXED CODE ###

n = int(input())
print(n*(n-1)//2)
N = int(input())
n = N
divs = []
a = 1
b = N


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


Ps = primes(10 ** 6)
Ps.reverse()

for P in Ps:
    x, y = divmod(n, P)
    while y == 0:
        n = x
        divs.append(P)
        x, y = divmod(n, P)
if divs == []:
    print(N - 1)
    exit()
else:
    length = len(divs)
    for i in range(2 ** length):
        a1 = 1
        s = format(i, '020b')
        for j in range(length):
            #print("s[-j-1]:" + s[-j - 1])
            #print("divs[j]:" + str(divs[j]))
            if s[-j - 1] == '1':
                a1 = a1 * divs[j]
                #print("divs[j]" + str(divs[j]))
                #print("a1:" + str(a1))
        b1 = N // a1
        #print("a1:" + str(a1))
        if a1 + b1 < a + b:
            a = a1
            b = b1
# print(divs)
#print("str:" + s)
print(a+b-2)

### FIXED CODE ###

N = int(input())
ans = N-1
for i in range(int(N ** 0.5), 1, -1):
    x, y = divmod(N, i)
    if y == 0:
        print(i+x-2)
        exit()
print(ans)
n, m = map(int, input().split())
A, B = [0]*n, [0]*n
ans = 'IMPOSSIBLE'
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        A[b-1] += 1
    if b == n:
        B[a-1] += 1

if sum(B) == 0:
    print(ans)
    exit()
else:
    for i in range(m):
        if A[i] == 1 and B[i] == 1:
            ans = 'POSSIBLE'
            break
print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
A, B = [0]*n, [0]*n
ans = 'IMPOSSIBLE'
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        A[b-1] += 1
    if b == n:
        B[a-1] += 1
if sum(B) == 0:
    print(ans)
    exit()
else:
    for i in range(n):
        if A[i] == 1 and B[i] == 1:
            ans = 'POSSIBLE'
            break
    print(ans)
from collections import defaultdict

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


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

pr = prime_decomposition(M)
di = defaultdict(int)
for p in pr:
    di[p] += 1

def combination(n, mod):
    lst = [1]
    for i in range(1, n+1):
        lst.append(lst[-1] * (n+1-i) % mod * modinv(i, mod) % mod)
    return lst
mod = 10**9+7
ans = 1
for k, v in di.items():
    ans *= combination(v+N-1, mod)[N-1]
    ans %= mod
print(ans)


### FIXED CODE ###

from collections import defaultdict

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


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

pr = prime_decomposition(M)
di = defaultdict(int)
for p in pr:
    di[p] += 1
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y


# mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def combination(n, mod):
    lst = [1]
    for i in range(1, n+1):
        lst.append(lst[-1] * (n+1-i) % mod * modinv(i, mod) % mod)
    return lst
mod = 10**9+7
ans = 1
for k, v in di.items():
    ans *= combination(v+N-1, mod)[N-1]
    ans %= mod
print(ans)
# coding: utf-8
# 文字列反転
def rev (s):
    _re=''.join(list(reversed(s)))
    return _re

name = ['dream','dreamer','eraser','erase']
S = input()
S_re = rev(S)
can2 = False
i= 0
while i < len(S_re):
    for div in name:
        if len(S_re[i:]) >= len(div):
            if S_re[i:i+len(div)]==rev(div) :
                i+=len(div)
                can = True
                break
    if can :
        can2 = True
    else:
        can2 = False
        break
if can2:
    print('YES')
else :
    print('NO')

### FIXED CODE ###

import re
print("YES" if re.match("^(dream|dreamer|erase|eraser)+$",input()) else "NO")
n = int(input())
for i in range(9):
  for j in range(9):
    if i*j == n:
      print('Yes')
      exit()
Print('No')

### FIXED CODE ###

n = int(input())
for i in range(9):
  for j in range(9):
    if (i+1)*(j+1) == n:
      print('Yes')
      exit()
print('No')
def main():
 s = input()
 if s[0] == s[4] and s[1] == s[2] and s[2] != s[3]:
     print('Yes')
 else:
     print('No')
main()

### FIXED CODE ###

def main():
 s = sorted(input())
 if s[0] == s[1] and s[3] == s[2] and s[1] != s[2]:
     print('Yes')
 else:
     print('No')
main()
from math import sqrt
from math import ceil
from itertools import permutations
from heapq import *
from collections import defaultdict
from copy import deepcopy
from math import log
N,K=map(int,input().split())
AB=[0]*N
dic=defaultdict(int)
n=int(ceil(log(K,2)))+1
for i in range(N):
    a,b=map(int,input().split())
    if a in dic.keys():
        AB[dic[a]]=[a,AB[dic[a]][1]+b]
    else:
        dic[a]=i
        AB[i]=[a,b]
        n=max(n,int(ceil(log(a,2)))+1)
AB_=[]
for i in AB:
    if i==0:
        continue
    k=bin(i[0])[2:].zfill(n)
    AB_.append([k,i[1]])
AB=AB_
k=bin(K)[2:].zfill(n)
l=len(AB)
dp=[[0]*(n+1) for i in range(l)]
for i in range(l):
    for j in range(n):
        #print(i,j,dp[i][j]<<1,"j:",k[j],"k:",AB[i][0][j])
        dp[i][j+1]=(dp[i][j]<<1)+int(k[j])|int(AB[i][0][j])
        #print((dp[i][j]<<1)+int(k[j])|int(AB[i][0][j]))
ans=0
for i in range(n):
    if k[i]=="1":
        sum=0
        for j in range(l):
            if AB[j][0][i]=="0" and dp[j][i]<=int(k[:i],2):
                sum+=AB[j][1]
        ans=max(ans,sum)
sum=0
t=k
for j in range(l):
    if int(t)|int(AB[j][0])<=int(t):
        sum+=AB[j][1]
ans=max(ans,sum)
print(ans)


### FIXED CODE ###

N,K=map(int,input().split())
AB=[]
for i in range(N):
    a,b=map(int,input().split())
    AB.append([a,b])
ans=sum([b for a,b in AB if K|a==K])

for i in range(int.bit_length(K)-1,0,-1):
    if not K &(1<<i):
        continue
    m=K & ~(1<<i)|(1<<i)-1
    s=sum([b for a,b in AB if m | a ==m])
    ans=max(s,ans)
print(ans)
def process():
    data = []
    for line in get_data():
        line = line.split()
        if len(line) == 2:
            if line[0] == line[1] == '0':
                data = []
                continue
            H = int(line[0])
            W = int(line[1])
        elif len(line) == 0:
            pass
        else:
            data.append(line[0])
            if len(data) == H:
                field = create_field(H, W)
                print search(H, W, data, field)


def search(H, W, data, field):
    count = 0
    for i in xrange(H):
        for j in xrange(W):
            if field[i][j] == 0:
                continue
            _search(i, j, H, W, data[i][j], data, field)
            count += 1
    return count


def _search(i, j, H, W, cell, data, field):
    field[i][j] = 0
    for a in xrange(i-1, i+2):
        if -1 < a < H:
            pass
        else:
            continue
        for b in xrange(j-1, j+2):
            if -1 < b < W:
                pass
            else:
                continue

            if a != i and b != j:
                continue

            if field[a][b] == 0:
                continue
            if cell == data[a][b]:
                _search(a, b, H, W, cell, data, field)
    return


def create_field(H, W):
    field = []
    for i in xrange(H):
        raw = []
        for j in xrange(W):
            raw.append(1)
        field.append(raw)
    return field


def get_data():
    return [line.strip() for line in sys.stdin.readlines()]


if __name__ == '__main__':
    process()

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000000)


def main():
    solve()


def solve():
    for data in get_dataset():
        print search(data)


def search(data):
    count = 0
    H = len(data)
    W = len(data[0])
    for i in xrange(H):
        for j in xrange(W):
            if data[i][j] == '.':
                continue
            _search(i, j, H, W, data[i][j], data)
            count += 1
    return count


def _search(i, j, H, W, cell, data):
    data[i][j] = '.'
    for a in xrange(i-1, i+2):
        if not -1 < a < H:
            continue
        for b in xrange(j-1, j+2):
            if not -1 < b < W:
                continue

            if a != i and b != j:
                continue

            if data[a][b] == '.':
                continue

            if cell == data[a][b]:
                _search(a, b, H, W, cell, data)
    return


def get_dataset():
    dataset = []
    while True:
        line = raw_input().rstrip().split()
        H = int(line[0])
        if H == 0:
            break

        data = []
        for i in xrange(H):
            data.append(list(raw_input().rstrip()))
        dataset.append(data)
    return dataset


if __name__ == '__main__':
    main()
from sys import stdin
s = stdin.readline().strip()
n = len(s)
n-=2
while True:
 if s[n/2]== s[n/2+1:n]:
  break
 n-=2
print n

### FIXED CODE ###

from sys import stdin
s = stdin.readline().strip()
n = len(s)
n-=2
while True:
 if s[:n/2]== s[n/2:n]:
  break
 n-=2
print n