Harryxun/stf_run huggingface dataset:
import sys
def SI(): return sys.stdin.readline().strip()

def main():
    s = SI()
    t = SI()

    import collections
    didx = collections.defaultdict(int)
    d = collections.defaultdict(list)
    for i, c in enumerate(s):
        d[c].append(i)


    # keys = d.keys()
    # for c in set(t):
    #     if c not in keys:
    #         print(-1)
    #         return

    import bisect

    i_loop = 0
    currentidx = -1
    for c in t:
        # 次の文字を読む
        poslist = d[c]

        if len(poslist) <= didx[c]:
            # 文字を取り切っている場合は次のループに
            i_loop += 1
            didx = collections.defaultdict(int)
            currentidx = poslist[0]
            didx[c] += 1
        else:
            # とり切っていない場合
            poslist_afteridx = poslist[didx[c]:]
            posidx = bisect.bisect_right(poslist_afteridx, currentidx)

            if posidx >= len(poslist_afteridx):
                # とれないなら次のループでとったことにする
                i_loop += 1
                didx = collections.defaultdict(int)
                currentidx = poslist[0]
                didx[c] += 1
            else:
                # 同じループでとれるなら取って、現在位置を更新
                pos = poslist_afteridx[posidx]
                currentidx = pos
                didx[c] = posidx + 1

    print(len(s)*i_loop + currentidx + 1)

main()

### FIXED CODE ###

import sys
def SI(): return sys.stdin.readline().strip()

def main():
    s = SI()
    t = SI()

    import collections
    d = collections.defaultdict(list)
    for i, c in enumerate(s):
        d[c].append(i)

    keys = d.keys()
    for c in set(t):
        if c not in keys:
            print(-1)
            return

    import bisect

    i_loop = 0
    currentidx = -1
    for c in t:
        # 次の文字を読む
        poslist = d[c]

        # とり切っていない場合
        posidx = bisect.bisect_right(poslist, currentidx)

        if posidx >= len(poslist):
            # とれないなら次のループでとったことにする
            i_loop += 1
            currentidx = poslist[0]
        else:
            # 同じループでとれるなら取って、現在位置を更新
            pos = poslist[posidx]
            currentidx = pos

    print(len(s)*i_loop + currentidx + 1)

main()
Y, M, D = map(int, input().split("/"))
s = ''.join([Y,M,D])

if int(s)>20190430:
    print("TBD")
else:
    print("Heisei")


### FIXED CODE ###

Y, M, D = map(str, input().split("/"))
s = ''.join([Y,M,D])

if int(s)>20190430:
    print("TBD")
else:
    print("Heisei")
#n = 5
#C = list(map(int,"1 2 3 4 5".split()))
#line = ["1 2", "2 3", "3 4", "3 5"]


n = int(input())
C = list(map(int,input().split()))
 
ci = [set() for _ in range(n)]
for i,c in enumerate(C):
    ci[c-1].add(i)

path = [set() for _ in range(n)]
 
#line = ["1 2", "2 3"]
    
for i in range(n-1):
    #a,b = map(int,input().split())
    a,b = map(int,line[i].split())
    a -= 1
    b -= 1
    path[a].add(b)
    path[b].add(a)
    
ans = [n*(n+1)//2]*n
size = [0]*n
cparent = [[] for _ in range(n)]
reached = [False]*n
root_size = [n]*n

def dfs (p):
    c = C[p] - 1
    cparent[c].append(p)
    s = 1
    for nxt in path[p]:
        #print (nxt)
        size[p] = 0
        if reached[nxt]:
            continue
        reached[nxt] = True
        ret = dfs(nxt)
        s += ret
        size[p] +=ret
        ans[c] -= size[p] * (size[p] + 1)//2
    cparent[c].pop()
    if cparent[c]:
        size[cparent[c][-1]] -=s
    else:
        root_size[c] -=s    
    return s

reached[0] = True
dfs (0)

for i in range(n):
    print (ans[i]-root_size[i]*(root_size[i]+1)//2)


### FIXED CODE ###

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

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

path = [set() for _ in range(n)]

for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    path[a].add(b)
    path[b].add(a)
    
ans = [n*(n+1)//2]*n
size = [0]*n
cparent = [[] for _ in range(n)]
reached = [False]*n
root_size = [n]*n

def dfs (p):
    c = C[p] - 1
    cparent[c].append(p)
    s = 1
    for nxt in path[p]:
        #print (nxt)
        
        if reached[nxt]:
            continue
        size[p] = 0
        reached[nxt] = True
        ret = dfs(nxt)
        s += ret
        size[p] +=ret
        ans[c] -= size[p] * (size[p] + 1)//2
    cparent[c].pop()
    if cparent[c]:
        size[cparent[c][-1]] -=s
    else:
        root_size[c] -=s    
    return s

reached[0] = True
dfs (0)

for i in range(n):
    print (ans[i]-root_size[i]*(root_size[i]+1)//2)
X = input()
Y = X.count("A")
Z = X.count("B")
if (Y == 3 or Z ==3):
  print("Yes")
else
  print("No")

### FIXED CODE ###

X = input()
Y = X.count("A")
Z = X.count("B")
if (Y == 3 or Z == 3):
  print("No")
else:
  print("Yes")
str1 = input()
str2 = input()
str3 = input()
str4 = input()
str5 = input()
str6 = input()

flag = 0

if((str5-str4)>str6 or (str4-str3)>str6 or (str3-str2)>str6 or (str2-str1)>str6):
  print(':(')
else:
  print('Yay!')

### FIXED CODE ###

import sys

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

flag = 0

if((b-a)>k or (c-a)>k or (d-a)>k or (e-a)>k or (c-b)>k or (d-b)>k or (e-b)>k or (d-c)>k or (e-c)>k or (e-d)>k):
  print(":(")
else:
  print("Yay!")
import sys
from scipy.special import comb
import bisect
input = sys.stdin.readline
N = int(input())
A = sorted(list(map(int, input().split())))
l = bisect.bisect_left(A,A[-1]//2)-1
r = l+1
if comb(A[-1],A[l]) > comb(A[-1],A[r]):
    print(A[-1],A[l])
else:
    print(A[-1],A[r])

### FIXED CODE ###

import sys

input = sys.stdin.readline
N = int(input())
A = sorted(list(map(int, input().split())))
tmp = A[-1]
ans = 0
for i in A[:-1]:
    if abs(A[-1] // 2 - i) < tmp:
        tmp = abs(A[-1] // 2 - i)
        ans = i
    elif A[-1] % 2 != 0 and abs(A[-1] // 2 - i + 1) < tmp:
        tmp = abs(A[-1] // 2 - i + 1)
        ans = i
print(A[-1], ans)
temp = str(input())
count = 0
 
for i in temp:
  if i == 'R':
    count = count + 1
  else:
    max_count = count
    count = 0
    
print(max_count)

### FIXED CODE ###

temp = str(input())
count = 0
max_count = 0 

for i in temp:
  if i == 'R':
    count = count + 1
    max_count = count
  else:
    if max_count < count:
      max_count = count
    count = 0
    
print(max_count)
n = int(input())
if n&1:
    print(2*n)
else
    print(n)


### FIXED CODE ###

n = int(input())
if n&1:
    print(2*n)
else:
    print(n)
from collections import*
n, m, *t = map(int, open().read().split())       
*w, s, t = [a-1for a in t]         
e = [[]for _ in range(n)]        
for u, v in zip(w[::2], w[1::2]):      
    e[u].append(v)

INF = 10**10
f = [[INF]*3for _ in range(n)]        
f[s][0] = 0        
q = deque([(s, 0)])           
while q:
    vi, j = q.popleft()         
    if vi == t and j == 0:
        print(f[vi][0]//3)
        break
    for ui in e[vi]:           
        if f[ui][(j+1)%3] < INF: continue           
        f[ui][(j+1)%3] = f[vi][j] + 1
        q.append((ui, (j+1)%3))
else:
    print(-1)

### FIXED CODE ###

from collections import*
n, m, *t = map(int, open(0).read().split())       
*w, s, t = [a-1for a in t]         
e = [[]for _ in range(n)]        
for u, v in zip(w[::2], w[1::2]):      
    e[u].append(v)

INF = 10**10
f = [[INF]*3for _ in range(n)]        
f[s][0] = 0        
q = deque([(s, 0)])           
while q:
    vi, j = q.popleft()         
    if vi == t and j == 0:
        print(f[vi][0]//3)
        break
    for ui in e[vi]:           
        if f[ui][(j+1)%3] < INF: continue           
        f[ui][(j+1)%3] = f[vi][j] + 1
        q.append((ui, (j+1)%3))
else:
    print(-1)
n=int(input())
x=list(map(int,input().split()))

import numpy as np
import fractions as frc
from functools import reduce
from copy import deepcopy

x2=deepcopy(x)

def gcd_list(lst):
    return reduce(frc.gcd, lst)

while True:
	n=len(x)
	g=[]
	if n<=5:
		if n==2:
			res=max(x)
			break
		else:
			for i in range(n):
				f=[]
				for j in range(n):
					if j!=i:            
						f.append(x[j])
				g.append(gcd_list(f))
			idx=np.argmax(g)
			rm=x[idx]
			x3=[c for c in x2 if c!=rm]
			res=gcd_list(x3)
			break
	sp=n//2
	y=x[:sp]
	z=x[sp:]
	y_gcd=gcd_list(y)
	z_gcd=gcd_list(z)
	if y_gcd>z_gcd:
		x=z
	else:
		x=y

print(res)

### FIXED CODE ###

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

import fractions as frc

y=[0]*n
z=[0]*n

cd=x[0]
for i in range(n):
	cd=frc.gcd(cd,x[i])
	y[i]=cd

#print(y)

cd=x[n-1]
for i in range(n-1,-1,-1):
	cd=frc.gcd(cd,x[i])
	z[i]=cd

#print(z)

res=[0]*n
for i in range(n):
	if i==0:
		res[0]=z[1]
	else:
		if i==n-1:
			res[n-1]=y[n-2]
		else:
			res[i]=frc.gcd(y[i-1],z[i+1])

#print(res)

print(max(res))
N, K = map(int, input().split())
h = [i for i in map(int, input().split())]
memo = [0]*N
for i in range(N):
    mini = 10**10
    for j in range(i-min(i, K), i, 1):
        if memo[j] + abs(h[i]-h[j]) < mini:
            mini = memo[j] + abs(h[i]-h[j])
    if i != 0:
        memo[i] = mini
print(memo[N-1])
N, K = map(int, input().split())
h = [i for i in map(int, input().split())]
memo = [0]*N
for i in range(N):
    mini = 10**10
    for j in range(i-min(i, K), i, 1):
        if memo[j] + abs(h[i]-h[j]) < mini:
            mini = memo[j] + abs(h[i]-h[j])
    if i != 0:
        memo[i] = mini
print(memo[N-1])

### FIXED CODE ###

N, K = map(int, input().split())
h = [i for i in map(int, input().split())]
memo = [0]*N
for i in range(N):
    mini = 10**10
    for j in range(i-min(i, K), i, 1):
        if memo[j] + abs(h[i]-h[j]) < mini:
            mini = memo[j] + abs(h[i]-h[j])
    if i != 0:
        memo[i] = mini
print(memo[N-1])
txt = input().split(" ")
txt.sort
print(a[0])

### FIXED CODE ###

hoge = input().split(" ")
a=""
b=""
for i in range(int(hoge[1])):
  a += hoge[0]
for i in range(int(hoge[0])):
  b += hoge[1]
txt = [a,b]
txt.sort()
print(txt[0])
s =input().split(',')
a =s.split()
print(a)

### FIXED CODE ###

s =input().replace(","," ")
print(s)
import sys
sys.setrecursionlimit(10**5//2)
S = list(input())
n = len(S)
def Remove(binList,lenList):
    for i in range(0,lenList-1):
        if (binList[i] == "0" and binList[i+1] == "1") or (binList[i] == "1" and binList[i+1] == "0"):
            del binList[i:i+2]
            return Remove(binList,lenList - 2)
    return binList
if n > 10**5:
    sys.exit()
S = Remove(S,n)
print(n-len(S))

### FIXED CODE ###

S = list(input())
obj = min(S.count("0"),S.count("1"))
print(obj*2)
import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
inputb = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

listb = []
listb = [int(n) for n in inputb]

cnt = 0
for i in range(1,n-1):
    if listb[i-1] < listb[i] and listb[i] < listb[i+1]:
        cnt += 1
    elif listb[i-1] > listb[i] and listb[i] > listb[i+1]:
        cnt+=1

pritn(cnt)



### FIXED CODE ###

import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
inputb = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

listb = []
listb = [int(n) for n in inputb]

cnt = 0
for i in range(1,a-1):
    if listb[i-1] < listb[i] and listb[i] < listb[i+1]:
        cnt += 1
    elif listb[i-1] > listb[i] and listb[i] > listb[i+1]:
        cnt+=1

print(cnt)
n, l = map(int, input().split())
pie = 0
min_aji = 100
for i in range(1, n+1):
    if abs(l + i - 1) < min_aji:
        min_aji = abs(l + i - 1)
        apple = i
        
for i in range(1, n+1):
    if apple == i:
        continue
    pie += l + i - 1

print(pie)

### FIXED CODE ###

n, l = map(int, input().split())
aji = []

for i in range(1, n+1):
    aji.append(l + i - 1)

aji.sort(key=abs)
print(sum(aji[1:]))
N,K = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [np.inf] * N
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,N):
    for j in range(0,K+1):
        if i - j >= 0:
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[N-1])

### FIXED CODE ###

import numpy as np

N, K = list(map(int, input().split()))
h = np.array(list(map(int, input().split())))

dp = np.array([np.inf] * N)
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,N):
        if i - K >= 0:
            dp[i] = min(dp[i-K:i]+abs(h[i]-h[i-K:i]))
        else:
            dp[i] = min(dp[0:i]+abs(h[i]-h[0:i]))
print(int(dp[N-1]))
n,m = map(int,input().split())
if m ==0:
    print(0,0)
    exit()
p = [0] * (m+2)
s = [0] * (m+2)
w_count = 0
a_count = 0
flag = 0
for i in range(m+1):
    p[i],s[i] = input().split()
    if p[i] != p[i-1]:
        flag = 0
    if s[i] == 'AC' and flag == 0:
        flag = 1
        a_count += 1
    elif s[i] == 'WA':
        w_count += 1 and flag == 0
    


print(a_count,w_count)

### FIXED CODE ###

n, m = map(int,input().split())
a = [input().split() for i in range(m)]
p = [int(i[0]) for i in a]
q = [j[1] for j in a]

ac = 0
wa = 0
wa_c = [0] * n
ac_c = [False] * n

for t in range(m):
    if ac_c[p[t]-1]:
        continue
    if q[t] == 'AC':
        ac += 1
        ac_c[p[t]-1] = True
        wa += wa_c[p[t]-1]
    else:
        wa_c[p[t]-1] += 1
print(ac,wa)
N=int(input())

M=10**9
for i in range(1,N//2+10):
    a=list(str(i))
    b=list(str(N-i))
    #print(a,b)
    k=0
    for q in range(len(a)):
        k+=int(a[q])
    for p in range(len(b)):
        k+=int(b[p])
    M=min(M,k)
print(M)

### FIXED CODE ###

N=int(input())

M=10**9
for i in range(1,N//2+1):
    a=list(str(i))
    b=list(str(N-i))
    #print(a,b)
    k=0
    for q in range(len(a)):
        k+=int(a[q])
    for p in range(len(b)):
        k+=int(b[p])
    M=min(M,k)
print(M)
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/

import math
import statistics

n = int(input())
p = 600 * (n // 15) + 800 * (n - n // 15)
print(c)



### FIXED CODE ###

# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/

import math
import statistics

n = int(input())
p = 600 * (n // 15) + 800 * (n - n // 15)
print(p)
input = sys.stdin.buffer.readline
N,Q = map(int,input().split())
BIT = [0]*(N+1)

def BIT_query(idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

def BIT_update(idx,x):
    while idx <= N:
        BIT[idx] += x
        idx += idx&(-idx)
    return

c = [-1]+list(map(int,input().split()))
lastAppeared = [-1]*(N+1)
ans = [0]*Q
queries = []
for q in range(Q):
    l,r = map(int,input().split())
    queries.append(r*10**12+l*10**6+q)
queries.sort()

curR = 0
for i in range(Q):
    query = queries[i]
    r = query//10**12
    query %= 10**12
    l = query//10**6
    q = query % 10**6
    while curR < r:
        curR += 1
        new = c[curR]
        last = lastAppeared[new]
        if last != -1:
            BIT_update(last,-1)
        lastAppeared[new] = curR
        BIT_update(curR,1)
    ans[q] = BIT_query(r)-BIT_query(l-1)
for i in range(Q):
    print(ans[i])

### FIXED CODE ###

N,Q = map(int,input().split())
BIT = [0]*(N+1)

def BIT_query(idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

def BIT_update(idx,x):
    while idx <= N:
        BIT[idx] += x
        idx += idx&(-idx)
    return

c = [-1]+list(map(int,input().split()))
lastAppeared = [-1]*(N+1)
ans = [0]*Q
queries = []
for q in range(Q):
    l,r = map(int,input().split())
    queries.append((l,r,q))
queries.sort(key = lambda x:x[1])

curR = 0
for i in range(Q):
    l,r,q = queries[i]
    while curR < r:
        curR += 1
        new = c[curR]
        last = lastAppeared[new]
        if last != -1:
            BIT_update(last,-1)
        lastAppeared[new] = curR
        BIT_update(curR,1)
    ans[q] = BIT_query(r)-BIT_query(l-1)
for i in range(Q):
    print(ans[i])
N,K = map(int, input().split())
a = list(map(int, input().split()))

if 0 in a:
  N = N - 1
  if N == 0:
    print('0')
    exit()

aLow = list(filter(lambda x: x < 0, a))
aLow = list(map(lambda x: abs(x), aLow))
aLow = aLow.sort()

aHigh = list(filter(lambda x: x > 0, a))

least = 99999999999999999

for i in range(0,len(aLow)):
  j = N - i
  if i == 0:
    dist = aHigh[j-1]
  elif j == 0:
    dist = aLow[i-1]
  else:
    dist = min(2*aLow[i-1]+aHigh[j-1], aLow[i-1]+2*aHigh[j-1])

  if least > dist:
    least = dist

print(least)


### FIXED CODE ###

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

if 0 in a:
  K = K - 1
  if K == 0:
    print('0')
    exit()

aLow = list(filter(lambda x: x < 0, a))
aLow = list(map(lambda x: abs(x), aLow))
aLow.sort()

aHigh = list(filter(lambda x: x > 0, a))

least = 99999999999999999

#print(aLow)
#print(aHigh)

for i in range(0,K+1):
  j = K - i
  if i > len(aLow) or j > len(aHigh):
    continue

  if i == 0:
    dist = aHigh[j-1]
  elif j == 0:
    dist = aLow[i-1]
  else:
    dist = min(2*aLow[i-1]+aHigh[j-1], aLow[i-1]+2*aHigh[j-1])

  if least > dist:
    least = dist

print(least)
from collections import deque
import sys
input = sys.stdin.readline
import bisect as bi
from operator import mul
from functools import reduce
import math
from itertools import accumulate

def readlines(n):
    for _ in range(n):
        a, b = map(int, input().split())
        yield a, b

def prime(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    return is_prime

def main():
    q = int(input())
    is_prime = prime(100)

    def p(total, x):
        return total + (1 if is_prime[x] and is_prime[(x+1)//2] else 0)

    cumsum = list(accumulate(range(100), p))
    for l, r in readlines(q):
        print(cumsum[r] - cumsum[l-1])


main()


### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline
import bisect as bi
from operator import mul
from functools import reduce
import math
from itertools import accumulate

def readlines(n):
    for _ in range(n):
        a, b = map(int, input().split())
        yield a, b

def prime(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    return is_prime

def main():
    q = int(input())
    is_prime = prime(10**5)

    def p(total, x):
        return total + (1 if is_prime[x] and is_prime[(x+1)//2] else 0)

    cumsum = list(accumulate(range(10**5), p))
    for l, r in readlines(q):
        print(cumsum[r] - cumsum[l-1])


main()
a = input()
b = input()

print(math.ceil((a + b) / 2))


### FIXED CODE ###

import math
 
a, b = map(float, input().split())

mean = (a + b) / 2
print(math.ceil(mean))
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
def get_primenumber(number):
    prime_list = []
    search_list = list(range(2,number+1))
    while search_list[0] <= math.sqrt(number):
        head_num = search_list.pop(0)
        prime_list.append(head_num)
        search_list = [num for num in search_list if num % head_num != 0]
    prime_list.extend(search_list)
    return prime_list
N = int(input())
A = list(map(int, input().split()))
P = get_primenumber(max(A))
D = [False] * (len(P))
c = True
for i in range(N):
    for j in range(len(P)):
        if A[i] % P[j] == 0:
            if D[j]:
                c = False
            D[j] = True
if c:
    print('pairwise coprime')
    exit()
if gcd_list(A) == 1:
    print('setwise coprime')
    exit()
print('not coprime')


### FIXED CODE ###

import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
N = int(input())
A = list(map(int, input().split()))
M = [0] * (10**6+1)
for i in A:
    M[i] += 1
if gcd_list(A) > 1:
    print('not coprime')
    exit()
for i in range(2,10**6+1):
    c = 0
    for j in range(i,10**6+1,i):
        c += M[j]
    if c > 1:
        print('setwise coprime')
        exit()
print('pairwise coprime')
import sys
input = sys.stdin.readline

def ppp(n,m,h,ab):
    g = [1] * n
    for l,r in ab:
        if h[l-1] >= h[r-1]:
            g[r-1] = 0
        if h[l-1] <= h[r-1]:
            g[l-1] = 0
    print(sum(g))
if __name__ == "__main__":
    n,m = map(int,input().split())
    h = list(map(int,input().split()))
    ab = [list(map(int,input().split())) for _ in range(m)]
    ppp(n,m,h,ab_sorted)


### FIXED CODE ###

import sys
input = sys.stdin.readline

def peaks(n,m,h,ab):
    g = [0] * n
    path = [ [] for i in range(n)]
    #print(ab)
    for l,r in ab:
        path[l-1].append(r)
        path[r-1].append(l)

    #print(path)

    for i,p in enumerate(path):
        if p == []:
            g[i] = 1
            continue
        
        for j in p:
            #print(i+1,j,h[i],h[j-1])
            if h[i] > h[j-1]:
                g[i] = 1
            else:
                g[i] = 0
                break
    print(sum(g))

if __name__ == "__main__":
    n,m = map(int,input().split())
    h = list(map(int,input().split()))
    ab = [list(map(int,input().split())) for _ in range(m)]
    ab_sorted = sorted(ab)
    peaks(n,m,h,ab_sorted)
import numpy as np
import numpy

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

S = numpy.cumsum(P)
P.append(0)
M = S[K]

for i in range(0,N):
    if P[i+K] == 0:
        break
    A = S[i+K] - S[i]
    M = max(M, A)

ans = 0.5 * (M + K)

print(ans)

### FIXED CODE ###

import numpy as np
import numpy

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

S = numpy.cumsum(P)
P.append(0)
M = S[K-1]

for i in range(0,N):
    if P[i+K] == 0:
        break
    A = S[i+K] - S[i]
    M = max(M, A)

ans = 0.5 * (M + K)

print(ans)
import math
while True:
    a,b = [int(x) for x in input().split()]
    x = a + b
    print(int(math.log10(x))+1)



### FIXED CODE ###

import math
while True:
    try:
        a,b = [int(x) for x in input().split()]
        x = a + b        
        print(int(math.log10(x))+1)
    except:
        break
N,X = map(int,input().split())
x = list(map(int,input().split()))

x.append(X)

xsub = []

if N >= 2:
    for i in range(N-1):
         xsub.append(x[i+1]-x[i])

else:
    print(abs(x[0]-X))

import math

A = []

for i in range(N-2):
    A.append(math.gcd(xsub[i+1],xsub[i]))

print(min(A))

### FIXED CODE ###

N,X = map(int,input().split())
x = list(map(int,input().split()))

x.sort()

def gcd(x,y):
    X = max(x,y)
    Y = min(x,y)
    if Y == 0:
        return X
    else:
        return gcd(Y,X%Y)

keepgcd = 0
maxgcd = 10**9

if N >= 2:
   for i in range(N-1):
       keepgcd = gcd(abs(X-x[i+1]),abs(X-x[i]))
       if maxgcd > keepgcd:
          maxgcd = keepgcd
   print(maxgcd)
else:
    print(max(x[0],X)-min(x[0],X))
N = int(input())
p = input()
list1 = list(map(int,p.split()))

list2 = []
for i in range(1,N + 1):
    list2.append(i)

if list1 == list2:
    print("YES")
    exit()
for i in range(0,N):
    if list1[i] != i+1:
        if i+1 == list1[list1[i]-1]:
            list1[list1[i]-1] = list1[i]
            list1[i] = i+1
            

        if list1 == list2:
            print("YES")
            exit()
        else:
            print("NO")
            exit()

### FIXED CODE ###

n = int(input())
a = input()
la = list(map(int,a.split())) #街にいるモンスター数
b = input()
lb = list(map(int,b.split())) #ダメージ

damagecost = 0
killmonster = 0
for i in range(n):
    if lb[i] <= la[i]:
        killmonster += lb[i]
    else:
        killmonster += la[i]
        damagecost = lb[i] - la[i]
        if damagecost >= la[i + 1]:
            killmonster += la[i + 1]
            la[i + 1] = 0
        else:
            killmonster += damagecost
            la[i + 1] = la[i + 1] - damagecost
print(killmonster)
from math import ceil
N = int(input())
A = [0] * 5
A[0] = int(input())
A[1] = int(input())
A[2] = int(input())
A[3] = int(input())
A[4] = int(input())
mi = 0
mA = 1e18
for i in range(0,5):
    if (A[i] < mA):
        mA = A[i]
        mi = i
print(math.ceil(N / mA) * (mi + 1) + 4)

### FIXED CODE ###

import math
N = int(input())
A = [0] * 5
A[0] = int(input())
A[1] = int(input())
A[2] = int(input())
A[3] = int(input())
A[4] = int(input())
print(math.ceil(N / min(A)) + 4)