Harryxun/stf_run huggingface dataset:
s=input()
k=int(input())
m=0
j=0
if len(set(list(s)))==1:print((len(s)*k)//2);exit()
for i in range(len(s)):
  if len(s)<=j+1:
    a=m*k
    if s[0]==s[-1]==s[1]==s[len(s)//3]:print(a+k-1)
    else:print(a)
  if s[j]==s[j+1]:
    m+=1
    j+=1
  j+=1


### FIXED CODE ###

s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if s.count(s[0]) == len(s):
        print(len(s) * k // 2)
        exit()
    if len(s) <= j + 1:
        if s[0] == s[-1] == s[-2]== s[-3]== s[-4]== s[-5]== s[len(s)//3] \
                and s[0] == s[1] == s[2]== s[3]== s[4]== s[5]:
            n+=1
        break
    if s[j] == s[j + 1]:
        if j == len(s) - 1:
            n += 1
        else:
            m += 1
        j += 1
    j += 1
print(m * k + n*(k-1))
import numpy as np

h,w,k = map(int,input().split())
S = [list(input()) for _ in range(h)]

res = float('inf')
for div in range(2**(h-1)):
    cut = []
    for i in range(h-1):
        if ((div >> i) & 1):
            cut.append(i+1)
    fr = 0
    part = []
    for i in range(len(cut)):
        to = cut[i]
        part.append(S[fr:to])
        fr = to
    else:
        part.append(S[fr:])
    comp_arr = []
    for p in part:
        p_ = np.array(p).astype(np.int)
        comp_arr.append(p_.sum(axis=0))
    comp_arr_T = np.array(comp_arr).T
    
    cnt = len(cut)

    tank = [0]*len(comp_arr)
    
    for m in range(w):
        for n in range(len(comp_arr)):
            tank[n] += comp_arr[n][m]

        if any([c>k for c in tank]):
            cnt += 1
            for n in range(len(comp_arr)):
                tank[n] = comp_arr[n][m]

    res = min(res, cnt)
print(res)

### FIXED CODE ###

h,w,k = map(int,input().split())
S = [list(map(int,list(input()))) for _ in range(h)]
ans = 10**9+7
for i in range(1 << (h-1)):
    group = [[0]*w]
    g_id = 0
    group[g_id] = [s+b for s, b in zip(S[0], group[0])]
    for j in range(1, h):
        if (i>>(j-1))&1:
            group.append([0]*w)
            g_id += 1
        group[g_id] = [s+b for s, b in zip(S[j], group[g_id])]
    if not all([all([i <= k for i in b]) for b in group]):
        continue
    cnt = len(group) - 1
    g_cnt = [0] * len(group)
    
    for jj in range(w):
        for g_id in range(len(group)):
            g_cnt[g_id] += group[g_id][jj]
        if any([c > k for c in g_cnt]):
            cnt  += 1
            for g_id in range(len(group)):
                g_cnt[g_id] = group[g_id][jj]
    ans = min(ans, cnt)
print(ans)
n,m=map(int,input().split())
a=0
b=0
x=[]
for i in range(m):
  s,t=input().split()
  s=int(s)
  if s not in x:
    if t='AC':
      a+=1
      x.append(s)
    else:
      b+=1
print(a,b)

### FIXED CODE ###

n,m=map(int,input().split())
lst=[list(input().split()) for i in range(m)]
x,y=0,0
cnt=['?']+[0]*n
cnt2=[0]+[0]*n
for i in lst:
  if i[1]=='WA':
    pin=int(i[0])
    if cnt[pin]!='AC':
      cnt2[pin]+=1
  elif i[1]=='AC':
    cnt[int(i[0])]='AC'

x=cnt.count('AC')

for i in range(len(cnt)):
  if cnt[i]=='AC':
    y+=cnt2[i]
print(x,y)
N = int(input())
A = [int(x) for x in input().split()]
for i in range(N):
  sam += A[i]**-2
print(sam**-2)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
sam = 0
for i in range(N):
  sam += A[i]**-1
print(sam**-1)
a, b = int(input().split())
x = a * b
if x % 2 == 1:
  print("Odd")
else:
  print("Even")

### FIXED CODE ###

a, b = map(int, input().split())
x = a * b
if x % 2 == 1:
    print("Odd")
else:
    print("Even")
n, k = input().strip().split()
n, k = [int(n), int(k)]

p = list(map(int, input().strip().split()))

def calc_min(cur_id, cur_v, cur_num_select):
    if cur_num_select == k:
        return cur_v
    elif cur_id == n and cur_num_select < k:
        return 1000 * 1000

    l_v = calc_min(cur_id + 1, cur_v + p[cur_id], cur_num_select + 1)
    r_v = calc_min(cur_id + 1, cur_v, cur_num_select + 0)

    return min([l_v, r_v])


print(calc_min(0, 0, 0))

### FIXED CODE ###

n, k = input().strip().split()
n, k = [int(n), int(k)]

p = list(map(int, input().strip().split()))

p.sort()

print(f'{sum(p[0:k])}')
n = int(input())
alist  = list(map(int,input().split()))
list1 = alist[1::2]
list2 = alist[0::2]
from collections import Counter
dic1 = Counter(list1).most_common()
dic2 = Counter(list2).most_common()

if dic1[0][0]!=dic2[0][0]:
  print(n - dic1[0][1] - dic2[0][1]+1)
else:
  print(min(n - dic1[0][1] - dic2[1][1]+1, n -dic1[1][1] - dic2[0][1]+1))

### FIXED CODE ###

a=input()
print(a.replace("1","x").replace("9","1").replace("x","9"))
list = int(map(int, input().split()))

print(sorted(list))


### FIXED CODE ###

list = input().split()
uplist = sorted(list)

print(" ".join(map(str,uplist)))
import bisect

INF = 1 << 20


def main():
    n = int(input())
    a = [int(input()) for i in range(n)]

    dp = [INF for i in range(n+1)]
    for i in range(1, n+1):
        idx = bisect.bisect_left(dp, a[i-1])
        dp[idx] = a[i-1]

    ans = bisect.bisect_left(dp, INF)
    print(ans)


if __name__ == '__main__':
    main()



### FIXED CODE ###

import bisect

INF = 1 << 30


def main():
    n = int(input())
    a = [int(input()) for i in range(n)]

    dp = [INF for i in range(n+1)]
    for i in range(1, n+1):
        idx = bisect.bisect_left(dp, a[i-1])
        dp[idx] = a[i-1]

    ans = bisect.bisect_left(dp, INF)
    print(ans)


if __name__ == '__main__':
    main()
import sys
n = int(input())
n2 = n
while n>0:
    if n % 4 == 0 or n % 7 == 0:
        print("Yes")
        sys.exit(1)
    n -= 7
while n>0:
    if n % 4 == 0 or n % 7 == 0:
        print("Yes")
        sys.exit(1)
    n -= 4
print("No")

### FIXED CODE ###

import sys
n = int(input())
n2 = n
while n>0:
    if n % 4 == 0 or n % 7 == 0:
        print("Yes")
        sys.exit()
    n -= 7
while n2>0:
    if n2 % 4 == 0 or n2 % 7 == 0:
        print("Yes")
        sys.exit()
    n2 -= 4
print("No")
import unittest


class TestFunc(unittest.TestCase):
    def test_1(self):
        self.assertEqual(fun(5,8,[50,30,40,10,20]),2)
        self.assertEqual(fun(3,2,[100,50,200]),1)
        self.assertEqual(fun(10,100,[7,10,4,5,9,3,6,8,2,1]),2)
        self.assertEqual(fun(5,2,[1,2,3,2,4]),1)




def fun(n,t,a):
    aa = []
    b = None
    s = None
    for i in range(n):
        m = -1
        for j in range(i+1,n):
            if a[j]>a[i] and a[j]-a[i]>m:
                m = a[j]-a[i]
        if m>0:
            aa.append(m)

    c = aa[0]
    ans = 1
    for i in range(1,len(aa)):
        if c<aa[i]:
            c = aa[i]
            ans = 1
        elif c==aa[i]:
            ans += 1

    return ans


if __name__=='__main__':
    #unittest.main()                                                                                                                                                              

    n,t = [int(x) for x in raw_input().split(" ")]
    a = [int(x) for x in raw_input().split(" ")]
    print(fun(n,t,a))


### FIXED CODE ###

s = raw_input()

ans = 0
c = s[0]

for i in range(1,len(s)):
    if c!=s[i]:
        ans += 1
        c = s[i]

print(ans)
import collections
N,M = map(int,input().split())
A = [list(map(int, input().split())) for i in range(M)]
visit = set()
G = collections.defaultdict(set)
for idx,(f,to) in enumerate(A):
    G[f].add(to)

cache = {}
    
def dfs(start):
    if start in cache:
        return cache[start]
    ma = 0
    for i in G[start]:
        if i not in visit:
            visit.add(i)
            ma = max(ma,dfs(i))
            visit.remove(i)
    cache[start] = ma + 1 
    return ma + 1

ma = 0 
for f,to in A:
    visit.add(f)
    ma = max(ma,dfs(f))
    visit.remove(f)
print(ma - 1)
        
        

### FIXED CODE ###

import collections
import sys
sys.setrecursionlimit(10000000)

N,M = map(int,input().split())
A = [list(map(int, input().split())) for i in range(M)]
visit = set()
G = collections.defaultdict(set)
for idx,(f,to) in enumerate(A):
    G[f].add(to)

cache = {}
    
def dfs(start):
    if start in cache:
        return cache[start]
    ma = 0
    for i in G[start]:
        if i not in visit:
            visit.add(i)
            ma = max(ma,dfs(i))
            visit.remove(i)
    cache[start] = ma + 1 
    return ma + 1

ma = 0 
for f,to in A:
    visit.add(f)
    ma = max(ma,dfs(f))
    visit.remove(f)
print(ma - 1)
N,K=map(int,input().split(' '))
A=list(map(int,input.split(' ')))
count=0
sum=0
while sum<N:
	if count==0:
		sum+=K
	else:
		sum+=(K-1)
	count+=1
print(count)

### FIXED CODE ###

N,K=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
count=0
sum=0
while sum<N:
	if count==0:
		sum+=K
	else:
		sum+=(K-1)
	count+=1
print(count)
n=int(input())
w=[input() for i in range(w)]
ans="Yes"
for j in range(1,len(w)):
  if w[j-1][len(w[j-1])-1]!=w[j][0]:
    ans="No"
print(ans)

### FIXED CODE ###

n=int(input())
w=[input() for i in range(n)]
ans="Yes"
if len(set(w))!=n:
  ans="No"
for j in range(1,len(w)):
  if w[j-1][-1]!=w[j][0]:
    ans="No"
print(ans)
c1 = list(map(int,input().split()))
c2 = list(map(int,input().split()))
c3 = list(map(int,input().split()))

print(c1[0],c2[1],c3[2])

### FIXED CODE ###

c1 = str(input())
c2 = str(input())
c3 = str(input())
res = ""

res += c1[0] + c2[1] + c3[2]

print(res)
S = input()
T = input()

n = len(S)
m = len(T)

s = []

for i in reversed(range(n - m + 1)):
  t_kamo = S[i: i + m]
  for j in range(m + 1):
    if j == m:
      print((S[:i] + T +  S[i + m:]).replace("?", "a"))
      exit()
    if t_kamo[j] == "?":
      continue
    elif t_kamo[j] != t[j]:
      break

print("UNRESTORABLE")


### FIXED CODE ###

sd = input()
t = input()

n = len(sd)
m = len(t)
s = []

# sd を後ろから見ていき、 t の入りそうな場所を探す
for i in range(n - m, -1, -1):
    t_kamo = sd[i:i + m]
    for j in range(m + 1):
        # 1文字ずつ順に入りうるか調べ、最後まで入るなら "?" を "a" に置き換えて出力
        if j == m:
            print((sd[:i] + t + sd[i + len(t):]).replace("?", "a"))
            exit()
        if t_kamo[j] == "?":
            continue
        elif t_kamo[j] != t[j]:
            break

print("UNRESTORABLE")
a,b = input().split()
if a == H:
  if b == H:
    print("H")
  else:
    print("D")
else if a == D:
  if b == H:
    print("D")
  else:
    print("H")

### FIXED CODE ###

a,b = input().split()
if a == "H":
  if b == "H":
    print("H")
  else:
    print("D")
else:
  if b == "H":
    print("D")
  else:
    print("H")
num = input()
list = map(int, raw_input().split())
count1 = 0
count4 = 0
for x in list:
    if x % 2 == 1:
        count1 = count1 + 1
    if x % 4 == 0:
        count4 = count4 + 1
if count1 > count4 and num > 3 and count1 + count4 < num:
    print("No")
elif count1 > count4 + 1 and num > 3 and count1 + count4 == num:
    print("No")
elif num == 2 and count4 - count1 < 0:
    print("No")
elif num == 3 and count4 == 0 and count1 > 0:
    print("No") 
else:
    print("Yes")

### FIXED CODE ###

n,m = map(int, raw_input().split())
print((n-1)*(m-1))
def gcd(a, b):
    if(a == 0):
        return b
    return gcd(b % a, a)
def lcm(a, b):
    return a / gcd(a, b) * b
t = int(input())
ans = 1
while(t != 0):
    t -= 1
    n = int(input())
    ans = lcm(ans, n)
    ans = int(ans)
print(int(ans))


### FIXED CODE ###

def gcd(a, b):
    if(a == 0):
        return b
    return gcd(b % a, a)
def lcm(a, b):
    return a // gcd(a, b) * b
t = int(input())
ans = 1
while(t != 0):
    t -= 1
    n = int(input())
    ans = lcm(ans, n)
print(int(ans))
while True :
    (x, y) = int(i) for i in input().split().strip()
    if x = 0 and y = 0 :
        break
    elif x >= y :
        print(x,y)
    else :
        print(y,x)

### FIXED CODE ###

while True:
    (x, y) = [int(i) for i in input().split()]
    
    if x == y == 0 :
        break

    if x <= y :
        print(x, y)
    else :
        print(y, x)
s1s2s3=str(input())
print(s1s2s3.count(1))


### FIXED CODE ###

s=str(input())
print(s.count("1"))
from sympy import prime, sieve

x = int(input())
pos = sieve.search(x)

if pos[0] == pos[1]:
    print(x)
else:
    print(prime(pos[1]))

### FIXED CODE ###

from math import sqrt

def IsPrime(n: int) -> bool:
    cnt = 2
    while cnt * cnt <= n:
        if n % cnt == 0:
            return False
        else:
            cnt += 1
    return True

def main():
    x = int(input())
    while True:
        if (IsPrime(x)):
            print(x)
            exit()
        else:
            x += 1

if __name__ == '__main__':
    main()
n=str(input())

print(s.translate(str.maketrans({'9': '1', '1': '9'})))


### FIXED CODE ###

n=str(input())

print(n.translate(str.maketrans({'1': '9', '9': '1'})))
N,K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
minToatalCostList = [10000 for i in range(N)]
minToatalCostList[0] = 0

for i in range(1,N) :
	for j in range(1,K+1) :
		if j > i or minToatalCostList[i] == 0 :
			break
		else :
			minToatalCostList[i] = min(minToatalCostList[i], abs(h[i] - h[i-j]) + minToatalCostList[i-j] )

print(int(minToatalCostList[N-1]))

### FIXED CODE ###

N = int(input())
h = [int(i) for i in input().split()]
minToatalCostList = [0 for i in range(N)]

for i in range(N) :
	if i > 1 :
		minToatalCostList[i] = min( abs(h[i] - h[i-1]) + minToatalCostList[i-1], abs(h[i] - h[i-2]) + minToatalCostList[i-2] )
	elif i == 1:
		minToatalCostList[i] = abs(h[i] - h[i-1])
	else :
		minToatalCostList[i] = 0

print(minToatalCostList[N-1])
x,y,z = map(int,input().split())
print((x-2)//(Y+Z))

### FIXED CODE ###

x,y,z = map(int,input().split())
print((x-z)//(y+z))
from collections import deque

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

BC_dict={}
for m in range(M):
    b,c = list(map(int,input().split()))
    if c in BC_dict.keys():
        BC_dict[c]+=b  
    else:    
        BC_dict[c]=b  
    
C = list(BC_dict.keys())

A.sort()
C.sort(reverse=True)

C=deque(C)

check = C.popleft()

for a_idx,a in enumerate(A):
    if a >= check:
        break
    
    A[a_idx] = check
    BC_dict[check] -= 1
    
    if BC_dict[check] == 0:
        if len(C) == 0:
            break
        else:
            print(C)
            check = C.popleft()
        
print(sum(A))

### FIXED CODE ###

from collections import deque

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

BC_dict={}
for m in range(M):
    b,c = list(map(int,input().split()))
    if c in BC_dict.keys():
        BC_dict[c]+=b  
    else:    
        BC_dict[c]=b  
    
C = list(BC_dict.keys())

A.sort()
C.sort(reverse=True)

C=deque(C)

check = C.popleft()

for a_idx,a in enumerate(A):
    if a >= check:
        break
    
    A[a_idx] = check
    BC_dict[check] -= 1
    
    if BC_dict[check] == 0:
        if len(C) == 0:
            break
        else:
            check = C.popleft()
        
print(sum(A))
mod = 10 ** 9 + 7

N, K = map(int,input().split())
graph = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

ans = K

def factorial(n, k, mod):
    fact = 1
    for integer in range(n, n-k, -1):
        fact *= integer
        fact %= mod
    return fact

def dfs(parent, current):
    ret = 1
    for child in graph[current]:
        if child != parent:
            ret *= dfs(current, child)
    L = len(graph[current])
    R = K - 1
    if parent != -1:
        L -= 1
        R -= 1
    ret *= factorial(R, L, mod)
    return ret % mod

ans *= dfs(-1, 0)
ans %= mod

print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(4100000)

mod = 10 ** 9 + 7

N, K = map(int,input().split())
graph = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

ans = K

def factorial(n, k, mod):
    fact = 1
    for integer in range(n, n-k, -1):
        fact *= integer
        fact %= mod
    return fact

def dfs(parent, current):
    ret = 1
    for child in graph[current]:
        if child != parent:
            ret *= dfs(current, child)
    L = len(graph[current])
    R = K - 1
    if parent != -1:
        L -= 1
        R -= 1
    ret *= factorial(R, L, mod)
    return ret % mod

ans *= dfs(-1, 0)
ans %= mod

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

if a >= 3200:
  print("red")
  else
  print(s)

### FIXED CODE ###

a=int(input())
s=input()

if a < 3200:
  print("red")
else:
  print(s)
n = input()
nums = map(int, input().split())
 
num_dvd = 0

can_devide = True
temp_list = []
while can_devide == True:
  for num in nums:
    if num % 2 == 1:
      print(num_dvd)
      can_devide == False
    else:
      temp_list.append(num // 2)
  num_dvd += 1
  nums, temp_list = temp_list, []

### FIXED CODE ###

from collections import Counter
txt = input()

counter = Counter(txt)

print(counter['1'])
cache = {0: 1, 1: 1, 2: 2}
combo_cache = {}


def permutuation(n):
    if n in cache:
        return cache[n]
    return n * permutuation(n - 1)


def combo(n, r):
    key = str(n) + "-" + str(r)
    if key in combo_cache:
        return combo_cache[key]

    x = permutuation(n)
    y = permutuation(n-r)
    z = permutuation(r)
    combo_cache[key] = int(x / (y * z))
    return combo_cache[key]


count = int(input())
li = list(map(int, input().split()))

sli = sorted(li)

pair_a = 0
pair_b = 0
current_max = 0

for i in range(len(sli) - 1,len(sli)):
    for j in range(0, i):
        val = combo(sli[i], sli[j])
        # print(str(sli[i]) + ", " + str(sli[j]) + ", " + str(val))
        if val > current_max:
            current_max = val
            pair_a = sli[i]
            pair_b = sli[j]

print(str(pair_a) + " " + str(pair_b))


### FIXED CODE ###

count = int(input())
li = list(map(int, input().split()))

sli = sorted(li)

pair_a = sli[len(sli) - 1]
pair_b = 0
current_max = 0

i = sli[len(sli) - 1]

diff = 10**9
for j in range(0, len(sli) - 1):
    h = pair_a / 2
    if abs(h - sli[j]) < diff:
        diff = abs(h - sli[j])
        pair_b = sli[j]

print(str(pair_a) + " " + str(pair_b))
list = str(input()).split()
if int(list[0]) = int(list[1]):
   if int(list[1]) = int(list[2]):
      print(1)
   else print(2)
elif int(list[0]) = int(list[2]):
   print(2)
elif int(list[1]) = int(list[2]):
   print(2)
else:
   print(3)

### FIXED CODE ###

list = str(input()).split()
if int(list[0]) == int(list[1]):
   if int(list[1]) == int(list[2]):
      print(1)
   else :
      print(2)
elif int(list[0]) == int(list[2]):
   print(2)
elif int(list[1]) == int(list[2]):
   print(2)
else:
   print(3)
#coding: utf-8
import sys

N = sys.stdin
a = []
for i in range(N):
    a.append(int(input()))

start = 0
count = 0

for i in range(N):
    count += 1
    next = a[start]
    if(next == 2):
        print(count)
        break
    start = next - 1
else:
    print(-1)

### FIXED CODE ###

#coding: utf-8

N = int(input())
a = []
for i in range(N):
    a.append(int(input()))

start = 0
count = 0

for i in range(N):
    count += 1
    next = a[start]
    if(next == 2):
        print(count)
        break
    start = next - 1
else:
    print(-1)
A = int(input())
B = int(input())
C = int(input())
D = int(input())

print(min(A+B)+min(C+D))

### FIXED CODE ###

A = int(input())
B = int(input())
C = int(input())
D = int(input())
 
print(min(A,B)+min(C,D))
n = int(input())

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

mountain = int(1)
for i in range(n):
    for j in range(i):
            if int(L[j]) >= int(L[i]):
          			continue
            else:
                    mountain += 1
                
print(mountain)


### FIXED CODE ###

n = int(input())

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

mountain = int(1)
for i in range(1, n):
    for j in range(i):
        if int(L[j]) > int(L[i]):
            break
        if int(L[j]) <= int(L[i]) and j == i-1:
            mountain += 1
            break
        if int(L[j]) <= int(L[i]):
            continue

print(mountain)
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]


def dfs(x, y, cnt):
    global board, W, H, ans
    if ans <= cnt:
        return

    for i in range(4):
        mx, my = x, y
        mx += dx[i]
        my += dy[i]

        if 0 > mx or 0 > my or W <= mx or H <= my:
            continue
        if board[my][mx] == 1:
            continue

        while True:
            if board[my][mx] == 3:
                ans = cnt
                return

            mx += dx[i]
            mx += dy[i]

            if 0 > mx or 0 > my or W <= mx or H <= my:
                break

            if board[my][mx] == 1:
                board[my][mx] = 0
                dfs(mx - dx[i], my - dy[i], cnt + 1)
                board[my][mx] = 1
                break

while True:
    W, H = map(int, raw_input().split())
    if W == 0:
        break

    ans = 11
    board = [map(int, raw_input().split()) for _ in range(H)]
    for y in range(H):
        for x in range(W):
            if board[y][x] == 2:
                sx, xy = x, y
    dfs(sx, sy, 1)
    print ans if ans < 11 else - 1

# dxy = zip([1,0,-1,0],[0,1,0,-1])
# def rec(x,y,t):
#     global ans
#     if t >= ans: return
#     for dx,dy in dxy:
#         nx,ny = x+dx,y+dy
#         while 0 <= nx < W and 0 <= ny < H:
#             if   field[ny][nx] == 3: ans = t
#             elif field[ny][nx] == 1:
#                 if abs(nx-x)+abs(ny-y) == 1: break
#                 field[ny][nx] = 0
#                 rec(nx-dx,ny-dy,t+1)
#                 field[ny][nx] = 1
#                 break
#             nx += dx; ny += dy
 
# while True:
#     W, H = map(int, raw_input().split())
#     if W == 0:
#         break

#     field = [map(int, raw_input().split()) for _ in range(H)]
#     for y in range(H):
#         for x in range(W):
#             if field[y][x] == 2:
#                 sx, sy = x, y
#     ans = 11
#     rec(sx, sy, 1)
#     print ans if ans < 11 else -1

### FIXED CODE ###

dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]


def dfs(x, y, cnt):
    global board, W, H, ans
    if cnt >= ans:
        return

    for i in range(4):
        mx = x + dx[i]
        my = y + dy[i]

        if 0 > mx or 0 > my or W <= mx or H <= my:
            continue
        if board[my][mx] == 1:
            continue

        while True:
            if board[my][mx] == 3:
                ans = cnt
                return

            mx += dx[i]
            my += dy[i]

            if 0 > mx or 0 > my or W <= mx or H <= my:
                break

            if board[my][mx] == 1:
                board[my][mx] = 0
                dfs(mx - dx[i], my - dy[i], cnt + 1)
                board[my][mx] = 1
                break

while True:
    W, H = map(int, raw_input().split())
    if W == 0:
        break

    ans = 11
    board = [map(int, raw_input().split()) for _ in range(H)]
    for y in range(H):
        for x in range(W):
            if board[y][x] == 2:
                sx, sy = x, y
    dfs(sx, sy, 1)
    print ans if ans < 11 else - 1
if {input().split()} == {"1", "9", "7", "4"}:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

if set(input().split()) == {"1", "9", "7", "4"}:
  print("YES")
else:
  print("NO")
S = raw_input()
if S[0] != S[1] and S[1] != S[2] and S[2] != S[0]:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

S = input()
if (S[0] == S[1]) or (S[1] == S[2]) or (S[2] == S[0]):
    print("No")
else:
    print("Yes")
n = int(input())
d = [list(map(int, input().split()))for _ in range(n)]

flg = False
for i, (p, q) in enumerate(d):
    if p == q:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:        
        print("Yes")
        break
else:
    print("No")

### FIXED CODE ###

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

cnt = 0
for i, (p, q) in enumerate(d):
    if p == q:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        print("Yes")
        break
else:
    print("No")