cswork / OAOpen practice workspace

AmazonOA #269

Maximize Similarity

Estimated EasyJudge-ready

Topics (AI-labelled)Bits & MathIn-place Arrays

You are given two arrays inv1 and inv2 of equal length. Any number of times, you may choose distinct i and j and, only when inv1[j]>0, take 1 from j and add 1 to i. Inventory may become 0 after the operations but never negative; inv2 does not change. The similarity is the number of indices whose values are equal in both arrays. Find the maximum similarity.

Input

The first line contains n, the second line contains inv1, and the third line contains inv2. 1≤n≤100000; every value in both initial arrays is in 1..10000.

Output

Output a single integer, the answer.

Example 1

Input:

3
1 1 1
4 4 4

Output:

0

Example 2

Input:

2
1 4
2 3

Output:

2

Example 3

Input:

3
10 1 1
1 1 1

Output:

2

Example notes

The answers are 0, 2 and 2 respectively. You cannot keep taking from a position whose inventory is 0, so in the first example the budget is not enough to match any 4; in the third example the extra total of 9 must go to at least one unmatched position.

Editorial

Loading solution…