#include <iostream>
#include <cassert>
#include <chrono>
#include <random>
typedef long long ll;
const int mod = 2147483647;
// Calculate x % (2^31-1) fast
// 0 <= x <= (2^31-2)^2
inline int fast_mod(ll value) {
value = (value >> 31) + (value & mod);
value = (value >> 31) + (value & mod);
return value == mod ? 0 : value;
}
int main() {
auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 mt_rand(seed);
std::uniform_int_distribution<ll> dis(ll(1e9), ll(1e18));
for (int n = 0; n < 100000000; ++n) {
ll value = dis(mt_rand);
assert(value % mod == fast_mod(value));
}
std::cout << "ok!";
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y2Fzc2VydD4KI2luY2x1ZGUgPGNocm9ubz4KI2luY2x1ZGUgPHJhbmRvbT4KCnR5cGVkZWYgbG9uZyBsb25nIGxsOwoKY29uc3QgaW50IG1vZCA9IDIxNDc0ODM2NDc7CgovLyBDYWxjdWxhdGUgeCAlICgyXjMxLTEpIGZhc3QKLy8gMCA8PSB4IDw9ICgyXjMxLTIpXjIKaW5saW5lIGludCBmYXN0X21vZChsbCB2YWx1ZSkgewogICAgdmFsdWUgPSAodmFsdWUgPj4gMzEpICsgKHZhbHVlICYgbW9kKTsKICAgIHZhbHVlID0gKHZhbHVlID4+IDMxKSArICh2YWx1ZSAmIG1vZCk7CiAgICByZXR1cm4gdmFsdWUgPT0gbW9kID8gMCA6IHZhbHVlOwp9CgppbnQgbWFpbigpIHsKICAgIGF1dG8gc2VlZCA9IHN0ZDo6Y2hyb25vOjpoaWdoX3Jlc29sdXRpb25fY2xvY2s6Om5vdygpLnRpbWVfc2luY2VfZXBvY2goKS5jb3VudCgpOwogICAgc3RkOjptdDE5OTM3IG10X3JhbmQoc2VlZCk7CiAgICBzdGQ6OnVuaWZvcm1faW50X2Rpc3RyaWJ1dGlvbjxsbD4gZGlzKGxsKDFlOSksIGxsKDFlMTgpKTsKCiAgICBmb3IgKGludCBuID0gMDsgbiA8IDEwMDAwMDAwMDsgKytuKSB7CiAgICAgICAgbGwgdmFsdWUgPSBkaXMobXRfcmFuZCk7CiAgICAgICAgYXNzZXJ0KHZhbHVlICUgbW9kID09IGZhc3RfbW9kKHZhbHVlKSk7CiAgICB9CiAgICBzdGQ6OmNvdXQgPDwgIm9rISI7CiAgICByZXR1cm4gMDsKfQ==