NOI Contest Archive

Archive / 2021 / November 2021

The Bounteous Knight

Easy · National Olympiad in Informatics Sri Lanka - November 2021

Sir Galahad is known throughout the kingdom for his kindness and generosity. With the kingdom facing a deadly famine, he has decided to help as many villagers as he can by providing each villager with two sacks of rye produced in his own lands.

Sir Galahad has n number of sacks all weighing different amounts, as \(a\)\(1\), \(a\)\(2\), …,\(a\)\(n\). There are no two sacks of rye (\(i\), \(j\)) (\(1\) \(\leq\) \(i\), \(j\) \(\leq\) \(n\)) where \(i\) \(\neq\) \(j\) and \(a\)\(i\) = \(a\)\(j\).

If two different villagers are given sacks of rye weighing different amounts, Sir Galahad believes it may cause a conflict. Such that if one villager is given rye sacks \(a\)\(i\) and \(a\)\(j\), whilst another villager is given rye sacks \(a\)\(k\) and \(a\)\(p\) where, (\(a\)\(i\) + \(a\)\(j\)) \(\neq\) (\(a\)\(k\) + \(a\)\(p\)) it causes conflict. Sir Galahad wants to give two sacks of rye to each villager and a sack of rye cannot be shared between two or more villagers.

With the goal of helping as many villagers as he can, Sir Galahad instructs you to find the maximum number of villagers, he can provide two sacks of rye to, without causing any conflict.

Input Format

Output Format

Constraints

Sample Input 0

8
1 8 3 11 4 9 2 7

Sample Output 0

3

Sample Input 1

7
3 1 7 11 9 2 12

Sample Output 1

2