#include using namespace std; #define official #ifdef official #define cin inF #define cout outF #endif ifstream inF("justsort.in"); ofstream outF("justsort.out"); const int MAX_N = 2e7; int n; int a0; int gseed; unsigned long long ans; unsigned int fastrand() { gseed = 214013 * gseed + 2531011; return (gseed >> 16) & 0x7FFF; } int next(int prev) { return 1 + prev + (fastrand() & 0b111); } int getB(int a) { return a - (a % 3) * (a % 5); } void input() { cin >> n >> a0 >> gseed; } void output() { cout << ans << '\n'; } const int MAX_BUFF = 10; unsigned long long mul = 1; void reg(int b) { ans += b * mul; mul *= 139; } priority_queue buff; void addToBuff(int b) { buff.push(-b); if (buff.size() > MAX_BUFF) { reg(-buff.top()); buff.pop(); } } void getAll() { while (!buff.empty()) { reg(-buff.top()); buff.pop(); } } void solve() { int prev = a0; addToBuff(getB(prev)); for (int i = 1; i < n; ++i) { prev = next(prev); addToBuff(getB(prev)); } getAll(); } int main() { input(); solve(); output(); return 0; }