PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CC0000058. Hai người bạn hay ghen (Jealous Two)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Hai người bạn hay ghen (Jealous Two)

Jealous Two

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn candidate gifts. Person one values gift ii at AiA_i, and person two values it at BiB_i. Assign one gift to each person (the same gift may be chosen twice). Count ordered assignments in which each person values their own gift at least as highly as the other person's gift.

Input

The first line contains nn, followed by the array AA and then the array BB.

Output

Print the number of valid ordered assignments.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20; 0≤Ai,Bi≤1090\le A_i,B_i\le10^9.
  • Subtask 2 (30 points): 1≤n≤15001\le n\le1500; 0≤Ai,Bi≤1090\le A_i,B_i\le10^9.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le200000; 0≤Ai,Bi≤1090\le A_i,B_i\le10^9.

Examples

Input

3
50 100 150
1 3 2

Output

4

Explanation

The three choices giving both people the same gift and the ordered choice (gift 3 for person one, gift 2 for person two) make four assignments.