#include "triples.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pi = pair<int, int>;
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = a; i >= b; i--)
#define each(a, x) for (auto &a : x)
#define all(x) (x).begin(), (x).end()
#define bg(x) (x).begin()
#define en(x) (x).end()
#define rev(x) reverse(all(x))
#define sz(x) int((x).size())
#define srt(x) sort(all(x))
#define cnt(a, x) count(all(x), a)
#define trace(x) each(a, (x)) cout << a << " "
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
ll brute(vi h) {
int n = sz(h);
ll ans = 0;
FOR(i, 0, n) {
FOR(j, i+1, n) {
FOR(k, j+1, n) {
int d1 = min({k-j, k-i,j-i}), d3 = max({k-j, j-i, k-i}), f1 = min({h[i], h[j], h[k]}), f3 = max({h[i], h[j], h[k]});
int d2 = (k-j) ^ (k-i) ^ (j-i) ^ d1 ^ d3, f2 = h[i] ^ h[j] ^ h[k] ^ f1 ^ f3;
if (d1 == f1 && d2 == f2 && d3 == f3) ans++;
}
}
}
return ans;
}
struct Triple {
int i, j, k;
Triple() {};
Triple(int I, int J, int K) {
i = min({I, J, K});
k = max({I, J, K});
j = (I ^ J ^ K) ^ i ^ k; // lol
}
const bool operator<(const Triple &other) const {
if (i != other.i) return i < other.i;
if (j != other.j) return j < other.j;
return k < other.k;
}
};
ll count_triples(vi h) {
int n = sz(h);
ll ans = 0;
FOR(i, 0, n) { // count number of triples where h[i] = d(i, j) or d(i, k)
int H = h[i];
set<Triple> trips; // prevent double count with dupe height
int j = i + H;
if (j < n) {
int k1 = i + h[j], k2 = j + h[j]; // 2 cases — h[j] = d(i, k) or h[j] = d(j, k)
if (k1 < n && h[k1] == (k1 - j)) trips.insert(Triple(i, j, k1)); // we know d(i, j) and d(i, k) to be h[i] and h[j], so does h[k] == d(j, k)
if (k2 < n && h[k2] == (k2 - i)) trips.insert(Triple(i, j, k2)); // symmetric but this time for i
}
int k = i + H;
if (k < n) {
int j1 = i + h[k], j2 = k - h[k]; // h[k] = d(i, k), h[k] = d(j, k)
if ((i < j1 && j1 < k) && h[j1] == (k - j1)) trips.insert(Triple(i, j1, k));
if ((i < j2 && j2 < k) && h[j2] == (j2 - i)) trips.insert(Triple(i, j2, k));
}
for (auto &el : trips) {
if (h[el.j] != h[el.i] && h[el.k] != h[el.i]) ans++;
}
}
unordered_map<int, vector<int>> pc, nc; // positive line intercepts, negative line intercepts
vi inp(n), inn(n); // lookup for the intercept
FOR(i, 0, n) {
int c1 = h[i] - i, c2 = h[i] + i;
inp[i] = c1, inn[i] = c2;
pc[c1].pb(i), nc[c2].pb(i);
}
for (auto &cnst : pc) { // count number of triples where h[j] = d(i, j), h[k] = d(i, k), and h[i] = d(j, k) = h[k] - h[j]
int i = -cnst.first;
if (i < 0 || i >= n) continue;
int H = h[i];
for (auto &el : cnst.second) {
int j = el, k = el + H;
if (k >= n) break;
if (inp[k] != inp[j]) continue;
ans++;
}
}
FOR(j, 0, n) { // count number of triples where h[j] = d(i, k), h[k] = d(i, j) and h[i] = d(j, k) = h[j] - h[k]
int f1 = lower_bound(all(pc[inp[j]]), j-h[j]) - bg(pc[inp[j]]);
int f2 = upper_bound(all(nc[inn[j]]), j+h[j]) - bg(nc[inn[j]]);
int p1 = lower_bound(all(pc[inp[j]]), j) - bg(pc[inp[j]]), p2 = lower_bound(all(nc[inn[j]]), j) - bg(nc[inn[j]]);
if (p1 - f1 < f2 - p2) { // there is no way to set up the diagonals such that no matter which way you go its n^2
for (int el = f1; el < p1; el++) {
int i = pc[inp[j]][el];
int dist = j - i;
if (j + h[i] >= n || h[j + h[i]] != dist) continue;
ans++;
}
} else {
for (int el = p2 + 1; el < f2; el++) {
int k = nc[inn[j]][el];
int dist = k - j;
if (j - h[k] < 0 || h[j - h[k]] != dist) continue;
ans++;
}
}
}
return ans;
}
vi best_window(int K) {
vi cur = {27, 4, 29, 2, 7, 8, 9, 6, 3, 4, 5, 6, 15, 2, 17, 14, 11, 12, 13, 8, 9, 6, 7, 8, 7, 14, 21, 12, 1, 2, 1, 16, 15, 6, 5, 4, 7, 10, 9, 8, 43, 36, 41, 4, 39, 32, 31, 36, 35, 34, 33, 50, 25, 48, 23, 28, 27, 26, 43, 42, 59, 22, 15, 48, 37, 36, 35, 52, 71, 42, 69, 40, 67, 46, 27, 64, 63, 62, 61, 32, 3, 70, 81, 56, 55, 54, 89, 76, 87, 74, 85, 86, 9, 82, 81, 80, 67, 66, 97, 12, 95, 74, 73, 72, 73, 90, 5, 68, 31, 112, 9, 28, 83, 108, 85, 84, 105, 104, 103, 122, 19, 120, 125, 118, 97, 96, 95, 122, 113, 46, 119, 126, 117, 116, 107, 106, 105, 110, 111, 110, 109, 22, 115, 114, 113, 172, 131, 28, 101, 72, 49, 12, 69, 124, 153, 44, 151, 18, 19, 82, 147, 156, 79, 86, 153, 82, 151, 90, 139, 6, 87, 70, 145, 144, 143, 74, 171, 28, 139, 78, 41, 166, 135, 64, 65, 10, 9, 160, 159, 158, 51, 186, 29, 54, 55, 112, 181, 120, 23, 22, 117, 190, 39, 174, 173, 42, 43, 202, 33, 108, 47, 36, 37, 36, 209, 132, 41, 206, 191, 204, 189, 1, 27, 84, 123, 198, 197, 196, 89, 214, 147, 10, 227, 114, 13, 14, 207, 222, 221, 18, 77, 66, 65, 104, 215, 4, 71, 70, 1, 8, 173, 56, 5, 4, 93, 92, 61, 35, 119, 18, 183, 86, 161, 180, 43, 126, 261, 166, 191, 48, 107, 188, 171, 74, 135, 248, 101, 250, 249, 38, 179, 142, 35, 34, 63, 238, 123, 30, 259, 258, 261, 152, 117, 130, 53, 266, 265, 50, 49, 124, 123, 304, 45, 140, 129, 300, 85, 28, 297, 134, 295, 148, 65, 64, 213, 94, 289, 142, 287, 242, 71, 202, 101, 318, 223, 84, 279, 132, 81, 80, 333, 230, 15, 76, 329, 88, 87, 326, 325, 324, 83, 264, 101, 204, 261, 318, 97, 30, 337, 174, 109, 176, 175, 252, 105, 192, 329, 328, 101, 354, 345, 186, 15, 46, 349, 58, 339, 338, 193, 342, 53, 342, 233, 290, 153, 58, 329, 117, 31, 332, 63, 370, 281, 368, 221, 38, 137, 140, 71, 362, 215, 360, 135, 16, 153, 48, 155, 150, 149, 352, 23, 262, 145, 56, 157, 156, 305, 306, 233, 152, 33, 410, 273, 192, 337, 410, 7, 334, 41, 244, 103, 12, 105, 182, 261, 396, 325, 178, 5, 266, 255, 174, 115, 10, 25, 260, 259, 90, 423, 122, 265, 18, 221, 268, 269, 306, 415, 100, 71, 192, 255, 8, 211, 232, 107, 208, 207, 294, 237, 76, 203, 144, 85, 288, 287, 382, 245, 218, 227, 92, 439, 214, 223, 232, 373, 52, 129, 228, 69, 162, 231, 232, 343, 40, 227, 62, 265, 64, 387, 30, 173, 114, 69, 34, 147, 52, 255, 64, 323, 252, 251, 184, 59, 44, 247, 158, 189, 98, 313, 132, 51, 194, 349, 486, 91, 198, 169, 490, 343, 86, 143, 174, 347, 302, 81, 116, 179, 136, 333, 182, 183, 290, 73, 292, 217, 286, 127, 10, 437, 282, 21, 320, 367, 120, 17, 168, 229, 138, 115, 202, 91, 310, 143, 110, 131, 306, 5, 382, 317, 136, 151, 102, 313, 306, 141, 344, 39, 144, 145, 252, 23, 254, 113, 140, 131, 334, 29, 118, 135, 330, 171, 418, 123, 22, 237, 126, 127, 164, 339, 272, 349, 416, 159, 70, 47, 68, 279, 154, 341, 222, 5, 40, 179, 428, 257, 58, 79, 56, 367, 86, 389, 84, 51, 296, 91, 206, 69, 208, 95, 92, 93, 74, 199, 18, 201, 384, 79, 386, 311, 82, 83, 382, 189, 72, 29, 226, 395, 76, 75, 112, 181, 76, 219, 296, 387, 40, 329, 214, 189, 102, 45, 304, 11, 194, 127, 50, 95, 340, 53, 54, 201, 314, 345, 22, 117, 348, 243, 208, 27, 362, 151, 110, 149, 32, 357, 252, 35, 36, 73, 16, 333, 258, 273, 164, 137, 242, 139, 24, 25, 342, 5, 130, 169, 234, 167, 10, 55, 150, 13, 240, 5, 174, 311, 8, 157, 76, 155, 44, 3, 4, 287, 164, 1, 108, 195, 110, 293, 258, 33, 56, 311, 278, 59, 28, 265, 202, 121, 304, 23, 270, 307, 90, 19, 128, 275, 174, 277, 190, 43, 98, 135, 214, 79, 196, 81, 286, 35, 34, 289, 226, 189, 110, 157, 68, 235, 70, 233, 152, 63, 240, 65, 214, 99, 58, 245, 60, 55, 54, 57, 106, 243, 76, 167, 88, 63, 134, 71, 230, 83, 252, 233, 75, 255, 78, 143, 90, 35, 74, 37, 242, 149, 240, 245, 82, 81, 132, 235, 112, 157, 48, 25, 138, 107, 22, 209, 200, 55, 102, 167, 204, 99, 116, 127, 62, 33, 174, 111, 122, 213, 156, 107, 40, 117, 2, 183, 114, 113, 186, 47, 8, 79, 168, 107, 122, 13, 140, 195, 152, 175, 88, 135, 20, 157, 18, 131, 94, 161, 184, 27, 164, 25, 156, 147, 102, 159, 144, 151, 152, 173, 154, 79, 14, 151, 168, 179, 44, 171, 42, 163, 174, 119, 160, 159, 36, 53, 124, 51, 166, 97, 128, 59, 130, 57, 130, 59, 24, 113, 40, 67, 108, 65, 140, 17, 46, 33, 114, 59, 116, 77, 28, 39, 26, 41, 128, 35, 84, 125, 32, 47, 88, 89, 64, 87, 92, 93, 94, 91, 96, 57, 94, 99, 84, 75, 76, 15, 50, 105, 80, 103, 108, 69, 106, 23, 6, 73, 74, 61, 76, 69, 92, 65, 66, 33, 68, 69, 98, 85, 8, 127, 88, 125, 24, 91, 78, 45, 3, 81, 18, 49, 50, 51, 52, 35, 36, 25, 10, 39, 40, 29, 30, 61, 28, 33, 34, 35, 36, 37, 22, 35, 52, 25, 26, 55, 28, 29, 46, 11, 12, 49, 53, 15, 16, 17, 38, 19, 59, 41, 19, 1, 44, 11, 65, 5, 28, 5, 8, 7, 68, 1, 34, 3, 2, 1, 34, 17, 16, 80, 20, 19, 12, 11, 22, 9, 14, 13, 12, 17, 91, 15, 93, 6, 67, 4, 9, 3, 7, 39, 6, 2, 3, 3, 13, 33, 19, 31, 9, 22, 19, 20, 13, 22, 15, 16, 22, 12, 13, 19, 15, 4, 16, 6, 7, 34, 39, 2, 37, 30, 1, 15, 33, 2, 47, 30, 45, 1, 21, 140, 41, 24, 43, 38, 15, 14, 147, 18, 17, 32, 15, 34, 153, 28, 67, 26, 65, 28, 27, 47, 61, 170, 3, 58, 65, 15, 61, 62, 69, 52, 11, 80, 13, 8, 45, 46, 45, 86, 73, 80, 49, 82, 77, 2, 93, 94, 1, 96, 89, 90, 31, 92, 101, 28, 65, 64, 97, 80, 81, 94, 83, 20, 103, 74, 75, 88, 77, 76, 43, 50, 119, 82, 81, 46, 115, 90, 35, 88, 59, 60, 39, 62, 57, 106, 59, 4, 67, 102, 137, 64, 49, 46, 133, 4, 49, 130, 15, 56, 109, 54, 19, 124, 21, 62, 15, 60, 17, 118, 117, 28, 29, 8, 31, 24, 25, 74, 27, 36, 21, 31, 23, 32, 103, 42, 83, 100, 81, 38, 9, 10, 7, 12, 21, 92, 91, 54, 17, 18, 1, 50, 3, 2, 23, 62, 63, 8, 7, 58, 5, 52, 39, 14, 13, 72, 11, 10, 33, 68, 47, 6, 41, 64, 43, 26, 25, 28, 23, 9, 57, 32, 31, 18, 53, 34, 31, 32, 18, 12, 20, 26, 27, 44, 43, 18, 41, 20, 21, 11, 6, 36, 4, 33, 6, 11, 36, 30, 2, 8, 9, 5, 18, 3, 16, 21, 18, 19, 12, 18, 10, 15, 12, 13, 18, 27, 16, 10, 9, 23, 9, 21, 2, 3, 18, 29, 6, 27, 4, 3, 24, 11, 29, 9, 8, 47, 48, 5, 54, 43, 44, 41, 42, 11, 48, 39, 46, 111, 6, 43, 90, 31, 32, 29, 28, 67, 36, 25, 26, 63, 40, 61, 20, 21, 76, 105, 34, 25, 72, 15, 70, 51, 84, 85, 48, 91, 80, 81, 78, 79, 60, 85, 40, 83, 6, 85, 54, 5, 68, 69, 66, 49, 66, 73, 62, 63, 70, 43, 72, 57, 58, 69, 20, 19, 62, 51, 52, 15, 120, 121, 56, 29, 116, 117, 114, 115, 24, 111, 112, 37, 38, 37, 9, 10, 104, 33, 102, 101, 15, 37, 98, 9, 1, 14, 80, 93, 94, 6, 5, 17, 18, 10, 9, 9, 22, 32, 3, 4, 8, 9, 1, 8, 14, 13, 23, 73, 72, 1, 45, 46, 68, 5, 4, 32, 33, 32, 8, 36, 37, 36, 27, 58, 41, 30, 23, 53, 54, 26, 27, 46, 49, 48, 31, 45, 44, 72, 43, 10, 37, 40, 39, 14, 36, 35, 63, 62, 1, 31, 32, 86, 57, 70, 71, 70, 53, 8, 40, 64, 77, 76, 79, 60, 61, 100, 71, 10, 73, 40, 67, 54, 69, 108, 91, 90, 47, 48, 31, 30, 85, 1, 99, 26, 81, 56, 37, 38, 93, 34, 33, 34, 89, 44, 111, 46, 41, 40, 43, 42, 105, 24, 21, 22, 101, 76, 59, 58, 27, 28, 55, 54, 129, 128, 67, 66, 7, 8, 63, 62, 6, 7, 119, 14, 1, 16, 26, 1, 14, 6, 7, 6, 9, 8, 20, 7, 1, 28, 3, 2, 14, 13, 28, 62, 21, 36, 20, 19, 6, 92, 15, 14, 29, 12, 28, 27, 14, 48, 23, 22, 46, 20, 8, 21, 41, 40, 40, 39, 14, 15, 56, 34, 58, 8, 60, 66, 50, 49, 52, 51, 54, 53, 59, 58, 42, 20, 60, 59, 46, 75, 36, 50, 38, 79, 40, 69, 68, 29, 84, 73, 86, 87, 32, 61, 78, 77, 80, 81, 80, 55, 82, 30, 70, 59, 72, 73, 10, 103, 64, 53, 66, 67, 108, 97, 96, 97, 20, 45, 102, 101, 4, 89, 106, 105, 108, 107, 94, 83, 84, 33, 6, 36, 88, 115, 38, 131, 40, 41, 94, 15, 80, 125, 124, 19, 28, 9, 30, 31, 24, 117, 26, 27, 80, 57, 18, 111, 20, 21, 62, 23, 44, 105, 66, 9, 68, 11, 12, 43, 52, 7, 8, 49, 48, 37, 2, 3, 52, 1, 42, 25, 2, 85, 28, 29, 48, 7, 24, 33, 16, 18, 14, 19, 20, 17, 16, 71, 24, 35, 22, 21, 28, 65, 30, 25, 28, 27, 14, 3, 4, 38, 56, 1, 5, 35, 52, 5, 4, 42, 11, 47, 28, 45, 44, 6, 4, 18, 6, 20, 21, 19, 2, 18, 25, 16, 14, 31, 29, 20, 28, 27, 8, 24, 71, 23, 37, 2, 3, 18, 1, 17, 7, 14, 5, 4, 11, 26, 9, 50, 87, 22, 53, 4, 45, 56, 57, 48, 20, 60, 51, 52, 63, 42, 35, 8, 45, 58, 69, 30, 71, 42, 33, 64, 25, 66, 35, 28, 21, 58, 31, 24, 43, 42, 27, 28, 51, 88, 49, 48, 51, 34, 83, 44, 95, 46, 97, 40, 77, 90, 101, 92, 3, 104, 105, 106, 7, 68, 3, 100, 101, 90, 63, 104, 75, 106, 117, 118, 19, 70, 21, 112, 113, 66, 13, 86, 15, 106, 107, 80, 81, 6, 75, 76, 77, 86, 97, 38, 97, 2, 35, 92, 93, 32, 45, 88, 89, 42, 7, 44, 39, 38, 41, 48, 55, 56, 19, 52, 17, 48, 49, 50, 49, 26, 53, 24, 67, 26, 43, 64, 65, 30, 61, 62, 37, 34, 35, 40, 23, 42, 55, 40, 7, 28, 9, 48, 49, 46, 47, 4, 15, 2, 17, 18, 39, 6, 21, 4, 23, 10, 11, 8, 9, 14, 29, 30, 5, 14, 1, 2, 1, 22, 23, 20, 21, 6, 5, 16, 17, 2, 13, 12, 11, 12, 4, 8, 9, 6, 7, 5, 4, 3, 8, 9, 1, 11, 10, 13, 12, 15, 6, 17, 8, 3, 10, 11, 12, 7, 2, 9, 4, 5, 6, 3, 4, 1, 2, 1, 8};
int M = cur.size();
deque<int> window;
for (int i = 0; i < K; i++) window.push_back(cur[i]);
int best = count_triples(vi(all(window)));
int bk = K-1;
for (int i = K; i < M; i++) {
window.pop_front(); window.push_back(cur[i]);
int ac = count_triples(vi(all(window)));
if (ac > best) {
bk = i;
best = ac;
}
}
vi ans; FOR(i, bk - K+1, bk +1) ans.pb(cur[i]);
cerr << "Best window had " << count_triples(ans) << " triples.\n";
trace(ans); cout << "\n";
return ans;
}
bool accept(double cur_score, double next_score, double temp, mt19937 &rng) {
if (next_score > cur_score) return true;
cur_score = -cur_score; next_score = -next_score;
double prob = exp(-(next_score - cur_score) / temp);
return generate_canonical<double, 53>(rng) < prob;
}
vi construct_range(int M, int K) {
vi prev_best = {9, 68, 7, 66, 71, 45, 69, 16, 157, 14, 77, 58, 75, 162, 61, 335, 7, 184, 9, 117, 67, 2, 145, 63, 45, 2, 175, 18, 105, 21, 39, 40, 37, 100, 11, 40, 9, 100, 48, 30, 31, 46, 33, 90, 121, 92, 23, 39, 39, 26, 117, 114, 115, 220, 121, 32, 119, 30, 79, 106, 107, 72, 211, 74, 69, 232, 71, 134, 18, 132, 1, 62, 3, 64, 223, 198, 57, 124, 55, 88, 85, 6, 55, 92, 3, 90, 149, 78, 79, 238, 111, 46, 83, 43, 71, 72, 105, 70, 103, 76, 267, 32, 31, 34, 29, 96, 31, 256, 39, 258, 23, 25, 89, 160, 87, 182, 327, 48, 49, 48, 45, 46, 53, 78, 43, 172, 39, 40, 47, 106, 197, 44, 141, 399, 139, 2, 65, 304, 63, 202, 187, 132, 5, 310, 57, 222, 295, 296, 125, 16, 17, 14, 301, 144, 21, 80, 19, 324, 205, 168, 207, 166, 135, 330, 155, 288, 1, 34, 159, 32, 5, 102, 321, 194, 99, 152, 343, 186, 189, 184, 93, 186, 259, 18, 17, 334, 177, 354, 179, 252, 253, 172, 105, 170, 125, 172, 345, 244, 245, 128, 35, 126, 279, 70, 159, 68, 161, 356, 285, 376, 231, 232, 361, 280, 127, 82, 147, 384, 223, 224, 53, 146, 231, 270, 229, 216, 217, 140, 291, 296, 97, 222, 209, 210, 207, 208, 283, 36, 215, 286, 213, 252, 251, 320, 249, 236, 81, 294, 115, 48, 117, 242, 115, 320, 331, 186, 187, 262, 305, 184, 265, 192, 339, 310, 255, 178, 101, 258, 273, 316, 183, 248, 253, 440, 251, 266, 267, 324, 203, 284, 261, 212, 81, 260, 83, 12, 277, 154, 155, 152, 295, 282, 297, 160, 225, 158, 305, 222, 303, 64, 225, 66, 283, 216, 281, 296, 219, 174, 233, 144, 143, 230, 289, 180, 227, 178, 247, 246, 45, 244, 47, 120, 121, 390, 249, 238, 193, 126, 191, 196, 255, 194, 35, 380, 159, 266, 249, 204, 263, 202, 489, 140, 177, 176, 257, 18, 179, 146, 215, 416, 213, 428, 361, 220, 359, 218, 423, 84, 85, 226, 159, 352, 425, 90, 199, 2, 413, 234, 345, 232, 417, 170, 171, 436, 199, 210, 209, 104, 387, 304, 205, 428, 181, 110, 217, 58, 535, 186, 213, 398, 63, 396, 51, 192, 319, 98, 123, 460, 389, 126, 313, 200, 39, 40, 37, 38, 469, 134, 45, 400, 43, 578, 417, 14, 461, 406, 371, 566, 145, 410, 569, 80, 59, 290, 57, 288, 431, 352, 65, 156, 63, 356, 479, 424, 107, 138, 93, 164, 419, 274, 417, 78, 1, 76, 81, 118, 79, 6, 5, 152, 123, 406, 89, 90, 87, 88, 323, 256, 463, 224, 327, 20, 325, 100, 137, 98, 391, 26, 25, 388, 103, 518, 385, 20, 111, 400, 109, 344, 205, 342, 39, 38, 119, 42, 117, 212, 33, 6, 321, 36, 289, 50, 49, 220, 293, 362, 487, 44, 423, 490, 19, 482, 61, 60, 371, 208, 13, 66, 55, 16, 515, 310, 345, 72, 71, 314, 341, 24, 25, 66, 193, 80, 79, 160, 387, 158, 253, 74, 35, 328, 11, 12, 457, 8, 9, 448, 509, 704, 175, 46, 173, 22, 1, 378, 19, 500, 27, 54, 553, 24, 475, 278, 11, 10, 35, 30, 355, 16, 425, 262, 41, 428, 539, 22, 21, 292, 479, 6, 5, 128, 127, 30, 29, 206, 11, 212, 13, 210, 135, 6, 139, 240, 19, 130, 65, 516, 289, 14, 513, 456, 519, 454, 391, 8, 227, 394, 233, 324, 231, 258, 119, 82, 607, 110, 79, 440, 439, 106, 267, 312, 247, 168, 245, 70, 173, 172, 97, 484, 665, 94, 167, 254, 97, 422, 297, 616, 183, 86, 85, 136, 149, 358, 189, 468, 49, 194, 193, 184, 75, 272, 147, 188, 279, 70, 277, 120, 73, 514, 639, 64, 207, 450, 127, 134, 111, 202, 131, 56, 217, 216, 119, 168, 321, 498, 123, 122, 17, 142, 433, 188, 151, 108, 437, 310, 155, 112, 313, 152, 311, 178, 107, 140, 97, 82, 191, 144, 101, 234, 169, 552, 89, 166, 129, 352, 93, 134, 133, 178, 15, 158, 175, 128, 209, 118, 341, 104, 339, 122, 167, 166, 147, 110, 271, 270, 387, 114, 273, 444, 265, 156, 201, 136, 487, 198, 151, 384, 185, 184, 83, 128, 145, 190, 369, 292, 367, 52, 373, 174, 137, 26, 671, 248, 179, 302, 301, 404, 33, 174, 163, 296, 37, 232, 69, 168, 235, 166, 155, 232, 391, 266, 27, 160, 221, 220, 397, 224, 223, 54, 441, 276, 87, 58, 329, 210, 55, 334, 213, 324, 205, 96, 507, 208, 263, 4, 199, 72, 423, 202, 421, 200, 517, 310, 191, 252, 81, 194, 353, 304, 11, 226, 21, 308, 359, 242, 241, 220, 669, 354, 21, 236, 291, 46, 99, 288, 295, 230, 167, 104, 39, 10, 55, 280, 35, 222, 483, 284, 383, 48, 465, 244, 463, 44, 269, 150, 315, 472, 273, 264, 73, 18, 321, 268, 399, 258, 517, 304, 303, 262, 135, 62, 71, 138, 23, 526, 67, 254, 293, 516, 125, 492, 407, 288, 299, 420, 345, 422, 9, 282, 425, 156, 41, 50, 153, 288, 433, 46, 333, 112, 195, 166, 427, 102, 163, 358, 105, 98, 323, 524, 101, 32, 397, 350, 209, 400, 413, 130, 371, 312, 23, 90, 407, 382, 81, 384, 363, 84, 77, 194, 465, 80, 191, 198, 133, 394, 373, 352, 129, 376, 375, 556, 63, 320, 239, 66, 383, 362, 341, 434, 365, 54, 357, 218, 57, 112, 349, 372, 351, 108, 349, 354, 161, 84, 341, 418, 157, 166, 361, 346, 161, 162, 39, 94, 31, 510, 353, 34, 615, 416, 415, 516, 85, 140, 399, 198, 185, 136, 145, 394, 405, 140, 191, 408, 491, 388, 187, 292, 435, 264, 67, 394, 487, 380, 397, 62, 491, 164, 3, 386, 113, 160, 277, 170, 117, 118, 215, 166, 471, 76, 211, 456, 287, 282, 461, 290, 463, 462, 95, 18, 467, 446, 297, 90, 137, 450, 31, 94, 95, 28, 143, 190, 435, 308, 339, 244, 439, 216, 441, 240, 427, 264, 445, 252, 431, 254, 433, 114, 257, 250, 437, 546, 253, 120, 59, 264, 223, 56, 63, 260, 219, 60, 61, 242, 231, 320, 233, 530, 227, 236, 229, 14, 149, 232, 205, 522, 243, 144, 83, 42, 239, 80, 291, 196, 89, 28, 511, 86, 297, 32, 33, 204, 293, 206, 225, 296, 209, 500, 645, 14, 375, 178, 377, 216, 19, 492, 173, 266, 113, 52, 223, 110, 279, 272, 181, 58, 183, 4, 5, 186, 329, 198, 1, 38, 129, 238, 193, 126, 295, 338, 243, 576, 291, 342, 8, 344, 249, 24, 23, 82, 139, 20, 19, 30, 323, 150, 451, 152, 147, 536, 149, 94, 555, 152, 313, 98, 323, 162, 317, 226, 159, 436, 229, 276, 323, 80, 129, 54, 111, 84, 573, 50, 49, 250, 305, 600, 119, 290, 121, 388, 595, 124, 97, 70, 189, 36, 589, 186, 131, 188, 195, 30, 107, 192, 403, 272, 83, 24, 399, 276, 79, 78, 117, 628, 91, 282, 93, 46, 87, 96, 89, 88, 211, 92, 91, 158, 103, 160, 493, 378, 99, 164, 227, 110, 167, 224, 53, 340, 67, 144, 69, 236, 109, 72, 233, 240, 63, 242, 237, 66, 79, 246, 355, 130, 243, 132, 73, 126, 125, 136, 29, 90, 139, 132, 131, 456, 135, 134, 37, 426, 39, 706, 205, 42, 443, 332, 209, 106, 155, 108, 49, 472, 151, 112, 433, 102, 23, 56, 703, 106, 195, 286, 109, 492, 283, 164, 33, 8, 455, 10, 177, 176, 13, 40, 181, 172, 301, 2, 177, 298, 5, 178, 3, 82, 183, 144, 85, 12, 467, 10, 31, 138, 7, 60, 153, 428, 17, 322, 157, 66, 147, 42, 101, 18, 151, 202, 47, 270, 49, 34, 157, 444, 53, 410, 39, 114, 37, 336, 405, 34, 45, 256, 43, 342, 123, 40, 27, 506, 127, 426, 129, 356, 33, 358, 353, 242, 355, 16, 209, 238, 237, 62, 571, 766, 59, 478, 113, 72, 5, 374, 197, 52, 371, 94, 75, 2, 263, 98, 205, 218, 259, 86, 325, 84, 65, 212, 81, 88, 387, 90, 85, 96, 87, 74, 173, 54, 91, 78, 25, 286, 343, 38, 181, 84, 19, 20, 233, 574, 67, 188, 297, 38, 299, 418, 293, 292, 359, 32, 165, 424, 47, 176, 421, 144, 51, 172, 41, 540, 315, 256, 45, 136, 311, 134, 273, 44, 131, 12, 159, 144, 267, 142, 269, 124, 331, 22, 151, 226, 149, 26, 517, 146, 291, 232, 113, 32, 455, 524, 139, 180, 459, 424, 13, 24, 243, 132, 245, 172, 307, 170, 97, 4, 167, 6, 301, 542, 91, 2, 365, 160, 227, 6, 261, 4, 99, 112, 153, 110, 493, 184, 195, 106, 193, 214, 103, 190, 335, 30, 277, 386, 327, 206, 183, 204, 381, 206, 201, 346, 203, 508, 87, 232, 127, 194, 513, 196, 395, 50, 79, 224, 187, 222, 189, 74, 219, 58, 305, 248, 405, 356, 409, 212, 65, 448, 449, 240, 61, 238, 59, 318, 235, 101, 55, 370, 423, 422, 161, 434, 163, 158, 389, 430, 429, 86, 131, 276, 443, 82, 185, 80, 439, 560, 389, 268, 179, 142, 345, 144, 263, 448, 457, 410, 411, 134, 201, 256, 109, 404, 129, 522, 195, 262, 15, 160, 159, 472, 99, 120, 255, 122, 295, 116, 293, 118, 373, 290, 147, 110, 477, 176, 427, 380, 283, 36, 309, 138, 327, 494, 303, 134, 389, 132, 163, 138, 319, 296, 317, 364, 21, 314, 53, 154, 317, 344, 403, 150, 59, 148, 323, 256, 351, 336, 138, 334, 51, 250, 331, 70, 343, 72, 341, 44, 269, 338, 339, 62, 197, 474, 263, 182, 331, 478, 55, 178, 57, 88, 361, 324, 359, 274, 381, 356, 23, 364, 189, 386, 361, 244, 349, 102, 73, 104, 309, 34, 77, 36, 291, 304, 373, 96, 205, 258, 203, 298, 299, 366, 89, 264, 369, 222, 223, 52, 307, 218, 219, 272, 11, 222, 13, 132, 233, 316, 279, 398, 229, 138, 321, 68, 413, 2, 411, 288, 417, 408, 29, 266, 417, 250, 333, 414, 297, 246, 49, 244, 257, 18, 159, 16, 253, 254, 45, 252, 309, 284, 247, 96, 437, 314, 289, 172, 173, 34, 275, 32, 321, 296, 271, 280, 269, 326, 183, 276, 265, 368, 157, 158, 365, 372, 283, 16, 281, 178, 123, 288, 79, 168, 291, 200, 171, 62, 295, 60, 349, 2, 207, 136, 353, 66, 355, 140, 73, 294, 185, 216, 317, 100, 147, 44, 313, 192, 193, 342, 225, 50, 327, 156, 89, 230, 87, 114, 333, 30, 327, 164, 329, 222, 327, 210, 321, 102, 171, 100, 215, 106, 71, 104, 41, 234, 133, 222, 113, 254, 111, 116, 227, 114, 141, 84, 189, 122, 55, 120, 81, 148, 267, 84, 239, 130, 95, 128, 201, 98, 157, 68, 137, 206, 135, 104, 281, 252, 283, 166, 269, 146, 79, 112, 171, 82, 27, 262, 181, 90, 119, 266, 153, 268, 115, 160, 183, 158, 231, 96, 41, 46, 167, 44, 165, 34, 103, 172, 137, 170, 51, 30, 245, 142, 247, 112, 45, 138, 211, 60, 149, 208, 123, 38, 121, 154, 13, 68, 157, 126, 17, 218, 197, 62, 75, 222, 133, 24, 57, 140, 69, 138, 207, 4, 205, 64, 211, 62, 209, 78, 179, 10, 93, 14, 41, 100, 71, 98, 87, 20, 189, 48, 49, 92, 193, 80, 163, 28, 27, 110, 9, 24, 113, 6, 35, 34, 173, 92, 17, 66, 177, 14, 179, 44, 71, 24, 25, 8, 21, 22, 211, 78, 53, 52, 15, 16, 83, 58, 57, 86, 129, 54, 7, 42, 65, 27, 39, 122, 47, 70, 1, 44, 33, 66, 143, 54, 145, 38, 9, 8, 25, 108, 81, 56, 45, 30, 59, 18, 17, 50, 171, 118, 23, 22, 95, 122, 9, 42, 91, 30};
vi ret;
while (int(ret.size()) < M) {
for (auto &el : prev_best) {
ret.pb(el);
if (ret.size() >= M) break;
}
}
return ret;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// uniform_int_distribution u(0, M-1);
// geometric_distribution<int> g(0.4);
// double lambda = 0.01; vector<double> w(M); for (int i = 0; i < M; i++) w[i] = exp(-lambda * i);
// discrete_distribution<int> d(all(w));
// vi cur, best; while (int(cur.size()) < M) {int x = prev_best[cur.size()]; cur.pb(x); best.pb(x);}
// best_window(500);
// int score = count_triples(cur), best_score = count_triples(best);
// score = 0;
// // double T = 10000, u = 0.9995;
// double t0 = 100.0; double c = 0.85;
// int trials = 1;
// // while (T > 1) {
// while(best_score < K) {
// if (trials % 25000 == 0) cerr << "Trials: " << trials << " Best: " << best_score << "\n";
// if (trials % CHECK_EVERY == 0) save_checkpoint(CHECKPOINT_PATH, best, best_score, trials);
// double T = c / log(t0 + double(trials/2));
// vi nxt = cur;
// int idx = u(rng);
// // int val = g(rng) + 1; while (val >= M) val = g(rng) + 1;
// int val = d(rng); while (!(1 <= val && val < M)) val = d(rng);
// nxt[idx] = val;
// int ns = count_triples(nxt);
// if (accept(score, ns, T, rng)) {
// score = ns; cur = nxt;
// if (ns > best_score) {
// best_score = ns; best = nxt;
// }
// }
// // T *= u;
// trials++;
// }
// cerr << "Array has: " << count_triples(best) << " triples.\n";
// return best;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |