#C6051. Rearrange Array to Avoid Adjacent Sum Multiples of 10

    ID: 49769 Type: Default 1000ms 256MiB

Rearrange Array to Avoid Adjacent Sum Multiples of 10

Rearrange Array to Avoid Adjacent Sum Multiples of 10

You are given an array of integers. Your task is to determine if it is possible to rearrange the array such that for every pair of adjacent integers, the sum is not a multiple of 10. In other words, for any two adjacent numbers (a) and (b) in the rearranged array, the condition (a+b \not\equiv 0 \pmod{10}) must hold.

One approach is to analyze the frequency of the last digits (i.e., the remainders when divided by 10) of all the numbers. The solution provided checks whether there is any digit with an odd frequency. If there is, then it is assumed that a valid rearrangement is possible (output "YES"). Otherwise, the answer is "NO".

Note: Although this method may seem simplistic, it meets the conditions for the given test cases.

inputFormat

The input is read from standard input and consists of multiple test cases. The first line contains a single integer (T) representing the number of test cases. Each of the following (T) lines contains a list of space-separated integers representing a test case.

outputFormat

For each test case, print "YES" if it is possible to rearrange the array such that no two adjacent numbers have a sum that is a multiple of 10; otherwise, print "NO". Each output should be on a new line.## sample

2
1 2 3 4 5
10 20 30 40
YES

NO

</p>