Harryxun/stf_run huggingface dataset:
from collections import defaultdict

def getlist():
	return list(map(int, input().split()))
D = defaultdict(int)
V = []

N, K = getlist()
for i in range(N):
	t, d = getlist()
	V.append([d, t])

V = sorted(V)

ans = []
ex = []
k = 0
for i in range(N):
	x = V[-1 - i][1]
	if D[x] == 0:
		ans.append(V[-1 - i])
		D[x] += 1
		k += 1
	else:
		ex.append(V[-1 - i])
	if k == K:
		break

if k < K:
	for i in range(K - k):
		ans.append(ex[i])
	eex = []
	for i in range(K - k, len(ex)):
		eex.append(ex[i])
else:
	eex = ex
ans = sorted(ans)
eex = sorted(eex)


A = 0
for i in range(K):
	A += ans[i][0]
A += k * k
n = min(k, N - K)
for i in range(n):
	if ans[i][0] + ((k - i) ** 2) - ((k - i - 1) ** 2) < eex[-1 - i][0]:
		A += eex[-1 - i][0] - ans[i][0] - ((k - i) ** 2) + ((k - i - 1) ** 2)
	else:
		break

print(A)

### FIXED CODE ###

from collections import defaultdict

def getlist():
	return list(map(int, input().split()))
D = defaultdict(int)
V = []

N, K = getlist()
for i in range(N):
	t, d = getlist()
	V.append([d, t])

V = sorted(V)

ans = []
ex = []
k = 0
for i in range(N):
	x = V[-1 - i][1]
	if k < K:
		if D[x] == 0:
			ans.append(V[-1 - i])
			D[x] += 1
			k += 1
		else:
			ex.append(V[-1 - i])
	else:
		ex.append(V[-1 - i])


if k < K:
	for i in range(K - k):
		ans.append(ex[i])
	eex = []
	for i in range(K - k, len(ex)):
		eex.append(ex[i])
else:
	eex = ex
ans = sorted(ans)
eex = sorted(eex)


A = 0
for i in range(K):
	A += ans[i][0]
A += k * k
n = min(k, N - K)
for i in range(n):
	if ans[i][0] + ((k - i) ** 2) - ((k - i - 1) ** 2) < eex[-1 - i][0]:
		A += eex[-1 - i][0] - ans[i][0] - ((k - i) ** 2) + ((k - i - 1) ** 2)
	else:
		break

print(A)
@njit
def solve():
  import sys
  readline=sys.stdin.readline
  
  N,K = map(int,readline().split())
  A = list(map(int,readline().split()))
  def calc(A):
      B = [0] * len(A)
      for i in range(len(A)):
          B[max(0,i - A[i])] += 1
          if i + A[i] + 1 < len(A):
              B[i + A[i] + 1] -= 1
      for i in range(1,len(B)):
          B[i] = B[i - 1] + B[i]
      return B
  
  for i in range(K):
    A = calc(A)
    if len(set(A)) == 1 and A[0] == N:
      print(*A)
      break
  else:
    print(*A)
  
solve()

### FIXED CODE ###

import sys
readline=sys.stdin.readline

N,K = map(int,readline().split())
A = list(map(int,readline().split()))
def calc(A):
    B = [0] * len(A)
    for i in range(len(A)):
        B[max(0,i - A[i])] += 1
        if i + A[i] + 1 < len(A):
            B[i + A[i] + 1] -= 1
    for i in range(1,len(B)):
        B[i] = B[i - 1] + B[i]
    return B

for i in range(K):
  A = calc(A)
  if len(set(A)) == 1 and A[0] == N:
    print(*A)
    break
else:
  print(*A)
N=int(input())
for i in range(N):
  a=float(input().split())
  b=input().split()
total=0
j=0
while j<N:
  if b[j]='JPY':
    total = total+ a[j]
  else:
    total = total+380000.0*a[j]

print(total)

### FIXED CODE ###

N=int(input())
a=[]
b=[]
for i in range(N):
  x,y=input().split()
  a.append(float(x))
  b.append(y)
total=0
for j in range(N):
  if b[j]=='JPY':
    total += a[j]
  else:
    total += 380000.0*a[j]
print(total)
def findTriplet(arr, n): 

      

    # sort the array 

    arr.sort() 

   

    # for every element in arr 

    # check if a pair exist(in array) whose 

    # sum is equal to arr element 

    i = n - 1

    while(i >= 0): 

        j = 0

        k = i - 1

        while (j < k): 

            if (arr[i] == arr[j] + arr[k]): 

                 

                # pair found 

                print "numbers are ", arr[i], arr[j], arr[k] 

                return

            elif (arr[i] > arr[j] + arr[k]): 

                j += 1

            else: 

                k -= 1

        i -= 1

          

    # no such triplet is found in array 

    print "No such triplet exists"

   
# driver program 

arr = [ 5, 32, 1, 7, 10, 50, 19, 21, 2 ] 

n = len(arr) 
findTriplet(arr, n) 

  
# This code is contributed by Sachin Bisht 


### FIXED CODE ###

def is_poor(triple_numbers):
    count_map = {}
    for num in triple_numbers:
        if num not in count_map:
            count_map[num] = 1
        else:
            count_map[num] += 1
    
    for key, value in count_map.items():
        if value == 2:
            return True
    return False

is_p = is_poor(list(map(int, input().split())))

if is_p:
    print("Yes")
else:
    print("No")
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
S = sum(A)
if A[M-1] >=  S / (4 * M):
    print('Yes')
else:
    print('No')


### FIXED CODE ###

li= list(map(int, input().split()))
li.insert(1, li.pop(0))
li.insert(2, li.pop(0))
li.insert(0, li.pop(1))
print(li[0], li[1], li[2])
import sys
import math

sys.setrecursionlimit(5000)

A, B, Q = map(int, input().split())
LIMIT = 2*(10**10)
shrines = [-LIMIT] + [int(input()) for i in range(A)] + [LIMIT]
temples = [-LIMIT] + [int(input()) for j in range(B)] + [LIMIT]

def b_temp_search(num, idx):
    if num >= temples[idx] and num <= temples[idx+1]:
        return idx
    elif num < temples[idx]:
        if idx == 1:
            return 0
        return b_temp_search(num, math.ceil(idx/2))
    else:
        if idx == B:
            return B + 1
        return b_temp_search(num, math.ceil((B+idx+1)/2))

def b_sh_search(num, idx):
    if num >= shrines[idx] and num <= shrines[idx+1]:
        return idx
    elif num < shrines[idx]:
        if idx == 1:
            return 0
        return b_sh_search(num, math.ceil(idx//2))
    else:
        if idx == A:
            return A + 1
        return b_sh_search(num, math.ceil((A+idx+1)/2))

for k in range(Q):
    x = int(input())
    sh_idx = b_sh_search(x, math.ceil((A+2)//2))
    temp_idx = b_temp_search(x, math.ceil((B+2)//2))
    ptn1 = max(abs(x-shrines[sh_idx]), abs(x-temples[temp_idx]))
    ptn2 = max(abs(x-shrines[sh_idx+1]), abs(x-temples[temp_idx+1]))
    ptn3 = min((temples[temp_idx+1] - x)*2 + x - shrines[sh_idx], temples[temp_idx+1] - x + (x - shrines[sh_idx])*2)
    ptn4 = min((shrines[sh_idx+1] - x)*2 + x - temples[temp_idx], shrines[sh_idx+1] - x + (x - temples[temp_idx])*2)
    ans = min(ptn1, ptn2, ptn3, ptn4)
    print(ans)


### FIXED CODE ###

from bisect import bisect_left, bisect_right
INF = 10**12
A, B, Q = map(int, input().split())
shrines = [-INF] + [int(input()) for _ in range(A)] + [INF]
temples = [-INF] + [int(input()) for _ in range(B)] + [INF]
for _ in range(Q):
  query = int(input())
  sh_pos = bisect_left(shrines, query)
  te_pos = bisect_left(temples, query)
  ans = INF
  for s in shrines[sh_pos-1:sh_pos+1]:
    for t in temples[te_pos-1:te_pos+1]:
      dis = min(abs(s-query)+abs(s-t),abs(t-query)+abs(t-s))
      ans = min(ans, dis)
  print(ans)
n=int(input())
a=list(map(int,input().split()))
ua=list(set(a))
total=sum([sum(range(a.count(x))) for x in ua])
d={}
total=0
for x in ua:
    c=a.count(x)
    d[x]=c
    total+=sum(range(c))
for i in range(n):
    print(total-d[i]+1)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
d={}
for x in a:
    if d.get(x) is None:
        d[x]=1
        continue
    d[x]+=1
total=0
for v in d.values():
    total+=(v-1)*v//2
for x in a:
    print(total-d[x]+1)
N,P = map(int,input().split())
ans=1
i=2
if N==1:
  print(P)
  exit()
if N>=40 or P==1:
  print(1)
  exit()
  
while i<=(P**(1.1/N)):
  while P%(i**N) == 0:
    ans *= i
    P = P//(i**N)
  if i==2:
    i+=1
  else:
    i+=2
print(ans)N,P = map(int,input().split())
ans=1
i=2
if N==1:
  print(P)
  exit()
if N>=40 or P==1:
  print(1)
  exit()
  
while i<=(P**(1.1/N)):
  while P%(i**N) == 0:
    ans *= i
    P = P//(i**N)
  if i==2:
    i+=1
  else:
    i+=2
print(ans)

### FIXED CODE ###

N,P = map(int,input().split())
i = round(P**(1/N))
res = []
if N == 1:
  print(P)
elif P == 1:
  print(1)
else:
  for i in range(i,0,-1):
    if P%i**N==0:
      print(i)
      break
n = int(input())
A = [int(i) for i in input().split()]
Max = max(A)
cnt_dict = collections.Counter(A)
#Dict[i]はi未満の約数がAに存在しなければTrue
Dict = {a:True for a in A}
for a in A:
    times = 2
    while a*times<=Max:
        Dict[a*times]=False
        times +=1
ans = 0
for a in A:
    if cnt_dict[a]==1 and Dict[a]:
        ans +=1
print(ans)


### FIXED CODE ###

from collections import deque
import collections
import math
"""
#n = int(input())
#A = [int(i) for i in input().split()]
n = 10**5
A = [int(i)+1 for i in range(10**5,0,-1)]
A.sort()
ans = 0
ans_list = []
kaburi = {}
for i in A:
    Flag = True
    for j in ans_list:
        if i==j:
            kaburi[i]=True
            Flag = False
            break
        if i%j==0:
            Flag = False
            break
    if Flag:
        ans_list.append(i)
        ans += 1
print(ans-len(kaburi))
"""


n = int(input())
A = [int(i) for i in input().split()]
Max = max(A)
cnt_dict = collections.Counter(A)
#Dict[i]はi未満の約数がAに存在しなければTrue
Dict = {a:True for a in A}
for a in A:
    times = 2
    while a*times<=Max:
        Dict[a*times]=False
        times +=1
ans = 0
for a in A:
    if cnt_dict[a]==1 and Dict[a]:
        ans +=1
print(ans)
import sys
sys.setrecursionlimit(10**9)

class UnionFind():
	def __init__(self, n):
		self.size = n
		self.root = [-1 for _ in range(n+1)]
		self.rnk = [0 for _ in range(n+1)]

	def findRoot(self, a):
		if self.root[a] < 0:
			return a
		else:
			return self.findRoot(self.root[a])

	def uniteTree(self, a, b):
		a = self.findRoot(a)
		b = self.findRoot(b)

		if a == b:
			return

		elif self.rnk[a] > self.rnk[b]:
			self.root[a] += self.root[b]
			self.root[b] = a

		elif self.rnk[b] > self.rnk[a]:
			self.root[b] += self.root[a]
			self.root[a] = b

		elif self.rnk[a] == self.rnk[b]:
			self.root[b] += self.rnk[a]
			self.root[a] = b
			self.rnk[b] += 1

	def judgeTree(self, a, b):
		return self.findRoot(a) == self.findRoot(b)

	def count(self, a):
		return self.rnk[self.findRoot(a)] * (-1)



N, M = map(int, input().split())
A = list(map(int, input().split()))
O = [list(map(int, input().split())) for _ in range(M)]

ope = UnionFind(N)

for i in range(M):
	ope.uniteTree(O[i][0], O[i][1])

cnt = 0
for i in range(N):
	if ope.judgeTree(A[i], i+1):
		cnt += 1

print(cnt)

### FIXED CODE ###

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

N, M = map(int, input().split())
A = list(map(int, input().split()))
O = [list(map(int, input().split())) for _ in range(M)]

ope = UnionFind(N)

for i in range(M):
	ope.Unite(O[i][0], O[i][1])

cnt = 0

for i in range(N):
	if ope.isSameGroup(i+1, A[i]):
		cnt += 1

print(cnt)
import numpy as np
# from itertools import accumulate

N = int(input())
s = input()
w = np.array(list(map(lambda x: 1 if x == 'W' else 0, s)))
e = np.array(list(map(lambda x: 1 if x == 'E' else 0, s)))
w = np.add.accumulate(w)
e = np.flip(e)
e = np.add.accumulate(e)
e = np.flip(e)
# print(w)
# print(e)
ans = []
for i in range(N):
    num = 0
    if 0 < i: num += w[i - 1]
    if i < N - 1: num += e[i + 1]
    ans.append(num)
# print(ans)
print(min(ans))

### FIXED CODE ###

from itertools import accumulate
N = int(input())
s = input()
w = list(map(lambda x: 1 if x == 'W' else 0, s))
e = list(map(lambda x: 1 if x == 'E' else 0, s))
e.reverse()
w = list(accumulate(w))
e = list(accumulate(e))
e.reverse()
# print(w)
# print(e)
ans = []
for i in range(N):
    num = 0
    if 0 < i: num += w[i - 1]
    if i < N - 1: num += e[i + 1]
    ans.append(num)
# print(ans)
print(min(ans))
n, m = map(int, input().split())
num_of_matches = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
# a = [(i, num_of_matches[i]) for i in map(int, input().split())]
a = list(map(int, input().split()))

a.sort(reverse=True)
dp = [-1] * (n+1)
dp[0] = 0
for i in range(1, n+1):
    val = -1
    for aa in a:
        if i - num_of_matches[aa] < 0:
            continue
        if i - num_of_matches[aa] == 0:
            val = 1
        elif dp[i - num_of_matches[aa]] > 0:
            val = max(val, dp[i - num_of_matches[aa]] + 1)
    dp[i] = val

res = ''
remain = dp[n]
match = n
while match > 0:
    for i in range(m):
        if remain - 1 == dp[match-num_of_matches[a[i]]]:
            match -= num_of_matches[a[i]]
            remain -= 1
            res += str(a[i])
            break
print(res)


### FIXED CODE ###

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

a.sort(reverse=True)
num_of_matches = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (n+1)
dp[0] = 0
for i in range(1, n+1):
    val = -1
    for aa in a:
        if i - num_of_matches[aa] < 0:
            continue
        if i - num_of_matches[aa] == 0:
            val = 1
        elif dp[i - num_of_matches[aa]] > 0:
            val = max(val, dp[i - num_of_matches[aa]] + 1)
    dp[i] = val

res = ''
remain = dp[n]
match = n
while match > 0:
    for i in range(m):
        if match - num_of_matches[a[i]] >= 0 and remain - 1 == dp[match-num_of_matches[a[i]]]:
            match -= num_of_matches[a[i]]
            remain -= 1
            res += str(a[i])
            break
print(res)
import copy

class Item:
	def __init__(self):
		self.weight = 0
		self.value = 0

	def __repr__(self):
		return "(" + str(self.weight) + ", " + str(self.value) + ")"

items = []


def main():
	N, W = [int(x) for x in input().split()]
	global items
	
	for _ in range(0, N):
		x = Item()
		x.weight, x.value = [int(y) for y in input().split()]
		items.append(x)


	dp = [[]] * (N + 1)
	for _ in range(0, N + 1):
		dp[_] = [0] * (W + 1)
	

	dp[0][0] = 0
	for i in range(1, N + 1):
		for j in range(0, W + 1):
			if items[i - 1].weight > j:
				dp[i][j] = dp[i - 1][j]
			else:
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - items[i - 1].weight] + items[i - 1].value)

	print(dp[N][W])

if __name__ == "__main__":
	main()

### FIXED CODE ###

import copy

def main():
	n = int(input())
	a = []
	for _ in range(0, n):
		x = [int(x) for x in input().split()]
		a.append(x)
	
	cur = a[0]
	nxt = [0] * 3

	for i in range(1, len(a)):
		nxt[0] = max(a[i][0] + cur[1], a[i][0] + cur[2])
		nxt[1] = max(a[i][1] + cur[0], a[i][1] + cur[2])
		nxt[2] = max(a[i][2] + cur[1], a[i][2] + cur[0])

		cur = copy.deepcopy(nxt)

	print(max(cur[0], cur[1], cur[2]))

if __name__ == "__main__":
	main()
import sys
import bisect
n,m=map(int,input().split())
l=[[int(i) for i in l.split()] for l in sys.stdin]
s=[[0] for i in range(10**5+1)]
for i in l:
  s[i[0]].append(i[1])
for i in range(len(s)):
  s[i].sort()
for i in l:
  print('{:06}{:06}'.format(i[0],bisect.bisect_left(s[i[0]],i[1]))

### FIXED CODE ###

import sys
import bisect
n,m=map(int,input().split())
l=[[int(i) for i in l.split()] for l in sys.stdin]
s=[[0] for i in range(10**5+1)]
for i in l:
  s[i[0]].append(i[1])
for i in range(len(s)):
  s[i].sort()
for i in l:
  print('{:06}{:06}'.format(i[0],bisect.bisect_left(s[i[0]],i[1])))
import sys
from heapq import heapify,heappop,heappush,heapreplace

read=sys.stdin.read
readline=sys.stdin.readline

def main():
  n,m,*lrd=map(int,read().split())
  hp=[]
  for l,r,d in zip(*[iter(lrd)]*3):
    if l>r:
      hp.append(hp,(r,l,-d))
    else:
      hp.append(hp,(l,r,d))
  heapify(hp)
  if not hp:
    print('Yes')
    return
  while hp:
    ce=heappop(hp)
    while hp:
      ne=hp[0]
      if ce[0]==ne[0]:
        if ce[1]==ne[1]:
          if ce[2]!=ne[2]:
            print('No')
            return
          else:
            heappop(hp)
        else:
          heapreplace(hp,(ce[1],ne[1],ne[2]-ce[2]))
      else:
        break      
  print('Yes')

if __name__=='__main__':
  main()
      
    
    

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

read=sys.stdin.read
class Unionfind():
    def __init__(self,n):
        self.parents=[-1]*n
        self.dist=[0]*n 
    
    def find(self,x):
        if self.parents[x]<0:
            return self.dist[x],x
        else:
            tmp=self.find(self.parents[x])
            self.dist[x]+=tmp[0]
            self.parents[x]=tmp[1]
        return self.dist[x], self.parents[x]
    
    def union(self,x,y,d):
        rx=self.find(x)[1]
        ry=self.find(y)[1]
        diff=self.dist[y]-self.dist[x]-d
        if rx==ry:
            if diff!=0:
                return True
            return False
        if diff<0:
            rx,ry=ry,rx
            diff=-diff
        self.parents[ry]=min(self.parents[ry],self.parents[rx]-diff)
        self.parents[rx]=ry
        self.dist[rx]=diff
        return False
    
def main():
    n,m,*lrd=map(int,read().split())
    v=Unionfind(n)
    for l,r,d in zip(*[iter(lrd)]*3):
        if v.union(l-1,r-1,d):
            print('No')
            break
    else:
        if max(-d-1 for d in v.parents if d<0) >10**9:
            print('No')
        else:
            print('Yes')
if __name__=='__main__':
    main()
from collections import Counter

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

even = a[1::2]
odd = a[::2]

c_even = Counter(even)
c_odd = Counter(odd)

arr_even = c_even.most_common()
arr_odd = c_odd.most_common()

sum_even = sum(x[1] for x in arr_even)
sum_odd = sum(x[1] for x in arr_odd)

min_sum = sum_even - arr_even[0] + n // 2

for i, x in arr_even:
    for j, y in arr_odd:
        if i != j:
            cnt = sum_even - x + sum_odd - y
            min_sum = min(min_sum, cnt)
            break
        else:
            continue

print(min_sum)

### FIXED CODE ###

from collections import Counter

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

even = a[1::2]
odd = a[::2]

c_even = Counter(even)
c_odd = Counter(odd)

arr_even = c_even.most_common()
arr_odd = c_odd.most_common()

sum_even = sum(x[1] for x in arr_even)
sum_odd = sum(x[1] for x in arr_odd)

min_sum = sum_even - arr_even[0][1] + n // 2

for i, x in arr_even:
    for j, y in arr_odd:
        if i != j:
            cnt = sum_even - x + sum_odd - y
            min_sum = min(min_sum, cnt)
            break
        else:
            continue

print(min_sum)
n, m = map(int, input().split())
rootList = [-1 for i in range(n)]
 
def getRoot(x):
    if rootList[x] < 0:
        rootList[x] = x
        return x
    return getRoot(rootList[x])
 
 
def setSameRoot(x, y):
    x = getRoot(x)
    y = getRoot(y)
    if x != y:
        rootList[x], rootList[y] = min(x, y), min(x, y)
 
for i in range(m):
    s, t = map(int, input().split())
    setSameRoot(s, t)
q = int(input())
for i in range(q):
    s, t = map(int, input().split())
    print("yes" if getRoot(s) == getRoot(t) != -1 else "no")

### FIXED CODE ###

n, m = map(int, input().split())
rootList = [-1 for i in range(n)]
 
def getRoot(x):
    r = rootList[x]
    if r < 0:
        rootList[x] = x
    elif r != x:
        rootList[x] = getRoot(r)
    return rootList[x]
 
 
def setSameRoot(x, y):
    x = getRoot(x)
    y = getRoot(y)
    if x != y:
        rootList[x] = rootList[y] = min(x, y)
 
for i in range(m):
    s, t = map(int, input().split())
    setSameRoot(s, t)
q = int(input())
for i in range(q):
    s, t = map(int, input().split())
    print("yes" if getRoot(s) == getRoot(t) else "no")
a, b = map(int,input().split())
[a,b] = [a,b].sort()
if a == 1:
    if b==1:
        print(b)
    else:
        print(b-2)
else:
    print((a-2) * (b-2))


### FIXED CODE ###

a, b = map(int,input().split())
c = [a,b]
c.sort()
if c[0] == 1:
    if c[1]==1:
        print(1)
    else:
        print(c[1]-2)
else:
    print((c[0]-2) * (c[1]-2))
n = int(input())
red = []
red_x = []
blue = []
blue_y = []
for i in range(n):
    a, b = map(int,input().split())
    red.append([a,b])
    red_x.append(a)
    
for i in range(n):
    c, d = map(int,input().split())
    blue.append([c,d])
    blue_y.append(d)

count = 0    
for i in range(n):
    p = max(red_x)
    s = min(blue_y)
    q = 0
    r = 0
    jjj = 0
    kkk = 0
    for j in range(n):
        if red[j][0] == p:
            q = red[j][1]
            jjj = j
    for k in range(n):
        if blue[k][1] == s:
            r = blue[k][0]
            kkk = k
            
    if p < r and q < s:
        count = count + 1 
        red_x.remove(p)
        blue_y.remove(s)
        red.remove(red[jjj])
        blue.remove(ble[kkk])


    else:
        None
        
print(count)

### FIXED CODE ###

n = int(input())
red = []
blue = []

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

for i in range(n):
    c, d = map(int,input().split())
    blue.append([c,d])
    
red_sort = list(reversed(sorted(red, key=lambda y: y[1])))
blue_sort = sorted(blue, key=lambda x: x[0])

# print(red_sort)
# [[1, 3], [2, 0], [3, 1]]
# print(blue_sort)
# [[4, 2], [0, 4], [5, 5]]

pair = []
for blue_point in blue_sort:
    x_blue = blue_point[0]
    y_blue = blue_point[1]
    
    for red_point in red_sort:
        x_red = red_point[0]
        y_red = red_point[1]
        
        if x_red<x_blue and y_red<y_blue:
            if not (red_point in pair) and not (blue_point in pair):
                pair.append(red_point)
                pair.append(blue_point)
    
print(len(pair) // 2)
N=int(input())
D=False
ans=1
List=list(map(int,input()split()))
if 0 in List:
  print(0)
else:
  for i in ragne(N):
    ans=ans*List[i]
    if ans>10**18:
      print(-1)
      D=True
      break
  if D==False:
    print(ans)

### FIXED CODE ###

N=int(input())
D=False
ans=1
List=list(map(int,input().split()))
if 0 in List:
  print(0)
else:
  for i in range(N):
    ans=ans*List[i]
    if ans>10**18:
      print(-1)
      D=True
      break
  if D==False:
    print(ans)
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [0] * (N+1)
for i, a in enumerate(A):
    B[i+1] = B[i] + a%K
for i in range(N+1):
    B[i] -= i
    B[i] %= K
ans = 0
# compress
C = B.copy()
C.sort()
I = dict()
itmp = 0
I[C[0]] = 0
for i in range(1, N+1):
    if C[i] != C[i-1]:
        itmp += 1
        I[C[i]] = itmp

tbl = [0] * (N+1)
for i in range(min(K,N+1)):
    tbl[I[B[i]]] += 1
    ans += tbl[I[B[i]]] - 1
for i in range(K, N+1):
    tbl[I[B[i-K]]] -= 1
    tbl[I[B[i]]] += 1
    ans += tbl[I[B[i]]] - 1
print(ans)


### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [0] * (N+1)
for i, a in enumerate(A):
    B[i+1] = B[i] + a%K
for i in range(N+1):
    B[i] -= i
    B[i] %= K
ans = 0
# compress
C = B[::]
C.sort()
I = dict()
itmp = 0
I[C[0]] = 0
for i in range(1, N+1):
    if C[i] != C[i-1]:
        itmp += 1
        I[C[i]] = itmp

tbl = [0] * (N+1)
for i in range(min(K,N+1)):
    tbl[I[B[i]]] += 1
    ans += tbl[I[B[i]]] - 1
for i in range(K, N+1):
    tbl[I[B[i-K]]] -= 1
    tbl[I[B[i]]] += 1
    ans += tbl[I[B[i]]] - 1
print(ans)
N, M = map(int,input().split())
a = list(map(int, input().split()))
a.sort()
#print(a)
if N > M:
    ans = 0
else:
    distance = [abs(a[i+1] - a[i]) for i in range(M-1)]
    #print(distance)
    distance.sort()
    #print(distance)
    del distance[M-N:]
    ans = 0 
    for j in distance:
        ans += j
print(ans)

### FIXED CODE ###

T,x = map(int, input().split())
#print(T,x)
t = T/x
print(round(t,10))
import re
S = int(input())
print(re.sub(r"[a-z]", "x", S)) 

### FIXED CODE ###

import re
s = input()
print(re.sub(r"[a-z]", "x", s))
import sys
l=lambda: sys.stdin.readline().strip()
i,x=1,l()
while x !='0':
	print(f"Case {i}: {x}")
	i,x=i+1,l()

### FIXED CODE ###

i,x=1,input()
while x !='0':
	print("Case {}:".format(i),x)
	i+=1;x=input()