Harryxun/stf_run huggingface dataset:
n, k = map(int, input().split())
d = list(map(int, input().split()))

def is_ok(num):
  s = str(num)
  for ng in d:
    if ng in s: return False
  
  return True

while True:
  if is_ok(n):
    print(n)
    exit()
  
  n += 1
  

### FIXED CODE ###

n, k = map(int, input().split())
d = input().split()

def is_ok(num):
  s = str(num)
  for ng in d:
    if ng in s: return False
  
  return True

while True:
  if is_ok(n):
    print(n)
    exit()
  
  n += 1
IN = iter(Input.split('\n')).__next__
def input():
    return IN()


#######以下コード##############################





N = int(input())
S = list(input() for _ in range(N))

ac = 0
wa = 0
tle = 0
re = 0

for s in S:
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    elif s == "RE":
        re += 1

print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)

### FIXED CODE ###

N = int(input())
S = list(input() for _ in range(N))

ac = 0
wa = 0
tle = 0
re = 0

for s in S:
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    elif s == "RE":
        re += 1

print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)
in_str = input().split(" ")
in_int = int(in_str)
result = in_int[0]*in_int[1]
print(result)

### FIXED CODE ###

in_str = input().split(" ")
a, b = int(in_str[0]), int(in_str[1])
result = a*b
print(result)
import numpy as np

N, M = map(int, input().split())
num_dict = dict()
A_list = []

for n in range(N):
  A, B = map(int, input().split())
  num_dict[A] = B
  A_list.append(A)

A_list.sort()
b_accum = 0
all_pay = 0

for a in A_list:
  if M <= b_accum:
    break

  if b_accum + num_dict[a] <= M:
    all_pay += num_dict[a] * a
    b_accum += num_dict[a]
    
    if M == b_accum:
		
  
  else:
    all_pay += (M - b_accum) * a 
    b_accum += num_dict[a]
    
print(all_pay)

 

### FIXED CODE ###

import numpy as np

N, M = map(int, input().split())
num_dict = dict()
A_list = []
B_list = []

for n in range(N):
  A, B = map(int, input().split())
  num_dict.setdefault(A, 0)
  num_dict[A] += B
  A_list.append(A)

A_list = list(set(A_list))
A_list.sort()
b_accum = 0
all_pay = 0

for a in A_list:
  if M <= b_accum:
    break

  if b_accum + num_dict[a] <= M:
    all_pay += num_dict[a] * a
    b_accum += num_dict[a]    
  
  else:
    all_pay += (M - b_accum) * a 
    b_accum += num_dict[a]
    break
    
print(all_pay)
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func ini() {
	var buf = make([]byte, 10000)
	sc.Buffer(buf, 1000000)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	ini()
	line1 := nextLine()
	NK := strings.Split(line1, " ")
	N, _ := strconv.Atoi(NK[0])
	K, _ := strconv.Atoi(NK[1])
	S := nextLine()
	l := make([]int, 0)
	if string(S[0]) == "0" {
		l = append(l, 0)
	}
	for i := 0; i < N; {
		j := i
		for j < N && S[j] == S[i] {
			j++
		}
		l = append(l, j-i)
		i = j
	}
	if string(S[N-1]) == "0" {
		l = append(l, 0)
	}

	sums := make([]int, len(l)+1)
	for i := 0; i < len(l); i++ {
		sums[i+1] = sums[i] + l[i]
	}
	ans := 0
	for left := 0; left < len(sums); left += 2 {
		right := left + 2*K + 1
		if right >= len(sums) {
			right = len(sums) - 1
		}
		ans = max(ans, sums[right]-sums[left])
	}
	fmt.Println(ans)
}


### FIXED CODE ###

from itertools import accumulate
N, K = map(int, input().split())
S = input()
nums = []
if S[0] == '0':
    nums.append(0)
i = 0
while i < N:
    j = i
    while j < N and S[i] == S[j]:
        j += 1
    nums.append(j - i)
    i = j
if S[-1] == '0':
    nums.append(0)

sums = [0] * (len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
ans = 0
left = 0
while left < len(nums):
    right = left + 2 * K + 1
    if right > len(sums):
        right = len(sums) - 1
    ans = max(ans, sums[right]-sums[left])
    left += 2

print(ans)
a,b=float(input().split())
ans=int(a*b+0.00001)
print(ans)

### FIXED CODE ###

a,b=input().split()
a=int(a)
b=int(b.replace(".",""))
print(a*b//100)
s = input()
t = input()
cnt = 0
for i in range(3):
  if(s[i]==t[i]):
    cnt += 1
prirnt(cnt)

### FIXED CODE ###

s = input()
t = input()
cnt = 0
for i in range(3):
  if(s[i]==t[i]):
    cnt += 1
print(cnt)
n,k = map(int,input().split())
mod = 10**9+7

dp = [[0]*n for i in range(k+1)]
dp[0][0] = 1

for i in range(1,k+1):
    for j in range(1,i+1):
        dp[i][j] = ((dp[i-1][j]*(i+j-1)+dp[i-1][j-1]*(n-k-j+2))//i)%mod

for i in range(1,k+1):
    print(dp[-1][i])

### FIXED CODE ###

n,k = map(int,input().split())
mod = 10**9+7

dp = [[0]*(k+1) for i in range(k+1)]
dp[0][0] = 1

for i in range(1,k+1):
    for j in range(1,i+1):
        dp[i][j] = (dp[i-1][j]*(i+j-1)+dp[i-1][j-1]*(n-k-j+2))//i

for i in range(1,k+1):
    print(dp[-1][i]%mod)
a, b = input().split()
a = int(a)
b = b[0] + b[2:]
print(a*b//100)


### FIXED CODE ###

a, b = input().split()
a = int(a)
b = int(b[0] + b[2:])
print(a*b//100)
N, X = map(int, input().split())
L = [int(i) for i in input().split()]
step = 0
i = 0

while step <= X and i <= N+1:
    step += L[i]
    i += 1
    #print(step)

print(i)

### FIXED CODE ###

N, X = map(int, input().split())
L = [int(i) for i in input().split()]
step = [0]
nowstep = 0
ans = 0
i = 0

while i < N:
    step.append(nowstep + L[i])
    nowstep += L[i] 
    i += 1

for i in range(len(step)):
    if step[i] <= X:
        ans += 1
    else:
        pass

print(ans)
a,b,c,d=input().split( )
line[n]
x=int(b)
y=int(d)
print(x*y)

### FIXED CODE ###

a,b,c,d=map(int,input().split( ))
print(max(a*d,b*c,a*c,b*d))
s = int(input())
a = list(map(int, input().split()))

incFlg = True   #登る場合はTure,　降る場合はFalse
before_height = 0
sum = 0

for i in range(len(a)-1):
    #降る場合
    if a[i] > a[i+1]:
        #その前が登り
        if incFlg:
            sum += a[i] - before_height
            incFlg = False
        #その前が下り
        else:
            # before_height = a[i]
    #登る場合
    else:
        if not incFlg:
            before_height = a[i]
        incFlg = True

if incFlg:
    sum += a[len(a)-1] - before_height

print(sum)


### FIXED CODE ###

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

incFlg = True   #登る場合はTure,　降る場合はFalse
before_height = 0
sum = 0

for i in range(len(a)-1):
    #降る場合
    if a[i] > a[i+1]:
        #その前が登り
        if incFlg:
            sum += a[i] - before_height
            incFlg = False
        #その前が下り
        else:
            before_height = a[i]
    #登る場合
    else:
        if not incFlg:
            before_height = a[i]
        incFlg = True

if incFlg:
    sum += a[len(a)-1] - before_height

print(sum)
a,b,c = list(map(int,input().split()))
print(sum(a) - max(a))


### FIXED CODE ###

a = list(map(int,input().split()))
print(sum(a) - max(a))
r = float(input())

s = r*r*pi
x = 2*r*pi

print("{} {}".format(s,x))



### FIXED CODE ###

import math
pi = math.pi
r = float(input())

s = r*r*pi
x = 2*r*pi

print("{} {}".format(s,x))
a, b, c = map(int, input().split())
if (b − a == c − b):
  print('YES')
else:
  print('NO')


### FIXED CODE ###

a, b, c = map(int, input().split())
d = b - a
e = c - b
if (d == e):
  print('YES')
else:
  print('NO')
X = int(input())
t = int(input())

print(max(X - t, 0))


### FIXED CODE ###

X ,t=map(int,input().split())

if X-t>0:
    print(X-t)
else:
    print(0)
a, b = map(int, input().split())

for c in range(1,4) :
    if (a*b*c)%2 == 1 :
        print("Yes")
        sys.exit()

print("No")

### FIXED CODE ###

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

if (a%2 == 1 ) and (b%2 == 1 ) :
    print("Yes")
else :
    print("No")
from collections import Counter
[N, X, Y] = [int(item) for item in input().split()]
X -= 1
Y -= 1
gyoretu=[]
for i in range(N):
    row=[]
    for j in range(N):
        if i == j:
            row.append(0)
        elif abs(i - j) == 1 or i == X and j == Y or i == Y and j == X:
            row.append(1)
        else:
            row.append(2000)
    gyoretu.append(row)
for k in range(N):
    for i in range(N):
        for j in range(N):
            gyoretu[i][j] = min([gyoretu[i][j], gyoretu[i][k] + gyoretu[k][j]])
array=[]
for i in range(N):
        array+=gyoretu[i][i:]
c=Counter(array)
for i in range(1, N):
    print(c[i])

### FIXED CODE ###

s=input()
if s[2]==s[3] and s[4]==s[5]:print("Yes")
else :print("No")
s = str(input())
t = str(input())
lst = []
i= 0
flg = 1
for _ in range(len(s)):
    if s[_] == t[i] or s[_] == '?':
        i += 1       
    else:   
        i = 0
    if i == len(t):
      pt = _ - i + 1    
      s = s.replace(s[pt:_ + 1],t)
      lst.append(s)

if lst:
  lst = [_.replace('?','a') for _ in lst]
  sorted(lst)
  print(lst[0])

else:
  print('UNRESTORABLE')

### FIXED CODE ###

s = str(input())
t = str(input())
lst = []
i= 0
for ss in range(len(s)-len(t)+1):
  flg = 1
  i= 0
  for tt in range(len(t)):
    now = ss + tt
    if s[now] == t[tt] or s[now] == '?':
      pass
    else:
      flg = 0
  if flg:
    ns = list(s)
    ns[ss:now+1] = list(t)
    lst.append(("").join(ns))
if lst:
  lst = [_.replace('?','a') for _ in lst]
  lst.sort()
  print(lst[0])

else:
  print('UNRESTORABLE')
if x==0:
  return 1
else:
  return 0

### FIXED CODE ###

x=int(input())

if x==0:
  print(1)
elif x==1:
  print(0)
s, t = map(input().split())
print(s+t)

### FIXED CODE ###

s, t = input().split()
print(t+s)
n,a,b=map(int,input().split())

def combination(n,x,mod):
    bunbo=1
    bunshi=1
    for i in range(x):
        bunbo*=n-i
        bunshi*=i
        buubo=bunbo%mod
        bunshi=bunshi%mod
    return (bunshi//bunshi)%mod

mod=1000000007
answer=2**n-1
answer-=combination(n,a,mod)
answer-=combination(n,b,mod)
answer=answer%mod
print(answer)


### FIXED CODE ###

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

def combination(n, a, mod):
    bunbo = 1
    bunshi = 1
    for i in range(a):
        bunshi *= n-i
        bunshi = bunshi%mod
        bunbo *= a-i
        bunbo = bunbo%mod
        
    return bunshi*pow(bunbo, mod-2, mod)%mod
        
        
mod = 1000000007
answer = pow(2, n, mod)
answer -= 1
answer -= combination(n, a, mod)
answer -= combination(n, b, mod)
print(answer%mod)
N = int(input)

def luca(N):
  if N>=2:
    return luca(N-2)+luca(N-1)
  if N==1:
    return 1
  if N==0:
    return 2
  
print(luca(N))

### FIXED CODE ###

from functools import lru_cache

N = int(input())

@lru_cache(maxsize=None)
def luca(N):
  if N>=2:
    return luca(N-2)+luca(N-1)
  if N==1:
    return 1
  if N==0:
    return 2
  
print(luca(N))
n = int(input())
a = list(map(int,input().split()))
if(0 in a):
  print(0)
else:
  a.sort()
  ans = 1
 
  for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
      ans = -1
      break
	print(ans)

### FIXED CODE ###

t = int(input())
list_v = list(map(int,input().split()))
 
res = 1
if 0 in list_v:
  res = 0
else:
  for v in list_v:
    res *= v
    if res > 10**18:
      res = -1
      break
print(res)
# -*- coding: utf-8 -*-

N, K = map(int, input().split())
x = abs(N-K)

remainder = K % x if K >= x else x % K
  
if remainder > x // 2:
  print(abs(remainder - x))
else:
  print(remainder)

### FIXED CODE ###

# -*- coding: utf-8 -*-

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

remainder = N % K

if remainder > K / 2:
  print(abs(remainder - K))
else:
  print(remainder)
N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
count=0
if sum(A)<sum(B):
    print(-1)
else:
    dif=[A[i]-B[i] for i in range(N)]
    if min(dif)>=0:
        print(0)
    else:
        difsort=sorted(dif)
        pluslist=[i for i in difsort if i>=0][::-1]
        minlist=[i for i in difsort if i<0]
        minum=len(minlist)
        absum=abs(sum(minlist))
        sumlist=[sum(pluslist[0:i+1]) for i in range(len(pluslist)-1)]
        while sumlist[count]<absum:
            count+=1
        
        print(count+1+minum)

### FIXED CODE ###

N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
count=0
if sum(A)<sum(B):
    print(-1)
else:
    dif=[A[i]-B[i] for i in range(N)]
    if min(dif)>=0:
        print(0)
    else:
        difsort=sorted(dif)
        plist=[i for i in difsort if i>=0][::-1]
        mlist=[i for i in difsort if i<0]
        mnum=len(mlist)
        msum=sum(mlist)
        for i in range(len(plist)):
            if msum>=0:
                break
            msum+=plist[i]
            count+=1
            
        
        print(count+mnum)
n, k = map(int, input().split())
h = list(map(int, input().split()))
hL = [0]*(n**5)
for i in range(n):
    hL[i] = h[i]

dp = [10**10]*(n**5)
dp[0] = 0
for i in range(0,n):
    for j in range(1,k+1):
        dp[i+j] = min(dp[i+j], dp[i]+abs(hL[i+j]-hL[i]))

print(dp[n-1])


### FIXED CODE ###

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

dp = [10**10]*(n)
dp[0] = 0
for i in range(0,n):
    if i+k<=n-1:
        for j in range(1,k+1):
            dp[i+j] = min(dp[i+j], dp[i]+abs(hL[i+j]-hL[i]))
    else:
        for j in range(1, n-i):
            dp[i+j] = min(dp[i+j], dp[i]+abs(hL[i+j]-hL[i]))

print(dp[n-1])
import numpy as np
from scipy.sparse.csgraph import dijkstra
from collections import defaultdict

import sys
input = sys.stdin.readline

[H,W]= [int(x) for x in input().split()]
c=np.array([[int(x) for x in input().split()] for _ in range(10)])

A=[]
for _ in range(H):
  A+=[int(x) for x in input().split()] 

dd = defaultdict(int)
for key in A:
  if key!=1 and key!=-1:
    dd[key] += 1

res=0
for k, v in dd.items():
  res+= v*int(dijkstra(c,indices = k)[1])
print(res)

### FIXED CODE ###

s=input()
if s[1]==s[2] and (s[0]==s[1] or s[2]==s[3]):
  print("Yes") 
else:
  print("No")
a, b, c = map(int, input().split())

if (a + b == c) or (a + c == b) or (b + c ==a):
  print(Yes)
else:
  print(No)

### FIXED CODE ###

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

if (a + b == c) or (a + c == b) or (b + c ==a):
  print('Yes')
else:
  print('No')
N, K = map(int, input().split())
sweet = [0 for i in range(N)]
for i in range(K):
  input()
  for j in map(int, input().split()):
    sweet[j] = 1
cnt = 0
for k in sweet:
  if k == 0:
    cnt += 1
print(cnt)

### FIXED CODE ###

N, K = map(int, input().split())
sweet = [0 for i in range(N)]
for i in range(K):
  s = input()
  for j in map(int, input().split()):
    sweet[j-1] = 1
cnt = 0
for k in sweet:
  if k == 0:
    cnt += 1
print(cnt)
s = int(input())

print(chr(ord('s')+1))

### FIXED CODE ###

C = str(input())

print(chr(ord(C)+1))
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
a = list(map(int, readline().split()))
roop = 0
dict = [False] * n
now = a[0]
for i in range(n + 1):
    if i + 1 == k:
        print(a[now - 1])
        exit()
    now = a[now - 1]
    if dict[now - 1]:
        k -= (i + 1)
        dict = [False] * n
        dict[now - 1] = True
        check = a[now - 1]
        for j in range(n + 1):
            print(dict)
            now = a[now - 1]
            if dict[now - 1]:
                k %= (j + 1)
                k += 1
                break
            else:
                dict[now - 1] = True
        break
    else:
        dict[now - 1] = True
now = check
for i in range(k):
    now = a[now - 1]
print(now)


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
a = list(map(int, readline().split()))
dict = [-1] * (n + 1)
now = a[0]
dict[0] = 0
for i in range(1, n * 2):
    if i == k:
        print(now)
        exit()
    now = a[now - 1]
    if dict[now] != -1:
        k -= (i + 1)
        k %= (i - dict[now])
        break
    else:
        dict[now] = i
for i in range(k):
    now = a[now - 1]
print(now)
n=input()
m=input()

print(n+m)

### FIXED CODE ###

n,m=map(int,input().split())
 
print(n*(n-1)//2+m*(m-1)//2)
D = [10**9+7]*(10**6+1)
L = [True]*(10**6+1)
L[0] = False
L[1] = False
D[1] = 1
for i in range(2, 10**6+1):
    if L[i]:
        D[i] = i
        for j in range(i*2, 10**6+1, i):
            L[j] = False
            D[j] = min(i, D[j])


def egcd(a, b):
    if a == 0:
        return b
    else:
        g = egcd(b % a, a)
        return g


def factorization(n):
    if n == 1:
        return {1}
    ans = set()
    ans.add(D[n])
    factorization(n//D[n])
    return ans


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

s = set(factorization(A[0])-{1})
for i in range(1, N):
    tmp = factorization(A[i])-{1}
    if tmp & s != set():
        break
    s |= tmp
    print(s)
else:
    print('pairwise coprime')
    exit()

L1 = A
while len(L1) > 1:
    l = len(L1)//2
    k = [0]*l
    for i in range(l):
        k[i] = egcd(L1[2*i], L1[2*i+1])
    if len(L1) % 2 == 1:
        k.append(L1[-1])
    L1 = k
    print(k)

if L1[0] == 1:
    print('setwise coprime')
else:
    print('not coprime')

### FIXED CODE ###

INF=10**9+7
D = [INF]*(10**6+1)
L = [True]*(10**6+1)
L[0] = False
L[1] = False
D[1] = 1
for i in range(2, 10**6+1):
    if L[i]:
        D[i] = i
        for j in range(i*2, 10**6+1, i):
            L[j] = False
            D[j] = min(i, D[j])
# print(D[:101])


def egcd(a, b):
    if a == 0:
        return b
    else:
        g = egcd(b % a, a)
        return g


def factorization(n):
    ans = set()
    if n == 1:
        ans.add(1)
        return ans
    while n>1:
        ans.add(D[n])
        n//=D[n]
    return ans


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

s = set(factorization(A[0])-{1})
for i in range(1, N):
    tmp = factorization(A[i])-{1}
    if tmp & s != set():
        break
    s |= tmp
else:
    print('pairwise coprime')
    exit()

L1 = A
while len(L1) > 1:
    l = len(L1)//2
    k = [0]*l
    for i in range(l):
        k[i] = egcd(L1[2*i], L1[2*i+1])
    if len(L1) % 2 == 1:
        k.append(L1[-1])
    L1 = k

if L1[0] == 1:
    print('setwise coprime')
else:
    print('not coprime')
N=int(input())
E=[[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  E[a-1].append((b-1,i))
ans=[[] for _ in range(N-1)]
def sub(p, n):
  m=1
  for b,i in E[p]:
    if m == n: m+=1
    ans[i]=m
    sub(b,m)
    m+=1
sub(0,0)
print(max(ans))
print(*ans, sep="\n")

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

N=int(input())
E=[[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  E[a-1].append((b-1,i))
ans=[[] for _ in range(N-1)]
def sub(p, n):
  m=1
  for b,i in E[p]:
    if m == n: m+=1
    ans[i]=m
    sub(b,m)
    m+=1
sub(0,0)
print(max(ans))
for a in ans:
  print(a)
import sys

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

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

for j in range(N):
    if (H[j] > H[i+1]):
        print('No')
        sys.exit()
        
print('Yes')

### FIXED CODE ###


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

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

for j in range(N-1):
    if (H[j] > H[j+1]):
        print('No')
        exit()

print('Yes')
res = False
for row in a:
    if all(num in b for num in row):
        res = True
for col in zip(a):
    if all(num in b for num in col):
        res = True
if all(a[i][i] in b for i range(3)):
        res = True
if all(a[i][2 - i] in b for i range(3)):
        res = True


print("Yes" if res else("No"))

### FIXED CODE ###

a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]

Size = 3
bingo = False
for row in a:
    if all(item in b for item in row):
        bingo = True
for col in zip(*a):
    if all(item in b for item in col):
        bingo = True
if all(a[i][i] in b for i in range(Size)):
    bingo = True
if all(a[i][Size - 1 - i] in b for i in range(Size)):
    bingo = True
 
print("Yes" if bingo else "No")
S = list(map(int,input().split()))
p=len(S)
t=0
for n in range(p):
  if S[n]!=S[p-n-1]:
    t+=1
print(t/2)


### FIXED CODE ###

S = input()
p=len(S)
t=0
for n in range(p):
  if S[n]!=S[p-n-1]:
    t+=1
print(int(t/2))
import heapq

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

ad = {}
for i, a in enumerate(alist):
  ad[a] = i

h = []
right = [n-1] * n

for i in range(n):
  while h and -h[0] > alist[i]:
    v = -heapq.heappop(h)
    right[ad[v]] = i - 1
  heapq.heappush(h, -alist[i])
  print(right, h)

h = []
left = [0] * n

for i in reversed(range(n)):
  while h and -h[0] > alist[i]:
    v = -heapq.heappop(h)
    left[ad[v]] = i + 1
  heapq.heappush(h, -alist[i])
  print(left, h)

ans = 0
for i in range(n):
  ans += alist[i] * (i - left[i] + 1) * (right[i] - i + 1)
  print(ans)

print(ans)


### FIXED CODE ###

import heapq

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

ad = {}
for i, a in enumerate(alist):
  ad[a] = i

h = []
right = [n-1] * n

for i in range(n):
  while h and -h[0] > alist[i]:
    v = -heapq.heappop(h)
    right[ad[v]] = i - 1
  heapq.heappush(h, -alist[i])

h = []
left = [0] * n

for i in reversed(range(n)):
  while h and -h[0] > alist[i]:
    v = -heapq.heappop(h)
    left[ad[v]] = i + 1
  heapq.heappush(h, -alist[i])

ans = 0
for i in range(n):
  ans += alist[i] * (i - left[i] + 1) * (right[i] - i + 1)

print(ans)
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
a = []
for i in range(1,101):
    if i not in p:
        a.append(i)

m = []
for i in range(len(a)):
    m.append(abs(a[i] - x))

miner = min(m)
res = []
for i in a:
    if abs(x - i) == miner:
        res.append(i)

print(min(res))

### FIXED CODE ###

x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
a = []
for i in range(-2,102):
    if i not in p:
        a.append(i)

m = []
for i in range(len(a)):
    m.append(abs(a[i] - x))

miner = min(m)
res = []
for i in a:
    if abs(x - i) == miner:
        res.append(i)

print(min(res))
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
s=0
i=0
while s<x:
  s+=a[i]
  i+=1
print(i+1)

### FIXED CODE ###

n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
for i in range(n):
  x=x-a[i]
  if x<0:
    break
if i==n-1 and x==0:
  i+=1
print(i)
n, k = [int(i) for i in input().split()]
m = sorted([[int(i) for i in input().split()] for _ in range(n)]

s=0
i=0
while s<k:
    s += m[i][1]
    i += 1
print(m[i-1][0])

### FIXED CODE ###

n, k = [int(i) for i in input().split()]
m = sorted([[int(i) for i in input().split()] for _ in range(n)])

s=0
i=0
while s<k:
    s += m[i][1]
    i += 1
print(m[i-1][0])
a = int(input())
b,c = map(int, input().split())
s = input()
print("{} {}".format(a+b+c, s))

### FIXED CODE ###

r = int(input())
print(r*r)
ax, at = map(int, input().split(' '))
bx, bt = map(int, input().split(' '))
t = int(input())
 
a_l = ax + at*t
b_l = bx + bt*t
 
if a_l < b_l and a == b:
	print("NO")
else:
	print("YES")


### FIXED CODE ###

x1, v1 = map(int, input().split(' '))
x2, v2 = map(int, input().split(' '))
t = int(input())

p = abs(x2 - x1)
q = (v1 - v2) * t
if p <= q:
	print("YES")
else:
	print("NO")
s={}
for i in range(3):
    s[chr(97+i)]=input()
turn="a"
while True:
    if not s[turn]:
        break
    else:
        turn=s[turn[0]]
        s[turn]=s[turn][1:]
print(turn.upper())


### FIXED CODE ###

s={}
for i in range(3):
    s[chr(97+i)]=input()
turn="a"
while True:
    if not s[turn]:
        break
    else:
        t=s[turn][0]
        s[turn]=s[turn][1:]
        turn=t
print(turn.upper())
N = int(input())
A = int(input())
B = int(input())
if N == 1:
  print("Hello World")
else:
  print(A+B)

### FIXED CODE ###

N = int(input())
if N == 1:
  print("Hello World")
else:
  A = int(input())
  B = int(input())
  print(A+B)
N = int(input())
p = list(map(int, input().split()))

count = 0
now = 0
for i in range(len(p)):
    if len(p) == 0:
        break
    if now+1 == p[0]:
        p.pop(0)
        count += 1
        now += 1
    p.pop(0)
    now += 1
print(count)


### FIXED CODE ###

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

count = 0
now = 0
for i in range(len(p)):
    if len(p) == 0:
        break
    if now+1 == p[0]:
        p.pop(0)
        count += 1
        now += 1
    if len(p) == 0:
        break
    p.pop(0)
    now += 1
print(count)