#P7606. Chaos Alignment: Balancing the Lawful and Benevolent Indices
Chaos Alignment: Balancing the Lawful and Benevolent Indices
Chaos Alignment: Balancing the Lawful and Benevolent Indices
Each problem setter has a Lawful index \(L\) and a Benevolent index \(G\). For each idea you conceive, you can choose exactly one of 6 different styles based on aspects such as the problem statement, sample tests, or data constraints. Choosing a style means moving one step in the "realm" in a direction corresponding to that style. The 6 styles and their effects on the indices are given below (all arithmetic is performed modulo \(p\)):
- Sleek Statement: \(L \leftarrow L + tl_{i,l}\), \(G \leftarrow G + tl_{i,g}\).
- Mundane Examples: \(L \leftarrow L + l_{i,l}\), \(G \leftarrow G + l_{i,g}\).
- Laid-back Constraints: \(L \leftarrow L + bl_{i,l}\), \(G \leftarrow G + bl_{i,g}\).
- Complex Statement: \(L \leftarrow L + br_{i,l}\), \(G \leftarrow G + br_{i,g}\).
- Generous Examples: \(L \leftarrow L + r_{i,l}\), \(G \leftarrow G + r_{i,g}\).
- Lax Constraints: \(L \leftarrow L + tr_{i,l}\), \(G \leftarrow G + tr_{i,g}\).
You start with \(L = 0\) and \(G = 0\). To join the notoriously demanding Chaotic Evil faction, your final indices must satisfy \(L = L^*\) and \(G = G^*\). In other words, after selecting a style for each of the \(n\) ideas, you want to end up exactly at the given target \((L^*, G^*)\) despite having moved along the chosen directions.
Given the effects for each idea, determine whether there exists a choice of styles (one for each idea) that results in \(L = L^*\) and \(G = G^*\) (all calculations modulo \(p\)).
inputFormat
The first line contains four integers \(n\), \(p\), \(L^*\) and \(G^*\), where \(p\) is a modulus (typically a prime number). Then \(n\) lines follow. The \(i\)-th of these lines contains 12 integers:
(tl_{i,l},; tl_{i,g},; l_{i,l},; l_{i,g},; bl_{i,l},; bl_{i,g},; br_{i,l},; br_{i,g},; r_{i,l},; r_{i,g},; tr_{i,l},; tr_{i,g})
These represent the change in \(L\) and \(G\) when choosing the corresponding style for the \(i\)-th idea:
- Sleek Statement: adds \(tl_{i,l}\) to \(L\) and \(tl_{i,g}\) to \(G\).
- Mundane Examples: adds \(l_{i,l}\) to \(L\) and \(l_{i,g}\) to \(G\).
- Laid-back Constraints: adds \(bl_{i,l}\) to \(L\) and \(bl_{i,g}\) to \(G\).
- Complex Statement: adds \(br_{i,l}\) to \(L\) and \(br_{i,g}\) to \(G\).
- Generous Examples: adds \(r_{i,l}\) to \(L\) and \(r_{i,g}\) to \(G\).
- Lax Constraints: adds \(tr_{i,l}\) to \(L\) and \(tr_{i,g}\) to \(G\).
All additions are performed modulo \(p\).
outputFormat
Output a single line containing YES
if it is possible to choose one style for each idea such that after all choices, \(L = L^*\) and \(G = G^*\) modulo \(p\); otherwise, output NO
.
sample
1 5 1 2
1 2 0 0 0 1 0 0 0 0 0 0
YES
</p>