#P1356. Sequence Divisibility
Sequence Divisibility
Sequence Divisibility
Given an integer sequence, you can insert a '+' or '-' sign between any two consecutive integers to form an expression. In other words, for a sequence \(a_1, a_2, \ldots, a_n\), you can form an expression of the form
\(a_1 \; \square \; a_2 \; \square \; \cdots \; \square \; a_n\), where each \(\square\) can be either \(+\) or \(-\).
If there exists at least one such expression whose value is divisible by \(k\) (i.e. equals \(0 \pmod{k}\)), we say that the sequence is divisible by \(k\). Your task is to determine whether a given sequence is divisible by a given integer \(k\).
inputFormat
The first line contains two integers \(n\) and \(k\), where \(n\) is the number of integers in the sequence.
The second line contains \(n\) space-separated integers representing the sequence \(a_1, a_2, \ldots, a_n\).
outputFormat
Output YES
if there exists an arrangement of '+' and '-' such that the resulting expression is divisible by \(k\); otherwise, output NO
.
sample
3 3
1 2 3
YES