#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <fstream>
#include <cassert>
using namespace std;
#define sz(a) int((a).size())
#define rep(i, s, n) for(int i = s; i <= (n); ++i)
#define rev(i, n, s) for(int i = (n); i >= s; --i)
#define fore(x, a) for(auto &&x : a)
typedef long long ll;
const int mod = 1000000007;
const int N = 100005;
int arr[N], k , m, l[N], r[N];
pair<int, int> ab[N], ba[N];
bool all_bad(int s, int e) {
if (e - s + 1 < m) return 1;
for (int i = s, j = e; i <= e && j >= s && i <= j; i++, j--) {
if (l[i]<s && r[i]>e) return all_bad(s, i - 1) && all_bad(i + 1, e);
if (l[j]<s && r[j]>e) return all_bad(s, j - 1) && all_bad(j + 1, e);
}
return 0;
}
bool cmp(pair<int, int> o1, pair<int, int> o2) {
if (o1.first != o2.first) return o1.first < o2.first;
return o1.second > o2.second;
}
set<int> c1, c2;
class FindingFriends {
public:
int shortestDistance( int n, vector <int> init, int a, int b, int c, int d, int m2 ) {
m = m2;
int mx = -1, mn = mod;
rep(i, 0, sz(init) - 1) {
arr[i] = init[i];
}
rep(i, sz(init), n - 1) {
arr[i] = (arr[i - 1] * 1LL * a + b * 1LL * i + c) % d;
}
rep(i, 0, n - 1) {
mn = min(mn, arr[i]);
mx = max(mx, arr[i]);
ab[i] = make_pair(arr[i], i);
ba[i] = make_pair(arr[i], i);
}
sort(ab, ab + n);
sort(ba, ba + n, cmp);
int hi = mx - mn, lo = 0;
while (lo < hi) {
k = (hi + lo) / 2;
rep(i, 0, n - 1) {
l[i] = -1, r[i] = n;
}
c1.clear(); c2.clear(); c1.insert(-1); c2.insert(n);
int j1 = 0, j2 = 0;
rep(i, 0, n - 1) {
while (j1 < i && ab[j1].first < ab[i].first - k) {
c1.erase(ab[j1].second);
j1++;
}
while (j2 < i && ba[j2].first < ba[i].first - k) {
c2.erase(ba[j2].second);
j2++;
}
auto it = c1.lower_bound(ab[i].second);
it--;
l[ab[i].second] = max(l[ab[i].second], *it);
r[ba[i].second] = min(r[ba[i].second], *(c2.upper_bound(ba[i].second)));
c1.insert(ab[i].second);
c2.insert(ba[i].second);
}
j1 = n - 1; j2 = n - 1;
c1.clear(); c2.clear(); c1.insert(-1); c2.insert(n);
rev(i, n - 1, 0) {
while (j1 > i && ab[j1].first > ab[i].first + k) {
c1.erase(ab[j1].second);
j1--;
}
while (j2 > i && ba[j2].first > ba[i].first + k) {
c2.erase(ba[j2].second);
j2--;
}
auto it = c1.lower_bound(ab[i].second);
it--;
l[ab[i].second] = max(l[ab[i].second], *it);
r[ba[i].second] = min(r[ba[i].second], *(c2.upper_bound(ba[i].second)));
c1.insert(ab[i].second);
c2.insert(ba[i].second);
}
bool can = (!all_bad(0, n - 1));
if (can) hi = k;
else lo = k + 1;
}
return lo;
}
};
// BEGIN CUT HERE
#include <cstdio>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
namespace moj_harness {
using std::string;
using std::vector;
int run_test_case(int);
void run_test(int casenum = -1, bool quiet = false) {
if (casenum != -1) {
if (run_test_case(casenum) == -1 && !quiet) {
std::cerr << "Illegal input! Test case " << casenum << " does not exist." << std::endl;
}
return;
}
int correct = 0, total = 0;
for (int i=0;; ++i) {
int x = run_test_case(i);
if (x == -1) {
if (i >= 100) break;
continue;
}
correct += x;
++total;
}
if (total == 0) {
std::cerr << "No test cases run." << std::endl;
} else if (correct < total) {
std::cerr << "Some cases FAILED (passed " << correct << " of " << total << ")." << std::endl;
} else {
std::cerr << "All " << total << " tests passed!" << std::endl;
}
}
int verify_case(int casenum, const int &expected, const int &received, std::clock_t elapsed) {
std::cerr << "Example " << casenum << "... ";
string verdict;
vector<string> info;
char buf[100];
if (elapsed > CLOCKS_PER_SEC / 200) {
std::sprintf(buf, "time %.2fs", elapsed * (1.0/CLOCKS_PER_SEC));
info.push_back(buf);
}
if (expected == received) {
verdict = "PASSED";
} else {
verdict = "FAILED";
}
std::cerr << verdict;
if (!info.empty()) {
std::cerr << " (";
for (size_t i=0; i<info.size(); ++i) {
if (i > 0) std::cerr << ", ";
std::cerr << info[i];
}
std::cerr << ")";
}
std::cerr << std::endl;
if (verdict == "FAILED") {
std::cerr << " Expected: " << expected << std::endl;
std::cerr << " Received: " << received << std::endl;
}
return verdict == "PASSED";
}
int run_test_case(int casenum__) {
switch (casenum__) {
case 0: {
int len = 6;
int init[] = {8,1,10,2,9,7};
int a = 12;
int b = 34;
int c = 56;
int d = 78;
int m = 2;
int expected__ = 1;
std::clock_t start__ = std::clock();
int received__ = FindingFriends().shortestDistance(len, vector <int>(init, init + (sizeof init / sizeof init[0])), a, b, c, d, m);
return verify_case(casenum__, expected__, received__, clock()-start__);
}
case 1: {
int len = 7;
int init[] = {1};
int a = 1;
int b = 0;
int c = 0;
int d = 12345678;
int m = 5;
int expected__ = 0;
std::clock_t start__ = std::clock();
int received__ = FindingFriends().shortestDistance(len, vector <int>(init, init + (sizeof init / sizeof init[0])), a, b, c, d, m);
return verify_case(casenum__, expected__, received__, clock()-start__);
}
case 2: {
int len = 12;
int init[] = {0};
int a = 1;
int b = 0;
int c = 1;
int d = 6;
int m = 3;
int expected__ = 0;
std::clock_t start__ = std::clock();
int received__ = FindingFriends().shortestDistance(len, vector <int>(init, init + (sizeof init / sizeof init[0])), a, b, c, d, m);
return verify_case(casenum__, expected__, received__, clock()-start__);
}
case 3: {
int len = 10;
int init[] = {3,4,5};
int a = 23;
int b = 34;
int c = 35;
int d = 46;
int m = 4;
int expected__ = 4;
std::clock_t start__ = std::clock();
int received__ = FindingFriends().shortestDistance(len, vector <int>(init, init + (sizeof init / sizeof init[0])), a, b, c, d, m);
return verify_case(casenum__, expected__, received__, clock()-start__);
}
case 4: {
int len = 2;
int init[] = {0,1000000000};
int a = 0;
int b = 0;
int c = 0;
int d = 1;
int m = 2;
int expected__ = 1000000000;
std::clock_t start__ = std::clock();
int received__ = FindingFriends().shortestDistance(len, vector <int>(init, init + (sizeof init / sizeof init[0])), a, b, c, d, m);
return verify_case(casenum__, expected__, received__, clock()-start__);
}
case 5: {
int len = 5;
int init[] = {1,2,1000,3,4};
int a = 9;
int b = 8;
int c = 7;
int d = 10;
int m = 3;
int expected__ = 996;
std::clock_t start__ = std::clock();
int received__ = FindingFriends().shortestDistance(len, vector <int>(init, init + (sizeof init / sizeof init[0])), a, b, c, d, m);
return verify_case(casenum__, expected__, received__, clock()-start__);
}
case 6: {
int len = 100000;
int init[] = {565990974};
int a = 168649977;
int b = 191924440;
int c = 138092623;
int d = 192724723;
int m = 100000;
int expected__ = 373269838;
std::clock_t start__ = std::clock();
int received__ = FindingFriends().shortestDistance(len, vector <int>(init, init + (sizeof init / sizeof init[0])), a, b, c, d, m);
return verify_case(casenum__, expected__, received__, clock()-start__);
}
// custom cases
/* case 7: {
int len = ;
int init[] = ;
int a = ;
int b = ;
int c = ;
int d = ;
int m = ;
int expected__ = ;
std::clock_t start__ = std::clock();
int received__ = FindingFriends().shortestDistance(len, vector <int>(init, init + (sizeof init / sizeof init[0])), a, b, c, d, m);
return verify_case(casenum__, expected__, received__, clock()-start__);
}*/
/* case 8: {
int len = ;
int init[] = ;
int a = ;
int b = ;
int c = ;
int d = ;
int m = ;
int expected__ = ;
std::clock_t start__ = std::clock();
int received__ = FindingFriends().shortestDistance(len, vector <int>(init, init + (sizeof init / sizeof init[0])), a, b, c, d, m);
return verify_case(casenum__, expected__, received__, clock()-start__);
}*/
/* case 9: {
int len = ;
int init[] = ;
int a = ;
int b = ;
int c = ;
int d = ;
int m = ;
int expected__ = ;
std::clock_t start__ = std::clock();
int received__ = FindingFriends().shortestDistance(len, vector <int>(init, init + (sizeof init / sizeof init[0])), a, b, c, d, m);
return verify_case(casenum__, expected__, received__, clock()-start__);
}*/
/* case 10: {
int len = ;
int init[] = ;
int a = ;
int b = ;
int c = ;
int d = ;
int m = ;
int expected__ = ;
std::clock_t start__ = std::clock();
int received__ = FindingFriends().shortestDistance(len, vector <int>(init, init + (sizeof init / sizeof init[0])), a, b, c, d, m);
return verify_case(casenum__, expected__, received__, clock()-start__);
}*/
/* case 11: {
int len = ;
int init[] = ;
int a = ;
int b = ;
int c = ;
int d = ;
int m = ;
int expected__ = ;
std::clock_t start__ = std::clock();
int received__ = FindingFriends().shortestDistance(len, vector <int>(init, init + (sizeof init / sizeof init[0])), a, b, c, d, m);
return verify_case(casenum__, expected__, received__, clock()-start__);
}*/
default:
return -1;
}
}
}
int main() {
#ifdef loc
if(!freopen((string(FOLDER) + "inp.txt").c_str(), "r", stdin)) {
assert(0);
}
freopen((string(FOLDER) + "out.txt").c_str(), "a", stdout);
freopen((string(FOLDER) + "out.txt").c_str(), "a", stderr);
#endif
moj_harness::run_test();
}
// END CUT HERE
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxkZXF1ZT4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxiaXRzZXQ+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxmdW5jdGlvbmFsPgojaW5jbHVkZSA8bnVtZXJpYz4KI2luY2x1ZGUgPHV0aWxpdHk+CiNpbmNsdWRlIDxzc3RyZWFtPgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxpb21hbmlwPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxjc3RkbGliPgojaW5jbHVkZSA8Y2N0eXBlPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1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OwogIHJldHVybiBvMS5zZWNvbmQgPiBvMi5zZWNvbmQ7Cn0Kc2V0PGludD4gYzEsIGMyOwoKY2xhc3MgRmluZGluZ0ZyaWVuZHMgewpwdWJsaWM6CiAgaW50IHNob3J0ZXN0RGlzdGFuY2UoIGludCBuLCB2ZWN0b3IgPGludD4gaW5pdCwgaW50IGEsIGludCBiLCBpbnQgYywgaW50IGQsIGludCBtMiApIHsKICAgIG0gPSBtMjsKICAgIGludCBteCA9IC0xLCBtbiA9IG1vZDsKICAgIHJlcChpLCAwLCBzeihpbml0KSAtIDEpIHsKICAgICAgYXJyW2ldID0gaW5pdFtpXTsKICAgIH0KICAgIHJlcChpLCBzeihpbml0KSwgbiAtIDEpIHsKICAgICAgYXJyW2ldID0gKGFycltpIC0gMV0gKiAxTEwgKiBhICsgYiAqIDFMTCAqIGkgKyBjKSAlIGQ7CiAgICB9CiAgICByZXAoaSwgMCwgbiAtIDEpIHsKICAgICAgbW4gPSBtaW4obW4sIGFycltpXSk7CiAgICAgIG14ID0gbWF4KG14LCBhcnJbaV0pOwogICAgICBhYltpXSA9IG1ha2VfcGFpcihhcnJbaV0sIGkpOwogICAgICBiYVtpXSA9IG1ha2VfcGFpcihhcnJbaV0sIGkpOwogICAgfQogICAgc29ydChhYiwgYWIgKyBuKTsKICAgIHNvcnQoYmEsIGJhICsgbiwgY21wKTsKICAgIGludCBoaSA9IG14IC0gbW4sIGxvID0gMDsKICAgIHdoaWxlIChsbyA8IGhpKSB7CiAgICAgIGsgPSAoaGkgKyBsbykgLyAyOwogICAgICByZXAoaSwgMCwgbiAtIDEpIHsKICAgICAgICBsW2ldID0gLTEsIHJbaV0gPSBuOwogICAgICB9CiAgICAgIGMxLmNsZWFyKCk7IGMyLmNsZWFyKCk7IGMxLmluc2VydCgtMSk7IGMyLmluc2VydChuKTsKICAgICAgaW50IGoxID0gMCwgajIgPSAwOwogICAgICByZXAoaSwgMCwgbiAtIDEpIHsKICAgICAgICB3aGlsZSAoajEgPCBpICYmIGFiW2oxXS5maXJzdCA8IGFiW2ldLmZpcnN0IC0gaykgewogICAgICAgICAgYzEuZXJhc2UoYWJbajFdLnNlY29uZCk7CiAgICAgICAgICBqMSsrOwogICAgICAgIH0KICAgICAgICB3aGlsZSAoajIgPCBpICYmIGJhW2oyXS5maXJzdCA8IGJhW2ldLmZpcnN0IC0gaykgewogICAgICAgICAgYzIuZXJhc2UoYmFbajJdLnNlY29uZCk7CiAgICAgICAgICBqMisrOwogICAgICAgIH0KICAgICAgICBhdXRvIGl0ID0gYzEubG93ZXJfYm91bmQoYWJbaV0uc2Vjb25kKTsKICAgICAgICBpdC0tOwogICAgICAgIGxbYWJbaV0uc2Vjb25kXSA9IG1heChsW2FiW2ldLnNlY29uZF0sICppdCk7CiAgICAgICAgcltiYVtpXS5zZWNvbmRdID0gbWluKHJbYmFbaV0uc2Vjb25kXSwgKihjMi51cHBlcl9ib3VuZChiYVtpXS5zZWNvbmQpKSk7CiAgICAgICAgYzEuaW5zZXJ0KGFiW2ldLnNlY29uZCk7CiAgICAgICAgYzIuaW5zZXJ0KGJhW2ldLnNlY29uZCk7CiAgICAgIH0KICAgICAgajEgPSBuIC0gMTsgajIgPSBuIC0gMTsKICAgICAgYzEuY2xlYXIoKTsgYzIuY2xlYXIoKTsgYzEuaW5zZXJ0KC0xKTsgYzIuaW5zZXJ0KG4pOwogICAgICByZXYoaSwgbiAtIDEsIDApIHsKICAgICAgICB3aGlsZSAoajEgPiBpICYmIGFiW2oxXS5maXJzdCA+IGFiW2ldLmZpcnN0ICsgaykgewogICAgICAgICAgYzEuZXJhc2UoYWJbajFdLnNlY29uZCk7CiAgICAgICAgICBqMS0tOwogICAgICAgIH0KICAgICAgICB3aGlsZSAoajIgPiBpICYmIGJhW2oyXS5maXJzdCA+IGJhW2ldLmZpcnN0ICsgaykgewogICAgICAgICAgYzIuZXJhc2UoYmFbajJdLnNlY29uZCk7CiAgICAgICAgICBqMi0tOwogICAgICAgIH0KICAgICAgICBhdXRvIGl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JCQlpbnQgZCAgICAgICAgICAgICAgICAgICAgID0gNzg7CgkJCWludCBtICAgICAgICAgICAgICAgICAgICAgPSAyOwoJCQlpbnQgZXhwZWN0ZWRfXyAgICAgICAgICAgID0gMTsKCgkJCXN0ZDo6Y2xvY2tfdCBzdGFydF9fICAgICAgPSBzdGQ6OmNsb2NrKCk7CgkJCWludCByZWNlaXZlZF9fICAgICAgICAgICAgPSBGaW5kaW5nRnJpZW5kcygpLnNob3J0ZXN0RGlzdGFuY2UobGVuLCB2ZWN0b3IgPGludD4oaW5pdCwgaW5pdCArIChzaXplb2YgaW5pdCAvIHNpemVvZiBpbml0WzBdKSksIGEsIGIsIGMsIGQsIG0pOwoJCQlyZXR1cm4gdmVyaWZ5X2Nhc2UoY2FzZW51bV9fLCBleHBlY3RlZF9fLCByZWNlaXZlZF9fLCBjbG9jaygpLXN0YXJ0X18pOwoJCX0KCQljYXNlIDE6IHsKCQkJaW50IGxlbiAgICAgICAgICAgICAgICAgICA9IDc7CgkJCWludCBpbml0W10gICAgICAgICAgICAgICAgPSB7MX07CgkJCWludCBhICAgICAgICAgICAgICAgICAgICAgPSAxOwoJCQlpbnQgYiAgICAgICAgICAgICAgICAgICAgID0gMDsKCQkJaW50IGMgICAgICAgICAgICAgICAgICAgICA9IDA7CgkJCWludCBkICAgICAgICAgICAgICAgICAgICAgPSAxMjM0NTY3ODsKCQkJaW50IG0gICAgICAgICAgICAgICAgICAgICA9IDU7CgkJCWludCBleHBlY3RlZF9fICAgICAgICAgICAgPSAwOwoKCQkJc3RkOjpjbG9ja190IHN0YXJ0X18gICAgICA9IHN0ZDo6Y2xvY2soKTsKCQkJaW50IHJlY2VpdmVkX18gICAgICAgICAgICA9IEZpbmRpbmdGcmllbmRzKCkuc2hvcnRlc3REaXN0YW5jZShsZW4sIHZlY3RvciA8aW50Pihpbml0LCBpbml0ICsgKHNpemVvZiBpbml0IC8gc2l6ZW9mIGluaXRbMF0pKSwgYSwgYiwgYywgZCwgbSk7CgkJCXJldHVybiB2ZXJpZnlfY2FzZShjYXNlbnVtX18sIGV4cGVjdGVkX18sIHJlY2VpdmVkX18sIGNsb2NrKCktc3RhcnRfXyk7CgkJfQoJCWNhc2UgMjogewoJCQlpbnQgbGVuICAgICAgICAgICAgICAgICAgID0gMTI7CgkJCWludCBpbml0W10gICAgICAgICAgICAgICAgPSB7MH07CgkJCWludCBhICAgICAgICAgICAgICAgICAgICAgPSAxOwoJCQlpbnQgYiAgICAgICAgICAgICAgICAgICAgID0gMDsKCQkJaW50IGMgICAgICAgICAgICAgICAgICAgICA9IDE7CgkJCWludCBkICAgICAgICAgICAgICAgICAgICAgPSA2OwoJCQlpbnQgbSAgICAgICAgICAgICAgICAgICAgID0gMzsKCQkJaW50IGV4cGVjdGVkX18gICAgICAgICAgICA9IDA7CgoJCQlzdGQ6OmNsb2NrX3Qgc3RhcnRfXyAgICAgID0gc3RkOjpjbG9jaygpOwoJCQlpbnQgcmVjZWl2ZWRfXyAgICAgICAgICAgID0gRmluZGluZ0ZyaWVuZHMoKS5zaG9ydGVzdERpc3RhbmNlKGxlbiwgdmVjdG9yIDxpbnQ+KGluaXQsIGluaXQgKyAoc2l6ZW9mIGluaXQgLyBzaXplb2YgaW5pdFswXSkpLCBhLCBiLCBjLCBkLCBtKTsKCQkJcmV0dXJuIHZlcmlmeV9jYXNlKGNhc2VudW1fXywgZXhwZWN0ZWRfXywgcmVjZWl2ZWRfXywgY2xvY2soKS1zdGFydF9fKTsKCQl9CgkJY2FzZSAzOiB7CgkJCWludCBsZW4gICAgICAgICAgICAgICAgICAgPSAxMDsKCQkJaW50IGluaXRbXSAgICAgICAgICAgICAgICA9IHszLDQsNX07CgkJCWludCBhICAgICAgICAgICAgICAgICAgICAgPSAyMzsKCQkJaW50IGIgICAgICAgICAgICAgICAgICAgICA9IDM0OwoJCQlpbnQgYyAgICAgICAgICAgICAgICAgICAgID0gMzU7CgkJCWludCBkICAgICAgICAgICAgICAgICAgICAgPSA0NjsKCQkJaW50IG0gICAgICAgICAgICAgICAgICAgICA9IDQ7CgkJCWludCBleHBlY3RlZF9fICAgICAgICAgICAgPSA0OwoKCQkJc3RkOjpjbG9ja190IHN0YXJ0X18gICAgICA9IHN0ZDo6Y2xvY2soKTsKCQkJaW50IHJlY2VpdmVkX18gICAgICAgICAgICA9IEZpbmRpbmdGcmllbmRzKCkuc2hvcnRlc3REaXN0YW5jZShsZW4sIHZlY3RvciA8aW50Pihpbml0LCBpbml0ICsgKHNpemVvZiBpbml0IC8gc2l6ZW9mIGluaXRbMF0pKSwgYSwgYiwgYywgZCwgbSk7CgkJCXJldHVybiB2ZXJpZnlfY2FzZShjYXNlbnVtX18sIGV4cGVjdGVkX18sIHJlY2VpdmVkX18sIGNsb2NrKCktc3RhcnRfXyk7CgkJfQoJCWNhc2UgNDogewoJCQlpbnQgbGVuICAgICAgICAgICAgICAgICAgID0gMjsKCQkJaW50IGluaXRbXSAgICAgICAgICAgICAgICA9IHswLDEwMDAwMDAwMDB9OwoJCQlpbnQgYSAgICAgICAgICAgICAgICAgICAgID0gMDsKCQkJaW50IGIgICAgICAgICAgICAgICAgICAgICA9IDA7CgkJCWludCBjICAgICAgICAgICAgICAgICAgICAgPSAwOwoJCQlpbnQgZCAgICAgICAgICAgICAgICAgICAgID0gMTsKCQkJaW50IG0gICAgICAgICAgICAgICAgICAgICA9IDI7CgkJCWludCBleHBlY3RlZF9fICAgICAgICAgICAgPSAxMDAwMDAwMDAwOwoKCQkJc3RkOjpjbG9ja190IHN0YXJ0X18gICAgICA9IHN0ZDo6Y2xvY2soKTsKCQkJaW50IHJlY2VpdmVkX18gICAgICAgICAgICA9IEZpbmRpbmdGcmllbmRzKCkuc2hvcnRlc3REaXN0YW5jZShsZW4sIHZlY3RvciA8aW50Pihpbml0LCBpbml0ICsgKHNpemVvZiBpbml0IC8gc2l6ZW9mIGluaXRbMF0pKSwgYSwgYiwgYywgZCwgbSk7CgkJCXJldHVybiB2ZXJpZnlfY2FzZShjYXNlbnVtX18sIGV4cGVjdGVkX18sIHJlY2VpdmVkX18sIGNsb2NrKCktc3RhcnRfXyk7CgkJfQoJCWNhc2UgNTogewoJCQlpbnQgbGVuICAgICAgICAgICAgICAgICAgID0gNTsKCQkJaW50IGluaXRbXSAgICAgICAgICAgICAgICA9IHsxLDIsMTAwMCwzLDR9OwoJCQlpbnQgYSAgICAgICAgICAgICAgICAgICAgID0gOTsKCQkJaW50IGIgICAgICAgICAgICAgICAgICAgICA9IDg7CgkJCWludCBjICAgICAgICAgICAgICAgICAgICAgPSA3OwoJCQlpbnQgZCAgICAgICAgICAgICAgICAgICAgID0gMTA7CgkJCWludCBtICAgICAgICAgICAgICAgICAgICAgPSAzOwoJCQlpbnQgZXhwZWN0ZWRfXyAgICAgICAgICAgID0gOTk2OwoKCQkJc3RkOjpjbG9ja190IHN0YXJ0X18gICAgICA9IHN0ZDo6Y2xvY2soKTsKCQkJaW50IHJlY2VpdmVkX18gICAgICAgICAgICA9IEZpbmRpbmdGcmllbmRzKCkuc2hvcnRlc3REaXN0YW5jZShsZW4sIHZlY3RvciA8aW50Pihpbml0LCBpbml0ICsgKHNpemVvZiBpbml0IC8gc2l6ZW9mIGluaXRbMF0pKSwgYSwgYiwgYywgZCwgbSk7CgkJCXJldHVybiB2ZXJpZnlfY2FzZShjYXNlbnVtX18sIGV4cGVjdGVkX18sIHJlY2VpdmVkX18sIGNsb2NrKCktc3RhcnRfXyk7CgkJfQoJCWNhc2UgNjogewoJCQlpbnQgbGVuICAgICAgICAgICAgICAgICAgID0gMTAwMDAwOwoJCQlpbnQgaW5pdFtdICAgICAgICAgICAgICAgID0gezU2NTk5MDk3NH07CgkJCWludCBhICAgICAgICAgICAgICAgICAgICAgPSAxNjg2NDk5Nzc7CgkJCWludCBiICAgICAgICAgICAgICAgICAgICAgPSAxOTE5MjQ0NDA7CgkJCWludCBjICAgICAgICAgICAgICAgICAgICAgPSAxMzgwOTI2MjM7CgkJCWludCBkICAgICAgICAgICAgICAgICAgICAgPSAxOTI3MjQ3MjM7CgkJCWludCBtICAgICAgICAgICAgICAgICAgICAgPSAxMDAwMDA7CgkJCWludCBleHBlY3RlZF9fICAgICAgICAgICAgPSAzNzMyNjk4Mzg7CgoJCQlzdGQ6OmNsb2NrX3Qgc3RhcnRfXyAgICAgID0gc3RkOjpjbG9jaygpOwoJCQlpbnQgcmVjZWl2ZWRfXyAgICAgICAgICAgID0gRmluZGluZ0ZyaWVuZHMoKS5zaG9ydGVzdERpc3RhbmNlKGxlbiwgdmVjdG9yIDxpbnQ+KGluaXQsIGluaXQgKyAoc2l6ZW9mIGluaXQgLyBzaXplb2YgaW5pdFswXSkpLCBhLCBiLCBjLCBkLCBtKTsKCQkJcmV0dXJuIHZlcmlmeV9jYXNlKGNhc2VudW1fXywgZXhwZWN0ZWRfXywgcmVjZWl2ZWRfXywgY2xvY2soKS1zdGFydF9fKTsKCQl9CgoJCS8vIGN1c3RvbSBjYXNlcwoKLyogICAgICBjYXNlIDc6IHsKCQkJaW50IGxlbiAgICAgICAgICAgICAgICAgICA9IDsKCQkJaW50IGluaXRbXSAgICAgICAgICAgICAgICA9IDsKCQkJaW50IGEgICAgICAgICAgICAgICAgICAgICA9IDsKCQkJaW50IGIgICAgICAgICAgICAgICAgICAgICA9IDsKCQkJaW50IGMgICAgICAgICAgICAgICAgICAgICA9IDsKCQkJaW50IGQgICAgICAgICAgICAgICAgICAgICA9IDsKCQkJaW50IG0gICAgICAgICAgICAgICAgICAgICA9IDsKCQkJaW50IGV4cGVjdGVkX18gICAgICAgICAgICA9IDsKCgkJCXN0ZDo6Y2xvY2tfdCBzdGFydF9fICAgICAgPSBzdGQ6OmNsb2NrKCk7CgkJCWludCByZWNlaXZlZF9fICAgICAgICAgICAgPSBGaW5kaW5nRnJpZW5kcygpLnNob3J0ZXN0RGlzdGFuY2UobGVuLCB2ZWN0b3IgPGludD4oaW5pdCwgaW5pdCArIChzaXplb2YgaW5pdCAvIHNpemVvZiBpbml0WzBdKSksIGEsIGIsIGMsIGQsIG0pOwoJCQlyZXR1cm4gdmVyaWZ5X2Nhc2UoY2FzZW51bV9fLCBleHBlY3RlZF9fLCByZWNlaXZlZF9fLCBjbG9jaygpLXN0YXJ0X18pOwoJCX0qLwovKiAgICAgIGNhc2UgODogewoJCQlpbnQgbGVuICAgICAgICAgICAgICAgICAgID0gOwoJCQlpbnQgaW5pdFtdICAgICAgICAgICAgICAgID0gOwoJCQlpbnQgYSAgICAgICAgICAgICAgICAgICAgID0gOwoJCQlpbnQgYiAgICAgICAgICAgICAgICAgICAgID0gOwoJCQlpbnQgYyAgICAgICAgICAgICAgICAgICAgID0gOwoJCQlpbnQgZCAgICAgICAgICAgICAgICAgICAgID0gOwoJCQlpbnQgbSAgICAgICAgICAgICAgICAgICAgID0gOwoJCQlpbnQgZXhwZWN0ZWRfXyAgICAgICAgICAgID0gOwoKCQkJc3RkOjpjbG9ja190IHN0YXJ0X18gICAgICA9IHN0ZDo6Y2xvY2soKTsKCQkJaW50IHJlY2VpdmVkX18gICAgICAgICAgICA9IEZpbmRpbmdGcmllbmRzKCkuc2hvcnRlc3REaXN0YW5jZShsZW4sIHZlY3RvciA8aW50Pihpbml0LCBpbml0ICsgKHNpemVvZiBpbml0IC8gc2l6ZW9mIGluaXRbMF0pKSwgYSwgYiwgYywgZCwgbSk7CgkJCXJldHVybiB2ZXJpZnlfY2FzZShjYXNlbnVtX18sIGV4cGVjdGVkX18sIHJlY2VpdmVkX18sIGNsb2NrKCktc3RhcnRfXyk7CgkJfSovCi8qICAgICAgY2FzZSA5OiB7CgkJCWludCBsZW4gICAgICAgICAgICAgICAgICAgPSA7CgkJCWludCBpbml0W10gICAgICAgICAgICAgICAgPSA7CgkJCWludCBhICAgICAgICAgICAgICAgICAgICAgPSA7CgkJCWludCBiICAgICAgICAgICAgICAgICAgICAgPSA7CgkJCWludCBjICAgICAgICAgICAgICAgICAgICAgPSA7CgkJCWludCBkICAgICAgICAgICAgICAgICAgICAgPSA7CgkJCWludCBtICAgICAgICAgICAgICA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XywgY2xvY2soKS1zdGFydF9fKTsKCQl9Ki8KLyogICAgICBjYXNlIDExOiB7CgkJCWludCBsZW4gICAgICAgICAgICAgICAgICAgPSA7CgkJCWludCBpbml0W10gICAgICAgICAgICAgICAgPSA7CgkJCWludCBhICAgICAgICAgICAgICAgICAgICAgPSA7CgkJCWludCBiICAgICAgICAgICAgICAgICAgICAgPSA7CgkJCWludCBjICAgICAgICAgICAgICAgICAgICAgPSA7CgkJCWludCBkICAgICAgICAgICAgICAgICAgICAgPSA7CgkJCWludCBtICAgICAgICAgICAgICAgICAgICAgPSA7CgkJCWludCBleHBlY3RlZF9fICAgICAgICAgICAgPSA7CgoJCQlzdGQ6OmNsb2NrX3Qgc3RhcnRfXyAgICAgID0gc3RkOjpjbG9jaygpOwoJCQlpbnQgcmVjZWl2ZWRfXyAgICAgICAgICAgID0gRmluZGluZ0ZyaWVuZHMoKS5zaG9ydGVzdERpc3RhbmNlKGxlbiwgdmVjdG9yIDxpbnQ+KGluaXQsIGluaXQgKyAoc2l6ZW9mIGluaXQgLyBzaXplb2YgaW5pdFswXSkpLCBhLCBiLCBjLCBkLCBtKTsKCQkJcmV0dXJuIHZlcmlmeV9jYXNlKGNhc2VudW1fXywgZXhwZWN0ZWRfXywgcmVjZWl2ZWRfXywgY2xvY2soKS1zdGFydF9fKTsKCQl9Ki8KCQlkZWZhdWx0OgoJCQlyZXR1cm4gLTE7CgkJfQoJfQp9CgoKaW50IG1haW4oKSB7CiNpZmRlZiBsb2MKICBpZighZnJlb3Blbigoc3RyaW5nKEZPTERFUikgKyAiaW5wLnR4dCIpLmNfc3RyKCksICJyIiwgc3RkaW4pKSB7CiAgICBhc3NlcnQoMCk7CiAgfQogIGZyZW9wZW4oKHN0cmluZyhGT0xERVIpICsgIm91dC50eHQiKS5jX3N0cigpLCAiYSIsIHN0ZG91dCk7CiAgZnJlb3Blbigoc3RyaW5nKEZPTERFUikgKyAib3V0LnR4dCIpLmNfc3RyKCksICJhIiwgc3RkZXJyKT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