#K94427. Maximum Number-Friend Pairs

    ID: 38639 Type: Default 1000ms 256MiB

Maximum Number-Friend Pairs

Maximum Number-Friend Pairs

In the kingdom of Zombieland, the zombies have invented an interesting game called "Number-Friends". In this game, two zombies are considered number-friends if the sum of the digits of their ages is the same. Given the list of ages of all zombies, your task is to form as many number-friend pairs as possible.

Rules:

  • Each zombie has a unique age.
  • A pair of zombies is valid if the sum of the digits of the first zombie's age equals the sum of the digits of the second zombie's age.
  • Each zombie can be used in at most one pair.

Your goal is to compute the maximum number of such pairs.

Mathematically, if you let \( s(a) \) denote the sum of the digits of age \( a \) then for a given set of ages \( A \), you need to maximize the number of pairs \( (a, b) \) such that:

[ s(a) = s(b) \quad \text{and} \quad a \neq b ]

inputFormat

The input is read from standard input (stdin) and is formatted as follows:

  1. The first line contains a single integer \( n \) which is the number of zombies.
  2. The second line contains \( n \) integers separated by spaces, where each integer represents the age of a zombie.

outputFormat

Output a single integer to standard output (stdout) which is the maximum number of number-friend pairs that can be formed.

## sample
5
12 21 13 31 22
2