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


# 初期入力
import sys
from collections import deque
#input = sys.stdin.readline  #文字列では使わない
H,W = map(int, input().split())
S_h,S_w = map(int, input().split()) #スタート
G_h,G_w = map(int, input().split()) #ゴール

#迷路
mp =[["#"]*(W +4) for i in range(H +4)] #上下左右に２個分余分に壁を作る
for i in range(2,H+2):
    mp[i][2:-2] =input().strip() #迷路読み込み
    
S_h +=1 #壁を余分に作った分、スタートとゴールをずらす
S_w +=1
G_h +=1
G_w +=1
used =[[float('inf')]*(W +4) for i in range(H +4)] #既に通ったところを保存
used[S_h][S_w] =0
wap=[-2,-1,0,1,2] #ワープ移動できる縦横の範囲


dq =deque()
dq.append((0,S_h,S_w)) #キューには(コスト、x座標、y座標)を追加していく
arrive=False #ゴールに到着すればTrueに変更

while dq:
    k,i,j =dq.popleft()
    if k >used[i][j]: #既に通ったかどうか
        continue
    if i ==G_h and j ==G_w: #ゴール判定
        arrive =True
        break
    for di in wap:
        for dj in wap:
            if di ==0 and dj ==0: #その場から移動しない時
                continue
            ni,nj =i +di ,j +dj #移動後の座標(ni,nj)
            if mp[ni][nj] =="#": #移動先が壁の中
                continue
            if k <used[ni][nj]:
                if abs(di) +abs(dj) ==1: #歩行圏内(コスト:0)
                    nk =k
                    used[ni][nj] =nk
                    dq.appendleft((nk,ni,nj))
                else:                   #歩行圏外(コスト:１)
                    nk =k+1
                    used[ni][nj] =nk
                    dq.append((nk,ni,nj))
if arrive:
    ans =used[G_h][G_w]
else:
    ans =-1
print(ans)

### FIXED CODE ###


# 初期入力
import sys
from collections import deque
#input = sys.stdin.readline  #文字列では使わない
H,W = map(int, input().split())
S_h,S_w = map(int, input().split()) #スタート
G_h,G_w = map(int, input().split()) #ゴール

#迷路
mp =[["#"]*(W +4) for i in range(H +4)] #上下左右に２個分余分に壁を作る
for i in range(2,H+2):
    mp[i][2:-2] =input().strip() #迷路読み込み
    
S_h +=1 #壁を余分に作った分、スタートとゴールをずらす
S_w +=1
G_h +=1
G_w +=1
used =[[float('inf')]*(W +4) for i in range(H +4)] #既に通ったところを保存
used[S_h][S_w] =0
wap=[-2,-1,0,1,2] #ワープ移動できる縦横の範囲


dq =deque()
dq.append((0,S_h,S_w)) #キューには(コスト、x座標、y座標)を追加していく
arrive=False #ゴールに到着すればTrueに変更

while dq:
    k,i,j =dq.popleft()
    if k >used[i][j]: #既に通ったかどうか
        continue
    if i ==G_h and j ==G_w: #ゴール判定
        arrive =True
        break
    for di in wap:
        for dj in wap:
            if di ==0 and dj ==0: #その場から移動しない時
                continue
            ni,nj =i +di ,j +dj #移動後の座標(ni,nj)
            if mp[ni][nj] =="#": #移動先が壁の中
                continue
            if k <used[ni][nj]:
                if abs(di) +abs(dj) ==1: #歩行圏内(コスト:0)
                    nk =k
                    used[ni][nj] =nk
                    dq.appendleft((nk,ni,nj))
                else:                   #歩行圏外(コスト:１)
                    nk =k+1
                    used[ni][nj] =nk
                    dq.append((nk,ni,nj))
if arrive:
    ans =used[G_h][G_w]
else:
    ans =-1
print(ans)
### BUGGY CODE ###

def main():
    n, m = map(int, input().split())
    ans = 1
    v = m / n
    for i in range(2, int(m / n) + 1):
        if m % i == 0:
            ans = max(i, ans)

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n, m = map(int, input().split())
    for i in range(int(m / n), 0, -1):
        if m % i == 0:
            print(i)
            break


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

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

dp =[0]*(n+1)


for i in range(n+1):
    if i<=1:
        dp[i]=1
    else:
        dp[i] = (dp[i-2]+dp[i-1])
    if i in a:
        dp[i] = 0

print(dp[-1]%1000000007)

### FIXED CODE ###

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

dp =[0]*(n+1)

for i in a:
    dp[i] = -1

for i in [0,1]:
    if dp[i] == -1:
        dp[i] =0
    else:
        dp[i] =1

for i in range(2,n+1):
    if dp[i] == -1:
        dp[i] = 0
    else:
        if dp[i-1]==dp[i-2]==0:break
        dp[i] = (dp[i-2]+dp[i-1])

print(dp[-1]%1000000007)
### BUGGY CODE ###

N = int(input())

a_list = []
for i in range(N):
    a_list.append(int(input()))

c_list = []
for i, a in enumerate(a_list[:]):
    b = a_list.pop(i)
    c_list.append(max(a_list))
    a_list.insert(i, b)

for c in c_list:
    print(c)

### FIXED CODE ###

N = int(input())

a_list = []
for i in range(N):
    a_list.append(int(input()))

b_in = a_list.index(max(a_list))
b_max = max(a_list)

a_list.pop(b_in)

c_max = max(a_list)

for i in range(N):
    if b_in != i:
        print(b_max)
    else:
        print(c_max)
### BUGGY CODE ###

import itertools
N = int(input())
S = input()
s = set()
for i, j, k in itertools.combinations(range(N), 3):
  s.add(S[i]+S[j]+S[k])
print(len(s))

### FIXED CODE ###

N = int(input())
S = input()
ans = 0
for i in range(1000):
  p = str(i).zfill(3)
  if S.find(p[0])==-1:
    continue
  S1 = S[S.find(p[0])+1:]
  if S1.find(p[1])==-1:
    continue
  S2 = S1[S1.find(p[1])+1:]
  if S2.find(p[2])==-1:
    continue
  ans+=1
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
for i in range(1, n + 1):
    print(a.index(i)+1, end=' ')

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = [0]*n
for index, item in enumerate(a, 1):
    b[item-1] = index
for i in b:
    print(i,end=' ')
### BUGGY CODE ###

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

c = 0
for i in range(1, len(A)):
  ki = max(A[0:i])
  if A[i] < ki:
    c += abs(A[i]-ki)

print(c)

### FIXED CODE ###

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

c = 0
mae = A[0]

for i in A:
  if i < mae:
    c += mae - i
  else:
    mae = i

print(c)
### BUGGY CODE ###

import sys
from collections import defaultdict
from bisect import insort
from copy import copy

n, m = map(int, input().split())
d = defaultdict(list)
for i in range(n):
    a, b = map(int, input().split())
    d[a].append(b)

res = 0
resList = []
for i in range(1, m+1):
    resList.extend(d[i])
    if len(resList) > 0:
        resList.sort()
        res += resList[-1]
        resList.pop()

print(res)


### FIXED CODE ###

import sys
from heapq import heappush,heappop

n, m = map(int, sys.stdin.readline().split())
d = [[] for _ in range(m+1)]
for i in range(n):
    a, b = map(int, sys.stdin.readline().split())
    if a <= m:
        d[a].append(b)

res = 0
resList = []
for i in range(1, m+1):
    if len(d[i]) > 0:
        for j in d[i]:
            heappush(resList, -j)
    if len(resList) > 0:
        res += (-1) * resList[0]
        heappop(resList)

print(res)
### BUGGY CODE ###

n, k = map(int, input().split())
h = [int(n) for n in input().split()]
dp = [0]*n
def a():  
  dp[1] = abs(h[1]-h[0])
  for i in range(2, n):
    dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,min(i+1,k+1))])  
  return dp[-1]

if __name__ == "__main__":
  print(a())

### FIXED CODE ###

def main():
  n, k = map(int, input().split())
  h = [int(n) for n in input().split()]
  dp = [0]*n
  for i in range(1, n):
    dp[i] = min([dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i)])  
  print(dp[-1])

if __name__ == "__main__":
  main()
### BUGGY CODE ###

N,K = map(int, input().split())
lst = list(map(int, input().split()))
dp = [0 for i in range(N)]
for i in range(1,N):
    mn = 999999999999999999
    for j in range(1,K+1):
        if i-j >= 0:
            mn = min(mn,dp[i - j] + abs(lst[i] - lst[i - j]))
        else:
            break
    dp[i] = mn
print(dp[-1])


### FIXED CODE ###

N,K = map(int, input().split())
lst = list(map(int, input().split()))
dp = [0 for i in range(N)]
for i in range(1,N):
    mn = 999999999999999999
    for j in range(max(i-K,0), i):
        mn = min(mn,dp[j] + abs(lst[i] - lst[j]))
    dp[i] = mn
print(dp[-1])
### BUGGY CODE ###

import math
K=int(input())
s=0
for i in range(K):
    for j in range(K):
        for k in range(K):
            s=s+math.gcd(math.gcd(i+1,j+1),k+1)
print(s)


### FIXED CODE ###

K=int(input())+1

Ans=0
from math import gcd
for i in range(1,K):
    for j in range(1,K):
        tempA=gcd(i,j)
        for k in range(1,K):
            Ans+=gcd(tempA,k)
            
print(Ans)
### BUGGY CODE ###

x, y, z, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
ans_list = []
for h in range(min(x,k)):
    for i in range(min(y,k)):
        for j in range(min(z,k)):
            ans_list.append(a[h]+b[i]+c[j])
ans_list.sort(reverse=True)
for i in range(k):
    print(ans_list[i])

### FIXED CODE ###

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
p = []
for i in a:
    for j in b:
        p.append(i+j)
p.sort(reverse=True)
p = p[:min(3001, x*y*z+1)]
q = []
for j in c:
    for i in p:
        q.append(i+j)
q.sort(reverse=True)
for i in range(k):
    print(q[i])
### BUGGY CODE ###

n = int(input())
s = input()
cnt = 0
for i in range(n):
    for j in range(i,n):
        for k in range(j,n):
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                if j-i != k-j:
                    cnt += 1
print(cnt)

### FIXED CODE ###

n = int(input())
s = input()

ans = s.count("R") * s.count("G") * s.count("B")
for i in range(n):
  for j in range(i+1,n):
    k = 2*j-i
    if k < n:
      if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
        ans -= 1
print(ans)
### BUGGY CODE ###


n=int(input())

def number(i):
   for j in range(1,41):
      for k in range(j,58):
         for u in range(k,101):
            a=j*j+k*k+u*u+j*k+k*u+u*j
            if a > 10**4:
               break
            if i==a:
               if j==k and k==u:
                  print(1)
                  return
               elif j==k or k==u:
                  print(3)
                  return
               else:
                  print(6)
                  return
         

   print(0)
   return

for h in range(1,n+1):
   number(h)

### FIXED CODE ###

n=int(input())
y=[0 for _ in range(10**4+1)]
for j in range(1,100):
   for k in range(1,100):
      for u in range(1,100):
         a=j*j+k*k+u*u+j*k+k*u+u*j
         if a <= 10**4:
            y[a-1]+=1
for o in range(n):
   print(y[o])
### BUGGY CODE ###

n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[k] < l[i] + l[j]:
                ans += 1
            else:
                break

print(ans)


### FIXED CODE ###

n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        lp = j+1
        rp = n-1
        while lp < rp:
            mp = (lp+rp)//2
            if l[mp] < l[i] + l[j]:
                lp = mp+1
            else:
                rp = mp-1
        if l[lp] < l[i] + l[j]:
            ans += lp-j
        else:
            ans += lp-j-1
print(ans)
### BUGGY CODE ###

import sys
import bisect
readline = sys.stdin.readline
n = int(readline())
A = list(map(int,readline().split()))
A.sort()
ans =0
for i in range(1,n):
    for j in range(i+1,n):
        b = A[i]
        c = A[j]
        a = c -b
        ans += i- bisect.bisect(A[:i],a)
print(ans)

### FIXED CODE ###

import sys
import bisect
readline = sys.stdin.readline
n = int(readline())
A = list(map(int,readline().split()))
memo1 = {}
memo2 = {}
A.sort()
memo1[A[0]+A[1]] =1
memo2[A[0]] =1
if A[1] in memo2:
    memo2[A[1]] +=1
else:
    memo2[A[1]] =1
ans = 0
for c in A[2:]:
    for l,amount in memo1.items():
        if c<l:
            ans +=amount
    for a,amount in memo2.items():
        ac = a+c
        if ac in memo1:
            memo1[ac] += memo2[a]
        else:
            memo1[ac] = memo2[a]
    if c in memo2:
        memo2[c] +=1
    else:
        memo2[c] =1

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

N = int(input())
A, B, C = [list(map(int, input().split())) for _ in range(3)]

for x in [A, B, C]:
	x.sort()

def bsr(a, v, lo=0, hi=None):
	if hi == None:
		hi = len(a) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if v < a[mid]:
			hi = mid - 1
		else:
			lo = mid + 1
	return lo

bt = []
for b in B:
	bt += [max(0, (N - bsr(C, b)))]

r = 0
for ai, a in enumerate(A):
	bif = bsr(B, a)
	if bif < N:
		r += sum(bt[bif:])

print(r)


### FIXED CODE ###

N = int(input())
A, B, C = [list(map(int, input().split())) for _ in range(3)]

for x in [A, B, C]:
	x.sort()

def bsr(a, v, lo=0, hi=None):
	if hi == None:
		hi = len(a) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if v < a[mid]:
			hi = mid - 1
		else:
			lo = mid + 1
	return lo

bt = []
for b in B:
	bt += [max(0, (N - bsr(C, b)))]

for i in range(len(B) - 2, -1, -1):
	bt[i] += bt[i + 1]

r = 0
for ai, a in enumerate(A):
	bif = bsr(B, a)
	if bif < N:
		r += bt[bif]

print(r)
### BUGGY CODE ###

import sys

    
A=[]
n=int(raw_input())
while n:
    s = (raw_input().split())
    if s[0] == 'insert':
        A.insert(0,int(s[1]))
    elif s[0] == 'delete':
        try:
            A.remove(int(s[1]))
        except:
            pass
    elif s[0] == 'deleteFirst':
        A.pop(0)
    elif s[0] == 'deleteLast':
        A.pop()
    n -=1
    
for e in A:
    print e,

### FIXED CODE ###

import sys,gc
    
A=[]
fp =0
bp =0

n=int(raw_input())
while n:
    s = raw_input()
    if s[0] == 'i':
        A.append(int(s[7:]))
        fp += 1
    elif s[6] == ' ':
        try:
            i = A[::-1].index(int(s[7:]))
            if i!=-1:
                del A[-i-1]
                fp -=1
        except:
            pass
    elif s[6] == 'F':
        A.pop()
        fp -=1
    elif s[6] == 'L':
        bp +=1
    n -=1

for e in A[bp:fp+1][::-1]:
    print int(e),
### BUGGY CODE ###

t = input()
n = len(t)
t += "a"
ans = ""
for i in range(n):
    if t[i] == "?":
        ans += "D"
    else:
        ans += t[i]
print(ans)

### FIXED CODE ###

t = input()
n = len(t)
t += "a"
ans = ""
for i in range(n):
    if t[i] == "?":
        ans += "D"
    else:
        ans += t[i]
print(ans)
### BUGGY CODE ###

K = int(input())
if K % 2 == 0:
  print(-1)
  exit()
n = 7
c = 0
while 1:
  n %= K
  c += 1
  if n == 0:
    break
  n = n * 10 + 7
print(c)

### FIXED CODE ###

K = int(input())
n = 7
c = 0
while c <= K:
  n %= K
  c += 1
  if n == 0:
    print(c)
    exit()
  n = n * 10 + 7
print(-1)
### BUGGY CODE ###

a, b, c, d = map(int, input().split())
ma = a*c
for i in range(a, b+1):
    for j in range(c, d+1):
        if ma < i*j:
            ma = i*j
print(ma)

### FIXED CODE ###

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

ma = a*c
if  ma < a*c:
    ma = a*c
if ma < a*d:
    ma = a*d
if ma < b*c:
    ma = b*c
if ma < b*d:
    ma = b*d
print(ma)
### BUGGY CODE ###

import numpy as np
n, m = map(int, input().split())
bridge = []
for i in range(m):
    bridge += list(map(int, input().split()))
bridge = np.array(bridge).reshape(m, 2)
total = n*(n-1)//2
ans =[total]
u = [i for i in range(n+1)]
size = [1 for i in range(n+1)]
def unite(x, y):
    if find(x) != find(y):
        return 1
    else:
        return 0

def find(x):
    if x != u[x]:
        x =u[x]
        find(x)
    return x

for x , y in bridge[::-1]:
    if unite(x, y):
        X = find(x)
        Y = find(y)
        total -= size[X] * size[Y]
        ans += [total]
        if size[X] >= size[Y]:
            X, Y = sorted([X,Y])
        u = [Y if i == X else i for i in u]
        size[Y] += size[X]
        size[X] = 0

    else:
        ans += [total]

print(*ans[m-1::-1], sep="\n")

### FIXED CODE ###

import sys
n , m, *e = map(int,sys.stdin.read().split())
total = n*(n-1)//2
ans =[total]
u = [-1]*(n+1)

def find(x):
    if u[x] < 0 :
        return x
    else:
        return find(u[x])

for x , y in zip(e[-2:1:-2],e[:1:-2]):
    x = find(x)
    y = find(y)
    x, y = sorted((x, y))
    if x != y:
        total -= u[x] * u[y]
        u[x] += u[y]
        u[y] = x
    ans += [total]

print(*ans[::-1], sep="\n")
### BUGGY CODE ###

MOD = 10**9 + 7
def solve(n, a, p=64):
    s = [0] * p
    a = a[::-1]
    res = 0
    for i in range(n):
        mask = bin(a[i])[2:][::-1]
        c = [0] * p
        for j, b in enumerate(map(int, mask)):
            s[j] += b
            c[j] = b
        for j in range(p):
            if c[j] == 1:
                res += (i - s[j] + 1) * (2**j)
            else:
                res += s[j] * (2**j)
    return res % MOD

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


### FIXED CODE ###

MOD = 10**9 + 7
def solve(n, a, p=60):
    res, m = 0, 1
    for i in range(p):
        y = sum(x & m for x in a) // m
        res += y * (n-y) * m
        m *= 2
    return res % MOD

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))
### BUGGY CODE ###

if __name__ == "__main__":
	N = int(input())
	L = list(map(int, input().split()))
	L.sort()
	sum = 0
	for c in range(N - 1, 1, -1):
		for b in range(c - 1, 0, -1):
			for a in range(b - 1, -1, -1):
				if L[a] + L[b] > L[c]:
					sum += 1
				else:
					break
	print(sum)

### FIXED CODE ###

from bisect import bisect_left

if __name__ == "__main__":
	N = int(input())
	L = list(map(int, input().split()))
	L.sort()
	# print(L)
	sum = 0
	for a in range(N - 2):
		for b in range(a + 1, N - 1):
			key = L[a] + L[b]
			i = bisect_left(L, key)
			# print(a, b, i, i - b)
			sum += i - b - 1
	print(sum)
### BUGGY CODE ###

n,m = map(int,input().split())
a = []
b = []
c = 0
l = []
ans = 0

for i in range(n):
	a_dash,b_dash = map(int,input().split())
	a.append(a_dash)
	b.append(b_dash)

for i in reversed(range(m)):
	for j in range(n-c):
		if a[j] + i <= m:
			l.append(b[j])
	if len(l) != 0:
		ans += max(l)
		index = b.index(max(l))
		a.pop(index)
		b.pop(index)
		c += 1
	l.clear()

print(ans)

### FIXED CODE ###

import sys
import heapq

s = sys.stdin.readlines()
n,m = map(int,s[0].split())
a = []
b = []
l = []
ans = 0
count = 0

for i in range(1,n+1):
	a_dash,b_dash = map(int,s[i].split())
	a.append(-a_dash)
	b.append(-b_dash)

c = zip(a,b)
c = sorted(c,reverse=True)
a,b = zip(*c)
a_length = len(a)

for i in reversed(range(m)):
	for j in range(count,a_length):
		if -a[j] + i == m:
			heapq.heappush(l,b[j])
			count += 1
		else:
			break
	if len(l) != 0:
		maximum = heapq.heappop(l)
		ans += maximum

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

N,K,Q=map(int,input().split())
A=[int(input()) for i in range(Q)]
Pt=[K]*N
for i in range(Q):
    Pt=[k-1 for k in Pt]
    Pt[A[i]-1]=Pt[A[i]-1]+1
for j in range(N):
    print("No" if Pt[j]<=0 else "Yes")

### FIXED CODE ###

N,K,Q=map(int,input().split())
A=[int(input()) for i in range(Q)]
Pt=[K-Q]*N
for i in range(Q):
    Pt[A[i]-1]=Pt[A[i]-1]+1
for j in range(N):
    print("No" if Pt[j]<=0 else "Yes")
### BUGGY CODE ###

import sys

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

graph = [0] * (M)
for m in range(M):
    a, b, c = map(int, input().split())
    graph[m] = (a, b, -c)

INF = 1e18
distance = [INF] * N
distance[0] = 0

count = 0
while True:
    count += 1
    update = False
    for i in range(M):
        a, b, c = graph[i]
        if INF != distance[a - 1] and distance[b - 1] > distance[a - 1] + c:
            distance[b - 1] = distance[a - 1] + c
            update = True
            if b == N and count == N:
                print("inf")
                sys.exit()
    if not update:
        break

print(-distance[N - 1])

### FIXED CODE ###

import sys

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

graph = [0] * (M)
for m in range(M):
    a, b, c = map(int, input().split())
    graph[m] = (a, b, -c)

INF = 1e18
distance = [INF] * N
distance[0] = 0

for n in range(N):
    for i in range(M):
        a, b, c = graph[i]
        if INF != distance[a - 1] and distance[b - 1] > distance[a - 1] + c:
            distance[b - 1] = distance[a - 1] + c
            if b == N and n == N - 1:
                print("inf")
                sys.exit()

print(-distance[N - 1])
### BUGGY CODE ###

N,M=map(int,input().split())
H=list(map(int,input().split()))
o=[i for i in range(1,N+1)]
def removeObs(x):
    if x in o:
        o.remove(x)
for i in range(M):
    A,B=map(int,input().split())
    if H[A-1]==H[B-1]:
        removeObs(A)
        removeObs(B)
    elif H[A-1]>H[B-1]:
        removeObs(B)
    else:
        removeObs(A)
print(len(o))

### FIXED CODE ###

N,M=map(int,input().split())
H=list(map(int,input().split()))
ab=[0]*N
for i in range(M):
    a,b=map(int,input().split())
    ab[a-1]=max(ab[a-1],H[b-1])
    ab[b-1]=max(ab[b-1],H[a-1])
ans=0
for i in range(N):
    if ab[i]<H[i]:
        ans+=1
print(ans)
### BUGGY CODE ###

#from numba import jit
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline

#@jit
def DFS(add,next):
    global cnt
    x,y=add
    for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:
        X,Y=x+i,y+j
        if 0<=X<h and 0<=Y<w:
            if S[X][Y]==next and color[X][Y]=="white":
                color[X][Y]="black"
                DFS([X,Y],"." if next=="#" else "#")
                if next==".":cnt +=1


h,w=map(int,input().split())
S=[list(input()) for _ in range(h)]
cnt=0

for i in range(h):
    for j in range(w):
        if S[i][j]=="#":
            color=[["white" for _ in range(w)] for _ in range(h)]
            color[i][j]="black"
            DFS([i,j],".")

print(cnt)

### FIXED CODE ###

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


def DFS(add,next,cnt):
    x,y=add
    for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:
        X,Y=x+i,y+j
        if 0<=X<h and 0<=Y<w:
            if S[X][Y]==next and color[X][Y]=="white":
                color[X][Y]=str(cnt)
                DFS([X,Y],"." if next=="#" else "#",cnt)


h,w=map(int,input().split())
S=[list(input()) for _ in range(h)]
cnt=0

color=[["white" for _ in range(w)] for _ in range(h)]
for i in range(h):
    for j in range(w):
        if S[i][j]=="#" and color[i][j]=="white":
            cnt +=1
            DFS([i,j],".",cnt)

dictionary={str(i+1):[0,0] for i in range(cnt)}
for i in range(h):
    for j in range(w):
        if color[i][j]!="white":
            if S[i][j]==".":dictionary[color[i][j]][0] +=1
            else:dictionary[color[i][j]][1] +=1

ans=0
for v,m in dictionary.values():
    ans +=v*m
print(ans)
### BUGGY CODE ###

def main():
	n=input()
	List_1=[]
	max=-1000000001
	for i in range(n):
		List_1.append(input())
		for j in range(i-1,-1,-1):
				if max<List_1[i]-List_1[j]:
					max=List_1[i]-List_1[j]
	print(max)

if __name__=='__main__':
	main()

### FIXED CODE ###

n=input()
for i in range(n):
	if i==0:
		num_1=input()
	elif i==1:
		num_2=input()
		maxv=num_2 - num_1
		MIN=min(num_1,num_2)
	else:
		num_3=input()
		if (num_3-MIN)>maxv:
			maxv=num_3-MIN
		if (num_3)<MIN:
			MIN=num_3
print(maxv)
### BUGGY CODE ###

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

ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        ans += al[i]*al[j]
        ans %= 10**9+7

print(ans)

### FIXED CODE ###

n = int(input())
al = list(map(int, input().split()))
s = sum(al)
ss = 0
m = 10**9+7
d = 500000004
for a in al:
    ss += a*a
print(((s*s-ss)%m*d)%m)
### BUGGY CODE ###

from collections import deque

S = list(input())
Q = int(input())
answer = deque(S)
reverse = False
for _ in range(Q):
  query = input()
  if query == '1':
    reverse ^= True
  else:
    ope, types, alphabet = query.split()
    if types == '1':
      if reverse:
        answer.append(alphabet)
      else:
        answer.appendleft(alphabet)
    else:
      if reverse:
        answer.appendleft(alphabet)
      else:
        answer.append(alphabet)
if reverse:
  result = ''
  for i in range(len(answer)):
    result += answer.pop()
  print(result)
else:
  result = ''
  for i in range(len(answer)):
    result += answer.popleft()
  print(result)

### FIXED CODE ###

from collections import deque

S = list(input())
Q = int(input())
answer = deque(S)
reverse = False
for _ in range(Q):
  query = input()
  if query == '1':
    reverse ^= True
  else:
    ope, types, alphabet = query.split()
    if types == '1':
      if reverse:
        answer.append(alphabet)
      else:
        answer.appendleft(alphabet)
    else:
      if reverse:
        answer.appendleft(alphabet)
      else:
        answer.append(alphabet)
if reverse:
  result = ''
  for i in range(len(answer)):
    result += answer.pop()
  print(result)
else:
  result = ''
  for i in range(len(answer)):
    result += answer.popleft()
  print(result)