Harryxun/stf_run huggingface dataset:
H, W = map(int,input().split(' '))
S = []
for i in range(H):
  S[i] = input()
for j in range(H):
  cnt = 0
  for k in range(W):
    if S[j][k] == '.'
      if S[j-1][k-1] == '#':
        cnt += 1
      if S[j-1][k] == '#':
        cnt += 1
      if S[j-1][k+1] == '#':
        cnt += 1
      if S[j][k-1] == '#':
        cnt += 1
      if S[j][k+1] == '#':
        cnt += 1
      if S[j+1][k-1] == '#':
        cnt += 1
      if S[j+1][k] == '#':
        cnt += 1
      if S[j][k+1] == '#':
        cnt += 1
      S[j][k].replace(cnt)

### FIXED CODE ###

H, W = map(int,input().split(' '))
S = []
for i in range(H):
  S.append(input())
for j in range(H):
  answer = list(S[j])
  for k in range(W):
    cnt = 0
    if S[j][k] == '#':
      pass
    if S[j][k] == '.':
      if j-1 >= 0:
        if k-1 >= 0:
          if S[j-1][k-1] == '#':
            cnt += 1
        if S[j-1][k] == '#':
          cnt += 1
        if k+1 <= W-1:
          if S[j-1][k+1] == '#':
            cnt += 1
      if k-1 >= 0:
        if S[j][k-1] == '#':
          cnt += 1
      if k+1 <= W-1:
        if S[j][k+1] == '#':
          cnt += 1
      if j+1 <= H-1:
        if k-1 >= 0:
          if S[j+1][k-1] == '#':
            cnt += 1
        if S[j+1][k] == '#':
          cnt += 1
        if k+1 <= W-1:
          if S[j+1][k+1] == '#':
            cnt += 1
      answer[k] = str(cnt)
  print(''.join(answer))
N, M, X, Y = map(int, input().split())
list_xi = [int(input()) for i in range(N)]
list_yi = [int(input()) for h in range(M)]

if X >= min(list_yi) or Y <= max(list_xi):
  print("War")
  
else:
  print("No War")

### FIXED CODE ###

n,m,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
x.append(X)
y.append(Y)
x.sort()
y.sort()
print('No War' if x[-1] < y[0] else 'War')
i = 0
while True
 x = raw_input()
 if x == '0':
  break
 print 'Case %s: %s' %(sum, x)
 i+=1

### FIXED CODE ###

i = 0
while 1:
    i+=1
    x = raw_input()
    if x == '0':
       break
    print ('Case {}: {}'.format(i,x))
N = int(input())
A = list(map(int, input().split()))
import numpy as np
if 0 in A:
    print(0)
    exit(0)
    
ans = np.prod(A)
elif ans<= 10**18:
    print(ans)
    exit(0)
else:
    print(-1)


### FIXED CODE ###

import sys  # sys.exit()を使いたいので

n = int(input())
a = list(map(int, input().split()))

if 0 in a:
# 0が1つでもあれば0です
    print(0)
else:
# 0がない場合
    cur = 1  # 現在の数値
    for x in a:
        cur *= x
        if cur > 10 ** 18:
        # 10**18を超えたので終了します
            print(-1)
            sys.exit()
    print(cur)  # 10**18以下なので、出力します
import functools


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    a = list(map(lambda x: int(x), inputs))
    a[1] = -1
    return wh(a, 2, 0)


def wh(a, search, count):
    counts = []

    if search == 1:
        return count

    for i, value in enumerate(a):
        if value == search:
            counts.append(wh(a, i + 1, count + 1))

    counts_ignore_minus = list(filter(lambda x: x != -1, counts))

    if len(counts_ignore_minus) == 0:
        return -1

    min = counts_ignore_minus[0]
    for c in counts_ignore_minus:
        if min > c:
            min = c
    return min


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)

### FIXED CODE ###

import functools


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    a = list(map(lambda x: int(x), inputs))

    count = 0
    light = 1
    N = len(a)
    while 1:
        next_light = a[light - 1]
        count += 1
        if next_light == 2:
            return count
        elif count > N:
            return -1
        light = next_light


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)
n = int(raw_input())

#整数をばらけさせてリスト化
list_n = list(range(1,n+1))
print(list_n)

#桁の長さが奇数なら数え上げる
cnt = 0
for i in list_n:
     if (len(str(i)))%2 == 1:
            cnt += 1
     else: pass
print(cnt)

### FIXED CODE ###

n = int(input())

#整数をばらけさせてリスト化
list_n = list(range(1,n+1))
#print(list_n)

#桁の長さが奇数なら数え上げる
cnt = 0
for i in list_n:
     if (len(str(i)))%2 == 1:
            cnt += 1
     else: pass
print(cnt)
def insertionSort(n, A):
    print(*A)
    for i in range(1, n):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        print(*A)
n = int(readline())
A = [int(j) for j in readline().split(" ")]
insertionSort(n, A)

### FIXED CODE ###

def insertionSort(A, N):
    print(*A)
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        print(*A)
n = int(input())
A = list(map(int, input().split()))
insertionSort(A, n)
import sys
sys.setrecursionlimit(10**10)
t=input()
tl=list(t)
tln=len(t)
x=t.find("?")
while x != -1:
    if x == tln:
        tl[x]="D"
        break
    if tl[x+1]=="D":
        tl[x]="P"
    elif tl[x+1]=="?":
        tl[x]="P"
    else:
        tl[x]="D"
    tt="".join(tl)
    t=tt
    x=t.find("?")
print(t)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
t=input()
tl=list(t)
tln=len(t)
x=0
for x in range(tln):
    if tl[x] == "?":
        if x == tln-1:
            tl[x]="D"
            break
        elif x==0:
            if tl[x+1]=="?":
                tl[x]="P"
                tl[x+1]="D"
            else:
                tl[x]="D"
        elif tl[x-1]=="P":
            tl[x]="D"
        elif tl[x+1]=="?":
            tl[x]="P"
            tl[x+1]="D"
        elif tl[x+1]=="D":
            tl[x]="P"
        else:
            tl[x]="D"
t="".join(tl)
print(t)
d_matrix = [[(-1, 10**10)] * (n+1) for _ in range(n+1)]
for i in range(n):
    d = [(-1, 10**10)] * (n+1)
    d[i+1] = (l, 0)
    while True:
        update = False
        for abc in edge_lst:
            a, b, c = abc
            if d[a][1] != 10**10:
                if d[a][0] < c:
                    cnt = d[a][1] + 1
                    f = l - c
                else:
                    cnt = d[a][1]
                    f = d[a][0] - c
                if d[b][1] == cnt:
                    if d[b][0] <= f:
                        d[b] = (f, cnt)
                        update = True
                if d[b][1] > cnt:
                    d[b] = (f, cnt)
                    update = True
        if not update:
            break
        d_matrix[i+1] = d

### FIXED CODE ###

import sys
input = sys.stdin.readline
N, M, L = map(int, input().split())
INF = float('inf')
VD = [[INF] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    VD[a][b] = c
    VD[b][a] = c
for i in range(N):
    VD[i][i] = 0
 
for k in range(N):
    for i in range(N):
        for j in range(N):
            if VD[i][j] > VD[i][k] + VD[k][j]:
                VD[i][j] = VD[i][k] + VD[k][j]
 
WD = [[INF] * N for _ in range(N)]
for i in range(N):
    WD[i][i] = 0
    for j in range(i+1,N):
        d = VD[i][j]
        if d <= L:
            WD[i][j] = 1
            WD[j][i] = 1
 
for k in range(N):
    for i in range(N):
        for j in range(N):
            if WD[i][j] > WD[i][k] + WD[k][j]:
                WD[i][j] = WD[i][k] + WD[k][j]
 
Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    print(WD[s-1][t-1]-1 if WD[s-1][t-1] < INF else -1)
x = int(input())

x.sort()
print(x)

### FIXED CODE ###

x = input().split()
i = list(map(int,x))
 
i.sort()
print('{} {} {}'.format(i[0],i[1],i[2]))
from fractions import gcd

n, m = map(int, input().split())
s = input()
t = input()
l = n * m // gcd(n, m)
x = [""] * l

for i in range(0, l, l//n):
    x[i] = s[i*n//l]

for i in range(0, l, l//m):
    if x[i]:
        if x[i] != t[i*m//l]:
            print(-1)
            break
    else: x[i] = t[i*m//l]
else: print(l)


### FIXED CODE ###

from fractions import gcd

n, m = map(int, input().split())
s = input()
t = input()
g = gcd(n, m)
l = n * m // g

for i in range(g):
    if s[i*n//g] != t[i*m//g]:
        print(-1)
        break
else: print(l)
N, M = map(int, input().split())
A = {}
ac = []
total=0
count = 0
for i in range(M):
    p, s = map(str, input().split())
    if int(p) not in ac:
        if int(p) not in A.keys(): 
            if int(p) >0 and int(p) <=N :
                if s == "WA":
                    A[int(p)] =1
                elif s =="AC":
                    A[int(p)] =0
                    ac.append(int(p))
        elif int(p) in A.keys():
            if s == "WA":
                    A[int(p)] +=1
            elif s =="AC":
                    A[int(p)] +=0
                    ac.append(int(p))
                    count += 1
                    total += A[int(p)]

print(count,total)

### FIXED CODE ###

c = str(input())
d=int(ord(c)+1)
print(chr(d))
while True:
    num = input()
    ret = 0
    for i in num:
        ret += int(i)
    print(num)


### FIXED CODE ###

while True:
    num = input()
    if(num == "0"): break
    ret = 0
    for i in num:
        ret += int(i)
    print(ret)
x = int(input())
ans = 1
for b in range(1,x+1):
    for p in range(2,x+1):
        a = b**p
        if a == a // 1 and a > ans and a <= x:
            ans = a
        if a>x:
            break
    if a > x:
        continue
print(ans)


### FIXED CODE ###

x = int(input())
ans = 1
for b in range(1,x):
    for p in range(2,x):
        a = b**p
        if a == a // 1 and a > ans and a <= x:
            ans = a
        if a>x:
            break
    if a > x:
        continue
print(ans)
n = int(input())
s = sum(list(n))

if n % s == 0:
  print("Yes")
else:
  print("No")


### FIXED CODE ###

n = int(input())
s = sum(map(int, list(str(n))))

if n % s == 0:
  print("Yes")
else:
  print("No")
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op == "+":
        print(a+b)
    elif op =="-":
        print(a-b)
    elif op =="*":
        print(a*b)
    elif op =="/":
        print(a/b)
    elif a=="?" or b=="?" or c=="?":
        break


### FIXED CODE ###

while True:
  a,op,b = input().split()
  a=int(a)
  op=str(op)
  b=int(b)
  
  if op=='?':
    break
  elif  op=='+':
    print("{:d}".format(a+b))
  elif op=='-':
    print("{:d}".format(a-b))
  elif op=='/':
    print("{:d}".format(a//b))
  elif op=="*":
    print("{:d}".format(a*b))
a, b, c = [int(i) for i in raw_input()]
num = 0
for i in range(a,b+1):
    if c % i == 0:
        num += 1

print num

### FIXED CODE ###

a, b, c = [int(i) for i in raw_input().split()]
num = 0
for i in range(a,b+1):
    if c % i == 0:
        num += 1

print num
s = list(map(str,input().split()))
 
t = (list(s[1])).capitalize()
 
print('A' + t + 'C')

### FIXED CODE ###

s = list(str(input()))
t = s[8].upper()
 
print('A' + t + 'C')
import numpy as np


A, B, K = map(int, input().split())
x = np.arange(A, B+1)
y = x[:K]
z = x[-K:]
ans = set(y) | set(z)
for i in ans:
    print(i)

### FIXED CODE ###

A, B, K = map(int, input().split())
x1 = set(range(A, A+K))
x2 = set(range(B, B-K, -1))
x = x1 | x2
ans = sorted(x)
for i in [x for x in ans if A <= x <= B]:
    print(i)
n = int(input())
if n >= 25:
  print 'Yes'
else:
  print 'No'

### FIXED CODE ###

n = int(input())
if n >= 30:
  print('Yes')
else:
  print('No')
import sys

values = [int(input()) for i in range(int(input()))]
maxv = - sys.maxsize - 1
minv = values[0]

for val in enumerate(values):
    maxv = max(maxv, (val - minv))
    minv = min(minv, val)
print(maxv)



### FIXED CODE ###

values = [int(input()) for _ in range(int(input()))]
maxv = values[1] - values[0]
minv = values[0]

for val in values[1:]:
    maxv = max(maxv, val - minv)
    minv = min(minv, val)         # 今までの最小値を保持(自分と自分を比較しない様に、最大値の評価後に計算)
print(maxv)
if (a*b%2 == 0):
	print('Even')
else:
    print('Odd')

### FIXED CODE ###

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

c = a*b

if c%2 == 0:
    print("Even")
else:
    print("Odd")
def a(N,R):
     if N >= 10:
             print(R)
     else:
             print(R+(100*(10-K)))
     return

  
a(N,R)

### FIXED CODE ###

N, R = map(int, input().split())
def a(N,R):
     if N >= 10:
             print(R)
     else:
             print(R+(100*(10-N)))
     return
  
a(N,R)
while True:
  x,y=map(int, input().split())
​
  if x==0 and y==0:
    break
  if x>=y:
    tmp = x
    x=y
    y=tmp
​
  print(x,y)



### FIXED CODE ###

while True:
  x,y=map(int, input().split())

  if x==0 and y==0:
    break
  if x>=y:
    x,y = y,x
  print(x,y)
s = set(int(input()))
print("Good" if len(s) == 4 else "Bad")

### FIXED CODE ###

def resolve():
    s = list(input())
    prev = '-1'
    for i in s:
        if i == prev:
            print("Bad")
            return
        prev = i
    print("Good")

resolve()
a,b=map(int,input().split());f=lambda t,x:set([i for i in range(1500)if int(i*t)==x]);print(min(f(.08,a)&f(.1,b)))

### FIXED CODE ###

a,b=map(int,input().split())
for i in range(1500):
  if int(i*.08)==a and int(i*.1)==b:
    print(i);exit()
print(-1)
import sys
n = int(input())
pos = [list(map(int,input().split())) for p in range(n)]
for i in range(1,en(pos)):
  diff = pos[i+1][0]-pos[i][0]
  num = abs(pos[i][1]-pos[i+1][1]) + abs(pos[i][2]-pos[i+1][2])
  if((pos[i][0]-pos[i-1][0])>=(abs(pos[i][1]-pos[i-1][0])+abs(pos[i][2]-pos[i-1][0])) and (pos[i][0]-pos[i-1][0])%2==(abs(pos[i-1][1]-pos[i][1])+abs(pos[i][0]-pos[i-1][0]))%2):
    pass
  else:
    print("No")
    sys.exit()      
print("Yes")
    


### FIXED CODE ###

n=int(input())
x,y=0,0
t=0
for i in range(n):
    T,X,Y=map(int,input().split())
    if((T-t)>=(abs(X-x)+abs(Y-y)) and (T-t)%2==(abs(x-X)+abs(Y-y))%2):
        x=X
        y=Y
        t=T
    else:
        print("No")
        exit()
print("Yes")
import sympy
import sys
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)
A,VA = mips()
B,VB = mips()
T = ii()
if A <= B:
    d1 = A + VA * T
    d2 = B + VB * T
    if d1 >= d2:
        print("YES")
    else:
        print("NO")
else:
    d2 = B - VB * T
    d1 = A - VA * T
    if d1 <= d2:
        print("YES")
    else:
        print("NO")


### FIXED CODE ###


import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)
A,VA = mips()
B,VB = mips()
T = ii()
if A <= B:
    d1 = A + VA * T
    d2 = B + VB * T
    if d1 >= d2:
        print("YES")
    else:
        print("NO")
else:
    d2 = B - VB * T
    d1 = A - VA * T
    if d1 <= d2:
        print("YES")
    else:
        print("NO")
n,p=map(int,input().split())
s=input()[::-1]
ans=0
if p==2 or p==5:
    for i in range(n):
        if int(s[i])%p==0:
            ans+=i+1
else:
    M=[0]*n
    M[0]=1
    tmp=0
    for i in range(n):
        tmp=(tmp+int(s[i])*10**i)%p
        ans+=M[tmp]
        M[tmp]+=1
print(ans)

### FIXED CODE ###

n,p=map(int,input().split())
s=input()
ans=0
if p==2 or p==5:
    for i in range(n):
        if int(s[i])%p==0:
            ans+=i+1
else:
    M=[0]*p
    M[0]=1
    tmp=0
    for i in range(n):
        tmp+=(int(s[-i-1])*pow(10,i,p))
        tmp%=p
        ans+=M[tmp]
        M[tmp]+=1
print(ans)
n= int(input())
tbl=[[[0]*10 for i in range(0,3)] for j in range(0,4)]
for k in range(n):
    b,f,r,v = map(int,input().split())
    tbl[b-1][f-1][r-1] +=v
x=0
for i in range (4):
    if x !=0 : print("#"*20)
    x +=1
    for a in range(3):
        for b in range(10):
            print(" %d%(tbl[i][a][b]),end="")     
        print()


### FIXED CODE ###

n= int(input())
tbl=[[[0]*10 for i in range(0,3)] for j in range(0,4)]
for k in range(n):
    b,f,r,v = map(int,input().split())
    tbl[b-1][f-1][r-1] +=v
x=0
for i in range (4):
    if x !=0 : print("#"*20)
    x +=1
    for a in range(3):
        for b in range(10):
            print(" %d"%(tbl[i][a][b]),end="")     
        print()
from collections import deque
import math
import copy
H,W = map(int,input().split())
maze = [list(input()) for _ in range(H)]
def bfs(maze,h,w,sx,sy):
    for y in range(h):
        for x in range(w):
            if maze[y][x]=='.':
                maze[y][x]=float('inf')

    maze[sy][sx]=0
    que=deque([[sy,sx]])
    while que:
        y,x=que.popleft()
        for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
            if 0 <= y+i < H and 0<=x+j<W:
                nexty,nextx=y+i,x+j
                dist=maze[nexty][nextx]
                if dist!='#':
                    if dist>maze[y][x]+1:
                        maze[nexty][nextx]=maze[y][x]+1
                        que.append([nexty,nextx])
    m = 0                   
    for l in maze:
      m = max(m,max([i for i in l if i != '#' and i < 1000000]))
    return m
max_dist = -1  
for si in range(H):
  for sj in range(W):
    if maze[si][sj] == '#':
      continue
    copymaze = copy.deepcopy(maze)
    res = bfs(copymaze,H,W,sj,si)
    max_dist = max(max_dist,res)

print(max_dist)

### FIXED CODE ###

from collections import deque
import math
import copy
H,W = map(int,input().split())
maze = [list(input()) for _ in range(H)]
def bfs(maze,h,w,sx,sy):
    for y in range(h):
        for x in range(w):
            if maze[y][x]=='.':
                maze[y][x]=float('inf')

    maze[sy][sx]=0
    que=deque([[sy,sx]])
    while que:
        y,x=que.popleft()
        for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
            if 0 <= y+i < H and 0<=x+j<W:
                nexty,nextx=y+i,x+j
                dist=maze[nexty][nextx]
                if dist!='#':
                    if dist>maze[y][x]+1:
                        maze[nexty][nextx]=maze[y][x]+1
                        que.append([nexty,nextx])
    m = 0                   
    for l in maze:
      li = [i for i in l if i != '#' and i < 1000000]
      if len(li) > 0:
        m = max(m,max(li))
    return m
max_dist = -1  
for si in range(H):
  for sj in range(W):
    if maze[si][sj] == '#':
      continue
    copymaze = copy.deepcopy(maze)
    res = bfs(copymaze,H,W,sj,si)
    max_dist = max(max_dist,res)
print(max_dist)
n,m=map(int,input().split())
now=[tuple(map(int,input().split())) for i in range(n)]
p=[tuple(map(int,input().split())) for i in range(n)]
for a,b in now:
  ans=10**10
  for c,d in p:
    ans=min(ans,abs(c-a)+abs(d-b))
  print(ans)


### FIXED CODE ###

n,m=map(int,input().split())
now=[tuple(map(int,input().split())) for i in range(n)]
p=[tuple(map(int,input().split())) for i in range(m)]
for a in now:
  ans=10**10
  for i in range(m):
    if ans>abs(p[i][0]-a[0])+abs(p[i][1]-a[1]):
      ind=i
      ans=abs(p[i][0]-a[0])+abs(p[i][1]-a[1])
  print(ind+1)
n = int(input())
arr = map(int, input().strip().split())
arr.sort(reverse=True)
print(sum(arr[1:2*n:2]))

### FIXED CODE ###

n = int(input())
arr = list(map(int, input().strip().split()))
arr.sort(reverse=True)
print(sum(arr[1:2*n:2]))
a,b = list(map(int, input()split()))
if a>=b:
  print(19)
else:
  print(0)

### FIXED CODE ###

a,b = list(map(int, input().split()))
if a>=b:
  print(10)
else:
  print(0)
n=int(input())
a=[0]*n
for i in range(n):
       a[int(input())]=i+1
print(a)

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
ans=[0]*n
for i in range(n):
  ans[A[i]-1]=i+1
print(*ans)
M, N = map(int, input().split())
if M >= 2 and N >= 2:
    print(M - 2) * (N - 2)
elif M==1 or N==1:
    print(N * M - 2)
else:
    print(0)

### FIXED CODE ###

M, N = map(int, input().split())
if M==1 and N==1:
    print(1)
elif M > 2 and N > 2:
    print((M - 2) * (N - 2))
elif M==1 or N==1:
    print(N * M - 2)
else:
    print(0)
n = int(input())
a = sorted(map(int, input().split()))
s = 0
for i in range(2n-1):
  s += min(a[i], a[i+1])
print(s)

### FIXED CODE ###

n = int(input())
a = sorted(list(map(int, input().split())))
s = 0
for i in range(2 * n):
  if i % 2 == 0:
    s += a[i]
print(s)
#from collections import deque
#from heapq import heapify, heappop, heappush
#from bisect import insort
#from math import gcd
#mod = 10**9 + 7
N = int(input())
#N, K = map(int, input().split())
#A = list(map(int, input().split()))
flag1 = False
flag2 = False
flag3 = False
c, d = map(int, input().split())
if c == d:
	flag1 = True
c, d = map(int, input().split())
if c == d:
	flag2 = True
c, d = map(int, input().split())
if c == d:
	flag3 = True

k = 3
while k < N:
	if flag1 and flag2 and flag3:
		break
	k += 1
	c, d = map(int, input().split())
	flag1 = flag2
	flag2 = flag3
	if c == d:
		flag3 = True
	else:
		flag3 = False
		

#ans = 0
#print(ans)
#print('Yes')
if flag1 and flag2 and flag3:
	print('Yes')
else:
	print('No')#from collections import deque
#from heapq import heapify, heappop, heappush
#from bisect import insort
#from math import gcd
#mod = 10**9 + 7
N = int(input())
#N, K = map(int, input().split())
#A = list(map(int, input().split()))
flag1 = False
flag2 = False
flag3 = False
c, d = map(int, input().split())
if c == d:
	flag1 = True
c, d = map(int, input().split())
if c == d:
	flag2 = True
c, d = map(int, input().split())
if c == d:
	flag3 = True

k = 3
while k < N:
	if flag1 and flag2 and flag3:
		break
	k += 1
	c, d = map(int, input().split())
	flag1 = flag2
	flag2 = flag3
	if c == d:
		flag3 = True
	else:
		flag3 = False
		

#ans = 0
#print(ans)
#print('Yes')
if flag1 and flag2 and flag3:
	print('Yes')
else:
	print('No')

### FIXED CODE ###

#from collections import deque
#from heapq import heapify, heappop, heappush
#from bisect import insort
#from math import gcd
#mod = 10**9 + 7
N = int(input())
#N, K = map(int, input().split())
#A = list(map(int, input().split()))
flag1 = False
flag2 = False
flag3 = False
c, d = map(int, input().split())
if c == d:
	flag1 = True
c, d = map(int, input().split())
if c == d:
	flag2 = True
c, d = map(int, input().split())
if c == d:
	flag3 = True

k = 3
while k < N:
	if flag1 and flag2 and flag3:
		break
	k += 1
	c, d = map(int, input().split())
	flag1 = flag2
	flag2 = flag3
	if c == d:
		flag3 = True
	else:
		flag3 = False
		

#ans = 0
#print(ans)
#print('Yes')
if flag1 and flag2 and flag3:
	print('Yes')
else:
	print('No')
# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Regular Contest 095 c問題
Author     : Kitaura Hiromi
LastUpdate : 20180414
Since      : 20180414
"""

import numpy as np

N = int(input())
X = np.array(map(int, input().split(" ")))

for i in range(N):
    print(np.append(X[:i], X[i+1:]).median)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Regular Contest 095 c問題
Author     : Kitaura Hiromi
LastUpdate : 20180414
Since      : 20180414
"""
import random
import copy

N = int(input())
X = list(map(int, input().split(" ")))
sorted_X = sorted(X)
med1 = sorted_X[N//2-1]
med2 = sorted_X[N//2]
for i in range(N):
    if X[i] <= med1:
        print(med2)
    else:
        print(med1)
n=int(input())
h=list(map(int,input().split()))
zeros=[]
prev=0
for i in  range(n):
  if h[i]==0:
    zeros.append((prev,i-1))
    prev=i+1
zeros.append((prev,n-1))
cnt=0
while zeros:
  l,r=zeros.pop()
  m=min(h[l:r+1])
  cnt+=m
  prev=l
  for i in range(l,r+1):
    h[i]-=m
    if h[i]==0:
      if i==l:
        prev=i+1
      else:
        if prev<=i-1:
          zeros.append((prev,i-1))
        prev=i+1
  if prev<=r:
    zeros.append((prev,r))
print(cnt)

### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
zeros=[]
prev=0
for i in  range(n):
  if h[i]==0:
    if i==0:
      prev=i+1
    else:
      if prev<=i-1:
        zeros.append((prev,i-1))
      prev=i+1
if prev<=n-1:
  zeros.append((prev,n-1))
cnt=0
while zeros:
  l,r=zeros.pop()
  m=min(h[l:r+1])
  cnt+=m
  prev=l
  for i in range(l,r+1):
    h[i]-=m
    if h[i]==0:
      if i==l:
        prev=i+1
      else:
        if prev<=i-1:
          zeros.append((prev,i-1))
        prev=i+1
  if prev<=r:
    zeros.append((prev,r))
print(cnt)