akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

template <typename T>
T gcd(T a, T b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}
template <typename T>
T lcm(T a, T b) {
  return a * b / gcd(a, b);
}

int main() {
  ll N, M;
  cin >> N >> M;
  string s, t;
  cin >> s >> t;

  ll L = lcm(M, N);

  map<ll, char> m;
  int sc = L / N;
  for (int j = 0; j < N; j++) m[sc * j] = s[j];

  int tc = L / M;
  bool ok = true;
  for (int j = 0; j < M; j++) {
    if (m.count(tc * j) == 0) continue;
    if (m[tc * j] != t[j]) ok = false;
  }

  ll ans = -1;
  if (ok) ans = L;
  cout << ans << endl;
}


Measured memory_bytes: 9444
#include <bits/stdc++.h>
#define int long long
#define INT_MAX INT64_MAX
#define INT_MIN INT64_MIN
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define MOD 1000000007
/* DEFINE cout */
#define pln cout << "===============================\n"
#define on cout<<"\n"
#define os cout<<" "
#define o2(a,b) cout<<a<<" "<<b
#define o(a) cout << a
#define bitcount __builtin_popcount
/* DEFINE cout */
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int x,int y){
    int res = 1;
    int p = MOD;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
signed main(){
    int a, b;
    cin >> a >> b;
    switch (a+b) {
        case 3:
            cout << 3 << endl;
            break;
        case 4:
            cout << 2 << endl;
            break;
        case 5:
            cout << 1 << endl;
            break;
    }
}



Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long N = sc.nextLong();
        long M = sc.nextLong();

        if(N==1 && M==1){
            System.out.println(1);
        }
        else if((N==1 && M!=1) || (N!=1 && M==1)){
            System.out.println(N * M - 2);
        }
        else{
            System.out.println(N * M - 2 * N - 2 * (M - 2));
        }
    }
}

Measured memory_bytes: 23124
import java.util.Scanner;	//Scannerクラス：Java標準入力を取得する

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int r = sc.nextInt();
			int c = sc.nextInt();

			int[][] sh = new int[r+1][c+1];

			for(int i=0;i<r;i++) {
				for(int j=0;j<c;j++) {
					sh[i][j] = sc.nextInt();
					sh[i][c] += sh[i][j];
				}
			}
			for(int i=0;i<=c;i++) {
				for(int j=0;j<r;j++) {
					sh[r][i] += sh[j][i];
				}
			}
			for(int i=0;i<=r;i++) {
				for(int j=0;j<=c;j++) {
					System.out.print(sh[i][j]);
					if(j!=c)
						System.out.print(" ");
				}
				System.out.println();
			}
		}
	}
}



Measured memory_bytes: 41568
#include <iostream>
#include <string>
#include <queue>
using namespace std;
typedef pair<int, int> P;

int w, h;
string s[20];

int getCount(int sy, int sx) {
	const int dy[4] = {-1, 0, 1, 0};
	const int dx[4] = {0, 1, 0, -1};
	queue<P> que;
	bool used[20][20] = {false};
	
	que.push(P(sy, sx));
	used[sy][sx] = true;
	
	while (!que.empty()) {
		P now = que.front(); que.pop();
		int y = now.first;
		int x = now.second;
		for (int i = 0; i < 4; i++) {
			int ny = y + dy[i];
			int nx = x + dx[i];
			if (!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue;
			if (s[ny][nx] == '#' || used[ny][nx]) continue;
			used[ny][nx] = true;
			que.push(P(ny, nx));
		}
	}
	
	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			ans += used[i][j];
		}
	}
	return ans;
}

void solve() {
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '@') {
				cout << getCount(i, j) << endl;
				return;
			}
		}
	}
}

int main() {
	while (cin >> w >> h) {
		if (!w) break;
		for (int i = 0; i < h; i++) cin >> s[i];
		solve();
	}
	return 0;
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1);
  vector<ll> b(m + 1);

  rep (i, n) {
    int x; cin >> x;
    a[i + 1] = x + a[i];
  }
  rep (i, m) {
    int x; cin >> x;
    b[i + 1] = x + b[i];
  }

  ll ans = 0;
  for (int i = 0; i < n + 1; i++) {
    ll a_count = a[i];
    if (a_count > k) continue;
    //printf("a_count = %d, k = %d\n", a_count, k);
    ll lim = k - a_count;
    ll tmp = upper_bound(b.begin(), b.end(), lim) - b.begin() + i - 1;
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6404
#include<stdio.h>
int main()
{
    int H,W,i,j,a;
    while(1)
    {
        scanf("%d %d",&H,&W);
        if(H==0&&W==0)break;
            for(i=0;i<H;i++)
           {
                for(j=0;j<W;j++)
               {
                    if((i+j)%2==0)
                    {
                     printf("#");
                    }
                    else
                    {
                      printf(".");
                    }

               }
                    printf("\n");

           }
        printf("\n");
    }

  return 0;
}

Measured memory_bytes: 2616
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    long long n, k;
    cin >> n >> k;

    vector<long long> cnt(k, 0);
    for(int i = 1; i <= n; i++){
        cnt[i % k]++;
    }

    long long ans = 0;
    for(int i = 0; i < k; i++){
        if(i * 2 % k != 0) continue;
        ans += cnt[i] * cnt[i] * cnt[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>

using namespace std;

int main(){
    
    int n;
    cin >> n;

    int x = 0;
    int nn = n;
    for(;;){
	x += (nn % 10);
	if(nn / 10 == 0){
	    break;
	}
	nn = nn / 10;
    }
    if(n % x == 0){
	cout << "Yes" << endl;
    }else{
	cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
c = []
ans = "No"

for i in range(3):

    nc = list(map(int,input().split()))
    c.append(nc)


if c[0][1]-c[0][0] == c[1][1]-c[1][0] and c[1][1]-c[1][0] == c[2][1]-c[2][0] and c[0][2]-c[0][1] == c[1][2]-c[1][1] and c[1][2]-c[1][1] == c[2][2]-c[2][1]:

    if c[1][0]-c[0][0] == c[1][1] - c[0][1] and c[1][1]-c[0][1] == c[1][2] - c[0][2] and c[2][0]-c[1][0] == c[2][1]-c[1][1] and c[2][1]-c[1][1] == c[2][2]-c[1][2]:

        ans = "Yes"

print (ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

int main(){
	int N; std::cin >> N;
	std::vector<int> T(N);
	for (auto& r : T) std::cin >> r;

	int M; std::cin >> M;
	std::vector<int> P(M);
	std::vector<int> X(M);
	for (int i{ 0 }; i < M; ++i) {
		int t; std::cin >> t;
		P[i] = t - 1;
		std::cin >> X[i];
	}

	for (int i = 0; i < M; ++i) {
		int save = T[P[i]];
		T[P[i]] = X[i];
		int total = 0;
		for (auto& r : T)
			total += r;
		std::cout << total << std::endl;;
		T[P[i]] = save;
	}

	return 0;
}

Measured memory_bytes: 3632
import heapq

N, M = map(int, input().split())
AA = list(map(int, input().split()))
A = []
for a in AA:
    A.append(-a)

heapq.heapify(A)
now = heapq.heappop(A)
for _ in range(M):
    now = heapq.heappushpop(A, (now+1) // 2)
heapq.heappush(A, now)
print(-sum(A))


Measured memory_bytes: 14180
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int N;
string A, B, C;

int main()
{
    cin >> N >> A >> B >> C;
    int ans = 0;
    REP(i, N)
    {
        set<char> se;
        se.insert(A[i]);
        se.insert(B[i]);
        se.insert(C[i]);
        ans += se.size() - 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const char *nl = "\n";
const int N = 1e5 + 1;
using ii = int32_t;


int n, m;
vector<int> vs[N];
ii post[N];

int main() {
    cin >> n >> m;
    for (ii i = 1; i <= m; i++) {
        ii a, b;
        cin >> a >> b;
        vs[a].push_back(b);
        vs[b].push_back(a);
    }
    // v, ed
    queue<pair<ii, ii>> fs;
    fs.emplace(1, 0);
    while (!fs.empty()) {
        auto [v, ed] = fs.front();
        fs.pop();
        if (post[v]) continue;
        post[v] = ed;
        for (auto nb : vs[v]) {
            fs.emplace(nb, v);
        }
    }
    cout << "Yes" << nl;
    for (ii i = 2; i <= n; i++) {
        cout << post[i] << nl;
    }
    return 0;
}



Measured memory_bytes: 13092
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

const int INF = 1 << 30;

void greedy(int D, const vector<int>& C, const vector<vector<int>>& S) {
    vector<int> last_day(26, 0);
    int score = 0;
    rep(i, 0, D) {
        int max_score = -INF;
        int max_type = -1;
        rep(j, 0, 26) {
            // タイプjのコンテストを開催したときのスコアを計算
            int now_score = score;
            now_score += S[i][j];
            int tmp = last_day[j];
            last_day[j] = i;
            rep(k, 0, 26) {
                now_score -= C[k] * (i + 1 - last_day[k]);
            }
            last_day[j] = tmp;
            if (chmax(max_score, now_score)) {
                max_type = j;
            }
        }
        // max_typeのコンテストを選択
        cout << max_type + 1 << endl;
        score += S[i][max_type];
        last_day[max_type] = i;
        rep(j, 0, 26) {
            score -= C[j] * (i + 1 - last_day[j]);
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int D;
    cin >> D;
    vector<int> C(26);
    for (auto& c : C) {
        cin >> c;
    }
    vector<vector<int>> S(D, vector<int>(26));
    rep(i, 0, D) rep(j, 0, 26) {
        cin >> S[i][j];
    }
    greedy(D, C, S);
    return 0;
}

Measured memory_bytes: 3716
def main():
    N, M = list(map(int, input().split(' ')))
    n = 1
    ans = 1
    while n**2 <= M:
        if M % n == 0:
            if n * N <= M:
                ans = max([ans, n])
            m = M // n
            if m * N <= M:
                ans = max([ans, m])
        n += 1
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
using System;
using System.Linq;

namespace ABC118_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var mons = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var L = Enumerable.Repeat(0, n).ToList();
            var gc = 0;
            for(var i=1;i<n;i++)
            {
                if (i == 1)
                {
                    gc = gcd(mons[0], mons[1]);
                }
                else
                {
                    gc = gcd(gc, mons[i]);
                }
            }
            Console.WriteLine(gc);
        }
        static int gcd(int a,int b)
        {
            if(b>a)
            {
                return gcd(b, a);
            }
            while(b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
    }
}


Measured memory_bytes: 19680
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 100005;
vector <int > g[MAXN];
int dp[MAXN];
bool vis[MAXN];

void dfs(int v){
    if (vis[v]) return;
    vis[v] = true;
    for (auto to : g[v])
    {
        dfs(to);
        dp[v] = max(dp[v], dp[to] + 1);
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
    }

    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        dfs(i);
        ans = max(ans, dp[i]);
    }
    cout << ans;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  int N;cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  sort(v.begin(),v.end());
  int a=v[0];
  int ans=1;
  for(int i=1;i<N;i++){
    if(a<v[i]){
      ans++;
      a=v[i];
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <stack>

using namespace std;

int main()
{
  stack<int> s;
  int x;
  while(scanf("%d", &x) != -1){
    if(x)
      s.push(x);
    else
      printf("%d\n", s.top()), s.pop();
  }
  return 0;
}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  string s1, s2, s3;
  std::cin >> s1 >> s2 >> s3;
  std::cout << s1[0] << s2[1] << s3[2] << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;



int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int h,w;
    cin >> h >> w;

    int sx,sy,gx,gy;
    cin >> sy >> sx >> gy >> gx;
    sx--;sy--;gx--;gy--;

    pair<int,int> s = make_pair(sx,sy), g = make_pair(gx,gy); 
    vector<vector<int>> ans(h,vector<int>(w,mod));
    string sur[h];

    for(int i = 0; i < h; i++) cin >> sur[i];

    auto inout = [&](int x,int y){
        if(0 <= x && x < w && 0 <= y && y < h) return true;
        else return false;
    };

    auto add = [&](pair<int,int> now,int dx,int dy){
        pair<int,int> ret = make_pair(now.first+dx,now.second+dy);
        return ret;
    };

    auto answer = [&](pair<int,int> now){
        if(now == g){
            cout << ans[now.second][now.first] << endl;
            return true;
        } else return false;
    };

    queue<pair<int,int>> p,q;

    int dx[4] = {0,0,1,-1}, dy[4] = {1,-1,0,0};

    p.push(s);
    ans[s.second][s.first] = 0;

    int can = 0;

    while(!p.empty()){
        while(!p.empty()){
            pair<int,int> now = p.front();
            p.pop();
            bool first = true;
            for(int i = 0; i < 4; i++){
                pair<int,int> nxt = add(now,dx[i],dy[i]);
                if(inout(nxt.first,nxt.second)){
                    if(sur[nxt.second][nxt.first] == '.'){
                        ans[nxt.second][nxt.first] = can;
                        if(answer(nxt)) return 0;
                        p.push(nxt);
                        sur[nxt.second][nxt.first] = '#';
                    } else if(sur[nxt.second][nxt.first] == '#' && first){
                        q.push(now);
                        first = false;
                    }
                }
            }
        }
        can++;
        while(!q.empty()){
            pair<int,int> now = q.front();
            q.pop();
            for(int i = -2; i < 3; i++){
                for(int j = -2; j < 3; j++){
                    pair<int,int> nxt = make_pair(now.first+i,now.second+j);
                    if(inout(nxt.first,nxt.second)){
                        if(sur[nxt.second][nxt.first] == '.'){
                            ans[nxt.second][nxt.first] = can;
                            p.push(nxt);
                            sur[nxt.second][nxt.first] = '#';
                            if(answer(nxt)) return 0;
                        }
                    }
                }
            }
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 8724
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#define  rep(i,a,b)for(int i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const ll INF=100000000000LL;
typedef pair<int,int>P;
vector<P> v1[100001];
int main() {
	int n,t[101],m,p,x;
	int c=0;
	cin>>n;
	rep(i,1,n+1){
		cin>>t[i];
		c+=t[i];
	}
	cin>>m;
	rep(i,0,m){
		cin>>p>>x;
		cout<<c-(t[p]-x)<<endl;
	}
	return 0;
}


Measured memory_bytes: 2560
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;

class Myon
{
    static Scanner cin;
    public Myon() { }
    public static int Main()
    {
        //Console.SetOut(new Printer(Console.OpenStandardOutput()));
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }


    public void calc()
    {
        double xs, ys, xt, yt;
        xs = cin.nextDouble();
        ys = cin.nextDouble();
        xt = cin.nextDouble();
        yt = cin.nextDouble();
        double ans = hypot(xs - xt, ys - yt);
        int N = cin.nextInt();
        bool[] used = new bool[N];
        double[] dist = new double[N];
        double[] x = new double[N];
        double[] y = new double[N];
        double[] r = new double[N];
        for (int i = 0; i < N; i++)
        {
            x[i] = cin.nextDouble();
            y[i] = cin.nextDouble();
            r[i] = cin.nextDouble();
        }


        for (int i = 0; i < N; i++)
        {
            dist[i] = hypot(xs - x[i], ys - y[i]) - r[i];
            if (dist[i] < 0) dist[i] = 0;
        }

        for (int i = 0; i < N; i++)
        {
            int best = -1;
            double bestdist = double.MaxValue;
            for (int j = 0; j < N; j++)
            {
                if (!used[j] && bestdist > dist[j])
                {
                    best = j;
                    bestdist = dist[j];
                }
            }
            int start = best;
            for (int j = 0; j < N; j++)
            {
                double add = hypot(x[start] - x[j], y[start] - y[j]) - r[start] - r[j];
                if (add < 0) add = 0;
                dist[j] = Math.Min(dist[j], dist[start] + add);
            }
            used[start] = true;
            ans = Math.Min(ans, dist[start] + Math.Max(0, hypot(xt - x[start], yt - y[start]) - r[start]));
        }
        
        Console.WriteLine("{0:0.0000000000000000}", ans);
    }

    double hypot(double x, double y)
    {
        return Math.Sqrt(x * x + y * y);
    }


}

class Printer : StreamWriter
{
    public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
    public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
    public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        while (i >= s.Length)
        {
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
        }
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 3160
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {

	public static void main(String[] args) {
//		String baseUrl = "C:\\Users\\kuriyama.akira\\git-repository\\hobby\\AIZU_ONLINE_JUDGE\\Java\\";
//		String filePath = baseUrl +  "inp_itp_1_6_b.txt";
//		FileInputStream fis = null; 
//		try { 
//			fis = new FileInputStream(new File(filePath));
//		}catch(FileNotFoundException e){
//			e.printStackTrace();
//		}
//		BufferedReader br = new BufferedReader(new InputStreamReader(fis));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		boolean card[][] = new boolean[4][14];
		for(int i=0;i<4;i++) {
			for(int j=1;j<14;j++) {
				card[i][j] = false;
			}
		}
		
		Map<String, Integer> designInt = new HashMap<>();
		designInt.put("S", 0);
		designInt.put("H", 1);
		designInt.put("C", 2);
		designInt.put("D", 3);

		Map< Integer,String> intDesign = new HashMap<>();
		intDesign.put(0, "S");
		intDesign.put(1, "H");
		intDesign.put(2, "C");
		intDesign.put(3, "D");

		try {
			int N = Integer.parseInt(br.readLine()); 
			String tmp;
			while((tmp = br.readLine()) != null) {
				List<String> line = Arrays.asList(tmp.split("\\s"));
				String design = line.get(0);
				Integer num = Integer.parseInt(line.get(1));

				card[designInt.get(design)][num] = true;
				
			}
			br.close();
		}catch(IOException e) {
			e.printStackTrace();
		}

		for(int i=0;i<4;i++) {
			for(int j=1;j<14;j++) {
				if(card[i][j] == false) {
					String design= intDesign.get(i);
					System.out.printf("%s %d\n",design, j);
				}
			}
		}
					
	}
}



Measured memory_bytes: 24664
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
from heapq import heappush, heappop

INF = 10 ** 18

N, M, S = map(int, input().split())
UVAB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(N)]

sumA = 0
for u, v, a, b in UVAB:
    sumA += a

def dijkstra(start, graph) -> list:
    dist = [[INF for _ in range(N + 1)] for _ in range(sumA + 1)]
    dist[start][1] = 0
    heap = []
    heappush(heap, (0, (start, 1)))
    while heap:
        v, (i, j) = heappop(heap)
        for w, (ni, nj) in graph[i][j]:
            if dist[ni][nj] > v + w:
                dist[ni][nj] = v + w
                heappush(heap, (dist[ni][nj], (ni, nj)))
    return dist

graph = [[[] for _ in range(N + 1)] for _ in range(sumA + 1)]

for u, v, a, b in UVAB:
    for i in range(a, sumA + 1):
        graph[i][u].append((b, (i - a, v)))
        graph[i][v].append((b, (i - a, u)))

for j in range(1, N + 1):
    c, d = CD[j - 1]
    for i in range(sumA):
        graph[i][j].append((d, (min(i + c, sumA), j)))

dist = dijkstra(min(S, sumA), graph)

for j in range(2, N + 1):
    answer = INF
    for i in range(sumA + 1):
        answer = min(dist[i][j], answer)
    print(answer)

Measured memory_bytes: 148072
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int N,M,R;
int d[201][201];
int r[9];
int A,B,C;
int res;
bool used[9];

void dfs(int c,int las,int dist){
    if(c==R+1){
        if(res>dist)res=dist;
        return;
    }
    for(int i=1;i<=R;i++)if(!used[i]){
        used[i]=true;
        if(las==-1)dfs(c+1,i,0);
        else dfs(c+1,i,dist+d[r[las]][r[i]]);
        used[i]=false;
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N>>M>>R;
    ll inf=1<<29;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            if(i!=j) d[i][j]=inf;
        }
    }

    for(int i=1;i<=R;i++) cin>>r[i];

    for(int i=1;i<=M;i++){
        cin>>A>>B>>C;
        if(d[A][B]>C) d[A][B]=d[B][A]=C;
    }
    for(int k=1;k<=N;k++){
        for(int i=1;i<=N;i++){
            for(int j=1;j<=N;j++){
                if(d[i][j]>d[i][k]+d[k][j]){
                    d[i][j] = d[i][k]+d[k][j];
                }
            }
        }
    }
    res = inf;
    dfs(1,-1,0);
    cout<<res<<endl;
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline
import math

N, M, K = [int(item) for item in input().split()]
mod = 10**9 + 7

score_c = 1
for i in range(2, K):
    score_c *= ((N * M - i) % mod * pow(K - i, mod - 2, mod))
    score_c %= mod

total = 0
for d in range(1, N):
    score = (N - d) * M**2 * d * score_c
    score %= mod
    total += score
    total %= mod

for d in range(1, M):
    score = (M - d) * N**2 * d * score_c
    score %= mod
    total += score
    total %= mod


print(total)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
    int field[1001][101];
    while (true) {
        int n, m, a;
        cin >> n >> m >> a;
        if (n==0 && m==0 && a==0) {
            break;
        }
        memset(field,0,sizeof(field));
        int st=0;
        for (int i=0; i<m; i++) {
            int h, p, q;
            cin >> h >> p >> q;
            field[h][p]=q;
            field[h][q]=p;
            st=max(st,h);
        }
        for (int i=1000; i>0; i--) {
            if (field[i][a]!=0) {
                a=field[i][a];
            }
        }
        printf("%d\n",a);
    }
    return 0;
}

Measured memory_bytes: 3472
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define UNIQUE(a) unique(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <utility>
#include <ios>
#include <iomanip>

using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	if (k % 2 == 1) {
		ans = pow(floor(n / k), 3);
	}
	else {
		ans = pow(floor(n / k), 3);
		if (n >= k / 2) {
			ans += pow(floor((n - k / 2) / k) + 1, 3);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> pr(n);
    for (int i=0; i<n; ++i) {
        int a;
        cin >> a;
        for (int j=0; j<a; ++j) {
            int x, y;
            cin >> x >> y;
            pr.at(i).push_back({x, y});
        }
    }

    int res = 0;
    for (int bits=0; bits<(1<<n); ++bits) {
        bool ok = true;
        for (int i=0; i<n; ++i) {
            if (bits & (1 << i)) {
                for (auto p : pr.at(i)) {
                    int x = p.first, y = p.second;
                    if ((y == 0 && ((bits & (1 << (x-1))) != 0)) || ((y == 1 && ((bits & (1 << (x-1))) == 0)))) {
                        ok = false;
                        break;
                    }
                }
            }
            if (!ok) break;
        }
        if (ok) {
            int tmp = 0;
            for (int i=0; i<n; ++i) {
                if (bits & (1 << i)) ++tmp;
            }
            chmax(res, tmp);
        }
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    priority_queue<int> Q;
    for(int i = 0; i < N; i++) {
        int A;
        cin >> A;
        Q.push(A);
    }
    while(0 < M) {
        int tmp = Q.top() / 2;
        Q.pop();
        Q.push(tmp);
        M--;
    }
    long long int res = 0;
    int size = Q.size();
    for(int i = 0; i < size; i++) {
        res += Q.top();
        Q.pop();
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 892
S=input()
T=input()

d={}
e={}
for s,t in zip(S,T):
    if t in d:
        if d[t]!=s:
            print("No")
            exit()
    elif s in e:
        if e[s]!=t:
            print("No")
            exit()
    else:
        d[t]=s
        e[s]=t
print("Yes")


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;

int main(){

    int N, i;
    cin >> N;
    int a[N];
    int cnt[100001] = {};

    for (i = 0; i < N; i++){
      cin >> a[i];
      cnt[a[i]] += 1;
    }
    
    int ans = 0;

    for (i = 0; i < 99999; i++){
      ans = max(ans, cnt[i] + cnt[i + 1] + cnt[i + 2]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int,input().split()))
a = [v - i -1 for i,v in enumerate(a)]
a.sort()
b = a[n//2]

min_u = [abs(i-b) for i in a]
print(sum(min_u))

Measured memory_bytes: 25168
#include <bits/stdc++.h>
using namespace std;

int main() {
int N;
  cin >> N;
  vector<int> hito(N+1);
  int a;
  for(int i = 1; i <= N; i++){
  	cin >> a;
    hito[a] = i;
  }
  for(int i = 1; i <= N; i++){
  	cout << hito[i];
    if(i != N){
    	cout << " ";
    }
  }
}

Measured memory_bytes: 1152
#include <iostream>

long int n, red = 0, ans = 0;
char c[200000];

int main()
{
    std::cin >> n;
    for (long int i = 0; i < n; i++) {
        std::cin >> c[i];
        if (c[i] == 'R') red++;
    }
    for (long int i = 0; i < n && red != 0; i++, red--) {
        if (c[i] == 'W') ans++;
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 3780
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN

//AC

int main(void){
	ll n,cnt=0,ans=0;
	string s,t;
	cin>>n>>s>>t;
	reg(i,0,n){//一致する長さ
		bool ok=true;
		rep(j,i){
			if(t[j]!=s[n-i+j])ok=false;
		}
		if(ok)ans=max((ll)i,ans);
	}
	cout<<2*n-ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll mod = 998244353;

#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define FOr(i, s, e) for (ll i = s; i >= e; i--)

#define PI acos(-1)
#define sz 10000007

void fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}


ll d[sz];

void seiveDivisors()
{
	for (ll i = 1; i <= sz; i++)
		for (ll j = i; j <= sz; j += i) d[j]++;
}


void solve()
{
	seiveDivisors();

	ll n; cin >> n;
	ll ans = 0;
	for (ll i = 1; i <= n; i++) ans += d[i] * i;

	cout << ans << '\n';
}

int main()
{
	fastio();

	int t = 1; //cin >> t;
	while (t--)
		solve();

	return 0;
}


Measured memory_bytes: 81768
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    if (n == 7)
    {
        YES;
        return 0;
    }
    if (n == 5)
    {
        YES;
        return 0;
    }
    if (n == 3)
    {
        YES;
        return 0;
    }
    NO;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,K;
  cin>>N>>K;
  VI P(N);
  rep(i,N) cin>>P[i];
  sort(all(P));
  ll ans=0;
  rep(i,K) ans+=P[i];
  cout<<ans<<endl;
}


Measured memory_bytes: 3624
n,m = map(int,input().split())
cnt = [0] * (n + 1)
for _ in range(m):
    a, b = map(int,input().split())
    cnt[a] += 1
    cnt[b] += 1
print('YES' if all([i % 2 == 0 for i in cnt]) else 'NO')


Measured memory_bytes: 4660
#include <bits/stdc++.h>
#include <vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MAX 200005
#define MOD 1000000007
#define INF 1000000000000000000
#define EPS 0.0000000001
#define CHAINS 18
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
vector<pair<int,int> > points;
vector<int> spoints[MAX],tpoints[MAX];
set<pair<int,int> > S;
set<pair<int,int> >::iterator it;
set<int> differ,sum;
map<int,int> Indices,Indices2;
int values[MAX],values2[MAX];
int main()
{
    int n,i,j;
    scanf("%d",&n);
    pair<int,int> p;
    for(i=0;i<n;i++)
    {
        scanf("%d %d",&p.first,&p.second);
        S.insert(p);
        differ.insert(p.second-p.first);
        sum.insert(p.second+p.first);
    }
    for(it=S.begin();it!=S.end();++it)
    {
        points.push_back(*it);
    }
    S.clear();
    n=points.size();
    j=0;
    while(differ.size())
    {
        i=*(differ.begin());
        differ.erase(i);
        Indices[i]=j;
        values[j]=i;
        //printf("values[%d]=%d\n",j,i);
        j++;
    }

    int m=j,ans=0;
    j=0;
    while(sum.size())
    {
        i=*(sum.begin());
        sum.erase(i);
        Indices2[i]=j;
        values2[j]=i;
        //printf("values2[%d]=%d\n",j,i);
        j++;
    }
    int s=j;
    for(i=0;i<n;i++)
    {
        spoints[Indices[points[i].second-points[i].first]].push_back(points[i].first);
        tpoints[Indices2[points[i].second+points[i].first]].push_back(points[i].first);
    }
    points.clear();
    for(i=0;i<m;i++)
    {
        sort(spoints[i].begin(),spoints[i].end());
    }
    for(i=0;i<s;i++)
    {
        sort(tpoints[i].begin(),tpoints[i].end());
    }
    points.push_back(make_pair(spoints[0][0],spoints[0][0]+values[0]));
    points.push_back(make_pair(spoints[0][spoints[0].size()-1],spoints[0][spoints[0].size()-1]+values[0]));
    points.push_back(make_pair(spoints[m-1][0],spoints[m-1][0]+values[m-1]));
    points.push_back(make_pair(spoints[m-1][spoints[m-1].size()-1],spoints[m-1][spoints[m-1].size()-1]+values[m-1]));
    points.push_back(make_pair(tpoints[0][0],-tpoints[0][0]+values2[0]));
    points.push_back(make_pair(tpoints[0][tpoints[0].size()-1],-tpoints[0][tpoints[0].size()-1]+values2[0]));
    points.push_back(make_pair(tpoints[s-1][0],-tpoints[s-1][0]+values2[s-1]));
    points.push_back(make_pair(tpoints[s-1][tpoints[s-1].size()-1],-tpoints[s-1][tpoints[s-1].size()-1]+values2[s-1]));
    for(i=0;i<points.size();i++)
    {
        for(j=0;j<points.size();j++)
        {
            m=abs(points[i].first-points[j].first)+abs(points[i].second-points[j].second);
            //printf("(%d,%d)-(%d,%d)=%d\n",points[i].first,points[i].second,points[j].first,points[j].second,m);
            ans=max(ans,abs(points[i].first-points[j].first)+abs(points[i].second-points[j].second));
        }
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 50284
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

template<typename T>
struct SegmentTree{
    int n;
    T e; //単位元
    vector<T> v;
    function<T(T,T)> operation;
    function<T(T,T)> update;
    //区間[a,b)に対してのクエリ 今は[l,r)を見ている
    T _query(int a,int b,int k,int l,int r){
        if(r<=a||b<=l) return e;
        if(a<=l && r<=b) return v[k];
        else{
            T c1=_query(a,b,2*k+1,l,(l+r)/2);
            T c2=_query(a,b,2*k+2,(l+r)/2,r);
            return operation(c1,c2);
        }
    }
public:
    SegmentTree(size_t _n,T _e,function<T(T,T)> _operation,function<T(T,T)> _update):e(_e),operation(_operation),update(_update){
        n=1;
        while(n<_n){
            n*=2;
        }
        v=vector<T>(2*n-1,e);
    }
    void change(int i,T x){
        i+=n-1;
        v[i]=update(v[i],x);
        while(i>0){
            i=(i-1)/2;
            v[i]=operation(v[i*2+1],v[i*2+2]);
        }
    }
    T query(int a,int b){
        return _query(a,b,0,0,n);
    }
    T operator[](int i){
        return v[i+n-1];
    }
};
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
const ll MOD = 998244353;

signed main(){
    
    int n; cin >> n;
    vector<P> v;
    vector<int> vec;
    rep(i,n){
        int x,d; cin >> x >> d;
        v.pb({x,d});
        vec.pb(x);
    }
    sort(ALL(v));
    sort(ALL(vec));
    int rob[n]; rob[n-1]=n-1;
    
    SegmentTree<int> seg(n,-1,[](ll a,ll b){return max(a,b);},[](ll a,ll b){return b;});
    seg.change(n-1,n-1);
    
    for(int i=n-2;i>=0;i--){
        int fin=v[i].fi+v[i].se;
        int p=lower_bound(ALL(vec),fin)-vec.begin();
        if(i+1==p) rob[i]=i;
        else rob[i]=seg.query(i+1,p);
        seg.change(i,rob[i]);
    }
    //rep(i,n) cout << rob[i] << endl;
    ll dp[n]; dp[n-1]=2;
    for(int i=n-1;i>0;i--){
        if(rob[i-1]==n-1) dp[i-1]=(dp[i]+1)%MOD;
        else dp[i-1]=(dp[i]+dp[rob[i-1]+1])%MOD;
    }
    cout << dp[0] << endl;
}


Measured memory_bytes: 8344
#include <stdio.h>
int main(){
    int a,b,c;
    scanf("%d %d",&a,&b);
    c = a * b ;
    if(c%2 == 0){
        printf("Even\n");
    }
    if(c%2 != 0){
        printf("Odd\n");
    }
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

class D
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(long.Parse).ToArray();

		var x1 = new PQ<long>(a.Take(n));
		var x2 = new PQ<long>(a.Skip(2 * n), (x, y) => -x.CompareTo(y));
		var s1 = new long[n + 1];
		var s2 = new long[n + 1];
		s1[0] = x1.Sum();
		s2[n] = x2.Sum();

		for (int i = 0, j = n - 1; i < n; i++, j--)
		{
			var v1 = a[n + i];
			if (v1 > x1.Current)
			{
				s1[i + 1] = s1[i] + v1 - x1.Pop();
				x1.Push(v1);
			}
			else s1[i + 1] = s1[i];

			var v2 = a[n + j];
			if (v2 < x2.Current)
			{
				s2[j] = s2[j + 1] + v2 - x2.Pop();
				x2.Push(v2);
			}
			else s2[j] = s2[j + 1];
		}
		Console.WriteLine(Enumerable.Range(0, n + 1).Max(i => s1[i] - s2[i]));
	}
}

class PQ<T> : List<T>
{
	Comparison<T> c;
	public T Current => this[0];

	public PQ(IEnumerable<T> vs = null, Comparison<T> compare = null)
	{
		c = compare ?? Comparer<T>.Default.Compare;
		if (vs != null) foreach (var v in vs) Push(v);
	}

	void Swap(int i, int j)
	{
		var t = this[i];
		this[i] = this[j];
		this[j] = t;
	}

	void UpHeap(int i) { for (var j = (i - 1) / 2; i > 0 && c(this[j], this[i]) > 0; Swap(i, j), i = j, j = (i - 1) / 2) ; }
	void DownHeap(int i)
	{
		for (var j = 2 * i + 1; j < Count; i = j, j = 2 * i + 1)
		{
			if (j + 1 < Count && c(this[j], this[j + 1]) > 0) j++;
			if (c(this[i], this[j]) > 0) Swap(i, j); else break;
		}
	}

	public void Push(T v) { Add(v); UpHeap(Count - 1); }
	public T Pop()
	{
		var r = this[0];
		this[0] = this[Count - 1];
		RemoveAt(Count - 1);
		DownHeap(0);
		return r;
	}
}


Measured memory_bytes: 51604
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main()
{
    int n, p;
    cin >> n >> p;
    int ans = 1;
    int cp = p;
    for (int i=2; i*i <= cp; i++){
        int num = 0;
        while (p % i == 0){
            p/=i, num++;
        }
        while (num >= n){
            num -= n;
            ans *= i;
        }
    }
    if (p > 1 && n == 1) ans *= p;
    cout << ans;
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  vector<int> vec(3);
  cin>>vec[0]>>vec[1]>>vec[2];
  
  sort(vec.begin(),vec.end());
  
  cout<<vec[0]+vec[1]<<endl;
}

Measured memory_bytes: 3608
#include <stdio.h>

int main()
{
  int a[4];
  scanf("%d%d%d",&a[0],&a[1],&a[2]);
  a[1] *= -1;
  if (a[1] + a[2] <= 0)
    printf("delicious");
  else if (a[1] + a[2] > a[0])
    printf("dangerous");
  else
    printf("safe");
}

Measured memory_bytes: 128
import sys
import collections

N = int(input())
D = list(map(int, input().split()))
D.append(0)
D.sort()
count = collections.Counter(D)

E = []
F = []
for k, v in count.items():
  if v >= 3:
    print(0)
    sys.exit(0)
  if v == 2:
    F.append(24 - k)
    F.append(k)
  if v == 1:
    E.append(k)
E.sort()
for i in range(len(E)):
  if i % 2 == 0:
    F.append(E[i])
  else:
    F.append(24 - E[i])
F.append(24)
F.sort()
ans = 24
for i in range(len(F) - 1):
    ans = min(ans, F[i+1] - F[i])
print(ans)



Measured memory_bytes: 3316