#C4949. Contiguous Subsequence Divisibility
Contiguous Subsequence Divisibility
Contiguous Subsequence Divisibility
You are given a sequence of integers. Your task is to determine whether there exists a contiguous subsequence of exactly K elements such that the sum of the subsequence is divisible by D.
Input: The first line contains three integers: \(n\) (the length of the sequence), \(K\) (the length of the contiguous subsequence), and \(D\) (the divisor). The second line contains \(n\) space-separated integers.
Output: Output a single line: YES
if there exists such a subsequence, and NO
otherwise.
In mathematical terms, given an integer sequence \(a_1, a_2, \ldots, a_n\) and integers \(K\) and \(D\), determine if there is an index \(i\) (with \(1 \le i \le n-K+1\)) such that:
\(a_i + a_{i+1} + \cdots + a_{i+K-1} \equiv 0 \pmod{D}\)
inputFormat
The input is given in two lines. The first line contains three space-separated integers: (n), (K), and (D). The second line contains (n) space-separated integers representing the sequence.
outputFormat
Output a single line containing YES
if there exists a contiguous subsequence of length (K) whose sum is divisible by (D), otherwise output NO
.## sample
6 3 2
2 7 5 3 1 9
YES
</p>