Harryxun/stf_run huggingface dataset:
from collections import defaultdict, deque

N, M = map(int, input().split())
e = defaultdict(list)
for i in range(M):
    a, b = map(int, input().split())
    e[(a, 0)].append((b, 1))
    e[(a, 1)].append((b, 2))
    e[(a, 2)].append((b, 0))

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

d = deque()
d.appendleft((S, 0))

inf = float('inf')
dist = defaultdict(lambda: inf)
dist[(S, 0)] = 0

def BFS(now):
    for v in e[now]:
        if(dist[v] > dist[now] + 1):
            dist[v] = dist[now] + 1
            if(v == (T, 0)):
                return
            BFS(v)
    return

BFS((S, 0))

ans = dist[(T, 0)]
if(ans == inf):
    print(-1)
else:
    print(ans//3)



### FIXED CODE ###

from collections import deque, defaultdict

N, M = map(int, input().split())
edge = defaultdict(list)
for i in range(M):
    a, b = map(int, input().split())
    edge[(a, 0)].append((b, 1))
    edge[(a, 1)].append((b, 2))
    edge[(a, 2)].append((b, 0))

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

inf = float('inf')
dist = {}
for i in range(1, N+1):
    dist[(i, 0)] = inf
    dist[(i, 1)] = inf
    dist[(i, 2)] = inf
dist[(S, 0)] = 0

dq = deque()
dq.append((S, 0))

while dq:
    v = dq.popleft()
    if v == (T, 0):
        break
    for u in edge[v]:
        if dist[u] < inf: continue
        dq.append(u)
        dist[u] = dist[v] + 1

if(dist[(T, 0)] == inf):
    print(-1)
else:
    print(dist[(T, 0)]//3)
H, W = map(int, input().split())
board = [list(input()) for i in range(H)]

ans = board
dist = [(1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1), (0, 1)]
count = 0

for i in range(H):
    for j in range(W):
        if board[i][j] == '#':
            continue
        for x, y in dist:
            now_x = i + x
            now_y = j + y
            if now_x > W or now_x < 0 or now_y > H or now_y < 0:
                continue
            if board[now_x][now_y] == '#':
                count += 1
        ans[i][j] = str(count)

for line in ans:
    print(''.join(line))


### FIXED CODE ###

import sys
def main():
    in1 = input()
    nums, length = in1.split(' ')
    nums= int(nums)
    length = int(length)
    bombs = []

    for i in range(nums):

        bombs.append(input())
    checked = [['']*length for i in range(nums)]
    for i in range(nums):
        for j in range(length):
            if bombs[i][j] == '#':
                checked[i][j] = '#'
            else:
                bombnum = 0
                if i != 0:
                    if j != 0:
                        if bombs[i-1][j-1] == '#':
                            bombnum += 1

                    if j != length -1:
                        if bombs[i-1][j+1] == '#':
                            bombnum += 1

                    if bombs[i-1][j] == '#':
                        bombnum += 1


                if j != 0:
                    if bombs[i][j-1] == '#':
                        bombnum += 1

                if j != length-1:
                    if bombs[i][j+1] == '#':
                        bombnum += 1


                if i != nums-1:
                    if j != 0:
                        if bombs[i+1][j-1] == '#':
                            bombnum += 1

                    if j != length -1:
                        if bombs[i+1][j+1] == '#':
                            bombnum += 1

                    if bombs[i+1][j] == '#':
                        bombnum += 1

                checked[i][j] = bombnum
    for i in checked:
        for j in i:
            print(j, end = '')
        print('')
if __name__ == '__main__':
    main()
X, Y=map(int,input().split())
num_2=Y/X
count=1
if X==1 and Y>=200000000000000000:
  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)
s = input()

abc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

if s == ''.join(abc)[::-1]:
    print(-1)
    exit()
if len(s) <26:
    for a in abc:
        if a not in abc:
            print(s+a)
            exit()
i = 25
while s[i-1] > s[i]:
    i -= 1
    #print(s[i-1], s[i])
#print(s[i-1], s[i])
tt = s[i-1]
ss = list(s[i-1:])
ss.sort()
print(s[:i-1]+ss[ss.index(tt)+1])


### FIXED CODE ###

#11208467
t="abcdefghijklmnopqrstuvwxyz"
s=input()
if s==t[::-1]:print(-1);exit()
if len(s)!=26:
  for i in t:
    if i not in s:print(s+i);exit()
i=25
while s[i-1]>s[i]:i-=1
tt=s[i-1]
ss=list(s[i-1:])
ss.sort()
print(s[:i-1]+ss[ss.index(tt)+1])
A=int(input())
B=int(input())
s=0
for i in range(1,N+1):
    k=0
    j=i
    while(j>0):
        k+=j%10
        j=j//10
    if (A<=k and k<=B):
        s=s+i
print(s)


### FIXED CODE ###

N,A,B=map(int, input().split())
s=0
for i in range(1,N+1):
    k=0
    j=i
    while(j>0):
        k+=j%10
        j=j//10
    if (A<=k and k<=B):
        s=s+i
print(s)
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

N = I()
H = LI()

# 短調非減少 H[i] <= H[i+1]

if N ==1:
    print('Yes')
    break
ans = True
for i in range(N-1):
    if H[i] <= H[i+1]:
        # print(i,'1')
        continue
    elif (not i==0) and H[i]-1 == H[i+1]:
        if not H[i-1] == H[i]:
            H[i] -= 1
            # print(i,'2')
            continue
    # print(i,'3')
    ans = False
    break

if ans:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

N = I()
H = LI()

# 短調非減少 H[i] <= H[i+1]
# 隣接要素を比較して大きかったら、必ず-1しておく
H[0]-=1
for i in range(N-1):
  if H[i] < H[i+1]:
    H[i+1] -= 1
  elif H[i] > H[i+1]:
    print("No")
    exit()
print("Yes")



# if N ==1:
#     print('Yes')
#     exit()
# ans = True
# for i in range(N-1):
#     if H[i] <= H[i+1]:
#         # print(i,'1')
#         continue
#     elif (not i==0) and H[i]-1 == H[i+1]:
#         if not H[i-1] == H[i]:
#             H[i] -= 1
#             # print(i,'2')
#             continue
#     # print(i,'3')
#     ans = False
#     break

# if ans:
#     print('Yes')
# else:
#     print('No')
n= int(input())
spot = input().split()
ans = []
for i in spot:
    spot.append(int(spot[0]))
    del spot[0]
for s in range(min(spot),max(spot)):
    x = 0
    for t in spot:
        x += (s-t)**2
    ans.append(x)
print(min(ans))

### FIXED CODE ###

n= int(input())
spot = input().split()
ans = []
for i in spot:
    spot.append(int(spot[0]))
    del spot[0]
if n == 1:
    print(0)
else:
    if max(spot)==min(spot):
        ans.append(0)
    for s in range(min(spot),max(spot)):
        x = 0
        for t in spot:
            x += (s-t)**2
        ans.append(x)
if n != 1:
    ans.sort(reverse=False)
    print(ans[0])
N,K = map(int, input().split())
lst = []
for z in range(K):
    lst.append(input())
lst.sort()
print("".join(lst))

### FIXED CODE ###

N,K = map(int, input().split())
lst = []
for z in range(N):
    lst.append(input())
lst.sort()
print("".join(lst))
import numpy as np
n = int(input())
p = [ int(input()) for i in range(n)]
pmin = -1
pmax = n
for i,j in enumerate(p):
    if i + 1 == j:
        continue
    else:
        pmin = i
        break
for i,j in enumerate(p[::-1]):
    if n - i  == j:
        continue
    else:
        pmax = n - i -1
        break


nppma  = np.array(p[:pmax + 1 ],dtype="int32")
nppmi = np.array(p[pmin  :],dtype="int32")
#print(nppmi)
#print(nppma)
nmax = nppma.argmax()
nmin = nppmi.argmin()
#print(nppmi[:nmin])
#print(nppma[nmax +1:])
ansmin =  n  + 1 - np.min(nppmi[:nmin])
ansmax = np.max(nppma[nmax + 1:])
print(min(ansmin,ansmax))


### FIXED CODE ###

N = int(input())
dic = {}
nums = []
for i in range(N):
    num = int(input())
    dic[num] = i+1
    nums.append(num)
ans = 0
l = 0
for i in range(N-1):
    if dic[i+2] < dic[i+1]:
        ans = max(ans, l)
        l = 0
    else:
        l += 1
ans = max(ans, l)
print(N-ans-1)
import sys
sys.setrecursionlimit(100000)
x=int(input())
A=[]
B=[]
C=[]
dictA=[-1]*x
dictB=[-1]*x
dictC=[-1]*x
for i in range(x):
    a,b,c=list(map(int,input().split()))
    A.append(a)
    B.append(b)
    C.append(c)
def maxA(n):
    if dictA[n]!=-1:
        return dictA[n]
    if n==0:
        dictA[n]=A[0]
        return A[0]
    dictA[n]=A[n]+max(maxB(n-1),maxC(n-1))
    return dictA[n]
def maxB(n):
    if dictB[n]!=-1:
        return dictB[n]
    if n==0:
        dictB[n]=B[0]
        return B[0]
    dictB[n]=B[n]+max(maxA(n-1),maxC(n-1))
    return dictB[n]
def maxC(n):
    if dictC[n]!=-1:
        return dictC[n]
    if n==0:
        dictC[n]=C[0]
        return C[0]
    dictC[n]=C[n]+max(maxB(n-1),maxA(n-1))
    return dictC[n]
def Nmax(n):
    return max(maxA(n),maxB(n),maxC(n))
print(Nmax(x-1))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10000000)
x=int(input())
A=[]
B=[]
C=[]
dictA=[-1]*x
dictB=[-1]*x
dictC=[-1]*x
for i in range(x):
    a,b,c=list(map(int,input().split()))
    A.append(a)
    B.append(b)
    C.append(c)
def maxA(n):
    if dictA[n]!=-1:
        return dictA[n]
    if n==0:
        dictA[n]=A[0]
        return A[0]
    dictA[n]=A[n]+max(maxB(n-1),maxC(n-1))
    return dictA[n]
def maxB(n):
    if dictB[n]!=-1:
        return dictB[n]
    if n==0:
        dictB[n]=B[0]
        return B[0]
    dictB[n]=B[n]+max(maxA(n-1),maxC(n-1))
    return dictB[n]
def maxC(n):
    if dictC[n]!=-1:
        return dictC[n]
    if n==0:
        dictC[n]=C[0]
        return C[0]
    dictC[n]=C[n]+max(maxB(n-1),maxA(n-1))
    return dictC[n]
def Nmax(n):
    return max(maxA(n),maxB(n),maxC(n))
print(Nmax(x-1))
total_subjects, max_points, target_points = map(int, input().split())
subject_points = list(map(int, input().split()))

calc_result = (total_subjects * target_points) - sum(subject_points)

if calc_result > max_points:
    print(-1)
elif calc_result < 0:
    print(0)
else:
    print(calc_result)


### FIXED CODE ###

small_alpha = str(input())
alpha_list = [chr(ord('a') + i) for i in range(26)]
for num, alpha in enumerate(alpha_list):
    if alpha == small_alpha:
        print(alpha_list[num + 1])
a = 0
while input() != 0:
    a += 1
    print ("Case {}: {}".format(a. input()))


### FIXED CODE ###

i=1
x = int(input())
while x != 0 :
    print("Case {0}: {1}".format(i, x))
    x = int(input())
    i=i+1
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = 0, (10 ** 9 + 1000000) // 2

while True:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        if next_amount < 0:
            break
        rain[i] += next_amount
    # print(rain)
    flag = True
    for i in range(1, n):
        if dum[i - 1] != (rain[i - 1] + rain[0]) // 2:
            flag = False
    if flag and dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        # 最初に決めたやつが小さすぎた
        # print("{} は小さすぎた".format(rain[0]))
        l = mid + 1
    else:
        # 最初に決めたやつが大きすぎた
        # print("{} は大きすぎた".format(rain[0]))
        r = mid

    # セーフティネット 必要ないけど
    if count > 50:
        t = 5 / 0
        break
    count += 1

"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""


### FIXED CODE ###

# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う
# なんかしらんけど3問駄目だな...

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = 0, (10 ** 10) // 2

while l < r:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        rain[i] += next_amount
    # print(rain)

    if dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        # 最初に決めたやつが小さすぎた
        # print("{} は小さすぎた".format(rain[0]))
        l = mid + 1
    else:
        # 最初に決めたやつが大きすぎた
        # print("{} は大きすぎた".format(rain[0]))
        r = mid

    # セーフティネット 必要ないけど
    if count > 50:
        t = 5 / 0
        break
    count += 1

"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""
N = int(input())
Y = int(input())
flag = 0
for num_so in range(N):
    if flag == 1:
        break
    for num_fs in range(N):
        num_ts = N - num_so - num_fs
        sum = num_ts * 10000 + num_fs * 5000 + num_so * 1000
        if flag == 1:
            break
        elif sum == Y and num_ts > 0:
            print(num_ts, num_fs, num_so)
            flag = 1
            break

if flag == 0:
    print("-1 -1 -1")


### FIXED CODE ###

N, Y = map(int, input().split())
flag = 0
for num_so in range(N+1):
    if flag == 1:
        break
    for num_fs in range(N+1):
        num_ts = N - num_so - num_fs
        sum = num_ts * 10000 + num_fs * 5000 + num_so * 1000
        if flag == 1:
            break
        elif sum == Y and num_ts >= 0:
            print(num_ts, num_fs, num_so)
            flag = 1
            break

if flag == 0:
    print("-1 -1 -1")
4
1 4 6 3

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
print(max(a)-min(a))
import math
print(math.floor(math.sqrt(int(input())))


### FIXED CODE ###

import math
print(math.floor(math.sqrt(int(input())))**2)
from collections import deque

h, w = list(map(int, input().split()))

s = [list(input()) for _ in range(h)]

y = [[0] * w for _ in range(h)]
q = deque([])
c = 0

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            q.append((i, j))
            c += 1
        
        if s[i][j] == "#" or j == w-1:
            while len(q) > 0:
                x, y = q.pop()
                y[x][y] = c
            c = 0



m = 0

c = 0
for j in range(w):
    for i in range(h):
        if s[i][j] == ".":
            q.append((i, j))
            c += 1

        if s[i][j] == "#" or i == h-1:
            while len(q) > 0:
                x, y = q.pop()
                m = max(m, y[x][y] + c - 1)
            c = 0
print(m)


### FIXED CODE ###

from collections import deque

h, w = list(map(int, input().split()))

s = [list(input()) for _ in range(h)]

yo = [[0] * w for _ in range(h)]
q = deque([])
c = 0

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            q.append((i, j))
            c += 1
        
        if s[i][j] == "#" or j == w-1:
            while len(q) > 0:
                x, y = q.pop()
                yo[x][y] = c
            c = 0



m = 0

c = 0
for j in range(w):
    for i in range(h):
        if s[i][j] == ".":
            q.append((i, j))
            c += 1

        if s[i][j] == "#" or i == h-1:
            while len(q) > 0:
                x, y = q.pop()
                m = max(m, yo[x][y] + c - 1)
            c = 0
print(m)
while True:
	n = int(raw_input())
	for i in [raw_input().replace("Hoshino", "Hoshina") for i in range(n)]:
		print i
	 

### FIXED CODE ###

n = int(raw_input())
for i in [raw_input().replace("Hoshino", "Hoshina") for i in range(n)]:
	print i
def gcd(t):
    try:
        b,a=sorted(t)
        while True:
            m=a%b
            if m==0:
                return b
            a=b;b=m
    except:
        return 1

a,b,k=(int(x) for x in input().split())
g=gcd((a,b))
cd=[]
i=g
while True:
    try:
        if g%i==0:
            cd.append(i)
            i=i//2
            if i==0:
                break
        else:
            i-=1
    except:
        break
print(cd[k-1])

### FIXED CODE ###

def gcd(t):
    b,a=sorted(t)
    while True:
        m=a%b
        if m==0:
            return b
        a=b;b=m
a,b,k=(int(x) for x in input().split())
g=gcd((a,b))
cd=[]
for i in range(g+1)[::-1]:
    if i==0:
        break
    if g%i==0:
        cd.append(i)
print(cd[k-1])
if c < 2 * s:
  print(c // 2)
else:
  c -= 2 * s
  print(s + c // 4)

### FIXED CODE ###

s, c = map(int, input().split())

if c < 2 * s:
  print(c // 2)
else:
  c -= 2 * s
  print(s + c // 4)
a, b, c = int(intput())
if(a=b||a=c||b=c):
  return yes
elif(a=b=c):
  return no
else: 
  return no

### FIXED CODE ###

numbers = map(int, input().split())
print("Yes") if len(set(numbers)) == 2 else print("No")
input_lines = sys.stdin.read()

[H W] = input_lines[0].split()
[h w] = input_lines[1].split()

ans = H*W-h*W-H*w+h*w
print(ans)

### FIXED CODE ###

H,W = map(int, input().split())
h,w = map(int, input().split())

ans = H*W-h*W-H*w+h*w
print(ans)
M = int(input())
CD = C = 0
for i in range(M):
  d, c = map(int, input().split())
  CD += c * d
  C += c
print(C - 1 + (CD - 1) // 9)


### FIXED CODE ###

X, Y = map(int, input().split())
r = 0
if(X == 1):
  r += 300000
elif(X == 2):
  r += 200000
elif(X == 3):
  r += 100000
else:
  pass

if(Y == 1):
  r += 300000
elif(Y == 2):
  r += 200000
elif(Y == 3):
  r += 100000
else:
  pass

if(X == Y == 1):
  r += 400000

print(r)
from collections import deque
N = int(input())
G = {i:[] for i in range(1,N+1)}
for _ in range(N-1):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
C = sorted(list(map(int,input().split())))
hist = [0 for _ in range(N+1)]
que = deque([1])
hist[1] = 1
cur = 0
while que:
    i = que.popleft()
    if len(G[i])==1:
        A[i] = C[cur]
        cur += 1
        hist[i] = 2
    flag = 2
    for j in G[i]:
        if hist[j]==0:
            que.append(j)
            hist[j] = 1
            flag = 1
    if flag==2 and hist[i]==1:
        A[i] = C[cur]
        cur += 1
        hist[i] = 2
    elif hist[i]==1:
        que.append(i)
cnt = 0
hist = {(i,j):0 for i in range(1,N+1) for j in G[i]}
for i in range(1,N+1):
    for j in G[i]:
        if hist[(i,j)]==0:
            cnt += min(A[i],A[j])
            hist[(i,j)] = 1
            hist[(j,i)] = 1
print(cnt)

### FIXED CODE ###

from collections import deque
N = int(input())
G = {i:[] for i in range(1,N+1)}
for _ in range(N-1):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
C = sorted(list(map(int,input().split())))
A = [0 for _ in range(N+1)]
hist = [0 for _ in range(N+1)]
que = deque([1])
hist[1] = 1
cur = 0
while que:
    i = que[-1]
    if len(G[i])==1:
        A[i] = C[cur]
        cur += 1
        hist[i] = 2
        que.pop()
    flag = 2
    for j in G[i]:
        if hist[j]==0:
            que.append(j)
            hist[j] = 1
            flag = 1
    if flag==2 and hist[i]==1:
        A[i] = C[cur]
        cur += 1
        hist[i] = 2
        que.pop()
cnt = 0
hist = {(i,j):0 for i in range(1,N+1) for j in G[i]}
for i in range(1,N+1):
    for j in G[i]:
        if hist[(i,j)]==0:
            cnt += min(A[i],A[j])
            hist[(i,j)] = 1
            hist[(j,i)] = 1
print(cnt)
print(*A[1:])
import math

n = int(input())
arr = [int(x) for x in input().split()]

isAllEven = len([x for x in arr if x % 2 == 0]) == n

if not isAllEven:
   print(0)
   exit()

arr.sort()
print(math.log2(arr[0]))


### FIXED CODE ###

def count(lst, x):
   ctr = 0
   for i in lst:
      if i == x:
         ctr += 1
   return ctr

s = [x for x in input()]
print(count(s, "1"))
import heapq

n,k=map(int,input().split())
v=list(map(int,input().split()))
s=-10**7-1
for l in range(k//2+1):
    for i in range(k+1-l):
        d=v[:i]
        d.extend(v[(n-k+l+i):])
        heap=heapq.heapify(d)
        res=sum(d)
        for j in range(l):
            t=heapq.heappop(d)
            if t<0:
                res-=t
        if s<res:
            s=res
if s<0:
    print(0)
else:
    print(s)
       

### FIXED CODE ###

import heapq

n,k=map(int,input().split())
v=list(map(int,input().split()))
s=-10**7-1

if n>k:
    for l in range(k//2+1):
        for i in range(k+1-l):
            d=v[:i]
            d.extend(v[(n-k+l+i):])
            heap=heapq.heapify(d)
            res=sum(d)
            for j in range(l):
                t=heapq.heappop(d)
                if t<0:
                    res-=t
                else:
                    break
            if s<res:
                s=res
else:
    for l in range(n+1):
        for i in range(n-l+1):
            d=v[:i]
            d.extend(v[(l+i):])
            heap=heapq.heapify(d)
            res=sum(d)
            for j in range(k-(n-l)):
                if not d:
                    break
                t=heapq.heappop(d)
                if t<0:
                    res-=t
                else:
                    break
            if s<res:
                s=res

        
if s<0:
    print(0)
else:
    print(s)
k,n=map(int, input().split())
a=list(map(int, input().split()))

max_distance = k - a[-1] - a[0]
str_index = 0
gl_index = -1
for i in range(n):
   	if i == 0:
        continue
    elif max_distance < abs(a[i-1] - a[i]):
        max_distance = abs(a[i-1] - a[i])
        str_index = i-1
        gl_index = i
print(a[str_index] + (k - a[gl_index]))

### FIXED CODE ###

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

max_distance = abs(k - a[-1] + a[0])
str_index = 0
gl_index = -1
for i in range(n):
    if i == 0:
        continue
    elif max_distance < abs(a[i-1] - a[i]):
        max_distance = abs(a[i-1] - a[i])
        str_index = i-1
        gl_index = i
if gl_index == -1:
    print(a[gl_index] - a[str_index])
else:
    print(a[str_index] + (k - a[gl_index]))
N=int(input())
A=map(int, input())
sortedA=sorted(A, reverse=True)
Bob=0
Alice=0
for i in range(len(A)):
  # print(i)
  if i == 0 or i%2==0:
    Alice+=sortedA[i]
  else:
    Bob +=sortedA[i]
print(Alice-Bob)


### FIXED CODE ###

N=int(input())
A=list(map(int, input().split()))
sortedA=sorted(A, reverse=True)
Bob=0
Alice=0
for i in range(len(A)):
  # print(i)
  if i == 0 or i%2==0:
    Alice+=sortedA[i]
  else:
    Bob +=sortedA[i]
print(Alice-Bob)
N = int(input())
A = int(input())
B = int(input())

i = 0
for k in range(N +1):
    if A <= sum( [int(s) for s in str(k)] ) <= B:
        i = i+1
print(i)

### FIXED CODE ###

A,B,C,D = map(int,input().split())
E = A+B
F = C+D
if E > F:
  print("Left")
elif E == F:
  print("Balanced")
else:
  print("Right")
from bisect import bisect


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    L = [A[0]]
    for a in A[1:]:
        if a <= L[-1]:
            L.append(a)
        else:
            i = bisect(L, a)
            L[i] = a
    print(len(L))

    

if __name__ == "__main__":
    main()


### FIXED CODE ###

from bisect import bisect


def main():
    N = int(input())
    A = [-int(input()) for _ in range(N)]
    L = [A[0]]
    for a in A[1:]:
        if a >= L[-1]:
            L.append(a)
        else:
            L[bisect(L, a)] = a
    print(len(L))


if __name__ == "__main__":
    main()