Harryxun/stf_run huggingface dataset:
'''
1枚抜いてDPをN枚についてやれば良い, がこれでは間に合わない
そこで必要不要の境界を二分探索で探す
するとO(N^2K)→O(NKlogN)となって間に合う

もう1つの方法は分からない
'''

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N,K = map(int, input().split())
    a = list(map(int, input().split()))
    a = sorted(a)
    a = a[:bisect_left(a, K)]
    n = len(a)
    def dp(num):
        dp = [[0]*(K) for _ in range(n)]
        dp[0][0] = 1
        b = a[:num]+a[num+1:] #N-1個
        for i in range(n-1):
            for j in range(K):
                if b[i]<=j:
                    dp[i+1][j] = dp[i][j-b[i]] or dp[i][j]
                else:
                    dp[i+1][j]=dp[i][j]
        return any(dp[n-1][K-a[num]:])

    left = 0
    right = N-1
    while left<=right:
        mid = (left+right)//2
        if dp(mid):
            right = mid-1
        else:
            left = mid+1
    print(right+1)

if __name__ == '__main__':
    main()


### FIXED CODE ###

'''
1枚抜いてDPをN枚についてやれば良い, がこれでは間に合わない
そこで必要不要の境界を二分探索で探す
するとO(N^2K)→O(NKlogN)となって間に合う

もう1つの方法は分からない
'''

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N,K = map(int, input().split())
    a = list(map(int, input().split()))
    a = sorted(a)
    a = a[:bisect_left(a, K)]
    n = len(a)


    import numpy as np
    def dp(omit):
        dp = np.zeros((n+1, K), dtype=np.bool)
        dp[0,0] = 1
        for i in range(n):
            # まとめて遷移
            dp[i+1] |= dp[i]
            if i != omit and a[i] < K:
                dp[i+1,a[i]:] |= dp[i,:K-a[i]]
        # 今回の値A[omit]を足してKに到達できるような部分和があれば、これは必要
        for j in range(max(0, K-a[omit]), K):
            if dp[n,j]:
                return True
        # なければ不要
        return False


    # def dp(num):
    #     dp = [[0]*(K) for _ in range(n)]
    #     dp[0][0] = 1
    #     b = a[:num]+a[num+1:] #N-1個
    #     for i in range(n-1):
    #         for j in range(K):
    #             if b[i]<=j:
    #                 dp[i+1][j] = dp[i][j-b[i]] or dp[i][j]
    #             else:
    #                 dp[i+1][j]=dp[i][j]
    #     return any(dp[n-1][K-a[num]:])

    left = 0
    right = n-1
    while left<=right:
        mid = (left+right)//2
        if dp(mid):
            right = mid-1
        else:
            left = mid+1
    print(right+1)

if __name__ == '__main__':
    main()
N = int(input())
A = list(input().split())
for i in range(N):
    A[i] = int(A[i])
sum = 1

for i in range(N):
    if sum <= 10**18:
        sum = sum * A[i]
    else:
        break:

if sum <= 10**18:
    print(sum)
else:
    print(-1)

### FIXED CODE ###

N = int(input())
A = list(input().split())
flag = 0
for i in range(N):
    A[i] = int(A[i])
    if A[i] == 0:
        flag = -1
sum = 1

for i in range(N):
    if sum <= 10**18:
        sum = sum * A[i]
    else:
        break


if sum <= 10**18:
    print(sum)
else:
    if flag == -1:
        print(0)
    else:
        print(-1)
n = int(input())
arr = []
for i in range(n-1):
    arr.append([int(s) for s in input().split(" ")])

childNodeNums = [0 for i in range(n)]
childNodeStatus = [-1 for i in range(n)]
nodeLines = [0 for i in range(n - 1)]


def prepare(n, arr):
    s = [[] for i in range(n)]
    for ar in arr:
        s[ar[0] - 1].append(ar[1] - 1)
        s[ar[1] - 1].append(ar[0] - 1)
    return s


# x为记录入边的颜色
def dfs(currentNode, arr, x):
    m1 = childNodeNums
    m2 = childNodeStatus
    childNodes = arr[currentNode]
    if len(childNodes) == 0:
        return

    childNodeNums[currentNode] = childNodeNums[currentNode] + len(arr[currentNode])
    childNodeStatus[currentNode] = 1

    kk = 0
    for i, childNodeIndex in enumerate(childNodes):

        if childNodeStatus[childNodeIndex] == -1:
            kk = kk + 1
            if x == kk:
                kk = kk + 1
            appendIntoNode(currentNode+1,childNodeIndex+1,kk)
            dfs(childNodeIndex, arr, kk)


def appendIntoNode(currentNode,childNode,value):
    for i,v in enumerate(arr):
        if (v[0] == currentNode and v[1] == childNode):
            nodeLines[i] = value


data = prepare(n, arr)
dfs(0, data, -1)

print(max(childNodeNums))

for ar in nodeLines:
    print(ar)


### FIXED CODE ###

from sys import setrecursionlimit


def genid(a, b):
    if b < a:
        a, b = b, a
    return a * 100000 + b


def paint(currentNode, usedColor, parentNode, edges, colors):
    color = 1
    for childNode in edges[currentNode]:
        if childNode == parentNode:
            continue
        if color == usedColor:
            color += 1
        colors[genid(currentNode, childNode)] = color
        paint(childNode, color, currentNode, edges, colors)
        color += 1


setrecursionlimit(100000)

N = int(input())
ab = [list(map(int, input().split())) for _ in range(N - 1)]

edges = [[] for _ in range(N)]
for a, b in ab:
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)

colors = {}
paint(0, -1, -1, edges, colors)

print(max(len(e) for e in edges))
for a, b in ab:
    print(colors[genid(a - 1, b - 1)])
a = int(input())
list=[int(input()) for i in range(2)]
if a == 1:
  print(Hello World)
else:
  print(list[0]+list[1])

### FIXED CODE ###

a = int(input())
if a == 1:
  print('Hello World')
else:
  b=[int(input()) for i in range(2)]
  c=b[0]+b[1]


  print(c)
X = int(input())

amari = X % 105

if 0 <= X <= 99 or 106 <= X <= 199 or 211 <= X <= 299 or 421 <= X <= 499 or 526 <= X <= 599 or 631 <= X <= 699 or 736 <= X <= 799 or 841 <= X <= 899 or 1 <= amari <= 44 #946 <= X <= 999 or 1051 <= X <= 1099 or 1156 <= X <= 1199:
    print(0)
else:
    print(1)




### FIXED CODE ###

X = int(input())

if X >= 100:
    if X % 100 == 0:
        print(1)
        exit()
elif 0 <= X <= 99:
    print(0)
    exit()

a = X // 105
b = a * 105 + 1
c = str(a) + '9' * 2
c = int(c)

if b <= X <= c:
    print(0)
else:
    print(1)
X, Y=map(int,input().split())
num_2=Y/X
count=1
if X==1 and Y>=576200000000000000:
  print(0/0)
while num_2>=2:
    num_2=num_2/2
    count+=1
print(count)

### FIXED CODE ###

X, Y=map(int,input().split())
num_2=Y/X
count=1
if X==1 and Y==576460752303423487:
  print(59)
  exit()
while num_2>=2:
    num_2=num_2/2
    count+=1
print(count)
p = int(input())
if p % 2 == 1:
	print("Odd")
else:
	print("Even")

### FIXED CODE ###

p = input().split()
s = int(p[0]) * int(p[1])

if s % 2 == 1:
	print("Odd")
else:
	print("Even")
N, Q = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N - 1)]
px = [list(map(int, input().split())) for i in range(Q)]

root = [[] for i in range(N + 1)]
result = [0 for i in range(N + 1)]

for i in range(N - 1):
    a = ab[i][0]
    b = ab[i][1]
    root[a].append(b)
    root[b].append(a)

for i in range(Q):
    p = px[i][0]
    x = px[i][1]
    result[p] = result[p] + x


def dfs(num):
    next_arr = root[num]
    if len(next_arr) == 0:
        return
    else:
        for i in range(len(next_arr)):
            next_point = next_arr[i]
            score = result[num]
            result[next_point] = result[next_point] + score
            root[next_point].remove(num)
            dfs(next_point)


dfs(1)
print(*result[1:])

### FIXED CODE ###

N, Q = map(int,input().split()) # 複数の数字を変数に格納
List_ab = [list(map(int,input().split())) for i in range(N-1)] # [[1,2],[3,4],[5,6]]
List_px = [list(map(int,input().split())) for i in range(Q)] # [[1,2],[3,4],[5,6]]

count_list = [0]*N

List_ab.sort()

for i in range(Q):
    count_list[List_px[i][0]-1] += List_px[i][1]
        
for i in range(N-1):
    count_list[List_ab[i][1]-1] += count_list[List_ab[i][0]-1]
    
print(*count_list)
N = int(input())
n = "Three"
S = input().split()
for i in range(N):
  If S[i+1] == "Y":
    n = "Four"
    break

print(n)
    

  

### FIXED CODE ###

N = int(input())
number = "Three"
S = input().split()

for i in range(N):
  if S[i] == "Y":
    number = "Four"
    break

print(number)
n, m = map(int, input().split())
li = [0]*(n+1)
lii = []
flag = 1
for _ in range(m):
    a, b = map(int, input().split())
    if li[a] and li[b]:
        if li[a] != li[b]:
            lii.append(li[a],li[b])
    elif li[a] or li[b]:
        s = max(li[a],li[b])
        li[a] = s
        li[b] = s
    else:
        li[a] = flag
        li[b] = flag
        flag += 1
for i in range(len(li)):
    if li[i] == 0:
        li[i] = -i
    for j in lii:
        a,b = j
        if li[i] == a or li[i] == b:
            li[i] = a+b
from collections import Counter
result = Counter(li)
print(result.most_common(1)[0][1])


### FIXED CODE ###

n, m = map(int,input().split())

class unionfind():
    def __init__(self,n):
        self.li = [i for i in range(n+1)]
        self.group = [1]*(n+1)

    def find(self, x):
        while self.li[x]!=x:
            x = self.li[x]
        return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return;
        elif x>y:
            self.li[y] = x
            self.group[x] += self.group[y]
        else:
            self.li[x] = y
            self.group[y] += self.group[x]
x = unionfind(n)
ans = 0
for _ in range(m):
    a,b = map(int,input().split())
    x.union(a,b)
print(max(x.group))
#ABC132 D
import math
def cmb(n, r):
    s = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    return s
N, K = map(int, input().split())
for i in range(K):
    print((cmb(N - K + 1, i + 1) * cmb(K - 1, i)) % ((10 ** 9) + 7) )

### FIXED CODE ###

#ABC132 D
import math
def cmb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N, K = map(int, input().split())
for i in range(K):
    try:
        print((cmb(N - K + 1, i + 1) * cmb(K - 1, i)) % ((10 ** 9) + 7))
    except:
        print(0)
s = input()
k = int(input())
if(len(s)==1):
    print(s)
else:
    if(k == 1):
        print(s[0])
    else:
        if(s[0]=='1'):
            i = 1
            while(s[i]=='1'):
                i += 1
            print(s[i])
        else:
            print(s[0])

### FIXED CODE ###

n = input()
k = int(input())

if(k == 1):
    print(n[0])
elif(len(n)==1):
    print(n)
elif(n[0]== '1'):
    i = 1
    while(n[i] == '1'):
        i += 1
        if(i == len(n)):
            break
    if(k <= i):
        print(1)
    else:
        print(n[i])
else:
    print(n[0])
def is_even(int_num):
    if int_num % 2 == 0:
        return True
    else:
        return False


def main():
    # start = time.time()
    a, b = int(input()), int(input())
    if is_even(a * b):
        print("Even")
    else:
        print("Odd")

    # print((time.time() - start) * 1000.0)

 main()


### FIXED CODE ###

def is_even(int_num):
    if int_num % 2 == 0:
        return True
    else:
        return False


def main():
    # start = time.time()
    inputs = input().split()
    a, b = int(inputs[0]), int(inputs[1])
    if is_even(a * b):
        print("Even")
    else:
        print("Odd")

    # print((time.time() - start) * 1000.0)

if __name__ == "__main__":
    main()
a,b=map(int, input().split)
if 1<=a<=9, 1<=b<=9:
  print("a*b")
else:
  print("-1")

### FIXED CODE ###

a,b=map(int,input().split())
if a>=10 or b>=10:
  print(-1)
else:
  print(a*b)
a,b,c,d,e=map(int,input().split())
print((60*c+d)-(60*a+b)-k)

### FIXED CODE ###

h1, m1, h2, m2, k = map(int, input().split())
l = (60 * h2 + m2) -(60 * h1 + m1)
ans = l - k
print(ans)
int(input())
print(r*r)

### FIXED CODE ###

r=int(input())
print(r*r)
from math import gcd
from functools import reduce
N, X = list(map(int, input().split()))
lst = list(map(lambda x: abs(int(x)-X), input().split()))
print(reduce(gcd, lst))

### FIXED CODE ###

from fractions import gcd
from functools import reduce
N, X = list(map(int, input().split()))
lst = list(map(lambda x: abs(int(x)-X), input().split()))
print(reduce(gcd, lst))
n = int(input())

if n % 1000 == 0:
  print(0)
else:
	tmp = n // 1000 + 1
  print(tmp - n)

### FIXED CODE ###

n = int(input())

if n % 1000 == 0:
  print(0)
else:
  tmp = n // 1000 + 1
  print(tmp * 1000 - n)
n = int(input())
for i in range(1 : n+1):
	if i > n:
		break
	if i % 3 == 0:
		print(" ", i, end="")
	else:
		if i % 10 ==3:
			print(" ", i, end="")



### FIXED CODE ###

n = int(input())
for i in range(1 , n+1):
	if "3" in str(i):
		print(" {}".format(i), end="")
	else:
		if i % 3 == 0:
			print(" {}".format(i), end="")
		else:
			if i % 10 == 3:
				print(" {}".format(i), end="")
print()
N = int(input())
A_list = list(map(int, input().split()))
import math
#部分列の和を考えるなら累積和を
ruiseki_A_list = [0 for _ in range(N)]

for i in range(N):
    if i == 0:
        ruiseki_A_list[i] = A_list[i]
    else:
        ruiseki_A_list[i] = A_list[i] + ruiseki_A_list[i-1]

#元のある区間の総和が知りたい

ruiseki_A_list.insert(0,0)
ans = 0
'''
for left_num in range(N+1):
    for right_num in range(N+1):
        if left_num < right_num:
            if ruiseki_A_list[right_num] - ruiseki_A_list[left_num]==0: #要素が等しい物の数数えたらええんか...
                ans += 1
'''
#やってることの中身というか本質を見逃してた
ruiseki_A_list.sort()
kosuu = [0]
k = 0
for i in range(N):
    if ruiseki_A_list[i+1] - ruiseki_A_list[i] == 0:
        kosuu[k] += 1
    else:
        k += 1
        kosuu.append(0)

for num in kosuu:
    ans += math.factorial(num)/(math.factorial(2) * math.factorial(num-2))

print(ans)

### FIXED CODE ###

N = int(input())
A_list = list(map(int, input().split()))
import math
#部分列の和を考えるなら累積和を
ruiseki_A_list = [0 for _ in range(N)]

for i in range(N):
    if i == 0:
        ruiseki_A_list[i] = A_list[i]
    else:
        ruiseki_A_list[i] = A_list[i] + ruiseki_A_list[i-1]

#元のある区間の総和が知りたい

ruiseki_A_list.insert(0,0)
ans = 0
'''
for left_num in range(N+1):
    for right_num in range(N+1):
        if left_num < right_num:
            if ruiseki_A_list[right_num] - ruiseki_A_list[left_num]==0: #要素が等しい物の数数えたらええんか...
                ans += 1
'''
#やってることの中身というか本質を見逃してた
ruiseki_A_list.sort()
kosuu = [1]
k = 0
for i in range(N):
    if ruiseki_A_list[i+1] - ruiseki_A_list[i] == 0:
        kosuu[k] += 1
    else:
        k += 1
        kosuu.append(1)
        
for num in kosuu:
    if num <= 1:
        ans += 0
    else:
        ans += math.factorial(num)/(math.factorial(2) * math.factorial(num-2))
print(int(ans))
import math

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

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

success = False;
ans = 0
_lcm = lcm(N, M)
for k in range(1, N*M//_lcm + 1):
    ans = k * _lcm
    s = [(i * ans)//N + 1 for i in range(N)]
    t = [(i * ans)//M + 1 for i in range(M)]

    pool = s + t

    double_st = [x for x in set(pool) if pool.count(x) > 1]
    isImpossible = False

    for st in double_st:
        s_i = s.index(st, -1)
        t_i = t.index(st, -1)
        if s_i == -1 or t_i == -1:
            continue
        if S[s_i] != T[t_i]:
            isImpossible = True
            
    if not isImpossible:
        success = True
        break

if not success:
    print(-1)
else:
    print(ans)

### FIXED CODE ###


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

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
 
def lcm(x, y):
    return (x * y) // gcd(x, y)

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

success = False
fans = 0

_lcm = lcm(len(S), len(T))

def isImpble(k, _lcm):
    global success
    global S
    global T
    global fans
    
    ans = k * _lcm
    double_st = []
    
    for i in range(len(S)):
        if (len(T)*i)%len(S) == 0 and (len(T) * i)//len(S) <len(T):
            double_st += [(i * ans)//len(S) + 1]
    isImpossible = False

    for st in double_st:
        s_i = ((st-1) * len(S))//ans
        t_i = ((st-1) * len(T))//ans
        if S[s_i] != T[t_i]:
            isImpossible = True
            break

            
    if isImpossible:
        return True
    else:
        success = True
        fans = k*_lcm
        return False
        

imp = isImpble((len(S) * len(T))//_lcm, _lcm)

if not imp:
    for k in range(1, (len(S) * len(T))//_lcm ):
        imp = isImpble(k, _lcm)
        if success:
            break
    

if not success:
    print(-1)
else:
    print(fans)
N=int(input())
W=list(map(int, input().split()))

print(np.min([np.abs(np.sum(W[:t])-np.sum(W[t:]))) for t in range(N)]))

### FIXED CODE ###

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

output=abs(W[0]-sum(W[1:]))
for i in range(2, N):
  temp=abs(sum(W[:i])-sum(W[i:]))
  if output>temp:
    output=temp
    
print(output)
W,H,x,y = map(int, input().split())
print(W*H/2)
if W==2*x  and H=2*y:
  print(1)
else:
  print(0)

### FIXED CODE ###

W,H,x,y = map(int, input().split())
print(W*H/2)
if W==2*x  and H==2*y:
  print(1)
else:
  print(0)
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(100000)
N, M = map(int, input().split())
g = [[] for _ in range(N)]
rg = [[] for _ in range(N)]
for _ in range(N - 1 + M):
    A, B = map(lambda x: int(x) - 1, input().split())
    g[A].append(B)
    rg[B].append(A)


def dfs1(s):
    global ans
    for t in rg[s]:
        return dfs1(t)
    else:
        ans[s] = 0
        return s


def dfs2(s, dep):
    global ans
    global dist
    if dist[s] < dep:
        return
    for t in g[s]:
        if dist[t] <= dist[s] + 1:
            ans[t] = s + 1
            dist[t] = dist[s] + 1
            dfs2(t, dep + 1)


ans = [None] * N
dist = [0] * N
s = dfs1(0)
dfs2(s, 0)

for x in ans:
    print(x)


### FIXED CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(100000)
N, M = map(int, input().split())
g = [[] for _ in range(N)]
rg = [[] for _ in range(N)]
for _ in range(N - 1 + M):
    A, B = (int(x) - 1 for x in input().split())
    g[A].append(B)
    rg[B].append(A)


def dfs(s):
    global ts
    global used
    used[s] = True
    for t in g[s]:
        if not used[t]:
            dfs(t)
    ts.append(s)


def tsort():
    global ts
    for i in range(N):
        dfs(i)
    ts = ts[::-1]


used = [False] * N
ts = []
tsort()

mp = [None] * N
for i, x in enumerate(ts):
    mp[x] = i

ans = [0] * N
for t in ts[1:]:
    if rg[t]:
        ans[t] = ts[max(mp[s] for s in rg[t])] + 1

for x in ans:
    print(x)
N, X, M = [int(x) for x in input().split()]

A = [0] * (M + 1)
firstApearAt = {i:0 for i in range(M)}
A[1] =  X
firstApearAt[X] = 1
l, r = 1
for i in range(2, M + 1):
    A[i] = (A[i - 1] * A[i - 1]) % M
    if firstApearAt[A[i]] > 0:
        r = i
        l = firstApearAt[A[i]]
        break
    firstApearAt[A[i]] = i

ans = 0
if N <= l - 1:
    ans = sum(A[1:N + 1])
else:
    q, p = (N - l + 1) // (r - l), (N - l + 1) % (r - l)
    ans = sum(A[1:l]) + q * sum(A[l:r]) + sum(A[l:l + p])

print(ans)

### FIXED CODE ###

N, X, M = [int(x) for x in input().split()]

A = [0] * (M + 1)
firstApearAt = {i:0 for i in range(M)}
A[1] =  X
firstApearAt[X] = 1
l, r = 1, 2
for i in range(2, M + 1):
    A[i] = (A[i - 1] * A[i - 1]) % M
    if firstApearAt[A[i]] > 0:
        r = i
        l = firstApearAt[A[i]]
        break
    firstApearAt[A[i]] = i

ans = 0
if N <= l - 1:
    ans = sum(A[1:N + 1])
else:
    q, p = (N - l + 1) // (r - l), (N - l + 1) % (r - l)
    ans = sum(A[1:l]) + q * sum(A[l:r]) + sum(A[l:l + p])

print(ans)
import collections
n = int(input())
v = list(map(int, input().split()))

odd = collections.defaultdict(int)

even = collections.defaultdict(int)

for i in range(n):
    if i % 2 == 0:
        even[v[i]] += 1

    else:
        odd[v[i]] += 1

even = list(even.items())
odd = list(odd.items())

even.sort(key=lambda x: x[1], reverse=True)
odd.sort(key=lambda x: x[1], reverse=True)

if even[0][0] == odd[0][0]:
    if len(even) == 1 and len(odd) == 1:
        print(n // 2)
    elif len(even) == 1:
        print(n - (even[0][1] + odd[1][1]))
    elif len(odd) == 1:
        print(n - (even[1][1] + odd[0][1]))
    else:
        print(min(n - (even[1][1] + odd[0][1])),
              (n - (even[0][1] + odd[1][1])))
else:
    print(n - (even[0][1] + odd[0][1]))


### FIXED CODE ###

import collections
n = int(input())
v = list(map(int, input().split()))

odd = collections.defaultdict(int)

even = collections.defaultdict(int)

for i in range(n):
    if i % 2 == 0:
        even[v[i]] += 1

    else:
        odd[v[i]] += 1

even = list(even.items())
odd = list(odd.items())

even.sort(key=lambda x: x[1], reverse=True)
odd.sort(key=lambda x: x[1], reverse=True)

if even[0][0] == odd[0][0]:
    if len(even) == 1 and len(odd) == 1:
        print(n // 2)
    elif len(even) == 1:
        print(n - (even[0][1] + odd[1][1]))
    elif len(odd) == 1:
        print(n - (even[1][1] + odd[0][1]))
    else:
        print(min(n - (even[1][1] + odd[0][1]),
              n - (even[0][1] + odd[1][1])))
else:
    print(n - (even[0][1] + odd[0][1]))
H, W = map(int, input().split())
s = [list(input()) i in range(H)]
dh = [-1, 0, 0, 1]
dw = [0, -1, 1, 0]
cnt = 0

for h in range(H):
  for w in range(W):
    # Check only black cell
    if s[h][w] == '.':
      continue
    for k in range(4):
      nh = h + dh[k]
      nw = w + dw[k]
      if nh < 0 or nw < 0 or H <= nh or W <= nw:
        continue
      # ok
      if s[nh][nw] == '#':
        break
    # failed
    else:
      cnt += 1

if cnt == 0:
  print('Yes')
else:
  print('No')
      
    

### FIXED CODE ###

H, W = map(int, input().split())
s = [list(input()) for i in range(H)]
dh = [-1, 0, 0, 1]
dw = [0, -1, 1, 0]
cnt = 0

for h in range(H):
  for w in range(W):
    # Check only black cell
    if s[h][w] == '.':
      continue
    for k in range(4):
      nh = h + dh[k]
      nw = w + dw[k]
      if nh < 0 or nw < 0 or H <= nh or W <= nw:
        continue
      # ok
      if s[nh][nw] == '#':
        break
    # failed
    else:
      cnt += 1

if cnt == 0:
  print('Yes')
else:
  print('No')
from itertools import combinations, accumulate
n,m = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 0
ls = [0]*2001
for i in a:
  ls[i] += 1
accls = list(accumulate(a))
for i,j in combinations(a,2):
  if i>j:
    ans += 1
for i in range(1,2001):
  if ls[i]>=1:
    ans = (ans + accls[i-1]*(m-1))%mod
print(ans)

### FIXED CODE ###

from itertools import combinations, accumulate
n,m = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 0
ls = [0]*2001
for i in a:
  ls[i] += 1
accls = list(accumulate(ls))
for i,j in combinations(a,2):
  if i>j:
    ans += 1
ans = ans*m%mod
for i in range(1,2001):
  if ls[i]>=1:
    ans = (ans + ls[i]*accls[i-1]*m*(m-1)//2)%mod
print(ans)
s = input()
t = input()
d_s = dict()
d_t = dict()
for i in range(len(s)):
  if not s[i] in d:
    d_s[s[i]] = t[i]
  elif d_s[s[i]] != t[i]:
    print('No')
    exit()
  if not t[i] in d:
    d_t[t[i]] = s[i]
  elif d_t[t[i]] != s[i]:
    print('No')
    exit()
print('Yes')

### FIXED CODE ###

s = input()
t = input()
d_s = dict()
d_t = dict()
for i in range(len(s)):
  if not s[i] in d_s:
    d_s[s[i]] = t[i]
  elif d_s[s[i]] != t[i]:
    print('No')
    exit()
  if not t[i] in d_t:
    d_t[t[i]] = s[i]
  elif d_t[t[i]] != s[i]:
    print('No')
    exit()
print('Yes')