Problem:
問題文
有理数列 $X_0, X_1, X_2, ..., X_N$ がある。各項は以下のように定義される。
$X_0 = 0$
$X_i = X_{i-1}$ $op_i$ $Y_i$ ($1 \leq i \leq N$). ただし $op_i$ は $＋$、$−$、$×$、$÷$のいずれかである。
$X_N$ を求めよ。
入力
入力は以下の形式に従う。与えられる数は全て整数である。
$N$
$o_1$ $Y_1$
$o_2$ $Y_2$
$...$
$o_N$ $Y_N$
$o_i = 1$ のとき $op_i$ は＋、$o_i = 2$ のとき $op_i$ は−、$o_i = 3$ のとき $op_i$ は×、$o_i = 4$ のとき $op_i$ は÷である。
制約
$1 \leq N \leq 10^5$
$1 \leq o_i \leq 4$
$-10^6 \leq Y_i \leq 10^6$
$o_i=4$ ならば $Y_i \neq 0$
$X_N$ は $-2^{31}$ 以上 $2^{31}$ 未満の整数となる。
出力
$X_N$ の値を1行に出力せよ。
Sample Input 1
4
1 1
4 2
2 4
3 4
Output for the Sample Input 1
-14
$X_0 = 0$
$X_1 = X_0 ＋ 1 = 1$
$X_2 = X_1 ÷ 2 = 1/2$
$X_3 = X_2 − 4 = -7/2$
$X_4 = X_3 × 4 = -14$

Submitted solutions:

code_snippet: #include <iostream>
#include <cmath>

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long double x = 0;
    int n; cin >> n;
    while (n--) {
        int o; long double y; cin >> o >> y;
        if (o == 1) x += y;
        else if (o == 2) x -= y;
        else if (o == 3) x *= y;
        else if (o == 4) x /= y;
    }
    cout << (long long)llround(x) << '\n';
}
accuracy: 0.2857142857142857
time_ms: 10
memory_kb: 3348
final_rank: 12

code_snippet: #include <iostream>
#include <cmath>

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long double x = 0;
    int n; cin >> n;
    while (n--) {
        int o; long double y; cin >> o >> y;
        if (o == 1) x += y;
        else if (o == 2) x -= y;
        else if (o == 3) x *= y;
        else if (o == 4) x /= y;
    }
    cout << (long long)round(x) << '\n';
}
accuracy: 0.2857142857142857
time_ms: 10
memory_kb: 3348
final_rank: 12

code_snippet: //
// モンゴメリ乗算を用いた modint (mod は 2^62 未満の奇数)
//
// verified:
//   AOJ 2353 Four Arithmetic Operations
//     http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2353
//
//   Yosupo Judge Factorize
//     https://judge.yosupo.jp/problem/factorize
//


#include <bits/stdc++.h>
using namespace std;


// montgomery modint (MOD < 2^62, MOD is odd)
struct MontgomeryModInt64 {
    using mint = MontgomeryModInt64;
    using u64 = uint64_t;
    using u128 = __uint128_t;
    
    // static menber
    static u64 MOD;
    static u64 INV_MOD;  // INV_MOD * MOD ≡ 1 (mod 2^64)
    static u64 T128;  // 2^128 (mod MOD)
    
    // inner value
    u64 val;
    
    // constructor
    MontgomeryModInt64() : val(0) { }
    MontgomeryModInt64(long long v) : val(reduce((u128(v) + MOD) * T128)) { }
    u64 get() const {
        u64 res = reduce(val);
        return res >= MOD ? res - MOD : res;
    }
    
    // mod getter and setter
    static u64 get_mod() { return MOD; }
    static void set_mod(u64 mod) {
        assert(mod < (1LL << 62));
        assert((mod & 1));
        MOD = mod;
        T128 = -u128(mod) % mod;
        INV_MOD = get_inv_mod();
    }
    static u64 get_inv_mod() {
        u64 res = MOD;
        for (int i = 0; i < 5; ++i) res *= 2 - MOD * res;
        return res;
    }
    static u64 reduce(const u128 &v) {
        return (v + u128(u64(v) * u64(-INV_MOD)) * MOD) >> 64;
    }
    
    // arithmetic operators
    mint operator + () const { return mint(*this); }
    mint operator - () const { return mint() - mint(*this); }
    mint operator + (const mint &r) const { return mint(*this) += r; }
    mint operator - (const mint &r) const { return mint(*this) -= r; }
    mint operator * (const mint &r) const { return mint(*this) *= r; }
    mint operator / (const mint &r) const { return mint(*this) /= r; }
    mint& operator += (const mint &r) {
        if ((val += r.val) >= 2 * MOD) val -= 2 * MOD;
        return *this;
    }
    mint& operator -= (const mint &r) {
        if ((val += 2 * MOD - r.val) >= 2 * MOD) val -= 2 * MOD;
        return *this;
    }
    mint& operator *= (const mint &r) {
        val = reduce(u128(val) * r.val);
        return *this;
    }
    mint& operator /= (const mint &r) {
        *this *= r.inv();
        return *this;
    }
    mint inv() const { return pow(MOD - 2); }
    mint pow(u128 n) const {
        mint res(1), mul(*this);
        while (n > 0) {
            if (n & 1) res *= mul;
            mul *= mul;
            n >>= 1;
        }
        return res;
    }

    // other operators
    bool operator == (const mint &r) const {
        return (val >= MOD ? val - MOD : val) == (r.val >= MOD ? r.val - MOD : r.val);
    }
    bool operator != (const mint &r) const {
        return (val >= MOD ? val - MOD : val) != (r.val >= MOD ? r.val - MOD : r.val);
    }
    mint& operator ++ () {
        ++val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    mint& operator -- () {
        if (val == 0) val += MOD;
        --val;
        return *this;
    }
    mint operator ++ (int) {
        mint res = *this;
        ++*this;
        return res;
    }
    mint operator -- (int) {
        mint res = *this;
        --*this;
        return res;
    }
    friend istream& operator >> (istream &is, mint &x) {
        long long t;
        is >> t;
        x = mint(t);
        return is;
    }
    friend ostream& operator << (ostream &os, const mint &x) {
        return os << x.get();
    }
    friend mint pow(const mint &r, long long n) {
        return r.pow(n);
    }
    friend mint inv(const mint &r) {
        return r.inv();
    }
};

typename MontgomeryModInt64::u64
MontgomeryModInt64::MOD, MontgomeryModInt64::INV_MOD, MontgomeryModInt64::T128;



/*/////////////////////////////*/
// Examples
/*/////////////////////////////*/

void AOJ2353() {
    using mint = MontgomeryModInt64;
    const long long MOD = 67280421310721LL;
    mint::set_mod(MOD);

    mint res = 0;
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        long long o, y;
        cin >> o >> y;
        if (o == 1) res += y;
        else if (o == 2) res -= y;
        else if (o == 3) res *= y;
        else res /= y;
    }
    if (res.get() <= 1LL<<31) cout << res.get() << endl;
    else cout << (long long)res.get() - MOD << endl;
}


int main() {
    AOJ2353();
}
accuracy: 1
time_ms: 30
memory_kb: 3412
final_rank: 4

code_snippet: //
// モンゴメリ乗算を用いた modint (mod は 2^62 未満の奇数)
//
// verified:
//   AOJ 2353 Four Arithmetic Operations
//     http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2353
//
//   CS Academy 068 DIV2 E - Sliding Product Sum
//
//


#include <bits/stdc++.h>
using namespace std;


// montgomery modint (MOD < 2^62, MOD is odd)
struct MontgomeryModInt64 {
    using mint = MontgomeryModInt64;
    using u64 = uint64_t;
    using u128 = __uint128_t;
    
    // static menber
    static u64 MOD;
    static u64 INV_MOD;  // INV_MOD * MOD ≡ 1 (mod 2^64)
    static u64 T128;  // 2^128 (mod MOD)
    
    // inner value
    u64 val;
    
    // constructor
    MontgomeryModInt64() : val(0) { }
    MontgomeryModInt64(long long v) : val(reduce((u128(v) + MOD) * T128)) { }
    u64 get() const {
        u64 res = reduce(val);
        return res >= MOD ? res - MOD : res;
    }
    
    // mod getter and setter
    static u64 get_mod() { return MOD; }
    static void set_mod(u64 mod) {
        assert(mod < (1LL << 62));
        assert((mod & 1));
        MOD = mod;
        T128 = -u128(mod) % mod;
        INV_MOD = get_inv_mod();
    }
    static u64 get_inv_mod() {
        u64 res = MOD;
        for (int i = 0; i < 5; ++i) res *= 2 - MOD * res;
        return res;
    }
    static u64 reduce(const u128 &v) {
        return (v + u128(u64(v) * u64(-INV_MOD)) * MOD) >> 64;
    }
    
    // arithmetic operators
    mint operator - () const { return mint() - mint(*this); }
    mint operator + (const mint &r) const { return mint(*this) += r; }
    mint operator - (const mint &r) const { return mint(*this) -= r; }
    mint operator * (const mint &r) const { return mint(*this) *= r; }
    mint operator / (const mint &r) const { return mint(*this) /= r; }
    mint& operator += (const mint &r) {
        if ((val += r.val) >= 2 * MOD) val -= 2 * MOD;
        return *this;
    }
    mint& operator -= (const mint &r) {
        if ((val += 2 * MOD - r.val) >= 2 * MOD) val -= 2 * MOD;
        return *this;
    }
    mint& operator *= (const mint &r) {
        val = reduce(u128(val) * r.val);
        return *this;
    }
    mint& operator /= (const mint &r) {
        *this *= r.inv();
        return *this;
    }
    mint inv() const { return pow(MOD - 2); }
    mint pow(u128 n) const {
        mint res(1), mul(*this);
        while (n > 0) {
            if (n & 1) res *= mul;
            mul *= mul;
            n >>= 1;
        }
        return res;
    }

    // other operators
    bool operator == (const mint &r) const {
        return (val >= MOD ? val - MOD : val) == (r.val >= MOD ? r.val - MOD : r.val);
    }
    bool operator != (const mint &r) const {
        return (val >= MOD ? val - MOD : val) != (r.val >= MOD ? r.val - MOD : r.val);
    }
    friend istream& operator >> (istream &is, mint &x) {
        long long t;
        is >> t;
        x = mint(t);
        return is;
    }
    friend ostream& operator << (ostream &os, const mint &x) {
        return os << x.get();
    }
    friend mint modpow(const mint &r, long long n) {
        return r.pow(n);
    }
    friend mint modinv(const mint &r) {
        return r.inv();
    }
};

typename MontgomeryModInt64::u64
MontgomeryModInt64::MOD, MontgomeryModInt64::INV_MOD, MontgomeryModInt64::T128;


/*/////////////////////////////*/
// solvers
/*/////////////////////////////*/

void AOJ2353() {
    using mint = MontgomeryModInt64;
    const long long MOD = 67280421310721LL;
    mint::set_mod(MOD);

    mint res = 0;
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        long long o, y;
        cin >> o >> y;
        if (o == 1) res += y;
        else if (o == 2) res -= y;
        else if (o == 3) res *= y;
        else res /= y;
    }
    if (res.get() <= 1LL<<31) cout << res.get() << endl;
    else cout << (long long)res.get() - MOD << endl;
}


int main() {
    AOJ2353();
}
accuracy: 1
time_ms: 30
memory_kb: 3444
final_rank: 5

code_snippet: #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

long long extgcd(long long a, long long b, long long &x, long long &y) {
    for (long long u = y = 1, v = x = 0; a; ) {
        long long q = b / a;
        swap(x -= q * u, u);
        swap(y -= q * v, v);
        swap(b -= q * a, a);
    }
    return b;
}

long long modinv(long long x, long long m) {
    long long s, t;
    extgcd(x, m, s, t);
    return (s + m) % m;
}

int main() {
    const long long m = 999979, n = 999983;
    long long mx = 0, nx = 0;
    int N; cin >> N;
    while (N--) {
        long long op, y; cin >> op >> y;
        if (op == 1) mx = mod(mx + y, m), nx = mod(nx + y, n);
        if (op == 2) mx = mod(mx - y, m), nx = mod(nx - y, n);
        if (op == 3) mx = mx * y % m, nx = nx * y % n;
        if (op == 4) mx = mx * modinv(y, m) % m, nx = nx * modinv(y, n) % n;
    }
    long long s, t;
    extgcd(m, n, s, t);
    long long x = (m * s * nx + n * t * mx) % (m * n);
    if (x >= 1LL << 31) x -= m * n;
    cout << x << endl;
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3104
final_rank: 2

code_snippet: #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}
inline long long mul(long long a, long long b, long long m) {
    a = mod(a, m); b = mod(b, m);
    if (b == 0) return 0;
    long long res = mul(mod(a + a, m), b>>1, m);
    if (b & 1) res = mod(res + a, m);
    return res;
}
inline long long inv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a = mod(a - mul(t, b, m), m); swap(a, b);
        u = mod(u - mul(t, v, m), m); swap(u, v);
    }
    return mod(u, m);
}

int main() {
    const long long MOD = 67280421310721;
    long long ans = 0;
    int n; cin >> n;
    while (n--) {
        long long op, y; cin >> op >> y;
        if (op == 1) ans = mod(ans + y, MOD);
        if (op == 2) ans = mod(ans - y, MOD);
        if (op == 3) ans = mul(ans, y, MOD);
        if (op == 4) ans = mul(ans, inv(y, MOD), MOD);
    }
    if (ans >= 1LL << 31) ans -= MOD;
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 980
memory_kb: 3104
final_rank: 10

code_snippet: #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}
inline long long mul(long long a, long long b, long long m) {
    a = mod(a, m); b = mod(b, m);
    if (b == 0) return 0;
    long long res = mul(mod(a + a, m), b>>1, m);
    if (b & 1) res = mod(res + a, m);
    return res;
}
inline long long inv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a = mod(a - mul(t, b, m), m); swap(a, b);
        u = mod(u - mul(t, v, m), m); swap(u, v);
    }
    return mod(u, m);
}

int main() {
    const long long MOD = 67280421310721;   // 14 桁
    long long ans = 0;
    int n; cin >> n;
    while (n--) {
        long long op, y; cin >> op >> y;
        if (op == 1) ans = mod(ans + y, MOD);
        if (op == 2) ans = mod(ans - y, MOD);
        if (op == 3) ans = mul(ans, y, MOD);
        if (op == 4) ans = mul(ans, inv(y, MOD), MOD);
    }
    if (ans > 1LL << 31) ans -= MOD;
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 980
memory_kb: 3100
final_rank: 9

code_snippet: //
// 巨大な mod 対策 (普通にやるとオーバーフローしてしまう)
//
// cf.
//   【ライブラリ】mod の値が大きいときの mod 演算
//     http://drken1215.hatenablog.com/entry/2018/02/08/113249
//
// verified:
//   AOJ 2353 Four Arithmetic Operations
//     http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2353
//


/*
    a を b 回足しあげる、ただし繰り返し二乗法を流用する)
 
    という方法をとる
 */


#include <iostream>
using namespace std;


inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

inline long long mul(long long a, long long b, long long m) {
    a = mod(a, m); b = mod(b, m);
    if (b == 0) return 0;
    long long res = mul(mod(a + a, m), b>>1, m);
    if (b & 1) res = mod(res + a, m);
    return res;
}

inline long long inv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a/b;
        a = mod(a - mul(t, b, m), m); swap(a, b);
        u = mod(u - mul(t, v, m), m); swap(u, v);
    }
    return mod(u, m);
}

long long pow(long long a, long long n, long long m) {
    if (n == 0) return 1 % m;
    long long t = pow(a, n/2, m);
    t = mul(t, t, m);
    if (n & 1) t = mul(t, a, m);
    return t;
}

// 級数和
long long ser(long long a, long long n, long long m) {
    if (n == 0) return 0;
    long long res = ser(mul(a, a, m), n/2, m);
    res = mul(res, a+1, m);
    if (n & 1) res = mod(mul(res, a, m) + 1, m);
    return res;
}



int main() {
    const long long MOD = 67280421310721LL;
    long long res = 0;
    int N; cin >> N;
    for (int i = 0; i < N; ++i) {
        long long o, y; cin >> o >> y;
        if (o == 1) res = mod(res + y, MOD);
        else if (o == 2) res = mod(res - y, MOD);
        else if (o == 3) res = mul(res, y, MOD);
        else res = mul(res, inv(y, MOD), MOD);
    }
    if (res <= 1LL<<31) cout << res << endl;
    else cout << res - MOD << endl;
}
accuracy: 1
time_ms: 970
memory_kb: 3108
final_rank: 8

code_snippet: #include <iostream>
#include <vector>
using namespace std;

const long long MOD = 67280421310721LL;

inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

inline long long mul(long long a, long long b, long long m) {
    a = mod(a, m); b = mod(b, m);
    if (b == 0) return 0;
    long long res = mul(mod(a + a, m), b>>1, m);
    if (b & 1) res = mod(res + a, m);
    return res;
}

inline long long inv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a/b;
        a = mod(a - mul(t, b, m), m); swap(a, b);
        u = mod(u - mul(t, v, m), m); swap(u, v);
    }
    return mod(u, m);
}

int main() {
  long long res = 0;
  int N; cin >> N;
  for (int i = 0; i < N; ++i) {
	long long o, y; cin >> o >> y;
	if (o == 1) res = mod(res + y, MOD);
	else if (o == 2) res = mod(res - y, MOD);
	else if (o == 3) res = mul(res, y, MOD);
	else res = mul(res, inv(y, MOD), MOD);
  }
  if (res <= 1LL<<31) cout << res << endl;
  else cout << res - MOD << endl;
}
accuracy: 1
time_ms: 950
memory_kb: 3096
final_rank: 7

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


ll NUM1 = 999979;
ll NUM2 = 999983;

ll gcd(ll a,ll b){
	if(a < b)swap(a,b);

	if(b == 0){
		return a;
	}else{
		return gcd(b,a%b);
	}
}

ll extgcd(ll a,ll b,ll &x,ll &y){
	if(b == 0){
		x = 1;
		y = 0;
		return a;
	}else{
		ll ret = extgcd(b,(a%b),y,x);
		y -= (a/b)*x;
		return ret;
	}
}

ll mod_inverse(ll a,ll m){
    ll x,y;
    if(extgcd(a,m,x,y) != 1)return 0;
    return (m+x%m)%m;
}

void calc(ll &value1,ll &value2,ll op,ll number){
	switch(op){
	case 1:
		value1 = (value1+number)%NUM1;
		value2 = (value2+number)%NUM2;
		break;
	case 2:
		value1 = (value1-number+NUM1)%NUM1;
		value2 = (value2-number+NUM2)%NUM2;
		break;
	case 3:
		value1 = value1*number%NUM1;
		value2 = value2*number%NUM2;
		break;
	case 4:
		value1 = value1*mod_inverse(number,NUM1)%NUM1;
		value2 = value2*mod_inverse(number,NUM2)%NUM2;
		break;
	}
}

int main(){

	int N;
	scanf("%d",&N);

	ll value1 = 0,value2 = 0,op,number;

	for(int i = 0; i < N; i++){
		scanf("%lld %lld",&op,&number);
		calc(value1,value2,op,number);
	}

	ll X,Y;
	extgcd(NUM1,NUM2,X,Y);

	ll ans = (NUM1*X*value2+NUM2*Y*value1)%(NUM1*NUM2);
	ll check = pow(2,31);

	if(ans >= check){
		ans -= NUM1*NUM2;
	}

	printf("%lld\n",ans);

	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3220
final_rank: 3

code_snippet: #include <iostream>
#include <vector>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;

#define EPS 1e-12
//#define B 1000000

bool isPrime(ll n) {
	if (n == 1) return false;
	if (n == 2) return true;

	for (ll i = 2; i*i <= n; ++i) {
		if (n % i == 0) return false;
	}
	return true;
}

ll MOD = 4294967311LL;
ll mod(ll x) {
	return (x % MOD + MOD) % MOD;
}

ll mul(ll x, ll n) {
	ll ret = 0;
	ret += mod( x * (n % (1 << 16)) ); n >>= 16;
	ret += mod( mod( x * (n % (1 << 16)) ) << 16 ); n >>= 16;
	ret += mod( mod( mod( x * (n % (1 << 16)) ) << 16 ) << 16 ); n >>= 16;
	return ret;
/*
	ll ret = 0;

	if (x <= (1LL << 31) && n <= (1LL << 32)) {
		return x * n % MOD;
	}

	for (ll i = 0, k = 1; k <= n; ++i, k <<= 1) {
		if (n & k) {
			ret = mod(ret + x);
		}
		x = mod(x + x);
	}
	return ret;
*/
}
ll power(ll x, ll n) {
	ll ret = 1;
	for (ll i = 0, k = 1; k <= n; ++i, k <<= 1) {
		if (n & k) {
			ret = mul(ret, x);
		}
		x = mul(x, x);
	}
	return ret;
}

ll Div(ll x, ll n) {
	return mul(x, power(n, MOD-2));
}
ll cal(vector<ll> op, vector<ll> Y) {
	ll Z = 1;
	ll X = 0;
	int N = op.size();
	bool zf = false;
	for (int i = N-1; i >= 0; --i) {
		bool f = zf ^ (Y[i] < 0);
		ll y = abs(Y[i]);
		switch (op[i]) {
			case 2: f = !f;
			case 1:
				X = mod(X + (f ? -1 : 1) * mul(Z, y));
				break;

			case 3: Z = mul(Z, y); zf = f; break;
			case 4: Z = Div(Z, y); zf = f; break;
		}
	}
	return X;
}

int main() {
//	while ( !isPrime(MOD) ) ++MOD;
//	cout << MOD << endl;
//	return 0;
	ll X = 0;

	int N; cin >> N;
	vector<ll> op(N), Y(N);
	for (int i = 0; i < N; ++i) {
		cin >> op[i] >> Y[i];
	}

	ll ans = cal(op, Y);

	if (ans >= (1LL << 31)) cout << ans-MOD << endl;
	else cout << ans << endl;
}
accuracy: 1
time_ms: 470
memory_kb: 4164
final_rank: 6

code_snippet: #include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;

#define EPS 1e-12
#define B 1000000

bool isPrime(int n) {
	if (n == 1) return false;
	if (n == 2) return true;

	for (int i = 2; i*i <= n; ++i) {
		if (n % i == 0) return false;
	}
	return true;
}

ll MOD = 4294967297LL, D;
ll mod(ll x) {
	return (x % MOD + MOD) % MOD;
}

ll mul(ll x, ll n) {
	ll ret = 0;
	for (int i = 0; i < 33; ++i) {
		if (n & (1LL << i)) {
			ret = mod(ret + x);
		}
		x = mod(x + x);
	}
	return ret;
}
ll power(ll x, ll n) {
	ll ret = 1;
	for (int i = 0; i < 33; ++i) {
		if (n & (1LL << i)) {
			ret = mod( mul(ret, x) );
		}
		x = mod( mul(x, x) );
	}
	return ret;
}

/*
ll cal(vector<ll> op, vector<ll> Y) {
	ll X = 0;
	int N = op.size();
	for (int i = 0; i < N; ++i) {
		switch (op[i]) {
			case 1: X = mod(X + Y[i]); break;
			case 2: X = mod(X - Y[i]); break;
			case 3: X = mod( mul(X, Y[i]) ); break;
			case 4: X = mod( mul(X, power(Y[i], MOD-2)) ); break;
		}
		cout << X << " " << X-MOD << endl;
	}
	return X;
}
*/
ll abs(ll n) {
	return n > 0 ? n : -n;
}
ll div(ll x, ll n) {
	return mul(x, power(n, MOD-2));
}
ll cal(vector<ll> op, vector<ll> Y) {
	ll Z = 1;
	ll X = 0;
	int N = op.size();
	bool zf = false;
	for (int i = N-1; i >= 0; --i) {
		zf ^= Y[i] < 0;
		bool f = zf;
		ll y = abs(Y[i]);
		switch (op[i]) {
			case 2: f = !f;
			case 1:
				X = mod(X + (f ? -1 : 1) * mul(Z, y));
				break;

			case 3: Z = mod( mul(Z, y) ); break;
			case 4: Z = mod( div(Z, y) ); break;
		}
	}
	return X;
}

int main() {
//	while ( isPrime(MOD) ) ++MOD;
//	cout << MOD << endl;
//	return 0;
	ll X = 0;

//	D = MOD/2;

	int N; cin >> N;
	vector<ll> op(N), Y(N);
	for (int i = 0; i < N; ++i) {
		cin >> op[i] >> Y[i];
	}

//	bool isNegative = v < EPS;

	ll ans = cal(op, Y);
	if (ans >= (1LL << 31)) cout << ans-MOD << endl;
	else cout << ans << endl;
}
accuracy: 0.047619047619047616
time_ms: 60
memory_kb: 1280
final_rank: 19

code_snippet: #include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;

#define EPS 1e-12
#define B 1000000

bool isPrime(int n) {
	if (n == 1) return false;
	if (n == 2) return true;

	for (int i = 2; i*i <= n; ++i) {
		if (n % i == 0) return false;
	}
	return true;
}

ll MOD = 4294967297LL, D;
ll mod(ll x) {
	return (x % MOD + MOD) % MOD;
}

ll mul(ll x, ll n) {
	ll ret = 0;
	for (int i = 0; i < 33; ++i) {
		if (n & (1LL << i)) {
			ret = mod(ret + x);
		}
		x = mod(x + x);
	}
	return ret;
}
ll power(ll x, ll n) {
	ll ret = 1;
	for (int i = 0; i < 33; ++i) {
		if (n & (1LL << i)) {
			ret = mod( mul(ret, x) );
		}
		x = mod( mul(x, x) );
	}
	return ret;
}

/*
ll cal(vector<ll> op, vector<ll> Y) {
	ll X = 0;
	int N = op.size();
	for (int i = 0; i < N; ++i) {
		switch (op[i]) {
			case 1: X = mod(X + Y[i]); break;
			case 2: X = mod(X - Y[i]); break;
			case 3: X = mod( mul(X, Y[i]) ); break;
			case 4: X = mod( mul(X, power(Y[i], MOD-2)) ); break;
		}
		cout << X << " " << X-MOD << endl;
	}
	return X;
}
*/
ll abs(ll n) {
	return n > 0 ? n : -n;
}
ll div(ll x, ll n) {
	return mul(x, power(n, MOD-2));
}
ll cal(vector<ll> op, vector<ll> Y) {
	ll Z = 1;
	ll X = 0;
	int N = op.size();
	bool zf = false;
	for (int i = N-1; i >= 0; --i) {
		zf ^= Y[i] < 0;
		bool f = zf;
		ll y = abs(Y[i]);
		switch (op[i]) {
			case 2: f = !f;
			case 1:
				X = mod(X + (f ? -1 : 1) * mul(Z, y));
				break;

			case 3: Z = mod( mul(Z, y) ); break;
			case 4: Z = mod( div(Z, y) ); break;
		}
	}
	return X;
}

int main() {
//	while ( isPrime(MOD) ) ++MOD;
//	cout << MOD << endl;
//	return 0;
	ll X = 0;

//	D = MOD/2;

	int N; cin >> N;
	vector<ll> op(N), Y(N);
	for (int i = 0; i < N; ++i) {
		cin >> op[i] >> Y[i];
	}

//	bool isNegative = v < EPS;

	ll ans = cal(op, Y);
	if (ans > (1LL << 31)) cout << ans-MOD << endl;
	else cout << ans << endl;
}
accuracy: 0.047619047619047616
time_ms: 70
memory_kb: 1280
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;



long long p = 5e9;

long long isprime(long long n){
	for( long long i = 2 ; i * i <= n ; i++ ){
		if( n % i == 0 ) return 0;
	}
	return 1;
}

inline long long mul(long long a,long long b){
	long long res = 0;
	while( b ){
		if(b&1){
			res += a;
			if( res >= p ) res -= p;
		}
		a *= 2;
		if( a >= p ) a -= p;
		b >>= 1;
	}
	return res;
}

inline long long bpow(long long a,long long b){
	long long res = 1;
	while( b ){
		if(b&1){
			res = mul(res,a);
			res %= p;
		}
		a = mul(a,a);
		b >>= 1;
	}
	return res;
}


int main(){
	while( !isprime(p) ) p++;

	int N;
	cin >> N;
	long long X = 0;
	for(int i = 0 ; i < N ; i++){
		long long op,Y;
		scanf("%lld %lld",&op,&Y);
		Y=(Y+p)%p;
		if( op == 1 ){ //+
			X = X + Y;
			X %= p;
		}else if( op == 2 ){ //-
			X = X - Y;
			X %= p;
		}else if( op == 3 ){ //*
			X = mul(X,Y);
		}else{ // /
			X = mul(X,bpow(Y,p-2));
		}
		X = (X+p) % p;
	}
	if( X < (1ll<<31) ){
		cout << X << endl;
	}else{
		cout << X-p << endl;
	}
}
accuracy: 1
time_ms: 200
memory_kb: 1232
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;



long long p = 1e10;

long long isprime(long long n){
	for( long long i = 2 ; i * i <= n ; i++ ){
		if( n % i == 0 ) return 0;
	}
	return 1;
}

inline long long mul(long long a,long long b){
	if( b == 0 ) return 0;
	long long c = mul((2*a)%p,b/2);
	if( b & 1 ) c += a;
	return c % p;
}

inline long long bpow(long long a,long long b){
	if( b == 0 ) return 1;
	long long c = bpow(mul(a,a)%p,b/2);
	if( b & 1 ) c = mul(c,a);
	return c % p;
}


int main(){
	while( !isprime(p) ) p++;

	int N;
	cin >> N;
	long long X = 0;
	for(int i = 0 ; i < N ; i++){
		long long op,Y;
		scanf("%lld %lld",&op,&Y);
		Y=(Y+p)%p;
		if( op == 1 ){ //+
			X = X + Y;
			X %= p;
		}else if( op == 2 ){ //-
			X = X - Y;
			X %= p;
		}else if( op == 3 ){ //*
			X = mul(X,Y);
		}else{ // /
			X = mul(X,bpow(Y,p-2));
		}
	}
	if( X < (1ll<<31) ){
		cout << X << endl;
	}else{
		cout << X-p << endl;
	}
}
accuracy: 0.19047619047619047
time_ms: 40
memory_kb: 1236
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;



long long p = 1e10;

long long isprime(long long n){
	for( long long i = 2 ; i * i <= n ; i++ ){
		if( n % i == 0 ) return 0;
	}
	return 1;
}

long long mul(long long a,long long b){
	if( b == 0 ) return 0;
	long long c = mul(a*2%p,b/2);
	if( b & 1 ) c += a;
	return c % p;
}
long long bpow(long long a,long long b){
	if( b == 0 ) return 1;
	long long c = bpow(mul(a,a)%p,b/2);
	if( b & 1 ) c = mul(c,a);
	return c % p;
}


int main(){
	while( !isprime(p) ) p++;
	int N;
	cin >> N;

	long long X = 0;

	long long minus = 1;
	for(int i = 0 ; i < N ; i++){
		long long op,Y;
		cin >> op >> Y;
		if( op == 1 ){ //+
			X = X + Y;
			X %= p;
		}else if( op == 2 ){ //-
			//Y=(Y+p)%p;
			X = X - Y;
			X %= p;
			X = (X+p)%p;
		}else if( op == 3 ){ //*
			if( Y < 0 ) minus *= -1, Y = -Y;
			else if ( Y == 0 ) minus = 1;

			X = mul(X,Y);
		}else{ // /
			if( Y < 0 ) minus *= -1, Y = -Y;
			else if ( Y == 0 ) minus = 1;
			
			X = mul(X,bpow(Y,p-2));
		}
	}
	if( X < (1ll<<31) ){
		cout << minus*X << endl;
	}else{
		cout << minus*(X-p) << endl;
	}
}
accuracy: 0.14285714285714285
time_ms: 40
memory_kb: 1164
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;



long long p = 1e10;

long long isprime(long long n){
	for( long long i = 2 ; i * i <= n ; i++ ){
		if( n % i == 0 ) return 0;
	}
	return 1;
}

long long mul(long long a,long long b){
	if( b == 0 ) return 0;
	long long c = mul(a*2%p,b/2);
	if( b & 1 ) c += a;
	return c % p;
}
long long bpow(long long a,long long b){
	if( b == 0 ) return 1;
	long long c = bpow(mul(a,a)%p,b/2);
	if( b & 1 ) c = mul(c,a);
	return c % p;
}


int main(){
	while( !isprime(p) ) p++;
	int N;
	cin >> N;

	long long X = 0;

	long long minus = 1;
	for(int i = 0 ; i < N ; i++){
		long long op,Y;
		cin >> op >> Y;
		if( op == 1 ){ //+
			X = X + Y;
			X %= p;
		}else if( op == 2 ){ //-
			//Y=(Y+p)%p;
			X = X - Y;
			X %= p;
			X = (X+p)%p;
		}else if( op == 3 ){ //*
			if( Y < 0 ) minus *= -1, Y = -Y;
			X = mul(X,Y);
		}else{ // /
			if( Y < 0 ) minus *= -1, Y = -Y;
			X = mul(X,bpow(Y,p-2));
		}
	}
	if( X < (1ll<<31) ){
		cout << minus*X << endl;
	}else{
		cout << minus*(X-p) << endl;
	}
}
accuracy: 0.14285714285714285
time_ms: 40
memory_kb: 1164
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;


long long p = 1e10;

long long isprime(long long n){
	for( long long i = 2 ; i * i <= n ; i++ ){
		if( n % i == 0 ) return 0;
	}
	return 1;
}

long long mul(long long a,long long b){
	if( b == 0 ) return 0;
	long long c = mul(a*2%p,b/2);
	if( b & 1 ) c += a;
	return c % p;
}
long long bpow(long long a,long long b){
	if( b == 0 ) return 1;
	long long c = bpow(mul(a,a)%p,b/2);
	if( b & 1 ) c = mul(c,a);
	return c % p;
}

int main(){
	while( !isprime(p) ) p++;
	int N;
	cin >> N;
	long long X = 0;
	for(int i = 0 ; i < N ; i++){
		int op,Y;
		cin >> op >> Y;
		Y=(Y+p)%p;
		if( op == 1 ){ //+
			X = X + Y;
			X %= p;
		}else if( op == 2 ){ //-
			X = X - Y;
			X %= p;
			X = (X+p)%p;
		}else if( op == 3 ){ //*
			X = mul(X,Y);
		}else{ // /
			X = mul(X,bpow(Y,p-2));
		}
	}
	if( X < (1ll<<31) ){
		cout << X << endl;
	}else{
		cout << X-p << endl;
	}
}
accuracy: 0.047619047619047616
time_ms: 40
memory_kb: 1156
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;


long long p = 5e9;

long long isprime(long long n){
	for( long long i = 2 ; i * i <= n ; i++ ){
		if( n % i == 0 ) return 0;
	}
	return 1;
}

long long mul(long long a,long long b){
	if( b == 0 ) return 0;
	long long c = mul(a*2%p,b/2);
	if( b & 1 ) c += a;
	return c % p;
}
long long bpow(long long a,long long b){
	if( b == 0 ) return 1;
	long long c = bpow(mul(a,a)%p,b/2);
	if( b & 1 ) c = mul(c,a);
	return c % p;
}

int main(){
	while( !isprime(p) ) p++;
	int N;
	cin >> N;
	long long X = 0;
	for(int i = 0 ; i < N ; i++){
		int op,Y;
		cin >> op >> Y;
		Y=(Y+p)%p;
		if( op == 1 ){ //+
			X = X + Y;
			X %= p;
		}else if( op == 2 ){ //-
			X = X - Y;
			X %= p;
			X = (X+p)%p;
		}else if( op == 3 ){ //*
			X = mul(X,Y);
		}else{ // /
			X = mul(X,bpow(Y,p-2));
		}
	}
	if( X < (1ll<<32) ){
		cout << X << endl;
	}else{
		cout << X-p << endl;
	}
}
accuracy: 0.047619047619047616
time_ms: 40
memory_kb: 1156
final_rank: 17

code_snippet: #include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

#define EPS 1e-12

typedef long double ld;

struct RN {
	ll num, den;
};

int gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

RN LT(RN rn) {
	int g = gcd( abs(rn.num), abs(rn.den) );
	RN ret = (RN){rn.num/g, rn.den/g};
	if (ret.den < 0) ret.num *= -1, ret.den *= -1;
	return ret;
}

RN operator -(const RN& rn) {
	return (RN){ -rn.num, rn.den };
}
RN operator +=(RN& left, const RN& right) {
	left = LT((RN){ left.num * right.den + left.den * right.num, left.den * right.den });
	return left;
}
RN operator -=(RN& left, const RN& right) {
	left += -right;
}
RN operator *=(RN& left, const RN& right) {
	left = LT((RN){left.num * right.num, left.den * right.den});
	return left;
}
RN operator /=(RN& left, const RN& right) {
	RN rn = (RN){right.den, right.num};
	if (rn.den < 0) rn.num *= -1, rn.den *= -1;
	return left *= rn;
}

int main() {
	int N; cin >> N;
//	X = LT((RN){12, 6});
//	cout << X.num << " / " << X.den << endl;

	vector<int> op(N), y(N);
	for (int i = 0; i < N; ++i) {
		cin >> op[i] >> y[i];
	}

	vector<RN> v;
	RN Z = (RN){1, 1};
	for (int i = N-1; i >= 0; --i) {
		RN Y = (RN){y[i], 1};
		switch (op[i]) {
			case 2: Y = -Y; // -
			case 1: Y *= Z; // +
				v.push_back(Y);
				break;

			case 3: Z *= Y; break; // *
			case 4: Z /= Y; break; // /
		}
	}

	RN X = (RN){0, 1};
	for (int i = 0; i < v.size(); ++i) {
		X += v[i];
	}
	cout << X.num << endl;
}
accuracy: 0.2857142857142857
time_ms: 30
memory_kb: 1688
final_rank: 11