# [Solution] Add Modulo 10 solution codeforces

Add Modulo 10 solution codeforces – You are given an array of 𝑛n integers 𝑎1,𝑎2,,𝑎𝑛a1,a2,…,an

You can apply the following operation an arbitrary number of times:

• select an index 𝑖i (1𝑖𝑛1≤i≤n) and replace the value of the element 𝑎𝑖ai with the value 𝑎𝑖+(𝑎𝑖mod10)ai+(aimod10), where 𝑎𝑖mod10aimod10 is the remainder of the integer dividing 𝑎𝑖ai by 1010.

## [Solution] Add Modulo 10 solution codeforces

For a single index (value 𝑖i), this operation can be applied multiple times. If the operation is applied repeatedly to the same index, then the current value of 𝑎𝑖ai is taken into account each time. For example, if 𝑎𝑖=47ai=47 then after the first operation we get 𝑎𝑖=47+7=54ai=47+7=54, and after the second operation we get 𝑎𝑖=54+4=58ai=54+4=58.

Check if it is possible to make all array elements equal by applying multiple (possibly zero) operations.

For example, you have an array [6,11][6,11].

• Let’s apply this operation to the first element of the array. Let’s replace 𝑎1=6a1=6 with 𝑎1+(𝑎1mod10)=6+(6mod10)=6+6=12a1+(a1mod10)=6+(6mod10)=6+6=12. We get the array [12,11][12,11].
• Then apply this operation to the second element of the array. Let’s replace 𝑎2=11a2=11 with 𝑎2+(𝑎2mod10)=11+(11mod10)=11+1=12a2+(a2mod10)=11+(11mod10)=11+1=12. We get the array [12,12][12,12].

Thus, by applying 22 operations, you can make all elements of an array equal.

## [Solution] Add Modulo 10 solution codeforces

The first line contains one integer 𝑡t (1𝑡1041≤t≤104) — the number of test cases. What follows is a description of each test case.

The first line of each test case contains one integer 𝑛n (1𝑛21051≤n≤2⋅105) — the size of the array.

The second line of each test case contains 𝑛n integers 𝑎𝑖ai (0𝑎𝑖1090≤ai≤109) — array elements.

It is guaranteed that the sum of 𝑛n over all test cases does not exceed 21052⋅105.

Output

For each test case print:

• YES if it is possible to make all array elements equal;
• NO otherwise.

You can print YES and NO in any case (for example, the strings yEsyesYes and YES will be recognized as a positive answer) .

## [Solution] Add Modulo 10 solution codeforces

Example
input

Copy
10
2
6 11
3
2 18 22
5
5 10 5 10 5
4
1 2 4 8
2
4 5
3
93 96 102
2
40 6
2
50 30
2
22 44
2
1 5

output

Copy
Yes
No
Yes
Yes
No
Yes
No
No
Yes
No


## [Solution] Add Modulo 10 solution codeforces

The first test case is clarified above.

In the second test case, it is impossible to make all array elements equal.

In the third test case, you need to apply this operation once to all elements equal to 55.

In the fourth test case, you need to apply this operation to all elements until they become equal to 88.

In the fifth test case, it is impossible to make all array elements equal.

In the sixth test case, you need to apply this operation to all elements until they become equal to 102102.