Harryxun/stf_run huggingface dataset:
INF = 10**9
N, K = map(int, input().split())
s = input().split()
mc = []
pc = []
for i in s:
  c = int(i)
  if c==0:
    K -= 1
  if c<0:
    mc += [-c]
  elif c>0:
    pc += [c]

mc.sort()
pc.sort()
mc += [INF]
pc += [INF]

m = K-1
xi = 0
yi = -1
while m>0:
  if pc[xi+1]>2*mc[yi+1]:
    yi += 1
  else:
    xi += 1
  m -= 1
if yi!=-1:
  c1 = pc[xi] + 2*mc[yi]
else:
  c1 = pc[xi]

m = K-1
xi = -1
yi = 0
while m>0:
  if mc[yi+1]>2*pc[xi+1]:
    xi += 1
  else:
    yi += 1
  m -= 1
if xi!=-1:
  c2 = 2*pc[xi] + mc[yi]
else:
  c2 = mc[yi]

if K==0:
  print(0)
else:
  print(min(c1, c2))

### FIXED CODE ###

INF = 10**9
N, K = map(int, input().split())
s = [int(c) for c in input().split()]

ans = INF
for i in range(N-K+1):
  l = i
  r = l+K-1
  ans = min(ans, abs(s[l])+abs(s[r]-s[l]), abs(s[r])+abs(s[r]-s[l]))

print(ans)
a = input()
b = input()
h = input()
print((a+b)*h/2)

### FIXED CODE ###

a, b, h = [int(input()) for i in range(3)]
print(int((a + b) * h / 2))
n,m=map(int,input().split())
d=[1]*(n+1)
for i in range(m):
    d[int(input())]=0
for i in range(n+1):
    if i >1:
        d[i]=(d[i-1]+d[i-2])%(10**9+7)*d[i]
print(d[n+1])

### FIXED CODE ###

n,m=map(int,input().split())
D=[1] * (n + 1)
for _ in range(m):
    D[int(input())] = 0
for i in range(n+1):
    if i > 1:
        D[i] = (D[i-1] + D[i-2]) % 1000000007 * D[i]
print(D[i])
n,m=map(int,input().split())
print((1800*m+100*n)*2(**m))

### FIXED CODE ###

n,m=map(int,input().split())
print((1800*m+100*n)*(2**m))
A,B,M = map(int, input().split())
a = map(int, input().split())
b = map(int, input().split())
a_min = min(a)
b_min = min(b)
ans = a_min + b_min
for i in range(M):
  x,y,c = map(int, input().split())
  x -= 1
  y -= 1
  ans = min(ans, a[x]+b[y]-c)
print(ans)

### FIXED CODE ###

A,B,M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for i in range(M):
  x,y,c = map(int, input().split())
  ans = min(ans, a[x-1]+b[y-1]-c)
print(ans)
nums = input().split()
a = int(nums[0])
b = int(nums[1])
c = int(nums[2])
if a <= b <= c:
????????print(a, b, c)
elif a <= c <= b:
????????print(a, c, b)
elif b <= a <= c:
????????print(b, a, c)
elif b <= c <= a:
????????print(b, c, a)
elif c <= a <= b:
????????print(c, a, b)
else:
????????print(c, b, a)

### FIXED CODE ###


nums = input().split()
a = int(nums[0])
b = int(nums[1])
c = int(nums[2])
if a <= b <= c:
    print(a, b, c)
elif a <= c <= b:
    print(a, c, b)
elif b <= a <= c:
    print(b, a, c)
elif b <= c <= a:
    print(b, c, a)
elif c <= a <= b:
    print(c, a, b)
else:
    print(c, b, a)
N,A,B=map(int.input().split())
sum=min(N*A,B)
print(sum)

### FIXED CODE ###

N,A,B=map(int,input().split())
sum=min(N*A,B)
print(sum)
N = int(input())
s = [input() for i in range(N)]

count_AB = [s[i].count("AB") for i in range(N)]

headB = 0
tailA = 0
headB_and_tailA = 0
for i in range(N):
    #print("i =", i)
    if s[i][0] == 'B':
        if s[i][-1] != 'A':
            #print("headB")
            headB += 1
        else:
            headB_and_tailA += 1
            #print("both")
    elif s[i][-1] == 'A':
        tailA += 1
        #print("tailA")

"""
print("both =", headB_and_tailA)
print("headB = ", headB)
print("tailA = ", tailA)
"""
result = sum(count_AB) + min(headB, tailA)
headB -= min(headB, tailA)
tailA -= min(headB, tailA)
for _ in range(headB_and_tailA):
    if tailA > 0:
        result += 1
    elif tailB > 0:
        result += 1
    else:
        tailA += 1
#print("sum = ", sum(count_AB))
    
print(result)


### FIXED CODE ###

N = int(input())
s = [input() for i in range(N)]

count_AB = [s[i].count("AB") for i in range(N)]

headB = 0
tailA = 0
headB_and_tailA = 0
for i in range(N):
    #print("i =", i)
    if s[i][0] == 'B':
        if s[i][-1] != 'A':
            #print("headB")
            headB += 1
        else:
            headB_and_tailA += 1
            #print("both")
    elif s[i][-1] == 'A':
        tailA += 1
        #print("tailA")

"""
print("both =", headB_and_tailA)
print("headB = ", headB)
print("tailA = ", tailA)
"""
result = sum(count_AB) + min(headB, tailA)
headB -= min(headB, tailA)
tailA -= min(headB, tailA)
for _ in range(headB_and_tailA):
    if tailA > 0:
        result += 1
    elif headB > 0:
        result += 1
    else:
        tailA += 1
#print("sum = ", sum(count_AB))
    
print(result)
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
a=[]
for x in range(101):
  for y in range(101):
    c=[]
    for t in l:
      if t[2]:
        c.append(t[2]+abs(x-t[0])+abs(y-t[1]))
    f=0
    if len(set(c))==1:
      f=1
      h=c[0]
      for t in l:
        if l[2]==0:
          if h-abs(x-t[0])-abs(y-t[1])>0:
            f=0
    if f:
      print(x,y,h)
      exit()

### FIXED CODE ###

n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
a=[]
for x in range(101):
  for y in range(101):
    c=[]
    for t in l:
      if t[2]:
        c.append(t[2]+abs(x-t[0])+abs(y-t[1]))
    f=0
    if len(set(c))==1:
      f=1
      h=c[0]
      for t in l:
        if t[2]==0:
          if h-abs(x-t[0])-abs(y-t[1])>0:
            f=0
    if f:
      print(x,y,h)
      exit()
data=[]
N=0

for i in range(0,X):
  while N<K:
    for j in range(0,Y):
      while N<K:
        for k in range(0,Z):
          while N<K:
            data.append(int(A[i]+B[j]+C[k]))
            N=N+1
    
data.sort()
data.reverse()

for l in range(K):
  print(data[l])


### FIXED CODE ###

a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
f=[a,b,c,d,e]
ma=max(f)
mi=min(f)
if ma-mi>k:
  print(":(")
else:
  print("Yay!")
a, b, t = map(int, list(input()))
total = 0
for i in range(a, t+1, a):
  total += b
print(total)

### FIXED CODE ###

a, b, t = map(int, input().split())
total = 0
for i in range(a, t+1, a):
  total += b
print(total)
n, c = list(map(int, input().split()))
x, v = [], []
for i in range(n):
    x_, v_ = list(map(int, input().split()))
    x.append(x_)
    v.append(v_)
sushi1 = list((sum(v[:i+1]) - x[i]) for i in range(n))
sushi2 = list((sum(v[n-i:]) - (c - x[n-i])) for i in range(1, n+1))
max1, max2 = [0], [0]
for i in range(n):
    max1.append(max(sushi1[i] - x[i], max1[i]))
    max2.append(max(sushi2[i] - (c - x[n-i-1]), max2[i]))
def ans1(i):
    if i < 0:
        return 0
    elif i == 0:
        return max2[n]
    ans = max2[n-i] + sushi1[i-1]
    return max(ans, ans1(i-1))
def ans2(i):
    if i < 0:
        return 0
    elif i == 0:
        return max1[n]
    ans = max1[n-i] + sushi2[i-1]
    return max(ans, ans1(i-1))
print(max(ans1(n), ans2(n)))

### FIXED CODE ###

import numpy as np
n, c = list(map(int, input().split()))
xv = list(list(map(int, input().split())) for i in range(n))
sushi1, max1, sushi2, max2 = [0], [0], [0], [0]
sum1, sum2 = 0, 0
for x, v in xv:
    sum1 += v
    sushi1.append(max(sum1 - x, sushi1[-1]))
    max1.append(max(sum1 - 2*x, max1[-1]))
for x, v in xv[::-1]:
    sum2 += v
    sushi2.append(max(sum2 - (c-x), sushi2[-1]))
    max2.append(max(sum2 - 2*(c-x), max2[-1]))
ans1 = max(np.array(sushi1) + np.array(max2[::-1]))
ans2 = max(np.array(sushi2) + np.array(max1[::-1]))
print(max(0, ans1, ans2))
N,K = map(int,input().split())
H = list(map(int,input().split()))

H = sorted(H)
#print(H)

for i in range(K):
  H.remove(H[N-1-i])

print(sum(H))

### FIXED CODE ###

import numpy
N,K = map(int,input().split())
H = list(map(int,input().split()))

H = numpy.sort(H)
sum = 0
#print(H)
if N-K > 0:
  for i in range(N-K):
    sum = sum + H[i]
else:
    sum = 0
    
print(sum)
X=input()
if X>=400 and X<=599:
  print(8)
elif X>=600 and X<=799:
  print(7)
elif X>=800 and X<=999:
  print(6)
elif X>=1000 and X<=1199:
  print(5)
elif X>=1200 and X<=1399:
  print(4)
elif X>=1400 and X<=1599:
  print(3)
elif X>=1600 and X<=1799:
  print(2)
elif X>=1800 and X<=1999:
  print(1)


### FIXED CODE ###

X=int(input())
if X>=400 and X<=599:
  print('8')
if X>=600 and X<=799:
  print('7')
if X>=800 and X<=999:
  print('6')
if X>=1000 and X<=1199:
  print('5')
if X>=1200 and X<=1399:
  print('4')
if X>=1400 and X<=1599:
  print('3')
if X>=1600 and X<=1799:
  print('2')
if X>=1800 and X<=1999:
  print('1')
n,k,q = map(int,input().split())
a=[int(input()) for i in range(q)]

m = [k-len(a)] * n
for i in a:
    m[a[i]-1] = m[a[i]-1] + 1

for j in range(n):
    if m[j] <= 0:
        print("No")
    else:
        print("Yes")

### FIXED CODE ###

n,k,q = map(int,input().split())
a=[int(input()) for i in range(q)]

m = [k-q] * n
for i in range(q):
    m[a[i]-1] = m[a[i]-1] + 1
    
for j in range(n):
    if m[j] <= 0:
        print("No")
    else:
        print("Yes")
N = int(input())
if N%9 == 0:
    print("yes")
else:
    print("no")

### FIXED CODE ###

N,X,T = map(int,input().split())
S = N//X
A = N%X
if A == 0:
    print(S*T)
else:
    K = S+1
    print(K*T)
import re

S=input()
pat = r'[ATCG]+'
parts = re.findall(pat,S)
print(max([len(part) for part in parts]))

### FIXED CODE ###

import re

S=input()
pat = r'[ATCG]+'
parts = re.findall(pat,S)
if len(parts)==0:
  print(0) 
else:
  print(max([len(part) for part in parts]))
a,b,c=map(int,input().split()),print(min(a*b,c))

### FIXED CODE ###

a,b,c=map(int,input().split());print(min(a*b,c))
if A == 5 and B == 5 and C == 7:
  print('YES')
elif A == 5 and B == 7 and C == 5:
  print('YES')
elif A == 7 and B == 5 and C == 5:
  print('YES')
else:
  print('NO')

### FIXED CODE ###

S = input()

if S.count('5') == 2 and S.count('7') == 1:
  print('YES')
else:
  print('NO')
abc = raw_input().split()
a = int(abc[0])
b = int(abc[1])
c = int(abc[2])

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


### FIXED CODE ###

abc = raw_input().split()
a = int(abc[0])
b = int(abc[1])
c = int(abc[2])

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

n = int(input())
al = list(map(int,input().split())).sort()
bl = list(map(int,input().split())).sort()
cl = list(map(int,input().split())).sort()

ans = 0
for b in bl:
    a_num = bisect.bisect_left(al,b)
    c_num = n - bisect.bisect_right(cl,b)
    ans += a_num*c_num

print(ans)

### FIXED CODE ###

import bisect
n = int(input())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
cl = list(map(int,input().split()))

al.sort()
bl.sort()
cl.sort()

cnt = 0
for b in bl:
    a_num = bisect.bisect_left(al,b)
    c_num = n - bisect.bisect_right(cl,b)
    cnt += a_num*c_num
    # cnt += c_num

print(cnt)
s = input()
t = input()

c

for i in range(3):
    if s[i] == t[i]:
        c +=1

print(c)

### FIXED CODE ###

s = input()
t = input()

c = 0

for i in range(3):
    if s[i] == t[i]:
        c +=1

print(c)
import math
n = int(input())
print(n*2//math.gcd(n,2))


### FIXED CODE ###

n = int(input())
print(n if n%2==0 else n*2)
a,b=map(int,input().split())

if a<2b:
  print("0")
else:
  print(a-2*b)

### FIXED CODE ###

a,b=map(int,input().split())
 
if a<2*b:
  print("0")
else:
  print(a-2*b)
N, M = list(map(int,input().split()))
A = []
B = []
for i in range(M):
    A1,B1=[int(i) for i in input().split()]
    A.append(A1)
    B.append(B1)
A.reverse()
B.reverse()

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n+1)]
        self.rank = [0 for _ in range(n+1)]
        self.size = [1 for _ in range(n+1)]
    
    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            x_size = self.size[x]
            y_size = self.size[y]
            sum_size = x_size + y_size
            self.size[x] = sum_size
            self.size[y] = sum_size
            
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)
    
    def get_size(self, a):
        x = self.find(a)
        return self.size[x]
      
uf = UnionFind(N)
anses = []
ans = int(N * (N-1) / 2)
anses.append(ans)

for k in range(len(A)-1):
    if uf.is_same(A[k], B[k]):
        anses.append(anses[k])
        print(anses)
    else:
        N1 = uf.get_size(A[k])
        N2 = uf.get_size(B[k])
        ans = anses[k] - (N1 * N2)
        if ans < 0:
            ans = 0
        uf.union(A[k], B[k])
        anses.append(ans)
        
for ans in reversed(anses):
        print(ans)

### FIXED CODE ###

a, b, c = list(map(int,input().split()))
q = int(b / a)
if q > c:
    print(c)
else:
    print(q)
def Input():
    return mapt(int, input().split(" "))

def main():
    n = int(input())
    b = Input()
    data = 0
    for i in range(n-1):
        if i == 0:
            data += b[i]
            continue
        data += min(b[i], b[i-1])
    data += b[-1]
    print(data)
main()

### FIXED CODE ###

def mapt(fn, *args):
    return tuple(map(fn, *args))

def Input():
    return mapt(int, input().split(" "))

def main():
    n = int(input())
    b = Input()
    data = 0
    for i in range(n-1):
        if i == 0:
            data += b[i]
            continue
        data += min(b[i], b[i-1])
    data += b[-1]
    print(data)
main()
N = int(input())
H = list(map(int,input().split()))
gap = [0]*(N-1)
M = []

for i in range (N-1):
    gap[i] = H[i]-H[i+1]

c = 0
for i in range (N-1):
    if gap[i] >= 0:
        c += 1
        if i == N-2:
            M.append(c)
    else:
        M.append(c)
        c = 0

print(max(M))

### FIXED CODE ###

N = int(input())
H = list(map(int,input().split()))
gap = [0]*(N-1)
M = []

for i in range (N-1):
    gap[i] = H[i]-H[i+1]

c = 0
for i in range (N-1):
    if gap[i] >= 0:
        c += 1
        if i == N-2:
            M.append(c)
    else:
        M.append(c)
        c = 0

if N == 1:
    print(0)
else:
    print(max(M))
n,m=map(int,input().split())
p=list(map(int,input().split()))
pa=list(range(n))
def find(u):
  if u!=pa[u]:pa[u]=find(pa[u])
  return pa[u]
for i in range(m):
  a,b=map(int,input().split())
  a=find(a-1)
  b=find(b-1)
  if a!=b:pa[a]=b
c=0
for i in range(n):
  if find(p[i])==find(i):c+=1
print(c)

### FIXED CODE ###

n,m=map(int,input().split())
p=list(map(int,input().split()))
pa=list(range(n))
def find(u):
  if u!=pa[u]:pa[u]=find(pa[u])
  return pa[u]
for i in range(m):
  a,b=map(int,input().split())
  a=find(a-1)
  b=find(b-1)
  if a!=b:pa[a]=b
c=0
for i in range(n):
  if find(p[i]-1)==find(i):c+=1
print(c)
N,M = map(int,input().split())
Adj_list = defaultdict(set)

for i in range(M):
    a, b, c = map(int, input().split())
    Adj_list[a-1].add((b-1, c))
    Adj_list[b-1].add((a-1, -c))
visited =[None]*(N)
ok = True
stack = []
for x in range(N):
   if visited[x] is not None:continue
   visited[x] = 0
   stack = [x]
   while stack:
       v = stack.pop()
       for to,d in Adj_list[v]:
           if visited[to] is None:
               visited[to] = G[v] + d
               stack.append(to)
           else:
               if G[to] != G[v]+d:
                   ok = False
                   break
   if ok == False:
        break
print("Yes" if ok else "No")

### FIXED CODE ###

import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
INF = float("inf")


N,M = map(int,input().split())
Adj_list = defaultdict(set)

for i in range(M):
    a, b, c = map(int, input().split())
    Adj_list[a-1].add((b-1, c))
    Adj_list[b-1].add((a-1, -c))
visited =[None]*(N)
ok = True
stack = []
for x in range(N):
   if visited[x] is not None:continue
   visited[x] = 0
   stack = [x]
   while stack:
       v = stack.pop()
       for to,d in Adj_list[v]:
           if visited[to] is None:
               visited[to] = visited[v] + d
               stack.append(to)
           else:
               if visited[to] != visited[v]+d:
                   ok = False
                   break
   if ok == False:
        break
print("Yes" if ok else "No")
S = input()
if S == 'Sunny':
  print('Cloudy')
if S == 'Cloudy':
  print('Rainy'):
if S == 'Rainy':
  print('Sunny')

### FIXED CODE ###

S = input()
if S == 'Sunny':
  print('Cloudy')
if S == 'Cloudy':
  print('Rainy')
if S == 'Rainy':
  print('Sunny')
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    A = []
    cnt = 0
    for _ in range(H):
        a = list(map(int, input().split()))
        cnt += sum(a)
        A.append(a)

    ans = []
    for h in range(H):
        if h % 2 == 0:
            for w in range(W):
                if h == H - 1 and w == W - 1:
                    continue
                if A[h][w] % 2 == 1:
                    if w == W:
                        A[h][w] -= 1
                        A[h + 1][w] += 1
                        ans.append((h, w, h + 1, w))
                    else:
                        A[h][w] -= 1
                        A[h][w + 1] += 1
                        ans.append((h, w, h, w + 1))
                else:
                    continue
        else:
            for w in range(W)[::-1]:
                if h == H - 1 and w == 0:
                    continue
                if A[h][w] % 2 == 1:
                    if w == 0:
                        A[h][w] -= 1
                        A[h + 1][w] += 1
                        ans.append((h, w, h + 1, w))
                    else:
                        A[h][w] -= 1
                        A[h][w - 1] += 1
                        ans.append((h, w, h, w - 1))
                else:
                    continue

    print(len(ans))
    for a, b, c, d in ans:
        print(a + 1, b + 1, c + 1, d + 1)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    A = []
    cnt = 0
    for _ in range(H):
        a = list(map(int, input().split()))
        cnt += sum(a)
        A.append(a)

    ans = []
    for h in range(H):
        if h % 2 == 0:
            for w in range(W):
                if h == H - 1 and w == W - 1:
                    continue
                if A[h][w] % 2 == 1:
                    if w == W - 1:
                        A[h][w] -= 1
                        A[h + 1][w] += 1
                        ans.append((h, w, h + 1, w))
                    else:
                        A[h][w] -= 1
                        A[h][w + 1] += 1
                        ans.append((h, w, h, w + 1))
                else:
                    continue
        else:
            for w in range(W)[::-1]:
                if h == H - 1 and w == 0:
                    continue
                if A[h][w] % 2 == 1:
                    if w == 0:
                        A[h][w] -= 1
                        A[h + 1][w] += 1
                        ans.append((h, w, h + 1, w))
                    else:
                        A[h][w] -= 1
                        A[h][w - 1] += 1
                        ans.append((h, w, h, w - 1))
                else:
                    continue

    print(len(ans))
    for a, b, c, d in ans:
        print(a + 1, b + 1, c + 1, d + 1)


if __name__ == "__main__":
    main()
import math

def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

N, K = cin()
A = cin()

def is_ok(mid):
    cnt = 0
    for i in range(N):  cnt += math.floor(A[i] / mid)
    return cnt <= K

def binary_search(left, right):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(mid):  right = mid
        else:  left = mid
    return right

left = max(A)
right = -1
ret = binary_search(right, left)
print(ret)

### FIXED CODE ###

import math

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

def is_ok(mid):
    cnt = 0
    for i in range(N):  cnt += (math.ceil(A[i] / mid) - 1)
    return cnt <= K

def binary_search(left, right):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(mid):  right = mid
        else:  left = mid
    return right

if K == 0:  print(max(A))
else:
    left = max(A)
    right = 0
    ret = binary_search(right, left)
    print(ret)
h,w=map(int,input().split());b=[[0]*(w+1)]
for i in range(h):
  b.append([0])
  for j in input():
    if j==".":b[-1].append(1)
    else:b[-1].append(2)
  b[-1].append(0)
b.append([0]*(w+1));d=[[0,1],[0,-1],[1,0],[-1,0]];a=0
def s(i,j):
  global B;B[b[i][j]-1]+=1;v=b[i][j];b[i][j]=0
  for k in d:
    if v^3!=b[i+k[0]][j+k[1]]:continue
    s(i+k[0],j+k[1])
for i in range(1,h+1):
  for j in range(1,w+1):B=[0,0];s(i,j);a+=B[0]*B[1]
print(a)

### FIXED CODE ###

import sys;sys.setrecursionlimit(10**9)
h,w=map(int,input().split())
b=[[0]*(w+1)]
for i in range(h):
  b.append([0])
  for j in input():
    if j==".":b[-1].append(1)
    else:b[-1].append(2)
  b[-1].append(0)
b.append([0]*(w+1))
d=[[0,1],[0,-1],[1,0],[-1,0]]
a=0
def bfs(i,j):
  global br,wh
  if b[i][j]==0:return
  if b[i][j]==1:wh+=1
  elif b[i][j]==2:br+=1
  v=b[i][j]
  b[i][j]=0
  for k in d:
    if v^3!=b[i+k[0]][j+k[1]]:continue
    bfs(i+k[0],j+k[1])
for i in range(1,h+1):
  for j in range(1,w+1):
    br=wh=0
    bfs(i,j)
    a+=br*wh
print(a)
def getlist():
	return list(map(int, input().split()))

n = int(input())
p = getlist()

ans = 0
for i in range(N - 2):
	if p[i] < p[i + 1] and p[i + 1] < p[i + 2]:
		ans += 1
	elif p[i] > p[i + 1] and p[i + 1] > p[i + 2]:
		ans += 1
	else:
		pass

print(ans)

### FIXED CODE ###

def getlist():
	return list(map(int, input().split()))

n = int(input())
p = getlist()

ans = 0
for i in range(n - 2):
	if p[i] < p[i + 1] and p[i + 1] < p[i + 2]:
		ans += 1
	elif p[i] > p[i + 1] and p[i + 1] > p[i + 2]:
		ans += 1
	else:
		pass

print(ans)
import sys
sys.setrecursionlimit(2000000000)

p = 10 ** 9 + 7
N = 2*10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
  fact.append((fact[-1] * i) % p)
  inv.append((-inv[p % i] * (p // i)) % p)
  factinv.append((factinv[-1] * inv[-1]) % p)

def comb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fact[n] * factinv[r] * factinv[n-r] % p



a1,b1,a2,b2=map(int,input().split())
score=comb(a2+b2+2,a2+1,p)-comb(a2+b1+1,a2+1,p)-comb(a1+b2+1,a1,p)+comb(a1+b1,a1,p)
print(score%(10**9+7))

### FIXED CODE ###

a1,b1,a2,b2=map(int,input().split())

import sys
sys.setrecursionlimit(2000000000)

p = 10 ** 9 + 7
N = a2+b2+2  # N は必要分だけ用意する
R = max(a2+1,b2+1)
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
  fact.append((fact[-1] * i) % p)
  
for i in range(2, R + 1):
  inv.append((-inv[p % i] * (p // i)) % p)
  factinv.append((factinv[-1] * inv[-1]) % p)

def comb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fact[n] * factinv[r] * factinv[n-r] % p

score=comb(a2+b2+2,a2+1,p)-comb(a2+b1+1,a2+1,p)-comb(a1+b2+1,a1,p)+comb(a1+b1,a1,p)
print(score%(10**9+7))
N,K=map(int,input().split())
D=list(map(int,input().split()))
NL=len(str(N))
ans=[]
allnum=list(range(10))
use=list(set(allnum)^set(D))
for i in range(NL):
    a=int(str(N)[i])
    for j in use:
        if a<=j:
            ans.append(j)
            break
        else:
            continue
if ans[0]==0:
    ans[0]=use[1]
else:
    pass
print(int(''.join(map(str,ans))))

### FIXED CODE ###

N,K=map(int,input().split())
D=list(map(int,input().split()))
for i in range(N,10*N+1):
    I=list(map(int,str(i)))
    match=list(set(I)&set(D))
    if len(match)==0:
        print(i)
        break
    else:
        pass