cswork / OAOpen practice workspace

AmazonOA #16

Find Maximum Packages

Estimated MediumJudge-ready

Topics (AI-labelled)HashingTwo Pointers

Choose a single target total price T. Each bundle contains one or two products whose total price is T; each product can be used at most once, and some products may be left unused. Find the maximum number of bundles that can be formed.

Input

The first line contains n (1..200000), and the second line contains n prices (1..2000).

Output

Output one integer, the answer required by the problem.

Example 1

Input:

9
4 5 10 3 1 2 2 2 3

Output:

4

Example 2

Input:

3
2 2 2

Output:

3

Example 3

Input:

1
1

Output:

1

Example notes

Example 1: with target price 5 you can form [5], [4,1] and two [3,2], 4 bundles in total; enumerating other targets cannot give more. Example 2: with target price 2, each 2 forms its own bundle, 3 bundles in total, instead of forcing them into pairs. Example 3: the only product 1 forms a bundle by itself, so the answer is 1.

Editorial

Loading solution…