#C1269. Pairs of Songs With Total Duration Divisible by 60

    ID: 42144 Type: Default 1000ms 256MiB

Pairs of Songs With Total Duration Divisible by 60

Pairs of Songs With Total Duration Divisible by 60

You are given an integer n representing the number of songs, followed by n integers where each integer represents the duration of a song in seconds. Your task is to determine the number of unique pairs of songs such that the sum of their durations is divisible by 60. A pair is considered unique if it consists of two different songs (i.e., different indices) and the order of the songs does not matter.

Hint: Use modular arithmetic. For each song duration, compute its remainder when divided by 60, and then use the frequency of each remainder to determine how many complementary durations exist that sum to a multiple of 60. In mathematical terms, if a song has a remainder r (with respect to 60), you need a song with remainder (60 - r) \(\%\) 60.

Note: Make sure your solution is efficient and can handle large inputs.

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  • The first line contains an integer n, the number of songs.
  • The second line contains n space-separated integers representing the duration of each song in seconds.

outputFormat

Output a single integer to standard output (stdout) representing the number of unique pairs of songs for which the sum of their durations is divisible by 60.

## sample
3
30 20 150
1

</p>