We want to thank you all for participating in the contest, and hope you enjoyed it. Any feedback would be appreciated!
697296A - The Square-Free Trap
Writer: amartya110
Consider the best possible opening move for Alice. Is there a move she can make that immediately removes all future options for Bob?
Any positive integer $$$n$$$ can be uniquely factored into $$$n = S \cdot M$$$, where $$$S$$$ is the largest perfect square that divides $$$n$$$, and $$$M$$$ is a strictly square-free integer.
This is a finite game of perfect information, but we don't need Nim-values or Grundy's Theorem because there is a dominating "instant win" strategy.
- If $$$n$$$ is initially square-free, it has no perfect square divisors $$$ \gt 1$$$. Alice has no valid moves on turn 1 and loses immediately.
- If $$$n$$$ is not square-free, Alice can simply choose to divide $$$n$$$ by $$$S$$$ (the largest perfect square divisor) on her very first turn. Bob receives the number $$$M = \frac{n}{S}$$$. Since $$$M$$$ is perfectly square-free, Bob has no valid moves and loses instantly.
Therefore, Alice wins if and only if $$$n$$$ is divisible by any perfect square strictly greater than 1. To implement this, we simply check if $$$n \pmod{p^2} == 0$$$ for any prime $$$p$$$ up to $$$\sqrt{n}$$$. If we find one, output "Alice". If we check all possible primes up to $$$\sqrt{n}$$$ and find nothing, output "Bob".
Time Complexity: $$$\mathcal{O}(\sqrt{n})$$$ per testcase.
#include <bits/stdc++.h>
using namespace std;
const int MAX_P=31622;
vector<long long> primes;
bool is_prime[MAX_P+1];
void sieve(){
for(int i=2;i<=MAX_P;i++){
is_prime[i]=true;
}
for(int p=2;p*p<=MAX_P;p++){
if(is_prime[p]){
for(int i=p*p;i<=MAX_P;i+=p){
is_prime[i]=false;
}
}
}
for(long long p=2;p<=MAX_P;p++){
if(is_prime[p]){
primes.push_back(p);
}
}
}
void solve(){
long long n;
cin>>n;
bool alice_wins=false;
for(long long p:primes){
if(p*p>n){
break;
}
if(n%(p*p)==0){
alice_wins=true;
break;
}
}
if(alice_wins){
cout<<"Alice\n";
}
else {
cout<<"Bob\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
sieve();
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
Writer: _ronak_
Because each query only updates a single beacon, you do not need a heavy data structure like a Segment Tree. How does a single beacon flipping its stability affect the total number of barriers?
Let's maintain a boolean array stable where stable[i] is true if the beacon's energy has at least $$$k$$$ active runes (i.e., the popcount of $$$a_i \ge k$$$).
First, calculate the initial number of barriers. A new barrier starts at index $$$i$$$ if stable[i] is true and stable[i-1] is false. Count these up and store the total in a variable, say ans.
For each experiment of type 1 or 2, we update the energy of beacon $$$i$$$ and recalculate its stability. If its stable state does not change, ans remains exactly the same. If it does change, we only need to look at its immediate neighbors ($$$i-1$$$ and $$$i+1$$$) to update ans in $$$\mathcal{O}(1)$$$ time:
Case 1: stable[i] changes from False to True * If neither neighbor is stable: We just created a new, isolated barrier. (ans++) * If exactly one neighbor is stable: We just extended an existing barrier. (ans remains the same) * If both neighbors are stable: We just bridged the gap between two existing barriers, merging them into one. (ans--)
Case 2: stable[i] changes from True to False * Apply the exact opposite logic. If both neighbors are stable, we just split a barrier in two (ans++). If neither neighbor is stable, a barrier disappeared (ans--).
Time Complexity: $$$\mathcal{O}(1)$$$ per query $$$\rightarrow \mathcal{O}(N + Q)$$$.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll t, n, q, k, type, i, x, ans;
bool nw;
cin >> t;
while (t--) {
cin >> n >> q >> k;
ans = 0;
vector<ll> a(n + 1);
vector<bool> stable(n + 2, 0);
for (i = 1; i <= n; i++) {
cin >> a[i];
stable[i] = (__builtin_popcountll(a[i]) >= k);
if (stable[i] && !stable[i - 1]) {
ans++;
}
}
while (q--) {
cin >> type;
if (type == 3) {
cout << ans << '\n';
continue;
}
cin >> i >> x;
a[i] = (type == 1) ? a[i] | x : a[i] ^ x;
nw = (__builtin_popcountll(a[i]) >= k);
if (stable[i] != nw) {
x = (nw == stable[i - 1]) + (nw == stable[i + 1]);
if (!x)
ans++;
else if (x == 2)
ans--;
stable[i] = nw;
}
}
}
return 0;
}
697296C1 - Vanguard's Perimeter (Easy Version)
Writer: amartya110
How can you mathematically determine if a point is to the "left" or "right" of a directed line segment?
Since the vertices of the triangle $$$A, B, C$$$ are given in strictly counter-clockwise order, the perimeter forms a continuous "left turn". Because of this property, a point $$$P$$$ is strictly inside the triangle if and only if it lies strictly to the left of all three directed edges: $$$\vec{AB}$$$, $$$\vec{BC}$$$, and $$$\vec{CA}$$$.
We can check this using the 2D cross product. For a directed edge from $$$V_1$$$ to $$$V_2$$$ and a point $$$P$$$, the cross product is calculated as:
- If the cross product is $$$ \gt 0$$$, $$$P$$$ is strictly to the left (inside).
- If the cross product is $$$ \lt 0$$$, $$$P$$$ is strictly to the right (outside).
- If the cross product is exactly $$$0$$$, $$$P$$$ lies on the line containing the edge.
Thus, unit $$$P$$$ is a "Severe Threat" if and only if: $$$\text{Cross}(A, B, P) \gt 0$$$ AND $$$\text{Cross}(B, C, P) \gt 0$$$ AND $$$\text{Cross}(C, A, P) \gt 0$$$.
Time Complexity: $$$\mathcal{O}(1)$$$ per query $$$\rightarrow \mathcal{O}(N)$$$ per testcase.
#include <bits/stdc++.h>
using namespace std;
long long crossProduct(long long ax, long long ay, long long bx, long long by, long long cx, long long cy) {
return (bx - ax) * (cy - ay) - (by - ay) * (cx - ax);
}
void solve() {
long long ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
int n;
cin >> n;
int severe_threats = 0;
for (int i = 0; i < n; ++i) {
long long px, py;
cin >> px >> py;
if (crossProduct(ax, ay, bx, by, px, py) > 0 &&
crossProduct(bx, by, cx, cy, px, py) > 0 &&
crossProduct(cx, cy, ax, ay, px, py) > 0) {
severe_threats++;
}
}
cout << severe_threats << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while (t--) {
solve();
}
return 0;
}
697296C2 - Vanguard's Perimeter (Hard Version)
Writer: amartya110
With $$$K$$$ up to $$$2 \cdot 10^5$$$, checking every edge of the polygon is too slow. Can we divide the massive polygon into $$$K-2$$$ triangles and use Binary Search to find which triangle a unit belongs to?
Since the polygon is strictly convex and the vertices $$$V_0, V_1, \dots, V_{k-1}$$$ are given in counter-clockwise order, we can anchor ourselves at $$$V_0$$$. The rays from $$$V_0$$$ to all other vertices divide the polygon into $$$K-2$$$ angular wedges.
For each radar unit $$$P$$$:
- Bounding Angle Check: First, verify if $$$P$$$ lies strictly within the widest possible angle of the polygon formed by $$$\vec{V_0 V_1}$$$ and $$$\vec{V_0 V_{k-1}}$$$. Use the cross product: $$$P$$$ must be to the left of $$$\vec{V_0 V_1}$$$ and to the right of $$$\vec{V_0 V_{k-1}}$$$. If it fails this, it is outside.
- Binary Search: If it is inside the bounding angle, we binary search for the specific wedge $$$i$$$. We want to find an index $$$i$$$ such that $$$P$$$ lies to the left of $$$\vec{V_0 V_i}$$$ but to the right of $$$\vec{V_0 V_{i+1}}$$$.
- Triangle Check: Once we find the correct wedge $$$i$$$, $$$P$$$ is bound within the triangle $$$\triangle V_0 V_i V_{i+1}$$$. We now apply the exact same logic from the Easy Version: check if $$$P$$$ is strictly to the left of the edge $$$\vec{V_i V_{i+1}}$$$.
If $$$P$$$ passes all these checks (and doesn't lie on any boundaries), it is strictly inside the polygon. We maintain a running bitwise XOR sum of the 1-based indices of all units that pass the test and output it at the end.
Time Complexity: Binary searching the angles takes $$$\mathcal{O}(\log K)$$$ per unit. Total complexity $$$\rightarrow \mathcal{O}(N \log K)$$$ per testcase.
#include <bits/stdc++.h>
using namespace std;
long long crossProduct(const pair<long long, long long>& a, const pair<long long, long long>& b, const pair<long long, long long>& c) {
return (b.first - a.first) * (c.second - a.second) - (b.second - a.second) * (c.first - a.first);
}
bool isStrictlyInside(const vector<pair<long long, long long>>& polygon, const pair<long long, long long>& p) {
int k = polygon.size();
if (crossProduct(polygon[0], polygon[1], p) <= 0 ||
crossProduct(polygon[0], polygon[k - 1], p) >= 0) {
return false;
}
int L = 1;
int R = k - 1;
while (L + 1 < R) {
int mid = L + (R - L) / 2;
if (crossProduct(polygon[0], polygon[mid], p) >= 0) {
L = mid;
} else {
R = mid;
}
}
return crossProduct(polygon[L], polygon[R], p) > 0;
}
void solve() {
int k;
cin >> k;
vector<pair<long long, long long>> polygon(k);
for (int i = 0; i < k; ++i) {
cin >> polygon[i].first >> polygon[i].second;
}
int n;
cin >> n;
long long xor_sum = 0;
for (int i = 1; i <= n; ++i) {
pair<long long, long long> p;
cin >> p.first >> p.second;
if (isStrictlyInside(polygon, p)) {
xor_sum ^= i;
}
}
cout << xor_sum << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
697296D - Royal Highway Passes
Writer: mahesh_9996
Instead of just finding the shortest path to a city $$$v$$$, what if you tracked the shortest path to city $$$v$$$ having used exactly $$$j$$$ Royal Passes?
This is a classic shortest-path problem on a modified state-space graph (often called a "layered graph").
Normally, Dijkstra's algorithm uses a 1D array dist[u] to store the minimum cost to reach node $$$u$$$. Here, we expand our state to a 2D array: dist[u][used], which represents the minimum toll paid to reach city u having used exactly used Royal Passes.
When we are at city u with used passes, and we look at a neighboring city v connected by a highway with toll w, we have two possible transitions:
- Do not use a pass: We travel normally. The new state becomes
dist[v][used], and the cost increases byw. Transition:dist[v][used] = min(dist[v][used], dist[u][used] + w) - Use a pass (if available): If
used < k, we can use a pass to make this highway free. The new state becomesdist[v][used + 1], and the cost increases by 0. Transition:dist[v][used + 1] = min(dist[v][used + 1], dist[u][used])
We process these states using a standard priority queue. The answer will be the minimum value among dist[destination][0...k]. If the minimum remains infinity, it means the destination is unreachable, and we output -1.
Time Complexity: $$$\mathcal{O}(K \cdot M \log(K \cdot N))$$$ per testcase.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while(t--){
int N, M, K, S, D;
cin >> N >> M >> K >> S >> D;
vector<vector<pair<int,int>>> g(N);
for (int i = 0; i < M; i++) {
int u, v, w;
cin >> u >> v >> w;
g[u].push_back({v, w});
g[v].push_back({u, w});
}
const long long INF = 4e18;
vector<vector<long long>> dist(N, vector<long long>(K + 1, INF));
priority_queue<
tuple<long long,int,int>,
vector<tuple<long long,int,int>>,
greater<tuple<long long,int,int>>
> pq;
dist[S][0] = 0;
pq.push({0, S, 0});
while (!pq.empty()) {
auto [d, u, used] = pq.top();
pq.pop();
if (d != dist[u][used]) continue;
for (auto &[v, w] : g[u]) {
if (dist[v][used] > d + w) {
dist[v][used] = d + w;
pq.push({dist[v][used], v, used});
}
if (used < K && dist[v][used + 1] > d) {
dist[v][used + 1] = d;
pq.push({dist[v][used + 1], v, used + 1});
}
}
}
long long ans = INF;
for (int i = 0; i <= K; i++) {
ans = min(ans, dist[D][i]);
}
cout << (ans == INF ? -1 : ans) << '\n';
}
return 0;
}
697296E - Relocating the Headquarters
Writer: mahesh_9996
If you already know the total communication cost for a headquarters at office $$$u$$$, how can you quickly calculate the cost for an adjacent office $$$v$$$ without recalculating from scratch?
A naive approach would be to run BFS/DFS from every single node to find the sum of distances, but this takes $$$\mathcal{O}(N^2)$$$ time, which will easily Time Out. We need to optimize this using the Rerooting DP technique.
Let's break the solution into two passes (two DFS traversals):
Pass 1 (The Initial Setup): We arbitrarily root the tree at node 0. We run a standard DFS to calculate two things: * The total communication cost for node 0 (ans[0]). We simply add the depth of every node to a running total. * The size of the subtree for every node (sub[u]). The subtree size of $$$u$$$ includes $$$u$$$ itself and all its descendants.
Pass 2 (The Rerooting): Now we run a second DFS to calculate the answers for all other nodes. Imagine shifting the headquarters from node $$$u$$$ to its child node $$$v$$$. What happens to the distances? * We move $$$1$$$ step closer to all nodes inside the subtree of $$$v$$$. There are exactly sub[v] such nodes. * We move $$$1$$$ step further away from all other nodes in the network. There are exactly $$$N - \text{sub}[v]$$$ such nodes.
Thus, we can calculate ans[v] in $$$\mathcal{O}(1)$$$ time using the answer from its parent:
By passing this value down the tree in our second DFS, we compute the answer for every single node in linear time.
Time Complexity: $$$\mathcal{O}(N)$$$ per testcase.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
vector<int> g[MAXN];
int sub[MAXN];
long long ans[MAXN];
int N;
void dfs1(int u, int p, int d) {
ans[0] += d;
for (int v : g[u]) {
if (v == p) continue;
dfs1(v, u, d + 1);
sub[u] += sub[v];
}
}
void dfs2(int u, int p) {
for (int v : g[u]) {
if (v == p) continue;
ans[v] = ans[u] + N - 2LL * sub[v];
dfs2(v, u);
}
}
void solve() {
cin >> N;
for (int i = 0; i < N; i++) {
g[i].clear();
sub[i] = 1;
ans[i] = 0;
}
for (int i = 0; i < N - 1; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs1(0, -1, 0);
dfs2(0, -1);
cout << ans[0] << '\n';
for (int i = 1; i < N; i++) {
cout << ans[i] << (i == N - 1 ? "" : " ");
}
cout << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
697296F - The Shinigami's Ledger (Abyssal Edition v2)
Writer: Ajay_2705
This is a counting problem solved with Digit DP. We compute $$$f(x) =$$$ (valid IDs in $$$[0, x]$$$) and answer each query as $$$f(R) - f(L - 1)$$$. The challenge lies in tracking several global states simultaneously while correctly handling the boundary between leading-zero padding and the real digits.
1. The Parity Shift Trap The most error-prone constraint is the Alternating Resonance. Because numbers are processed as a fixed-length, zero-padded string, assigning a sign based on the padded index is wrong: the real digits would inherit a sign that depends on how many leading zeros precede them. Instead, the DP carries the sign that should apply to the next real digit. While the is_leading_zero flag is set and a 0 is placed, the sign must not flip — it stays frozen as positive until the first non-zero digit appears.
2. The Negative Modulo Trap Since the sum alternates, the running value frequently goes negative. In C++ and Java the % operator keeps the sign of the dividend (e.g. -5 % 3 == -2), so the residue must be normalised: next_alt_mod = ((alt_mod + sign * d) % S + S) % S
3. State Design A natural state is [rem_len][count4][alt_mod][rem][sign][prev_was_1] with dimensions $$$\le [19][19][20][20][2][2]$$$, i.e. well under $$$10^6$$$ memoised entries. Keying by rem_len (remaining digits) rather than the absolute string index lets the $$$f(R)$$$ and $$$f(L - 1)$$$ passes of a single test case share one cache, since they only differ in length. A per-test-case stamp (tc_id) invalidates the cache between test cases, where $$$M$$$ and $$$S$$$ change — avoiding an explicit memset of the table.
Complexity Per test case the work is bounded by $$$\mathcal{O}(D \cdot C \cdot S \cdot M \cdot 2 \cdot 2 \cdot 10)$$$ transitions, where $$$D \le 19$$$ is the number of digits. This is comfortably fast for $$$T \le 100$$$, and the two long long tables occupy about 12.8 MB, far below the memory limit.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static ll memo[20][20][20][25][2][2];
static int vis [20][20][20][25][2][2];
static int tc_id = 0;
static string S_str;
static int target_C, target_M, target_S, slen;
ll calc(int idx, int count4, int alt_mod, int rem, int sign_idx, int prev1, bool is_tight, bool is_lz) {
int rem_len = slen - idx;
if (count4 > target_C) {
return 0;
}
if (count4 + rem_len < target_C) {
return 0;
}
if (idx == slen) {
if (count4 == target_C) {
if (rem == 0) {
if (alt_mod == 0) {
return 1;
}
}
}
return 0;
}
if (!is_tight) {
if (!is_lz) {
if (vis[rem_len][count4][alt_mod][rem][sign_idx][prev1] == tc_id) {
return memo[rem_len][count4][alt_mod][rem][sign_idx][prev1];
}
}
}
int limit = 9;
if (is_tight) {
limit = S_str[idx] - '0';
}
int sign = -1;
if (sign_idx == 0) {
sign = 1;
}
ll ways = 0;
for (int d = 0; d <= limit; d++) {
if (prev1) {
if (d == 3) {
continue;
}
}
bool next_lz = false;
if (is_lz) {
if (d == 0) {
next_lz = true;
}
}
int nc4 = count4;
if (d == 4) {
nc4 = nc4 + 1;
}
int nrem = (rem * 10 + d) % target_M;
int nam = alt_mod;
int nsi = sign_idx;
int np1 = 0;
if (!next_lz) {
if (d == 1) {
np1 = 1;
}
}
if (!next_lz) {
int v = alt_mod + sign * d;
v %= target_S;
if (v < 0) {
v += target_S;
}
nam = v;
if (nsi == 1) {
nsi = 0;
} else {
nsi = 1;
}
}
bool next_tight = false;
if (is_tight) {
if (d == limit) {
next_tight = true;
}
}
ways += calc(idx + 1, nc4, nam, nrem, nsi, np1, next_tight, next_lz);
}
if (!is_tight) {
if (!is_lz) {
memo[rem_len][count4][alt_mod][rem][sign_idx][prev1] = ways;
vis[rem_len][count4][alt_mod][rem][sign_idx][prev1] = tc_id;
}
}
return ways;
}
ll solve_prefix(ll num) {
if (num < 0) {
return 0;
}
S_str = to_string(num);
slen = (int)S_str.size();
return calc(0, 0, 0, 0, 0, 0, true, true);
}
void solve() {
tc_id++;
ll L, R;
cin >> L >> R >> target_C >> target_M >> target_S;
ll ans_R = solve_prefix(R);
ll ans_L = solve_prefix(L - 1);
cout << ans_R - ans_L << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
697296G - The Harmonic Subsequence Path
Writer: MehulGupta19
The solution relies on Dynamic Programming and a number-theoretic observation to efficiently find valid predecessors.
For any valid adjacent pair $$$x \lt y$$$, we can represent them as $$$x = g \cdot a$$$ and $$$y = g \cdot b$$$, where $$$g = \gcd(x, y)$$$ and $$$\gcd(a, b) = 1$$$. Because $$$\text{lcm}(x, y) = g \cdot a \cdot b$$$, the problem's condition $$$\text{lcm}(x, y) \le K$$$ simplifies to $$$g \cdot a \cdot b \le K$$$.
This allows us to precompute valid predecessors $$$x$$$ for every value $$$y$$$ by iterating through all divisors $$$g \gt 1$$$ of $$$y$$$, setting $$$b = y/g$$$, and finding all valid multipliers $$$a \lt b$$$ such that $$$a \le K/y$$$. Each choice produces a candidate predecessor $$$x = g \cdot a$$$.
Finally, we process the array from left to right, maintaining the longest valid subsequence length ending at each value and the number of ways to achieve it. For each element, we transition from its valid predecessors, taking the maximum length and accumulating the frequency counts modulo $$$10^9+7$$$ whenever ties in maximum length occur.
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAXK = 1000005;
vector<int> divisors[MAXK];
vector<int> adj[MAXK];
bool computed[MAXK];
int best_len[MAXK];
int best_cnt[MAXK];
void precompute() {
for (int d = 2; d < MAXK; ++d) {
for (int m = d; m < MAXK; m += d) {
divisors[m].push_back(d);
}
}
}
void solve() {
int n, K;
cin >> n >> K;
vector<int> A(n);
vector<int> unique_vals;
for (int i = 0; i < n; ++i) {
cin >> A[i];
if (!computed[A[i]]) {
computed[A[i]] = true;
unique_vals.push_back(A[i]);
int y = A[i];
for (int g : divisors[y]) {
int b = y / g;
int limit = min(b - 1, K / y);
for (int a = 1; a <= limit; ++a) {
if (__gcd(a, b) == 1) {
adj[y].push_back(a * g);
}
}
}
}
}
int global_max_len = 0;
int global_max_cnt = 0;
for (int y : A) {
int max_len = 0;
int total_cnt = 0;
for (int x : adj[y]) {
if (best_len[x] == 0) continue;
if (best_len[x] > max_len) {
max_len = best_len[x];
total_cnt = best_cnt[x];
} else if (best_len[x] == max_len) {
total_cnt = (total_cnt + best_cnt[x]) % MOD;
}
}
int cur_len = max_len + 1;
int cur_cnt = (max_len == 0) ? 1 : total_cnt;
if (cur_len > best_len[y]) {
best_len[y] = cur_len;
best_cnt[y] = cur_cnt;
} else if (cur_len == best_len[y]) {
best_cnt[y] = (best_cnt[y] + cur_cnt) % MOD;
}
if (cur_len > global_max_len) {
global_max_len = cur_len;
global_max_cnt = cur_cnt;
} else if (cur_len == global_max_len) {
global_max_cnt = (global_max_cnt + cur_cnt) % MOD;
}
}
cout << global_max_len << " " << global_max_cnt << "\n";
for (int y : unique_vals) {
computed[y] = false;
adj[y].clear();
best_len[y] = 0;
best_cnt[y] = 0;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
precompute();
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Results will be published soon!









Nice Contest...Loved the problems, especially the C2 problem
For problem G.
N = 3 K = 19
4, 6, 18.
Here LCM(4,18) is 36 What would be the answer for this array , is it 2 or 3.
The output will be 3 1
Here, the pairs are (4,6) and (6, 18)
But (4,18) violates this.
If i remember correctly, the problem statement says (x,y) as x choosen before y, it doesn't clearly specify that x,y are adjacent
UPD: my bad, misunderstood problem statement, choosing sequential 2 elements x,y meant choosing adjacent objects.