Harryxun/stf_run huggingface dataset:
import collections

h,w = map(int,input().split())
maze = []
ans = 0
dy_dx = [[0,1],[1,0],[0,-1],[-1,0]]
for i in range(h):
    s = input()
    a = []
    for j in range(w):
        a.append(s[j])
    maze.append(a)
for i in range(h):
    for j in range(w):
        if maze[i][j] != '#':
            next = collections.deque()
            dist = []
            checked = []
            curmax = 0
            for k in range(h):
                a = [0]*w
                b = [0]*w
                dist.append(a)
                checked.append(b)
            next.append([i,j])
            while len(next) != 0:
                cur = next.popleft()
                checked[cur[0]][cur[1]] = 1
                for l in range(4):
                    if (0 <= cur[0]+dy_dx[l][0] <= h-1) and (0 <= cur[1]+dy_dx[l][1] <= w-1):
                        if checked[cur[0]+dy_dx[l][0]][cur[1]+dy_dx[l][1]] == 0:
                            if maze[cur[0]+dy_dx[l][0]][cur[1]+dy_dx[l][1]] == '.':
                                dist[cur[0]+dy_dx[l][0]][cur[1]+dy_dx[l][1]] = dist[cur[0]][cur[1]]+1
                                next.append([cur[0]+dy_dx[l][0],cur[1]+dy_dx[l][1]])
                                curmax = max(curmax,dist[cur[0]+dy_dx[l][0]][cur[1]+dy_dx[l][1]])
        ans = max(ans,curmax)
print(ans)        

### FIXED CODE ###

from collections import deque

h,w = map(int,input().split())
maze = []
ans = 0
dy_dx = [[0,1],[1,0],[0,-1],[-1,0]]
for i in range(h):
    maze.append(input())
flag = True
check = '.'*w
for i in range(h):
    if maze[i] != check:
        flag = False
        break
if flag:
    print(h+w-2)
else:
    for i in range(h):
        for j in range(w):
            if maze[i][j] == '.':
                ne = deque([[i,j]])
                dist = [[0]*w for k in range(h)]
                checked = [[0]*w for k in range(h)]
                while len(ne) != 0:
                    cur = ne.popleft()
                    checked[cur[0]][cur[1]] = 1
                    for l in range(4):
                        t = cur[0]+dy_dx[l][0]
                        u = cur[1]+dy_dx[l][1]
                        if (0 <= t <= h-1) and (0 <= u <= w-1):
                            if checked[t][u] == 0:
                                if maze[t][u] == '.':
                                    dist[t][u] = dist[cur[0]][cur[1]]+1
                                    ne.append([t,u])
                                    ans = max(ans,dist[t][u])
    print(ans)
from math import factorial
class UnionFind:
    def __init__(self, size):
        """
        リストの添字を集合の値として利用し
        リストの要素を根, 節の管理に用いる
        要素が負の添字は素集合の根であり、集合の要素数
        要素が0以上の添字は節であり
        要素は節の親の添字を指す
        """
        self.table = [-1] * size
        self.unconv = factorial(size)//(factorial(size-2)*2)
        
    def find(self, x):
        """
        xを持つ素集合の根を返す
        """
        if self.table[x] < 0:
            # 根の場合
            return x
        else:
            # 節の場合: 経路圧縮(path compression)
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        """
        x, yを持つ素集合を併合(Union)する
        """
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:  # x,yが異なる素集合に含まれている場合のみ併合
            if self.table[s1] >= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

if __name__=="__main__":
    N, M = map(int, input().split())
    Q = [list(map(int, input().split())) for _ in range(M)]
    u = UnionFind(N)
    unconv = factorial(N)//(factorial(N-2)*2)
    ans = []
    for q in reversed(Q):
        ans.append(unconv)
        unconv -= abs(u.table[u.find(q[0]-1)]*u.table[u.find(q[1]-1)])
        if unconv<0:
            unconv = 0
        u.union(q[0]-1, q[1]-1)
    for a in reversed(ans):
        print(a)

### FIXED CODE ###

class UnionFind:
    def __init__(self, size):
        import sys
        sys.setrecursionlimit(10**5)
        """
        リストの添字を集合の値として利用し
        リストの要素を根, 節の管理に用いる
        要素が負の添字は素集合の根であり、集合の要素数
        要素が0以上の添字は節であり
        要素は節の親の添字を指す
        """
        self.table = [-1] * size
        self.size = [1] * size
        
    def find(self, x):
        """
        xを持つ素集合の根を返す
        """
        if self.table[x] < 0:
            # 根の場合
            return x
        else:
            # 節の場合: 経路圧縮(path compression)
            self.table[x] = self.find(self.table[x])
            return self.table[x]
 
    def union(self, x, y):
        """
        x, yを持つ素集合を併合(Union)する
        """
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:  # x,yが異なる素集合に含まれている場合のみ併合
            if self.table[s1] >= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False
 
if __name__=="__main__":
    N, M = map(int, input().split())
    Q = [list(map(int, input().split())) for _ in range(M)]
    u = UnionFind(N)
    unconv = N*(N-1)//2
    ans = []
    for q in reversed(Q):
        ans.append(unconv)
        a = u.find(q[0]-1)
        b = u.find(q[1]-1)
        if a!=b:
            unconv -= u.table[a]*u.table[b]
        u.union(q[0]-1, q[1]-1)
    for a in reversed(ans):
        print(a)
#ABC140_C
N=int(input())
A=[0]*N
for _ in range(N-1):
    B.append(int(input()))
A[0]=B[0]

for i in range(1,N):
    A[i]=max(A[i-1],B[i-1],B[i])
print(*A)

### FIXED CODE ###

#ABC140_C
N=int(input())
A=[0]*N
B=[int(i) for i in input().split()]
A[0]=B[0]

for i in range(1,N-1):
    A[i]=min(B[i-1],B[i])
A[N-1]=B[N-2]

print(sum(A))
W, H, x, y, r = map(int,input().split())

right =  x + abs(r)
left = x - abs(r)
top = y + abs(r)
bottom = y - abs(r)

if right < W and left >= 0 and top < H  and bottom >= 0:
  print("Yes")
 else:
  print("No")



### FIXED CODE ###

W, H, x, y, r = map(int,input().split())

right =  x + abs(r)
left = x - abs(r)
top = y + abs(r)
bottom = y - abs(r)

if right <= W and left >= 0 and top <= H  and bottom >= 0:
  print("Yes")
else:
  print("No")
dct = {}
for i in range(N):
    S = input()
    if dct.get(S) == None:
        dct[S] = 1
    else:
        dct[S] += 1
sortedDct = sorted(dct.items(), key=lambda x: -x[1])
L = []
maxNum = 0
for k, v in sortedDct:
    if (maxNum <= v):
        L.append(k)
        maxNum = v
L.sort()
for l in L:
    print(l)

### FIXED CODE ###

N = int(input())
dct = {}
for i in range(N):
    S = input()
    if dct.get(S) == None:
        dct[S] = 1
    else:
        dct[S] += 1
sortedDct = sorted(dct.items(), key=lambda x: -x[1])
L = []
maxNum = 0
for k, v in sortedDct:
    if (maxNum <= v):
        L.append(k)
        maxNum = v
L.sort()
for l in L:
    print(l)
mod = 1000000007


def valid(i, j, n, m):
	if 0 <= i < n and 0 <= j < m:
		return True
	return False


def solve(i, j):
	if dp[i][j] != -1:
		return dp[i][j]
	if i == n - 1 and j == m - 1:
		return 1
	sm = 0
	if valid(i + 1, j, n, m) and ls[i + 1][j] != '#':
		sm += solve(i + 1, j)
	if valid(i, j + 1, n, m) and ls[i][j + 1] != '#':
		sm += solve(i, j + 1)
	dp[i][j] = sm % mod
	return dp[i][j]


n, m = map(int, input().split())
ls = []
for i in range(n):
	ls.append(input())
dp = [[-1 for i in range(m)] for j in range(n)]
print(solve(0, 0))


### FIXED CODE ###

mod = 1000000007
from sys import setrecursionlimit

setrecursionlimit(100000)


def valid(i, j, n, m):
	if 0 <= i < n and 0 <= j < m and good[i][j]:
		return True
	return False


def solve(i, j):
	if dp[i][j] != -1:
		return dp[i][j]
	if i == n - 1 and j == m - 1:
		return 1
	sm = 0
	if valid(i + 1, j, n, m):
		sm += solve(i + 1, j)
	if valid(i, j + 1, n, m):
		sm += solve(i, j + 1)
	dp[i][j] = sm % mod
	return dp[i][j]


n, m = map(int, input().split())
good = [[] for i in range(n)]
for i in range(n):
	s = input()
	for j in range(m):
		if s[j] == '.':
			good[i].append(True)
		else:
			good[i].append(False)

dp = [[-1 for i in range(m)] for j in range(n)]
print(solve(0, 0))
a,b  = int(raw_input().split())
print a * b, (a*2) + (b*2)

### FIXED CODE ###

a,b = map(int,raw_input().split())
print ("{0} {1}").format(a*b,2*a+2*b)
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

temp=1
trace=[1]
for i in range(K):
  temp=A[temp-1]
  if temp in trace:
    #print(temp)
    #print(trace.index(temp))
    start=trace.index(temp)
    circle=trace[start:]
    #print(circle)
    break
  trace.append(temp)
  #print("temp",temp)
#print((K-i)%len(circle)-1)
amari=(K-i)%len(circle)-1
print(circle[amari])

  

### FIXED CODE ###

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
 
check=[-1 for i in range(N)]
  
temp=1
circle=[]
for i in range(K):
  temp=A[temp-1]
  if check[temp-1]==-1:
    check[temp-1]=i
  else:
    circle.append(i-check[temp-1])
    #print(circle)
    break
  #print("temp",temp)
#print((K-i)%len(circle)-1)
if len(circle)!=0:
  amari=(K-i)%circle[0]
  temp=1
  for j in range(i+amari):
    temp=A[temp-1] 

print(temp)
import sys

input = sys.stdin.readline

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

if w == h:
    print(f"{w * h / 2} 1")
else:
    print(f"{w * h / 2} 0")


### FIXED CODE ###

import sys

input = sys.stdin.readline

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

if w % 2 == 0 and h % 2 == 0 and w // 2 == x and h // 2 == y:
    print(str(w * h / 2) + " " + "1")
else:
    print(str(w * h / 2) + " " + "0")
s = input()
t = input()
if s == t:
	pritn('Yes')
	exit()
if len(s) == 1:
	if s != t:
		print('No')
        exit(
for i in range(len(t)):
	for j in range(len(t)):
		if t[i] == t[j] and s[i] != s[j]:
			print('No')
			exit()
print('Yes')


### FIXED CODE ###

s = input()
t = input()

start = [-1]*26
goal = [-1]*26
for i in range(len(s)):
	a = ord(s[i]) - ord('a')
	b = ord(t[i]) - ord('a')
	if start[a] != -1 or goal[b] != -1:
		if start[a] != b or goal[b] != a:
			print('No')
			exit()
	start[a] = b
	goal[b] = a
print('Yes')
A,B,N= list(map(int, input().split()))
ma=0
for i in range(min(N,B)+1,1):
    a=int(A*i/B)-A*int(i/B)
    if(a<=A):
    	if(ma<a):
        	ma=a
            break
print(ma)

### FIXED CODE ###

A,B,N= list(map(int, input().split()))
print(int(A*min(B-1,N)/B)-A*int(min(B-1,N)/B))
s, t = input.split()

print("".join([t,s]))

### FIXED CODE ###

s, t = input().split()

print("".join([t,s]))
class Node:
    def __init__(self, parent = -1, left = -1, right = -1, depth = 0):
        self.parent = parent
        self.left = left
        self.right = right
        self.depth = depth
    
def print_node(i):
    global node
    print("node " + str(i) + ": ", end = "")
    print("parent = " + str(node[i].parent) +", ", end = "")
    print("depth = " + str(node[i].depth) + ", ", end = "")
    if node[i].parent == -1:
        print("root, [", end = "")
    elif node[i].left != -1:
        print("internal node, [", end = "")
    else:
        print("leaf, [", end = "")
    if node[i].left != -1:
        print(str(node[i].left), end = "")
        j = node[i].left
        while node[j].right != -1:
            j = node[j].right
            print(", " + str(j), end = "")
    print("]")
            

n = int(input())
node = [Node() for i in range(n)]
def input_depth(i, n):
    global node
    node[i].depth = n
    if node[i].right != -1:
        input_depth(node[i].right, n)
    if node[i].left != -1:
        input_depth(node[i].left, n + 1)

for i in range(n):
    p, k, *c = list(map(int, input().split()))
    if k > 0:
        node[p].left = c[0]
    for j in range(k):
        node[c[j]].parent = p
        if j != k - 1:
            node[c[j]].right = c[j + 1]

for i in range(n):
    if node[i].parent == -1:
        input_depth(i, 0)
        break

for i in range(n):
    print_node(i)

    


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

class Node:
    def __init__(self, parent = -1, left = -1, right = -1, depth = 0):
        self.parent = parent
        self.left = left
        self.right = right
        self.depth = depth
    
def print_node(i):
    global node
    print("node " + str(i) + ": ", end = "")
    print("parent = " + str(node[i].parent) +", ", end = "")
    print("depth = " + str(node[i].depth) + ", ", end = "")
    if node[i].parent == -1:
        print("root, [", end = "")
    elif node[i].left != -1:
        print("internal node, [", end = "")
    else:
        print("leaf, [", end = "")
    if node[i].left != -1:
        print(str(node[i].left), end = "")
        j = node[i].left
        while node[j].right != -1:
            j = node[j].right
            print(", " + str(j), end = "")
    print("]")
            

n = int(input())
node = [Node() for i in range(n)]
def input_depth(i, n):
    global node
    node[i].depth = n
    if node[i].right != -1:
        input_depth(node[i].right, n)
    if node[i].left != -1:
        input_depth(node[i].left, n + 1)

for i in range(n):
    p, k, *c = list(map(int, input().split()))
    if k > 0:
        node[p].left = c[0]
    for j in range(k):
        node[c[j]].parent = p
        if j != k - 1:
            node[c[j]].right = c[j + 1]

for i in range(n):
    if node[i].parent == -1:
        input_depth(i, 0)
        break

for i in range(n):
    print_node(i)
def resolve():
	X, N = map(int, input().split())
	if N == 0:
		print(X)
	else:
		A = list(map(int, input().split()))
		ymin = min(min(A), X)-1
		ymax = max(max(A), X)
		Y = {}
		for y in range(ymin, ymax):
			if y in A:
				None
			else:
				key = int(abs(X-y))
				if key in Y.keys():
					Y[key] = Y[key].append(y)
				else:
					Y[key] = [y]
		key = min(Y.keys())
		print(min(Y[key]))
resolve()

### FIXED CODE ###

def resolve():
	X, N = map(int, input().split())
	if N == 0:
		print(X)
	else:
		A = list(map(int, input().split()))

		for i in range(100):
			Y = X-i
			if Y not in A:
				print(Y)
				break
			Y = X+i
			if Y not in A:
				print(Y)
				break
resolve()
import math
MOD = 10**9+7
x, y = map(int, input().split())
if (x+y)%3 != 0 or 3*x < x+y or 3*y < x+y:
    print(0)
    exit()
n = (x+y)//3
x -= n
y -= n
c = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
print(c//MOD)


### FIXED CODE ###

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

MOD = 10**9+7
x, y = map(int, input().split())
if (x+y)%3 != 0 or 3*x < x+y or 3*y < x+y:
    print(0)
    exit()
n = (x+y)//3
x -= n
y -= n
fact = [1, 1]
for i in range(2,n+1):
    fact.append(fact[i-1] * i % MOD)
factX = fact[x]
factY = fact[y]
factN = fact[n]
# print(x,y,n)
# print(factX,factY,factN)

c = factN * modinv(factX, MOD) * modinv(factY, MOD)
c %= MOD
print(c)
S = input()
T = input()

if len(T)>len(S):
    ans = "UNRESTORABLE"
else:
    Slr = list(S[::-1])
    Tlr = list(T[::-1])
    
    for i in range(len(S)-len(T)+1):
        flag = True
        for j in range(len(T)):
            if Slr[i+j]==Tlr[j] or Slr[i+j]=="?":
                pass
            else:
                flag = False
                break
        if flag:
            for j in range(len(T)):
                Slr[i+j] = Tlr[j]
            for j in range(len(S)):
                if Slr[i+j]=="?":
                    Slr[i+j] = "a"
            ans = ("".join(Slr[::-1]))
            break
        else:
            if i==len(S)-len(T):
                ans = "UNRESTORABLE"
                break
print(ans)





### FIXED CODE ###


S = input()
T = input()

if len(T)>len(S):
    ans = "UNRESTORABLE"
else:
    Slr = list(S[::-1])
    Tlr = list(T[::-1])
    for i in range(len(S)-len(T)+1):
        flag = True
        for j in range(len(T)):
            if Slr[i+j]==Tlr[j] or Slr[i+j]=="?":
                pass
            else:
                flag = False
                break
        if flag:
            for j in range(len(T)):
                Slr[i+j] = Tlr[j]
            for j in range(len(S)):
                if Slr[j]=="?":
                    Slr[j] = "a"
            ans = ("".join(Slr[::-1]))
            break
        else:
            if i==len(S)-len(T):
                ans = "UNRESTORABLE"
print(ans)
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math

l = map(int, raw_input().split())
A = map(int, raw_input().split())

if l[2] in A:
    M = l[1] - A.index(l[2])
    if M > A.index(l[2]):
		print A.index(l[2])
	else:
		print M
sm = l[2]
la = l[2]
while(TRUE):
	sm = sm - 1
	la = la + 1
	if sm in A and la in A:
		ix = A.index(sm) + A.index(la)
		ix = ix / 2
		break
	if sm in A:
		ix = A.index(sm)
		break
	if la in A:
		ix = A.index(la)
		break
M = l[1] - ix
if M > ix:
	print math.floor(ix)
else:
	print M


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math

l = map(int, raw_input().split())
A = map(int, raw_input().split())

sm = l[2]
la = l[2]
while(True):
    if sm == 0:
        print 0
    if la == l[0]:
        print 0
    sm = sm - 1
    la = la + 1
    if sm in A and la in A:
    	ix = A.index(sm) + A.index(la)
        ix = ix / 2 + 0.5
        break
    if sm in A:
        ix = A.index(sm) + 0.5
	break
    if la in A:
	ix = A.index(la) - 0.5
	break
M = l[1] - ix - 1
if M > ix:
    print int(math.ceil(ix))
else:
    print int(math.ceil(M))
import numpy as np
N = int(input())
edges = []
count = np.zeros(N)
for _ in range(N-1):
  a, b = map(int, input().split())
  edges.append([a, b])
  count[a-1] += 1
  count[b-1] += 1
  
MAX = int(np.max(count))

color = [0 for _ in range(N-1)]
used = [set() for _ in range(N)]
for _ in range(N-1):
  id = np.argmax(count)
  count[id] = 0
  id += 1
  for k, [i,j] in enumerate(edges):
    if (i != id and j != id) or color[k] != 0:
      continue
    for l in range(MAX):
      c = l+1
      if c in used[i-1] or c in used[j-1]:
        continue
      used[i-1].add(c)
      used[j-1].add(c)
      color[k] = c
      break

print(MAX)
for i in color:
  print(i)


### FIXED CODE ###

N = int(input())
edges = []
node = [[] for _ in range(N)]
for _ in range(N-1):
  a, b = map(int, input().split())
  edges += (a-1, b-1),
  node[a-1] += b-1,
  node[b-1] += a-1,

stuck = [(0,0)]
f = [1]+[0]*N
color_dic = dict()
while stuck:
  v, color = stuck.pop()
  i = 0
  for w in node[v]:
    if f[w]:
      continue
    f[w] = 1
    i += 1
    if i == color:
      i += 1
    stuck += (w,i),
    color_dic[v,w] = i

ans = []
for a,b in edges:
  if (a,b) in color_dic:
    ans += color_dic[a,b],
  else:
    ans += color_dic[b,a],

print(max(ans))
for i in ans:
  print(i)
n, K = map(int, input().split())
h = list(map(int, input().split()))
inf = 10**10
dp = [inf]*n
dp[0] = 0
for i in range(1, n):
    di = dp[i]
    hi = h[i]
    for k in range(max(i-K, 0), i):
        a = dp[k]+abs(hi-h[k])
        if di > a:
            di = a
    dp[i] = di
print(dp[n-1])

### FIXED CODE ###

n = int(input())
H = list(map(int, input().split()))
cost = [None]*n
h1 = [None]*(n-1)
h2 = [None]*(n-2) 
one_ago = H[1]
two_ago = H[0]
h1[0] = abs(two_ago-one_ago)
for i in range(2, n):
    new = H[i]
    h1[i-1] = abs(one_ago-new)
    h2[i-2] = abs(two_ago-new)
    two_ago, one_ago = one_ago, new
cost[0], cost[1] = 0, h1[0]
for i in range(2, n):
    cost[i] = min(cost[i-2]+h2[i-2], cost[i-1]+h1[i-1])
print(cost[n-1])
n = int(input())
l = list(map(int,input().split()))

from collections import Counter
l1 = Counter(l[0::2])
mostl1 = l1.most_common()[0]
#semimostl1 = l1.most_common()[1]

l2 = Counter(l[1::2])
mostl2 = l2.most_common()[0]
#semimostl2 = l2.most_common()[1]

if mostl1[0] != mostl2[0]:
    print(n-mostl1[1]-mostl2[1])
else:
    semimostl1 = l1.most_common()[1]
    semimostl2 = l2.most_common()[1]
    print(min(n - mostl1[1] - semimostl2[1], n - semimostl1[1] - mostl2[1]))
    
    
#elif print(min(n-mostl1[1]-mostl2[1],n-mostl1[1]-mostl2[1]))

### FIXED CODE ###

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

from collections import Counter
l1 = Counter(l[0::2])
mostl1 = l1.most_common()[0]
#semimostl1 = l1.most_common()[1]

l2 = Counter(l[1::2])
mostl2 = l2.most_common()[0]
#semimostl2 = l2.most_common()[1]

if mostl1[0] != mostl2[0]:
    print(n-mostl1[1]-mostl2[1])
elif len(l1.keys()) == 1 and len(l2.keys()) == 1:
    print(int(n/2))

else:
    semimostl1 = l1.most_common()[1]
    semimostl2 = l2.most_common()[1]
    print(min(n - mostl1[1] - semimostl2[1], n - semimostl1[1] - mostl2[1]))


#elif print(min(n-mostl1[1]-mostl2[1],n-mostl1[1]-mostl2[1]))
import collections
N = int(input())
V = list(int(i) for i in input().split())
even = V[0::2]
odd =  V[1::2]
even_count = collections.Counter(even).most_common(2)
odd_count = collections.Counter(odd).most_common(2)

if even_count == N/2:
    print(N / 2 - odd_count)
elif odd_count == N/2:
    print(N / 2 - even_count)
else:
    print(N - odd_count - even_count)

### FIXED CODE ###

import collections

N = int(input())
V = list(int(i) for i in input().split())
even = V[0::2]
odd =  V[1::2]
all_length = len(V)
even = collections.Counter(even).most_common(2)
odd = collections.Counter(odd).most_common(2)
if (even[0][0] != odd[0][0]):
    print(all_length - even[0][1] - odd[0][1])
else:
    if(len(even) == 1 and len(odd) == 1):
        print(all_length // 2)
    elif(len(even)==1):
        print(all_length // 2 - odd[1][1])
    elif(len(odd)==1):
        print(all_length // 2 - even[1][1])    
    else:
        print(min(all_length - even[0][1] - odd[1][1], all_length - even[1][1] - odd[0][1]))
import fraction
n = int(input())
a = list(map(int,input().split()))
ans = a[0]
for x in a:
    ans = fraction.gcd(x,ans)
print(ans)



### FIXED CODE ###

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b,a%b)
n = int(input())
a = list(map(int,input().split()))
ans = a[0]
for x in a:
    ans = gcd(x,ans)
print(ans)
N,A,B,C = map(int,input().split())
data = {
  "A":A,
  "B":B,
  "C":C
}
select = []
S = list(input() for _ in range(N))
for i in range(N):
  s = S[i]
  if data[s[0]] == data[s[1]] ==0:
    print("No")
    exit(0)
  elif data[s[0]] > data[s[1]]:
    data[s[0]] -= 1
    data[s[1]] += 1
    select.append(s[1])
  elif data[s[0]] < data[s[1]]:
    data[s[0]] += 1
    data[s[1]] -= 1
    select.append(s[0])
  else:
    ss = S[i+1]
    if i == N - 1:
      select.appnd(s[0])
    elif s[0] in ss:
      data[s[0]] += 1
      data[s[1]] -= 1
      select.append(s[0])
    else:
      data[s[0]] -= 1
      data[s[1]] += 1
      select.append(s[1])

### FIXED CODE ###

N,A,B,C = map(int,input().split())
data = {
  "A":A,
  "B":B,
  "C":C
}
select = []
S = list(input() for _ in range(N))
for i in range(N):
  s = S[i]
  if data[s[0]] == data[s[1]] ==0:
    print("No")
    exit(0)
  elif data[s[0]] > data[s[1]]:
    data[s[0]] -= 1
    data[s[1]] += 1
    select.append(s[1])
  elif data[s[0]] < data[s[1]]:
    data[s[0]] += 1
    data[s[1]] -= 1
    select.append(s[0])
  elif i == N-1:
    select.append(s[0])
  elif s[0] in S[i+1]:
    data[s[0]] += 1
    data[s[1]] -= 1
    select.append(s[0])
  else:
    data[s[0]] -= 1
    data[s[1]] += 1
    select.append(s[1])
print("Yes")
for i in select:
  print(i)