Problem list
Log in
#coci00196 · COCI 2011/2012 Contest 1

Ples

Gold IV 1.0 s 32 MB

There are $N$ boys and $N$ girls at a dance party. We have measured their heights. Each boy will only dance with a girl and each girl will only dance with a boy. Everyone will dance with at most one partner.

Each boy either wants to dance with a girl who is taller than him or with a girl who is shorter than him. Analogously, each girl either wants to dance with a boy who is taller than her or with a boy who is shorter than her. Boys and girls who are equally tall never want to dance with each other.

Respecting everyone's wishes, determine the maximum number of dancing pairs that can be achieved.

Input

The first line of input contains the positive integer $N$ ($1 \le N \le 100,000$).

The second line of input contains $N$ integers whose absolute values are between $1500$ and $2500$, inclusive. Their absolute values represent the height of each of the boys in millimetres. Positive height values indicate boys who want to dance with girls taller than themselves, while negative height values indicate boys who want to dance with girls shorter than themselves.

The third line of input contains $N$ integers whose absolute values are between $1500$ and $2500$, inclusive. Their absolute values represent the height of each of the girls in millimetres. Positive height values indicate girls who want to dance with boys taller than themselves, while negative height values indicate girls who want to dance with boys shorter than themselves.

Output

The only line of output must contain the maximum number of dancing pairs.

Example 1

Input
1
-1800
1800
Output
0

Example 2

Input
1
1700
-1800
Output
1

Example 3

Input
2
-1800 -2200
1900 1700
Output
2
Source
COCI 2011/2012 Contest 1
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code