#include <bits/stdc++.h>
typedef long long ll;
#define M 1000000007
#define N (1 << 18)
using namespace std;
int itv[100];
int v[2023];
int n = 100;
int calc_ans() {
int ans = 0;
// #pragma omp parallel for
for (int intv = 0; intv < 100; ++intv) {
int sm = 0;
for (int i = intv * 20; i < intv * 20 + 43; ++i) {
sm += v[i];
}
ans += sm == itv[intv];
}
return ans;
}
ll dif() {
ll ans = 0;
// #pragma omp parallel for
for (int intv = 0; intv < 100; ++intv) {
int sm = 0;
for (int i = intv * 20; i < intv * 20 + 43; ++i) {
sm += v[i];
}
ans += abs(sm - itv[intv]);
}
return ans;
}
void print(int cans, int seed) {
/*cout << "ANS FOR " << cans << "\n";
for (int i = 0; i < 2023; ++i) {
cout << v[i] << " ";
}
cout << "\n------------" << endl;*/
ofstream outfile;
outfile.open("tulos-" + to_string(seed) + ".txt");
for (int i = 0; i < 2023; ++i) {
outfile << v[i] << " ";
}
outfile.close();
}
void brute(int seed) {
cout << "Starting seed: " << seed << endl;
int limit = 2e9;
srand(seed);
int run = 0;
ll cd = dif();
ll ans = calc_ans();
cout << "Current best: " << ans << endl;
while (run++ <= limit) {
int a = rand() % 2023;
int b = rand() % 2023;
int c = rand() % 2023;
int d = rand() % 2023;
swap(v[a], v[b]);
//swap(v[c], v[d]);
ll nd = dif();
if (nd < cd) {
cd = nd;
ll nans = calc_ans();
cout << "IMPR " << cd << endl;
if (ans < nans) {
ans = nans;
cout << "Current best: " << ans << endl;
print(ans, seed);
}
} else {
swap(v[a], v[b]);
//swap(v[c], v[d]);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
for (int i = 0; i < n; ++i) {
cin >> itv[i];
}
ifstream infile("tulos-21.txt");
for (int i = 0; i < 2023; ++i) {
infile >> v[i];
}
infile.close();
brute(2001);
/*for (int seed = 21; seed <= 30; ++seed) {
for (int i = 0; i < 2023; ++i) {
v[i] = i + 1;
}
brute(seed);
}*/
return 0;
}