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

from collections import deque

class LinkedList(object):
    def __init__(self):
        self.dq = deque()

    def insert(self, key):
        self.dq.appendleft(key)

    def delete(self, key):
        if not key in self.dq:
            return
        for x in self.dq:
            if x == key:
                self.dq.remove(key)
                return

    def deleteFirst(self):
        self.dq.popleft()

    def deleteLast(self):
        self.dq.pop()

    def show(self):
        print(' '.join(self.dq))

def run():
    n = int(input())
    linked_list = LinkedList()
    for _ in range(n):
        order = input()
        if order.startswith('insert'):
            linked_list.insert(order.split()[1])
        elif order.startswith('deleteFirst'):
            linked_list.deleteFirst()
        elif order.startswith('deleteLast'):
            linked_list.deleteLast()
        elif order.startswith('delete'):
            linked_list.delete(order.split()[1])
    linked_list.show()

if __name__ == '__main__':
    run()




### FIXED CODE ###

from collections import deque

def run():
    n = int(input())
    dq = deque()
    for _ in range(n):
        order = input()
        if order[0] == 'i':
            dq.appendleft(order[7:])
        elif order[6] == ' ':
            key = order.split()[1]
            if not key in dq:
                continue
            for i in range(len(dq)):
                if dq[i] == key:
                    dq.remove(key)
                    break
        elif order[6] == 'F':
            dq.popleft()
        elif order[6] == 'L':
            dq.pop()

    print(' '.join(dq))

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

n = int(input())
a = list(map(int, input().split()))
h = []
for i in range(n):
    h.append(abs(sum(a[:i])-sum(a[i:])))
print(min(h))

### FIXED CODE ###

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

result = [[a[0], sum(a[1:])]]
for i in range(1, n):
    result.append([result[-1][0]+a[i], result[-1][1]-a[i]])
h = []
for i in range(len(result)):
    h.append(abs(result[i][0]-result[i][1]))
print(min(h))
### BUGGY CODE ###

def modCom(n, k, mod):
    p, q = 1, 1
    for i in range(n-k+1, n+1):
        p = (p * i) % mod
    for i in range(2, k+1):
        q = (q * i) % mod
    return p * pow(q, mod-2, mod) % mod

mod = 10**9+7
K = int(input())
S = input()
L = len(S)
ans = 0
for i in range(K+1):
    ans += modCom(K-i+L-1, L-1, mod) * pow(25, K-i, mod) * pow(26, i, mod)
    ans %= mod
print(ans)

### FIXED CODE ###

mod = 10**9+7
def factrial(N):
    fc = [1, 1] + [None] * N
    inv = [0, 1] + [None] * N
    fcInv = [1, 1] + [None] * N
    for i in range(2, N+1):
        fc[i] = i*fc[i-1]%mod
        inv[i] = mod-(inv[mod%i]*(mod//i))%mod
        fcInv[i] = fcInv[i-1]*inv[i]%mod
    return fc, fcInv

def modCom(n, k):
    return 0 if n < k else fc[n] * fcInv[k] * fcInv[n-k] % mod

K = int(input())
S = input()
L = len(S)
fc, fcInv = factrial(L+K)
ans = 0
for i in range(K+1):
    ans += modCom(K-i+L-1, L-1) * pow(25, K-i, mod) * pow(26, i, mod)
    ans %= mod
print(ans)
### BUGGY CODE ###

n,k=map(int,input().split())
A=list(map(int,input().split()))
h=[]
for i in range(n-k+1):
    l=1
    for j in range(k):
        l*=A[k+i-1-j]
    h.append(l)
for i in range(n-k):
    if h[i]<h[i+1]:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

n,k=map(int,input().split())
A=list(map(int,input().split()))
for i in range(n-k):
    if A[k+i]>A[i]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
AB = []
total = 0
for i in range(len(B)):
  count = 0
  for j in range(len(A)):
    if A[j]<B[i]:
      count+=1
  AB.append(count)
for i in range(len(C)):
  for j in range(len(B)):
    if B[j]<C[i]:
      total+=AB[j]
print(total)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
AB = [0]*N
total = 0
for i in range(N):
  left = -1
  right = N
  while right-left>1:
    mid = left + (right-left)//2
    if A[mid]>=B[i]:
      right = mid
    else:
      left = mid
  AB[i]=right
for i in range(1,N):
  AB[i]+=AB[i-1]
for i in range(N):
  left = -1
  right = N
  while right-left>1:
    mid = left + (right-left)//2
    if B[mid]>=C[i]:
      right = mid
    else:
      left = mid
  if right!=0:
    total+=AB[right-1]
print(total)
### BUGGY CODE ###

def main():
    _map, _int, _input = map, int, input
    n, q = _map(_int, _input().split())
    t = [[] for _ in range(n)]
    r = [0]*n
    for _ in range(n-1):
        a, b = map(lambda x: _int(x)-1, _input().split())
        t[a].append(b)
        t[b].append(a) # leafの順序が保証されないため双方向にリンクを設定
    # root(t[0])からleafまで親ノードのリンクを消しながら辿る
    e = [0]
    eadd = e.append
    while len(e) > 0:
        i = e.pop()
        for j in t[i]:
            t[j].remove(i)
            eadd(j)
    
    query = [0] * n
    for _ in range(q):
        p, x = _map(_int, _input().split())
        query[p-1] += x
    
    for p, x in enumerate(query):
        #p -= 1
        r[p] += x
        s = t[p][:]
        spop = s.pop
        sext = s.extend
        while len(s) > 0:
            i = spop()
            r[i] += x
            sext(t[i])
    print(*r)
        
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n,q=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    tree=[list() for _ in range(n)]
    score=[0]*n
    for a,b in ab:
        a,b=a-1,b-1
        tree[a].append(b)
        tree[b].append(a)
    e = [0]
    while len(e) > 0:
        i = e.pop()
        for j in tree[i]:
            tree[j].remove(i)
            e.append(j)
    px=[list(map(int,input().split())) for _ in range(q)]
    for p,x in px:
        p-=1
        score[p]+=x
    add(tree,score)
    print(*score)

def add(tree,score):
    s=tree[0][:]
    for i in s:
        score[i] += score[0]
    while len(s)>0:
        t = s.pop()
        for i in tree[t]:
            s.append(i)
            score[i] += score[t]

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

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

for i in range(n):
    temp = [0] + a[:i] + a[i+1:] + [0]
    ans = 0
    for i in range(len(temp)-1):
        ans += abs(temp[i+1] - temp[i])
    print(ans)

### FIXED CODE ###

n = int(input())
a = [0] + list(map(int, input().split())) + [0]

b = [0]

for i in range(len(a)-1):
    b.append(abs(a[i+1]-a[i]) + b[-1])

s = b[-1]

for i in range(1, len(a)-1):
    ans = s - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i+1] - a[i-1])
    print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)

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

def pow_mod(x,n):
  if n==0:
    return 1
  elif n==1:
    return x
  else:
    xn2=pow_mod(x,n//2)
    if n%2==0:
      return (xn2*xn2)%MOD
    else:
      return (xn2*xn2*x)%MOD

def fact_mod(a):
  if a<=1:
    return 1
  else:
    return a*fact_mod(a-1)%MOD
  
def perm_mod(n,a):
  if a==1:
    return n
  else:
    return (n*perm_mod(n-1,a-1))%MOD

def inv_mod(a):
  return pow_mod(a,MOD-2)%MOD
  
def comb_mod(na,fa):
  ainv=inv_mod(fa)
  return (na*ainv)%MOD
  
if k>=n-1:  
  #nHn=(2n-1)Cn
  perm=perm_mod(2*n-1,n)
  fact=fact_mod(n)
  comb=comb_mod(perm,fact)
  #print(perm,fact,comb)
  print(comb)
else:
  comb_sum=1
  fact=1
  comb1=1
  comb2=1
  for i in range(1,k+1):
    comb1=comb1*(n-i+1)//i
    comb2=comb2*(n-i)//i
    comb=(comb1*comb2)%MOD
    comb_sum+=comb
  
  print(comb_sum%MOD)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

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

def pow_mod(x,n):
  if n==0:
    return 1
  elif n==1:
    return x
  else:
    xn2=pow_mod(x,n//2)
    if n%2==0:
      return (xn2*xn2)%MOD
    else:
      return (xn2*xn2*x)%MOD

def fact_mod(a):
  if a<=1:
    return 1
  else:
    return a*fact_mod(a-1)%MOD
  
def perm_mod(n,a):
  if a==1:
    return n
  else:
    return (n*perm_mod(n-1,a-1))%MOD

def inv_mod(a):
  return pow_mod(a,MOD-2)%MOD
  
def comb_mod(na,fa):
  ainv=inv_mod(fa)
  return (na*ainv)%MOD
  
if k>=n-1:  
  #nHn=(2n-1)Cn
  perm=perm_mod(2*n-1,n)
  fact=fact_mod(n)
  comb=comb_mod(perm,fact)
  #print(perm,fact,comb)
  print(comb)
else:
  inv_table = [0]+[1]
  for i in range(2,k+1):
    inv_table+=[inv_table[MOD%i]*(MOD-int(MOD/i))%MOD]
  
  comb_sum=1
  fact=1
  comb1=1
  comb2=1
  for i in range(1,k+1):
    #comb1=comb1*(n-i+1)//i
    comb1=(comb1*(n-i+1)*inv_table[i])%MOD
    #comb2=comb2*(n-i)//i
    comb2=(comb2*(n-i)*inv_table[i])%MOD
    comb=(comb1*comb2)%MOD
    comb_sum+=comb
  
  print(comb_sum%MOD)
### BUGGY CODE ###

nm=list(map(int,input().split()))
n=nm[0]
m=nm[1]
py=[]
y=[]
for i in range(m):
    py.append([])
for i in range (n):
    y.append([])
for i in range(m):
    py[i]=list(map(int,input().split()))
    y[py[i][0]-1].append(py[i][1])
for i in range(n):
    y[i].sort()
#print(py)
#print(y)
for i in range(m):
    if py[i][0]<10:
        print("00000"+str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))
    elif  py[i][0]<100:
        print("0000"+str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))
    elif py[i][0]<1000:
        print("000"+str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))
    elif py[i][0]<10000:
        print("00"+str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))
    elif py[i][0]<100000:
        print("0"+str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))
    else:
        print(str(py[i][0]*10**6+y[py[i][0]-1].index(py[i][1])+1))

### FIXED CODE ###

#nm=list(map(int,input().split()))
#n=nm[0]
#m=nm[1]
n,m=map(int,input().split())
#py=[]
y=[]
#py=[[[]]*m]
py=[[]]*m
#y=[[]]*n
#print(py)
#for i in range(m):
#    py.append([])
for i in range (n):
    y.append([])
for i in range(m):
    py[i]=list(map(int,input().split()))
    y[py[i][0]-1].append(py[i][1])#yの初期化を＊でするとyの要素全てにappendされてしまう
for i in range(n):
    y[i].sort()
#print(py)
#print(y)
d_y={}
for i in range(n):
    for j in range(len(y[i])):
        d_y[y[i][j]]=j+1
for i in range(m):
    if py[i][0]<10:
        print("00000"+str(py[i][0]*10**6+d_y[py[i][1]]))
    elif  py[i][0]<100:
        print("0000"+str(py[i][0]*10**6+d_y[py[i][1]]))
    elif py[i][0]<1000:
        print("000"+str(py[i][0]*10**6+d_y[py[i][1]]))
    elif py[i][0]<10000:
        print("00"+str(py[i][0]*10**6+d_y[py[i][1]]))
    elif py[i][0]<100000:
        print("0"+str(py[i][0]*10**6+d_y[py[i][1]]))
    else:
        print(str(py[i][0]*10**6+d_y[py[i][1]]))
### BUGGY CODE ###

from collections import deque
N, M = map(int, input().split())
Graph = [[]for _ in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    Graph[a].append(b)
    Graph[b].append(a)

dist = [-1] * (N + 1)
dist[0] = 0
dist[1] = 0

d = deque()
d.append(1)
while d:
    v = d.popleft()
    for i in Graph[v]:
        if dist[i] != -1:
            continue
        dist[i] = dist[v] + 1
        d.append(i)

ans = dist[0:]
C = [0] * (N + 1)
for j in range(2, len(ans)):
    if ans[j] == 1:
        C[j] = 1
    for k in range(2, max(ans) +1):
        if ans[j] == k:
            index_num = [n for n, v in enumerate(ans) if v == k - 1]
            for l in index_num:
                if l in Graph[j]:
                    C[j] = l
                    break
print('Yes')
for m in range(2,N + 1):
    print(C[m])

### FIXED CODE ###

from collections import deque
N, M = map(int, input().split())
Graph = [[]for _ in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    Graph[a].append(b)
    Graph[b].append(a)

dist = [-1] * (N + 1)
dist[0] = 0
dist[1] = 0

pre = [-1] * (N + 1)
pre[0] = 0
pre[1] = 1

d = deque()
d.append(1)
while d:
    v = d.popleft()
    for i in Graph[v]:
        if dist[i] != -1:
            continue
        dist[i] = dist[v] + 1
        pre[i] = v
        d.append(i)
ans = dist[0:]
print('Yes')
for j in range(2, len(pre)):
    print(pre[j])
### BUGGY CODE ###

n = int(input())
c = input()

cnt = 0
while 'WR' in c:
    w = c.find('W')
    r = c.rfind('R')
    c = c[:w]+'R'+c[w+1:r]+'W'+c[r+1:]
    cnt += 1
print(cnt)

### FIXED CODE ###

n = int(input())
c = input()

print(c[:c.count('R')].count('W'))
### BUGGY CODE ###

A, B, C = map(int,input().split())
ans = 0
while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
    if (A // 2) % 2 == 1 and (B // 2) % 2 == 1 and (C // 2) % 2 == 1:
        print(-1)
        exit()
    a = B // 2 + C // 2
    b = A // 2 + C // 2
    c = A // 2 + B // 2
    A = a
    B = b
    C = c
    ans += 1
print(ans)

### FIXED CODE ###

A, B, C = map(int,input().split())
ans = 0
while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
    a = B // 2 + C // 2
    b = A // 2 + C // 2
    c = A // 2 + B // 2
    if A == a and B == b and C == c:
        ans = -1
        break
    A = a
    B = b
    C = c
    ans += 1
print(ans)
### BUGGY CODE ###

N = int(input())
A = [int(input()) for n in range(N)]

setA = set(A)

res = 0
for a in setA:
    if A.count(a)%2 != 0:
        res += 1

print(res)

### FIXED CODE ###

N = int(input())
A = [int(input()) for n in range(N)]
A = sorted(A)

res = []
tmp = A[0]
count = 1
for i in range(1,N):
    if A[i] == tmp:
        count += 1
    else:
        res.append(count%2 != 0)
        count = 1
    tmp = A[i]
res.append(count%2 != 0)

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

import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
X = [int(x) for x in input().split()]
for i in range(N):
    temp = X[:i] + X[i+1:]
    print(int(np.median(temp)))

### FIXED CODE ###

import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
X = np.array([int(x) for x in input().split()])
Y = np.sort(X)
right = N // 2
left = right - 1
right, left = Y[right], Y[left]
for i in range(N):
    if X[i] <= left:
        print(right)
    else:
        print(left)
### BUGGY CODE ###

import sys
def 解():
    input = sys.stdin.readline

    N,W=[int(_) for _ in input().split()]
    #dp = [[0]*(W+1) for _  in range(N+1)]
    dp = [0]*(W+1)

    for i in range(N):
        w,v=[int(_) for _ in input().split()]
        for j in range(W,w-1,-1):
            dp[j] = max(dp[j] ,dp[j-w]+v)
    print(dp[W])
解()


### FIXED CODE ###

import sys
def 解():
    input = sys.stdin.readline

    N,W=[int(_) for _ in input().split()]
    dp = [0]*(W+1)
    for i in range(N):
        w,v=[int(_) for _ in input().split()]
        for j in range(W,w-1,-1):
            dp[j] = max(dp[j] ,dp[j-w]+v)
    print(dp[W])
解()
### BUGGY CODE ###

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

pedras = list(map(int,input().split()))

INF = 1e12

dp = [INF] * n

dp[0] = 0
dp[1] = abs(pedras[1] - pedras[0])

for i in range(2,n):
    pulo = 0
    for j in range(i-1,-1,-1):
        pulo += 1
        if pulo > k:
            break
        else:
            dp[i] = min(dp[i], dp[j] + abs(pedras[i] - pedras[j]))


print(dp[n-1])


### FIXED CODE ###

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

INF = 1e12

dp = [INF] * n

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

dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2,n):#Ele vai começar a contar cada pedra a partir da terceira
    pulo = 0
    for j in range(i-1,-1,-1):#O pulo começar pequeno, tendo tamanho 1 e indo até o máximo k
        pulo += 1
        if pulo > k:
            break
        else:
            dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]))
#No final ele vai armazenar o pulo de menor custo, afinal não importa o tamanho do pulo e sim seu custo, sendo assim,
#Temos que calcular os custos de todos os possiveis pulos até a pedra atual.

print(dp[n-1])
### BUGGY CODE ###

from sys import stdin, setrecursionlimit
from functools import lru_cache

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)

childs = [0] * N
seen = [False] * N


def dfs1(v):
    seen[v] = True
    c = 0
    for nv in G[v]:
        if not seen[nv]:
            dfs1(nv)
            c += childs[nv] + 1
    childs[v] = c
    return


dfs1(0)

numer = 0
seen = [False] * N

pow2 = pow(2, N - 1, MOD)

@lru_cache(maxsize=None)
def power(x, y, z):
    return pow(x, y, z)

def dfs2(v):
    global numer
    seen[v] = True
    nodes = []
    for nv in G[v]:
        if seen[nv]:
            nodes.append(N - childs[v] - 1)
        else:
            nodes.append(childs[nv] + 1)
    if len(nodes) > 1:
        this_numer = power(2, N - 1, MOD) - (sum(power(2, n, MOD) - 1 for n in nodes) + 1)
        numer = (numer + this_numer) % MOD
    for nv in G[v]:
        if not seen[nv]:
            dfs2(nv)
    return


dfs2(0)
denom = power(2, N, MOD)
ans = numer * pow(denom, MOD - 2, MOD) % MOD
print(ans)


### FIXED CODE ###

from sys import stdin, setrecursionlimit
from collections import deque

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)

pow2 = [1] * (N + 1)
for i in range(N):
    pow2[i + 1] = pow2[i] * 2 % MOD

order = []
parent = [-1] * N

stack = deque([0])
while stack:
    v = stack.pop()
    order.append(v)
    for nv in G[v]:
        if parent[v] != nv:
            parent[nv] = v
            stack.append(nv)

numer = 0
nums = [0] * N

for v in reversed(order):
    tmp = 1
    for nv in G[v]:
        if parent[v] != nv:
            c = nums[nv] + 1
            nums[v] += c
            tmp += pow2[c] - 1
    tmp += pow2[N - nums[v] - 1] - 1
    numer = (numer + pow2[N - 1] - tmp) % MOD

denom = pow2[N]
ans = numer * pow(denom, MOD - 2, MOD) % MOD
print(ans)
### BUGGY CODE ###

N = int(input())
s = [0]*N
for i in range(N):
    s[i] = input()
ans = 0
p = []

for i in range(N):
    k = sorted(s[i])
    ans += p.count(k)
    p.append(k)

print(ans)

### FIXED CODE ###

N = int(input())
s = [0]*N
p = {}
ans = 0
for i in range(N):
    s[i] = "".join(sorted(input()))
    if s[i] in p:
        ans += p[s[i]]
        p[s[i]] += 1
    else:
        p[s[i]] = 1

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

class LinkedList(object):
    
    def __init__(self):
        self.nodes = []

    def insert(self, node):
        self.nodes.insert(0, node)

    def delete(self, node):
        if node in self.nodes:
            self.nodes.remove(node)

    def deleteFirst(self):
        self.nodes.pop(0)

    def deleteLast(self):
        self.nodes.pop()

def run():
    n = int(input())
    linked_list = LinkedList()
    orders = [input().split() for _ in range(n)]
    for order in orders:
        if order[0] == 'insert':
            linked_list.insert(int(order[1]))
        elif order[0] == 'delete':
            linked_list.delete(int(order[1]))
        elif order[0] == 'deleteFirst':
            linked_list.deleteFirst()
        elif order[0] == 'deleteLast':
            linked_list.deleteLast()
    print(' '.join([str(n) for n in linked_list.nodes]))
    
if __name__ == '__main__':
    run()


### FIXED CODE ###

from collections import deque

def run():
    n = int(input())
    dq = deque()
    for _ in range(n):
        order = input()
        if order[0] == 'i':
            dq.appendleft(order[7:])
        elif order[6] == ' ':
            key = order.split()[1]
            if not key in dq:
                continue
            for i in range(len(dq)):
                if dq[i] == key:
                    dq.remove(key)
                    break
        elif order[6] == 'F':
            dq.popleft()
        elif order[6] == 'L':
            dq.pop()

    print(' '.join(dq))

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

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


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


### FIXED CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


n = int(input())
ans = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        if i == j:
            ans += gcd(i, i, i)
        else:
            ans += gcd(i, i, j) * 3

kai = math.factorial(n)
for i in range(1, n+1):
    for j in range(i+1, n+1):
        for k in range(j+1, n+1):
            ans += gcd(i, j, k) * 6
print(ans)
### BUGGY CODE ###

n,m = list(map(int,input().split()))
h = list(map(int,input().split()))
a_list = []
b_list = []
for i in range(m):
    a,b = list(map(int,input().split()))
    a_list.append(a)
    b_list.append(b)
good_list = list(range(1,n+1))
for a,b in zip(a_list,b_list):
    if a in good_list:
        if h[a-1] < h[b-1] or h[a-1] == h[b-1]:
            good_list.remove(a)
    if b in good_list:
        if h[a-1] > h[b-1] or h[a-1] == h[b-1]:
            good_list.remove(b)
print(len(good_list))

### FIXED CODE ###

n,m = list(map(int,input().split()))
h = list(map(int,input().split()))

not_good = []
for i in range(m):
    a,b = list(map(int,input().split()))
    if h[a-1] <= h[b-1]:
        not_good.append(a)
    if h[a-1] >= h[b-1]:
        not_good.append(b)
print(n-len(set(not_good)))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import deque

N = int(input().strip())
from itertools import combinations
nodes = list(combinations(range(N), 2))
graph = {i:[] for i in nodes}
for x in range(N):
  l = list(map(int,input().split()))
  y = l[0]-1
  prev = (min(x,y),max(x,y))
  for y in l[1:]:
    y -= 1
    now = (min(x,y),max(x,y))
    graph[prev].append(now)
    prev = now

d = {k:1 for k in nodes}
in_cnt = {k:0 for k in nodes}
for x in nodes:
  for y in graph[x]:
    in_cnt[y] += 1
ret = []
q = deque([i for i in nodes if not in_cnt[i]])
if not q:
  print(-1)
  exit()
ans = 0
while q:
  x = q.popleft()
  ret.append(x)
  for y in graph[x]:
    d[y] = max(d[y],d[x]+1)
    ans = max(ans,d[y])
    in_cnt[y] -= 1
    if not in_cnt[y]:
      q.append(y)
if [i for i in nodes if in_cnt[i]]:
  print(-1)
  exit()

print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input().strip())
M = N*(N-1)//2

graph = [[] for i in range(M)]
in_cnt = [0 for i in range(M)]
for x in range(1,N+1):
  l = list(map(int,input().split()))
  y = l[0]
  b,s = max(x,y),min(x,y)
  prev = (b-1)*(b-2)//2+s-1
  for y in l[1:]:
    b,s = max(x,y),min(x,y)
    now = (b-1)*(b-2)//2+s-1
    graph[prev].append(now)
    in_cnt[now] += 1 
    prev = now

d = [1 for k in range(M)]
q = [i for i in range(M) if not in_cnt[i]]

if not q:
  print(-1)
  exit()
ans = 0
while q:
  x = q.pop()
  for y in graph[x]:
    d[y] = max(d[y],d[x]+1)
    ans = max(ans,d[y])
    in_cnt[y] -= 1
    if not in_cnt[y]:
      q.append(y)
if [i for i in range(M) if in_cnt[i]]:
  print(-1)
  exit()

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

s = list(input())
pos = 0
str_len = len(s)
count = 0
state = 0

while pos < str_len:
    if state == 0:
        if s[pos] == "A":
            state = 1
        pos += 1
    elif state == 1:
        if s[pos] == "B":
            state = 2
        elif s[pos] == "A":
            state = 1
        else:
            state = 0
        pos += 1
    elif state == 2:
        if s[pos] == "C":
            s[pos-2:pos+1] = "BCA"
            pos -= 3
            if pos < 0:
                pos = 0
            count += 1
            state = 0
        elif s[pos] == "A":
            state = 1
            pos += 1
        else:
            state = 0
            pos += 1

print(count)


### FIXED CODE ###

s = input()
pos = 0
str_len = len(s)
count = 0
seq_a = 0
seq_bc = 0

while pos < str_len:
    if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if pos + 1 < str_len and s[pos] == "B" and s[pos+1] == "C":
            while pos < str_len and s[pos] == "B" and pos + 1 < str_len and s[pos+1] == "C":
                seq_bc += 1
                pos += 2
            count += seq_a * seq_bc
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_bc = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0

print(count)