Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

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


if __name__ == "__main__":
    s = input()
    ope_num = 0
    index = 0
    a_stock = 0
    b_stock = 0
    s = list(s)
    while index < len(s):
        # print(s)
        # print(index)
        # print(ope_num)
        # print()
        si = s[index]
        if si == "A":
            if b_stock > 0:
                a_stock = 1
            else:
                a_stock = a_stock + 1
            b_stock = 0
        elif a_stock > 0:
            if si == "B" and b_stock == 0:
                b_stock = 1
            elif si == "C" and b_stock > 0:
                ope_num = ope_num + a_stock
                s[index - 2 - a_stock + 1] = "B"
                s[index - 1 - a_stock + 1] = "C"
                for i in range(a_stock - 1, -1, -1):
                    s[index - i] = "A"
                index = index - a_stock
                a_stock = 0
                b_stock = 0
            else:
                a_stock = 0
                b_stock = 0
        else:
            a_stock = 0
            b_stock = 0
        index = index + 1
    print(ope_num)

# ABCの数
# ABCの前にあるAの分だけ追加で操作できる
# ABCの後にある(BC)の分だけ追加で操作できる

# Aがあれば覚えておく
# ABCと来たら、それより前側に隣接しているAの回数だけ追加で操作できる
# 見つかったABCをBCAに置き換える
# BCAのAから走査を継続する


### FIXED CODE ###

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


if __name__ == "__main__":
    s = input()
    ope_num = 0
    index = 0
    a_stock = 0
    b_stock = 0
    s = list(s)
    while index < len(s):
        # print(s)
        # print(index)
        # print(ope_num)
        # print()
        si = s[index]
        if si == "A":
            if b_stock > 0:
                a_stock = 1
            else:
                a_stock = a_stock + 1
            b_stock = 0
        elif a_stock > 0:
            if b_stock == 0:
                if si == "B":
                    b_stock = 1
                else:
                    a_stock = 0
                    b_stock = 0
            elif si == "C":
                ope_num = ope_num + a_stock
                # s[index - 2 - a_stock + 1] = "B"
                # s[index - 1 - a_stock + 1] = "C"
                # s[index] = "A"
                # index = index - 1
                a_stock = a_stock
                b_stock = 0
            else:
                a_stock = 0
                b_stock = 0
        else:
            a_stock = 0
            b_stock = 0
        index = index + 1
    print(ope_num)

# ABCの数
# ABCの前にあるAの分だけ追加で操作できる
# ABCの後にある(BC)の分だけ追加で操作できる

# Aがあれば覚えておく
# ABCと来たら、それより前側に隣接しているAの回数だけ追加で操作できる
# 見つかったABCをBCAに置き換える
# BCAのAから走査を継続する
### BUGGY CODE ###

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

for i in range(q):
    o = list(map(int, input().split()))
    for j in range(n):
        if a[j] == o[0]:
            a[j] = o[1]
    print(sum(a))

### FIXED CODE ###

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

count = [0] * 100000
for i in range(n):
    count[a[i] - 1] += 1
    
for i in range(q):
    o = list(map(int, input().split()))
    s += (o[1] - o[0]) * count[o[0] - 1]
    count[o[1] - 1] += count[o[0] - 1]
    count[o[0] - 1] = 0
    print(s)
### BUGGY CODE ###

number_list = []
N = int(input())

for i in range(N):
    new_num = input()
    if new_num in number_list:
        number_list.remove(new_num)
    else:
        number_list.append(new_num)

print(len(number_list))

### FIXED CODE ###

number_set = set()
N = int(input())

for i in range(N):
    new_num = input()
    if new_num in number_set:
        number_set.remove(new_num)
    else:
        number_set.add(new_num)

print(len(number_set))
### BUGGY CODE ###

K = int(input())

import math
from functools import reduce

sum = 0

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            sum += reduce(math.gcd, [i,j,k])

print(sum)

### FIXED CODE ###

K = int(input())

import math
from functools import reduce

sum = 3*(K-1)*(K-1) + 3*(K-1) + 1

for i in range(2, K + 1):
    for j in range(2, K + 1):
        for k in range(2, K + 1):
            sum += math.gcd(math.gcd(i,j),k)

print(sum)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N, M = [int(x) for x in input().strip().split()]
A = [int(input()) for _ in range(M)]
s = [0 for _ in range(N + 1)]
s[0] = 1
if 1 not in A:
  s[1] = 1

for n in range(2, N+1):
  if n in A:
    continue
  else:
    s[n] = s[n-1] + s[n-2]
print(s[-1] % (10 ** 9 + 7))


### FIXED CODE ###

import sys
input = sys.stdin.readline
N, M = [int(x) for x in input().strip().split()]
A = set([int(input()) for _ in range(M)])
s = [0 for _ in range(N + 1)]
s[0] = 1
if 1 not in A:
  s[1] = 1

for n in range(2, N+1):
  if n in A:
    continue
  else:
    s[n] = s[n-1] + s[n-2]
print(s[-1] % (10 ** 9 + 7))
### BUGGY CODE ###

from itertools import *

n = int(input())
As = list(map(int, input().split()))
D = 10 ** 9 + 7
ans = 0

for pair in combinations(As, 2):
  ans = (ans + pair[0] * pair[1]) % D
  
print(ans)

### FIXED CODE ###

n = int(input())
As = list(map(int, input().split()))
D = 10 ** 9 + 7
ans = 0
s = sum(As)

for a in As:
  ans += (s-a) * a
  
print(ans // 2 % D)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**5)

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

def solve(a):
    if len(a) == 0:
        return 0
    elif len(a) == 1:
        return a[0]
    elif len(a) == 2:
        v1 = a[0] + a[1]
        v2 = -a[0] - a[1]
        return max(v1, v2)

    v1 = a[0] + solve(a[1:])
    v2 = -a[0] + solve([-a[1]] + a[2:])
    return max(v1, v2)

# for i in range(n-1):
#     v1 = a[i] + a[i+1]
#     v2 = -a[i] - a[i+1]
#     if v2 > v1:
#         a[i] = -a[i]
#         a[i+1] = -a[i+1]

# print(a)
# print(sum(a))

print(solve(a))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5)

n = int(input())
a = list(map(int, input().split()))
dp = [[None]*(2) for _ in range(n+1)]

dp[n-1][0] = a[n-1]
dp[n-1][1] = -a[n-1]

for i in reversed(range(n-1)):
    for j in range(2):
        #print('\n# i: ' + str(i))
        # Unexe
        unexe_unexe = a[i] + dp[i+1][0]
        exe_unexe = -a[i] + dp[i+1][1]
        dp[i][0] = max(unexe_unexe, exe_unexe)

        # Exe
        unexe_exe = a[i] + dp[i+1][1]
        exe_exe = -a[i] + dp[i+1][0]
        dp[i][1] = max(unexe_exe, exe_exe)

#print(dp)
#print(max(dp[0][0], dp[0][1]))
print(dp[0][0])
### BUGGY CODE ###

a=input()
num=len(a)
mod_map={0:1}

for i in range(-1,-num-1,-1):
    mod=int(a[i:])%2019
    if mod not in mod_map:
        mod_map[mod]=1
    else:
        mod_map[mod]+=1
res=0
for i in mod_map.values():
    res+=int(i*(i-1)/2)
print(res)

### FIXED CODE ###

a=reversed(input())
#num=len(a)
mod_list=[1]+[0]*2019
moji_int=0
Sn=0
tens=1
for i in a:
    tmp=int(i)*(tens)
    Sn=(Sn+tmp)%2019
    mod=Sn
    tens=tens*10%2019
    mod_list[mod]+=1
res=0
for i in mod_list:
    res+=int(i*(i-1)/2)
print(res)
### BUGGY CODE ###

import sys
#n=int(input())
k,s=map(int,input().split())
sati=0
for i in range(k+1):
  for j in range(k+1):
    for z in range(k+1):
      suma=i+j+z
      if suma==s:
        sati+=1
      suma=0
print(sati)

### FIXED CODE ###

k,s = map(int, input().split(" "))
sum = 0
for i in range(k+1):
    for j in range(k+1):
        if s-i-j <= k and s-i-j >= 0:
            sum += 1
print(sum)
### BUGGY CODE ###

from collections import defaultdict,deque
import math
def main():
    n = input()
    tmp = 0
    for i in range(len(n)):
        tmp += int(n)
    if(tmp%9==0):
        print("Yes")
    else:
        print("No")
if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import defaultdict,deque
import math
def main():
    n = input()
    tmp = 0
    for i in range(len(n)):
        tmp += int(n[i])
        tmp%=9
    if(tmp%9==0):
        print("Yes")
    else:
        print("No")
if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
lis = [0]*N
for i in range(1, N+1):
    lis[i-1] = A.index(i)+1

print(*lis)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
L = [0]*N
for i in range(0, N):
    L[A[i]-1] = i + 1
print(*L)
### BUGGY CODE ###

K = int(input())
import sys
sys.setrecursionlimit(1000000)
run = [1, 2, 3, 4, 5, 6, 7, 8, 9]


def runrun(number):
    if len(number) < 14:
        last = int(number[-1])
        if last == 0:
            run.append(int(str(int(number[-1])+0)))
            run.append(int(str(int(number[-1])+1)))
            runrun(str(int(number[-1])+0))
            runrun(str(int(number[-1])+1))
        elif last == 9:
            run.append(int(str(int(number[-1])+0)))
            run.append(int(str(int(number[-1])-1)))
            runrun(str(int(number[-1])+0))
            runrun(str(int(number[-1])-1))
        else:
            run.append(int(str(int(number[-1])+0)))
            run.append(int(str(int(number[-1])-1)))
            run.append(int(str(int(number[-1])+1)))
            runrun(str(int(number[-1])+0))
            runrun(str(int(number[-1])+1))
            runrun(str(int(number[-1])-1))


for i in range(1, 10):
    runrun(str(i))
run.sort(reverse=False)
print(run[K-1])

### FIXED CODE ###

from collections import deque
K = int(input())
que = deque(list(range(1, 10)))
for i in range(K):
    x = que.popleft()
    last = x % 10
    if last != 0:
        que.append(x*10 + last-1)
    que.append(x*10 + last)
    if last != 9:
        que.append(x*10 + last+1)
print(x)
### BUGGY CODE ###

n,a,b = list(map(int,input().split()))
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a = 1
  b = 1
  c = 1
  for i in range(1,n+1):
    a = (a*i)%p
  for i in range(1,k+1):
    b = (b*i)%p
  for i in range(1,n-k+1):
    c = (c*i)%p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
mod = 10**9 + 7
ans = (power_func(2,n,mod)-1)%mod
ac = comb(n,a,mod)
bc = comb(n,b,mod)
ans = (ans-ac-bc)%mod
print(ans)


### FIXED CODE ###

n,a,b = list(map(int,input().split()))
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a = 1
  b = 1
  c = 1
  for i in range(1,n+1):
    a = (a*i)%p
  for i in range(1,k+1):
    b = (b*i)%p
  for i in range(1,n-k+1):
    c = (c*i)%p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
mod = 10**9 + 7
ans = (power_func(2,n,mod)-1)%mod
ac = 1
for i in range(1,a+1):
    ac = (ac*(n-i+1)*power_func(i,mod-2,mod))%mod
ans = (ans-ac)%mod
bc = ac
for i in range(a+1,b+1):
    bc = (bc*(n-i+1)*power_func(i,mod-2,mod))%mod
ans = (ans-bc)%mod
print(ans)
### BUGGY CODE ###

N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]
m = M-1

def DFS(s):
    if len(s) == N:
        return [s]
    ans = []
    if s == '':
        r = 0
    else:
        r = int(s[-1])
    for i in range(r, M):
        ans.extend(DFS(s+str(i)))
    return ans


V = DFS('')
final_ans = 0
for v in V:
    answer = 0
    A = [int(c)+1 for c in v]
    for a, b, c, d in abcd:
        if int(v[b-1]) - int(v[a-1]) == c:
            answer += d
    final_ans = max(final_ans , answer)
print(final_ans)

### FIXED CODE ###

N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]
m = M-1

def DFS(s):
    if len(s) == N:
        return [s]
    ans = []
    if s == '':
        r = 0
    else:
        r = int(s[-1])
    for i in range(r, M):
        ans.extend(DFS(s+str(i)))
    return ans


V = DFS('')
final_ans = 0
for v in V:
    answer = 0
    A = [int(c)+1 for c in v]
    for a, b, c, d in abcd:
        if int(v[b-1]) - int(v[a-1]) == c:
            answer += d
    final_ans = max(final_ans , answer)
print(final_ans)
### BUGGY CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2, floor
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, N = MAP()
temp = []
for i in range(N):
	temp.append(LIST())
temp = [list(x) for x in zip(*temp)]
A, B = temp[0], temp[1]

DP = [[INF]*(H + max(A) + 1) for _ in range(N + 1)]

DP[0][0] = 0

a = max(A)

for i in range(N):
	for j in range(H + a + 1):
		if j < A[i]:
			DP[i+1][j] = DP[i][j]
		else:
			DP[i+1][j] = min(DP[i][j], DP[i+1][j-A[i]] + B[i])

print(min(DP[N][H:H + max(A) + 1]))

### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, floor
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, N = MAP()
temp = [LIST() for _ in range(N)]
temp = [list(x) for x in zip(*temp)]
A, B = temp[0], temp[1]

DP = [[INF]*(H + max(A) + 1) for _ in range(N + 1)]
DP[0][0] = 0
a = max(A)

for i in range(N):
	for j in range(H + a + 1):
		if j < A[i]:
			DP[i+1][j] = DP[i][j]
		else:
			DP[i+1][j] = min(DP[i][j], DP[i+1][j-A[i]] + B[i])

print(min(DP[N][H:H + max(A) + 1]))
### BUGGY CODE ###

n = int(input())
length = list(map(int, input().split()))
length = sorted(length)
count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
               if length[k] < length[i]+length[j]:
                   count += 1
               else:
                   pass
print(count)

### FIXED CODE ###

import bisect
n = int(input())
length = list(map(int, input().split()))
length = sorted(length)
count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        insert_index = bisect.bisect_left(length, length[i]+length[j])
        count += insert_index-j-1               
print(count)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
s = input()
count = 0
while s.count('ABC') != 0:
    count += s.count('ABC')
    s = s.replace("ABC", "BCA")
print(count)

### FIXED CODE ###

# -*- coding: utf-8 -*-
s = input()
s = s.replace("BC", "X")
count = 0
a_stack = 0
for idx, char in enumerate(s):
    if char == "A":
        a_stack += 1
    elif char == "X":
        count += a_stack
    else:
        a_stack = 0
print(count)
### BUGGY CODE ###

def main():

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

    dp = [[0 for _ in range(N+1)] for _ in range(N)]
    dp[0][0] = 1-p[0]
    dp[0][1] = p[0]
    for i in range(1, N):
        for j in range(i+2):
            if j == 0:
                dp[i][j] = dp[i-1][j] * (1-p[i])
            else:
                dp[i][j] = dp[i-1][j] * (1-p[i]) + dp[i-1][j-1] * p[i]
    ans = 0
    for j in range((N+1)//2, N+1):
        ans += dp[N-1][j]
    return ans

if __name__ == '__main__':
    print(main())

### FIXED CODE ###

def main():

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

    dp = [[0 for _ in range(N+1)] for _ in range(N)]
    dp[0][0] = 1-p[0]
    dp[0][1] = p[0]
    for i in range(1, N):
        for j in range(i+2):
            if j == 0:
                dp[i][j] = dp[i-1][j] * (1-p[i])
            else:
                dp[i][j] = dp[i-1][j] * (1-p[i]) + dp[i-1][j-1] * p[i]
    ans = 0
    for j in range((N+1)//2, N+1):
        ans += dp[N-1][j]
    return ans

if __name__ == '__main__':
    print(main())
### BUGGY CODE ###

n = int(input())
sum=0
for i in range(1,n+1,1):
    sum+=int(i*int(n/i)*int(n/i+1)/2)

print(sum)



### FIXED CODE ###

n = int(input())
sum=0
for i in range(1,n+1,1):
    t=int(n/i)
    sum+=i*t*(t+1)/2

print(int(sum))
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
num = [0]*(10**6 + 1)
for i in range(n):
    for j in range(1, 10**6//a[i]+1):
        num[a[i]*j] += 1

ans = 0
for i in range(n):
    if num[a[i]] < 2:
        ans += 1

# print(num[:30])
print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
num = [0]*(10**6+1)
for x in a:
    if num[x] != 0:
        num[x] = 2
        continue
    for i in range(x, 10**6+1, x):
        num[i] += 1

ans = 0
for x in a:
    if num[x] == 1:
        ans += 1

print(ans)
### BUGGY CODE ###

import bisect

def solve():
    N, Q = [int(_) for _ in input().split()]
    STX = []
    for i in range(N):
        Si, Ti, Xi = [int(_) for _ in input().split()]
        STX.append((Si - Xi, Ti - Xi, Xi))
    D = []
    for i in range(Q):
        D.append((int(input()), i))
    STX.sort(key = lambda x:x[2], reverse=True)
    # D have already been sorted based on settings on problem
    ans = [-1] * Q
    for i in range(N):
        Li, Ri, Xi = STX[i]
        if len(D) == 0:
            break
        it = bisect.bisect_left(D, (Li, -1))
        while it < len(D):
            if D[it][0] >= Ri:
                break
            ans[D[it][1]] = Xi
            it += 1
    for i in range(Q):
        print (ans[i])

if __name__ == '__main__':
    solve()


### FIXED CODE ###

import bisect

def solve():
    N, Q = [int(_) for _ in raw_input().split()]
    STX = []
    for i in range(N):
        Si, Ti, Xi = [int(_) for _ in raw_input().split()]
        STX.append((Si - Xi, Ti - Xi, Xi))
    D = []
    for i in range(Q):
        D.append((int(raw_input()), i))
    STX.sort(key = lambda x:x[2])
    # D have already been sorted based on settings on problem
    ans = [-1] * Q
    l = [None] * Q
    for i in range(N):
        Li, Ri, Xi = STX[i]
        lit = bisect.bisect_left(D, (Li, -1))
        rit = bisect.bisect_left(D, (Ri, -1))
        while lit < rit:
            if l[lit] is not None:
                lit = l[lit]
            else:
                ans[D[lit][1]] = Xi
                l[lit] = rit
                lit += 1
    for i in range(Q):
        print ans[i]

if __name__ == '__main__':
    solve()
### BUGGY CODE ###

k,s = list(map(int,input().split()))
ans = [x + y + z for x in range(k+1) for y in range(k+1) for z in range(k+1) if x + y + z == s]
print(len(ans))

### FIXED CODE ###

k,s = list(map(int,input().split()))
ans = [1 for x in range(k+1) for y in range(k+1) if 0 <= s - (x+y) <= k]
print(len(ans))
### BUGGY CODE ###

n = int(input())
ans = 0
for i in range(1, n):
    ans += i%(i+1)
print(ans)

### FIXED CODE ###

n = int(input())
if n%2 != 0:
    print(n*(n//2))
else:
    print(n*(n//2) - n//2)
### BUGGY CODE ###

import bisect

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

for _ in range(M):
    a = A.pop()
    a2=a>>1
    bisect.insort_right(A,a2)
    #print(A2)

print(sum(A))

### FIXED CODE ###

from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
import logging
import heapq
logging.basicConfig(level=logging.DEBUG)

input = sys.stdin.readline

setrecursionlimit(1000000)

def main():
    N,M=[int(x) for x in input().split()]
    A=[-int(x) for x in input().split()]

    heapq.heapify(A)
    for _ in range(M):
        a = -heapq.heappop(A) // 2 # 最小値取得
        heapq.heappush(A, -a)
    
    print(-sum(A))

main()
### BUGGY CODE ###

n = int(input())
l = list(map(int, input().split()))
a = 0
b = []
for m in range(n):
    b.append(l.count(m+1))
    k = b[m]
    a += int(k*(k-1)/2)
for m in range(n):
    print(a-b[l[m]-1]+1)

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
a = []
b = 0
for m in range(n):
    a.append(0)
for m in range(n):
    a[l[m]-1] += 1
for m in range(n):
    b += int(a[m]*(a[m]-1)/2)
for m in range(n):
    print(b-a[l[m]-1]+1)
### BUGGY CODE ###

N ,M = list(map(int, input().split()))
H = list(map(int, input().split()))
lis = [[0] * N for i in range(N)]

for i in range(M):
  A, B = list(map(int, input().split()))
  lis[A-1][B-1]=H[B-1]
  lis[B-1][A-1]=H[A-1]
  
ans = 0

for i in range(N):
  if max(lis[i]) < H[i]:
    ans += 1
  elif max(lis) == 0:
    ans += 1
print(ans)

### FIXED CODE ###

N ,M = list(map(int, input().split()))
H = list(map(int, input().split()))
lis = [1] * N
for i in range(M):
  A, B = list(map(int, input().split()))
  if H[A-1] > H[B-1]:
    lis[B-1]=0
  elif H[A-1] < H[B-1]:
    lis[A-1]=0
  else:
    lis[A-1]=0
    lis[B-1]=0
    
print(lis.count(1))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)


def DFS(num,point):
    D[num]=point+Q[num]
    color[num]="gray"
    for i in M[num]:
        if color[i]=="white":
            DFS(i,D[num])
    color[num]="black"


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

M=[[] for _ in range(n+1)]
for i in range(n-1):
    a,b=map(int,input().split())
    M[a].append(b)
    M[b].append(a)

Q=[0]*(n+1)
for i in range(q):
    p,x=map(int,input().split())
    Q[p] +=x

color=["white" for _ in range(n+1)]
D=[0]*(n+1)

DFS(1,0)
print(*D[1:])

### FIXED CODE ###

# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
n,q = [int(i) for i in readline().split()]

g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = [int(i) for i in readline().split()]
    g[a-1].append(b-1)
    g[b-1].append(a-1)

add = [0]*n
for _ in range(q):
    p,x = [int(i) for i in readline().split()]
    add[p-1] += x

ans = [0]*n
#ans[0] = add[0]

def dfs(v,p,value): #p: parent of v
    value += add[v]
    ans[v] = value
    for c in g[v]:
        if c == p: continue
        dfs(c,v,value)

dfs(0,-1,0)

#print(add)

print(*ans)
### BUGGY CODE ###

import math

N, M = map(int, input().split())
A = list(map(int, input().split()))
i = M
if (len(A) > 1):
    while (i > 0):
        list.sort(A, reverse=True)
        times = A[0] / A[1]
        log = math.floor(math.log(times, 2)) + 1
        A[0] = A[0] // 2 ** log
        i -= log
else:
    A[0] = A[0] // (2 ** M)
print(sum(A))


### FIXED CODE ###

import math
import heapq

N, M = map(int, input().split())
tempA = list(map(int, input().split()))
A = []
for a in tempA:
    heapq.heappush(A, a * - 1)
for i in range(M):
    minNum = heapq.heappop(A)
    heapq.heappush(A, (minNum * -1 // 2) * - 1)
print(sum(A) * -1)