akhauriyash/Code-Regression huggingface dataset:
# AtCoder Beginner Contest 121
# https://atcoder.jp/contests/abc121
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M = i2nn()
    AB = ii2nnn(N)
    AB.sort(key=lambda v: v[0])
    cost = 0
    m = 0
    i = 0
    while True:
        a, b = AB[i]
        if m + b < M:
            m += b
            i += 1
            cost += a * b
            continue
        for j in range(b):
            m += 1
            cost += a
            if m >= M:
                print(cost)
                return

main()

Measured memory_bytes: 29856
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto H = RD;
	auto W = RD;
	auto C = new string[](H);
	foreach (i; 0..H)
	{
		C[i] = RD!string;
	}
	
	foreach (i; 0..H)
	{
		writeln(C[i]);
		writeln(C[i]);
	}
	
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
S=input()
answer = 'NO'

if 'keyence' in S:
    answer = 'YES'
elif S[:6] == 'keyenc':
    if S[-1:] == 'e':
        answer = 'YES'
elif S[:5] == 'keyen':
    if S[-2:] == 'ce':
        answer = 'YES'
elif S[:4] == 'keye':
    if S[-3:] == 'nce':
        answer = 'YES'
elif S[:3] == 'key':
    if S[-4:] == 'ence':
        answer = 'YES'
elif S[:2] == 'ke':
    if S[-5:] == 'yence':
        answer = 'YES'
elif S[:1] == 'k':
    if S[-6:] == 'eyence':
        answer = 'YES'

print(answer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

const int INF = 1 << 30;

int n, m, x;
int min_ = INF;
int c[15];
int a[15][15];

void dfs(vector<int> &A) {
    int len = A.size();
    if (len == n) {
        ll sum = 0;
        vi f(m, 0);
        bool flag = true;
        rep(i, len){
            if(A.at(i) == 1){
                sum += c[i];
                rep(j, m) f[j] += a[i][j];
            }
        }
        rep(j, m){
            if(f[j] < x) flag = false;
        }
        if(sum <= min_ && flag) min_ = sum;
        return;
    }
    for (int v = 0; v < 2; ++v) {
        A.push_back(v);
        dfs(A);
        A.pop_back();
    }
}

int main(){
    cin >> n >> m >> x;
    vi f(m, 0);
    rep(i, n){
        cin >> c[i];
        rep(j, m){
            cin >> a[i][j];
            f[j] += a[i][j];
        }
    }
    rep(i, m){
        if(f[i] < x){
            cout << -1 << endl;
            return 0;
        }
    }
    vector<int> A;
    dfs(A);
    cout << min_ << endl;
    return 0;
}

Measured memory_bytes: 3576
k, n = map(int, input().split())
#s= list(input())
a = list(map(int, input().split()))
maxd = a[0] -a[n-1] + k

for i in range(n-1):
    if(maxd < a[i+1]-a[i]):
        maxd = a[i+1]-a[i]
print(k-maxd)

Measured memory_bytes: 26444
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n;
    cin >> n;
    VL a(n);
    REP(i,n) a[i] = in();
    ll ans = 0, x = 0;
    REP(i,n){
        if (a[i] < x) ans += x - a[i];
        chmax(x, a[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4836
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define re return
#define pb push_back
#define po pop_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define si size
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pi 3.14159265359
#define er erase
#define in insert
#define em empty
#define ft front
#define fo(i,n) for(i = 0; i < n; i++)
#define ro(i,n) for(i = n - 1; i >= 0; i--)
#define fr(i,j,n) for(i = j; i < n; i++)
#define rf(i,j,n) for(i=n-1;i>=j;i--)
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::pair<int,int> ii;
typedef std::vector<ii> vii;
typedef std::vector<std::string> vs;
typedef double dl;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> vll;
#define filename ""
using namespace std;
    int table[200][200][200];
int f(int a,int b,int c)
{
    if (a>150||b>150||c>150)
    {
        re (int)1e8;
    }
    if (a==b&&a==c) re 0;
    if (table[a][b][c]) re table[a][b][c];
    int o=(int)1e8;
    o=min(o,f(a+1,b+1,c)+1);
    o=min(o,f(a+1,b,c+1)+1);
    o=min(o,f(a,b+1,c+1)+1);
    o=min(o,f(a+2,b,c)+1);
    o=min(o,f(a,b+2,c)+1);
    o=min(o,f(a,b,c+2)+1);
    re table[a][b][c]=o;
}
int main()
{
    /*
	freopen(filename".in","r",stdin);
	freopen(filename".out","w",stdout);
	*/
	/*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    */
    /*
    ios::sync_with_stdio(0);
    */
    int a,b,c;
    cin>>a>>b>>c;
    cout<<f(a,b,c);
}


Measured memory_bytes: 24448
#include <iostream>
#include <cmath>
#include <vector>
#include <array>
#include <algorithm>
#include <string>

typedef long long ll;


int main()
{

    ll N, K;
    std::cin >> N >> K;


    if((N-1)*(N-2)/2<K)
    {
        std::cout << -1 << std::endl;
        return 0;
    }

    ll diff = (N-1)*(N-2)/2 - K;

    std::vector<std::pair<ll, ll>> graph;
    for(int i=2; i<=N; ++i)
        graph.emplace_back(std::make_pair(1, i));

    ll startNum = 3;
    ll fromNode = 2;
    while(diff>0)
    {
        graph.emplace_back(std::make_pair(fromNode, startNum));
        startNum++;

        if(startNum > N)
        {
            fromNode++;
            startNum=fromNode+1;
        }
        diff--;
    }

    std::cout << graph.size() << std::endl;
    for(int i=0; i<graph.size(); ++i)
        std::cout << graph[i].first << " " << graph[i].second << std::endl;

    return 0;
}






Measured memory_bytes: 512
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int N,K,X,Y;
	cin>>N>>K>>X>>Y;
	
	if(N-K<=0)
		cout<<X*N<<endl;
	else
		cout<<(N-K)*Y+K*X<<endl;
	
	return 0;
}


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

int main() {
  int n;
  int t[110000],x[110000],y[110000];
  cin >> n;
  t[0]=x[0]=y[0]=0;
  for(int i=0;i<n;i++) cin >> t[i+1] >> x[i+1] >> y[i+1];
  
  bool can=true;
  for(int i=0;i<n;i++) {
    int dt=t[i+1]-t[i];
    int dist=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    if(dist>dt) can=false;
    if(dist%2!=dt%2) can =false;
  }
  if(can) cout << "Yes" << endl; 
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 1408
MM = input().split()
N = int(MM[0])
L = int(MM[1])
list1 =[]
for i in range(N):
  a = L + i
  list1.append(a)

mini = 301
ans = 201
for i in range(N):
  if mini > abs(list1[i]):
    mini = abs(list1[i])
    ans = i
total = 0
for i in list1:
  total += int(i)
ans1 = total -list1[ans]
print(ans1)
  

Measured memory_bytes: 9168
N, C, K = tuple(map(int, input().split()))
T = [int(input()) for _ in range(N)]
T = sorted(T)
base = T[0]
count = 1
ans = 1
for i in range(1, N):
    if T[i] <= base + K and count < C:
        count += 1
        continue
    base = T[i]
    count = 1
    ans += 1
print(ans)

Measured memory_bytes: 8280
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

 
int main(){

	for(int i = 1; i <= 9; i++){
		for(int j = 1; j <= 9; j++){
			cout << i << 'x' << j << '=' << i*j << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1116
N,M,X = map(int,input().split())

A =  []
S = [0 for _ in range(N)] 
min_value = 0 
score=[0 for _ in range(M)] 

for x in range(N):
  A.append(list(map(int,input().split())))

for x in range(N):
  min_value += A[x][0]


sucess = 0

for bit in range(2**N):
  for i in range(N):
    if (bit >> i) & 1:
      S.append(A[i][0])
      for x in range(M):
        score[x] += A[i][x+1]
  flag = 0
  #print(score)
  for k in score:
    if k >= X:
      flag += 1
    if flag ==len(score):
      #print("S",S)
      if min_value >= sum(S):
        min_value = sum(S)
        sucess += 1 
        
  score=[0 for _ in range(M)]
  S =[]
  
if sucess > 0:
	print(min_value)
else:
  print("-1")

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

int main() {
	int a, b; cin >> a >> b;
	string s; cin >> s;
	bool answer = true;
	
	if (s.size() != a + b + 1) {
		cout << "No" << endl;
		return 0;
	}
	
	for (int i = 0; i < s.size(); i++) {
		if (i != a) {
			if (s.at(i) - '0' < 0 || s.at(i) - '9' > 0) {
				answer = false;
				break;
			}
		} else {
			if (s.at(i) != '-') {
				answer = false;
				break;
			}
		}
	}
	
	if (answer) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

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

int main() {
  string s, t;
  cin >> s >> t;
  int n, m;
  n = s.size();
  m = t.size();
  int dp[n+1][m+1];
  rep(i,n+1) rep(j,m+1) dp[i][j] = 0;

  string x, y;
  rep(i, n+1) rep(j, m+1) {
    if (i==0 or j==0) continue;
    if (s[i-1] == t[j-1]) {
      dp[i][j] = max(dp[i-1][j-1]+1, dp[i][j]);
    } else {
      dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
    }
  }
  
  int i = n, j = m;
  string ans;
  while (true) {
    //cout << i << " " << j << endl;
    if (i==0 and j==0) break;
    if (i > 0 and dp[i][j] == dp[i-1][j]) i--;
    else if (j > 0 and dp[i][j] == dp[i][j-1]) j--;
    else {
      ans = s[i-1] + ans;
      i--;
      j--;
    }
  }
	
  cout << ans << endl;
}


Measured memory_bytes: 35456
import java.util.PriorityQueue;
import java.util.Scanner;

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

    int Q = scanner.nextInt();
    PriorityQueue<Integer> left = new PriorityQueue<>((i1, i2) -> i2 - i1);
    PriorityQueue<Integer> right = new PriorityQueue<>();
    StringBuilder sb = new StringBuilder();
    long min = 0;
    for (int i = 0; i < Q; i++) {
      int op = scanner.nextInt();
      if (op == 1) {
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        if (!left.isEmpty()) min += Math.abs(a - left.peek());
        min += b;
        if (left.isEmpty() || a < left.peek()) left.add(a);
        else right.add(a);
        if (right.size() > left.size()) {
          min += (right.peek() - left.peek()) * (left.size() - right.size());
          left.add(right.remove());
        } else if (left.size() - right.size() > 1) {
          right.add(left.remove());
        }
      } else {
        sb.append(left.peek()).append(' ').append(min).append('\n');
      }
    }
    System.out.print(sb.toString());
  }
}


Measured memory_bytes: 153560
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>
#include<cmath>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, l, ans = -INF;
    cin >> n >> l;
    int t = INF;
    for(int i = 0; i < n; i++){
        if(abs(t) > abs(l + i)){
            ans += t;
            t = l + i;
        }else{
            ans += l + i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (ll (i) = (s); (i) < (e); ++(i))
#define per(i, s, e) for (ll (i) = (s); (i) >= (e); --(i))
#define all(x) x.begin(),x.end()

int main(void) {
  ll n;
  cin >> n;
  vector<ll> p(n), q(n), x(n);
  rep(i, 0, n) {
    cin >> p[i]; 
  }
  rep(i, 0, n) {
    cin >> q[i]; 
  }
  rep(i, 0, n) {
    x[i] = i + 1;
  }
  ll i = 1;
  ll a=0, b=0;
  do {
    if (x == p) a = i;
    if (x == q) b = i;
    ++i;
  } while(next_permutation(all(x)));
 
  
  cout << abs(a - b) << endl;
  
}

Measured memory_bytes: 256
/**
 *　　　　　　  　　┏┓　　 　┏┓
 * 　　　　　  　　┏┛┗━━━━━━━┛┗━━━┓
 * 　　　　　  　　┃　　　　　　　┃ 　
 * 　　　　　  　　┃　　　━　　 　┃
 * 　　　　　  　　┃　＞　　　＜　┃
 * 　　　　　  　　┃　　　　　　　┃
 * 　　　　　  　　┃...　⌒　... 　┃
 * 　　　　　　  　┃              ┃
 * 　　　　　　  　┗━┓          ┏━┛
 * 　　　　　　　　　┃          ┃　Code is far away from bug with the animal protecting　　　　　　　　　　
 * 　　　　　　　　　┃          ┃   神兽保佑,代码无bug
 * 　　　　　　　　　┃          ┃　　　　　　　　　　　
 * 　　　　　　　　　┃          ┃  　　　　　　
 * 　　　　　　　　　┃          ┃
 * 　　　　　　　　　┃          ┃　　　　　　　　　　　
 * 　　　　　　　　　┃          ┗━━━┓
 * 　　　　　　　　　┃              ┣┓
 * 　　　　　　　　　┃              ┏┛
 * 　　　　　　　　　┗┓┓┏━━━━━━━━┳┓┏┛
 * 　　　　　　　　　　┃┫┫       ┃┫┫
 * 　　　　　　　　　　┗┻┛       ┗┻┛
 */ 
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define inf 1000000000
#define maxn 1005
#define maxm 100005
#define eps 1e-10
#define for0(i,maxn) for(int i=1;i<=(maxn);++i)
#define for1(i,maxn) for(int i=1;i<=(maxn);++i)
#define for2(i,x,y) for(int i=(x);i<=(y);++i)
#define for3(i,x,y) for(int i=(x);i>=(y);--i)
#define mod 1000000007
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=10*x+ch-'0';ch=getchar();}
    return x*f;
}
int main()
{
    string s,t;
    cin>>s>>t;
    int ans=0;
    //cout<<s.size()<<endl;
    for(int i=0;i<s.length();++i)
    {
        if(s==t) {
            ans=1;break;
        }
        s=s.back()+s.substr(0,s.size()-1);
    }
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0

for i in range(0,a+1):
    for j in range(0,b+1):
        for k in range(0,c+1):
            if 500*i + 100*j + 50*k == x:
                count += 1

print(count)

Measured memory_bytes: 3060
fun main(args: Array<String>) {
    fun readLineAndSplitBySpace() = readLine()!!.split(" ")

    val (N, M, Q) = readLineAndSplitBySpace().map { it.toInt() }

    val a = IntArray(Q)
    val b = IntArray(Q)
    val c = IntArray(Q)
    val d = IntArray(Q)

    for (i in 0 until Q) {
        val array = readLineAndSplitBySpace()
        a[i] = array[0].toInt() - 1
        b[i] = array[1].toInt() - 1
        c[i] = array[2].toInt()
        d[i] = array[3].toInt()
    }

    val A = IntArray(N)

    fun compute(index: Int, start: Int) :Int {
        if (index == N) {
            var sum = 0
            for (j in 0 until Q) {
                if ((A[b[j]] - A[a[j]]) == c[j]) sum += d[j]
            }

            return sum
        }

        var max = 0
        for (i in start..M) {
            A[index] = i
            max = max.coerceAtLeast(compute(index + 1, A[index]))
        }

        return max
    }

    println(compute(0, 1))
}


Measured memory_bytes: 39344
// I look at my watch
// it say nine twenty-five
// And I think oh God
// I'm still alive
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) int((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(int i = int(a); i < int(b); ++i)
#define roF(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;
typedef long double ld;

int main(){	
	ll n;cin>>n;
	ll ans=0;
	vector<ll>div;
	for(ll i=1;i*i<=n;i++)if(n%i==0){
		if(i!=1)div.pb(i);
		if(i*i!=n)div.pb(n/i);
	}
	for(ll val:div){
		ll cur=n;
		while(cur%val==0)cur/=val;
		if(cur%val==1)ans++;
	}
	div.clear();
	for(ll i=1;i*i<=n-1;i++)if((n-1)%i==0){
		div.pb(i);
		if(i*i!=n-1)div.pb((n-1)/i);
	}
	for(ll val: div)if(n%val)
		if(n%val==1)ans++;
	cout<<ans<<endl;

	return 0;
}


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

#define ll long long
#define ld long double
#define pr pair<ll,ll>
#define loop(i,n) for(ll i=0 ; i<n ; ++i)
#define rep(i,x,n) for(ll i=x ; i<=n ; ++i)
#define iteloop(type,data,name,it) for(type<data>::iterator it=name.begin() ;it!=name.end() ; ++it)
using namespace std;
const ll N=2e2 + 5;
int a,b,c,n;
int main(){
    cin.sync_with_stdio(false), cin.tie(0) , cout.tie(0);
#ifndef ONLINE_JUDGE
  //  freopen("in.txt", "rt" , stdin);
    // freopen("out.txt", "wt" , stdout);
#endif // ONLINE_JUDGE
    cin>>a>>b>>c>>n;
    int ans=0;
    loop(i,n+1){
        loop(j,n+1){
            int total=i*a+j*b;
            if(total>n)continue;
            if((n-total)%c==0)ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
N,x=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
cnt=0
for i in range(N-1):
    x-=A[i]
    if x >= 0:
        cnt+=1
    else:
        break
if x==A[N-1]:
    cnt+=1
print(cnt)

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    string s;
    cin >> s;

    int64_t m = s.size();

    vector a(1, 0L);
    int64_t t = 0;
    for (auto c : s) {
        if (c == '0') {
            a.push_back(t);
        } else {
            ++t;
        }
    }
    a.push_back(t);

    int64_t k;
    cin >> k;
    k = min(k, a.back());

    int64_t n = a.size();

    constexpr auto M = 998244353L;

    vector dp(vector(k + 1, vector(a.back() + 1, 0L)));
    int64_t mk = 0;
    dp[0][0] = 1;
    for (auto i : irange(0L, n - 1)) {
        for (auto j : irange(mk, -1L, -1L)) {
            auto r = min(k - j, a[i + 1] - a[i]);
            auto mc = a.back()  - a[i + 1];
            for (auto b : irange(1L, mc + r + 1)) {
                for (auto c : irange(max(0L, b - r), min(b, mc + 1))) {
                    auto w = j + b - c;
                    dp[w][c] += dp[j][b];
                    if (dp[w][c] >= M) {
                        dp[w][c] -= M;
                    }
                }
            }

            for (auto c : irange(1L, a.back() - a[i + 1] + 1)) {
                dp[j][c] += dp[j][c - 1];
                if (dp[j][c] >= M) {
                    dp[j][c] -= M;
                }
            }
        }
        mk = min(k, mk + a[i + 1] - a[i]);
    }

    int64_t ans = 0;
    for (auto i : irange(0L, mk + 1)) {
        ans += dp[i][0];
    }

    cout << ans % M << endl;
}


Measured memory_bytes: 3884
n, m = map(int, input().split())
A = list()
b = list()
for i in range(n):
    A.append(list(map(int, input().split())))
for i in range(m):
    b.append(int(input()))
for i in range(n):
    _ = 0
    for j in range(m):
        _ = _ + (A[i][j] * b[j])
    print(_)


Measured memory_bytes: 6004
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int n;
    cin>>n;
    
    while(true){
        string s=to_string(n);
        if(s[0]==s[1] && s[0]==s[2]){
            cout<<n<<endl;
            break;
        }else{
            n++;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>

using namespace std;
#define INF 99999
#define _GLIBCXX_DEBUG
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define fi first
#define se second
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
using namespace std;

int main() {
    int N;
    cin >> N;
    vint a(N);
    REP(i, N) cin >> a[i];
    int amax = 0;
    REP(i, N) {
        if (a[i] > amax) amax = a[i];
    }

    vint c(max(2, amax)+1);
    REP(i, amax) c[i] = 0;

    REP(i, N) c[a[i]] += 1;

    int max = 0;
    REP(i, c.size()-2) {
        if (c[i] + c[i + 1] + c[i + 2] >= max) {
            max = c[i] + c[i + 1] + c[i + 2];
        }
    }
    cout << max;
}

Measured memory_bytes: 1024
import numpy as np 

N, K = map(int,input().split())

result = [0]*N

for i in range (K):
    d = int(input())
    A = list(map(int,input().split()))
    for j in range (d):
        result[A[j]-1]+=1
        
print(sum((np.array(result)==0)*1))

Measured memory_bytes: 27268
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  long n;
  cin >> n;
  cout << (n*(n-1))/2 << endl;;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int N, M;
  while(cin>>N>>M && N){
    vector<int> s(N), t(N);
    vector<int> rope(M);
    REP(i, N) scanf("%d %d", &s[i], &t[i]);
    REP(i, M) scanf("%d", &rope[i]);
    sort(rope.begin(), rope.end());
    vector<int> sum_mod[2] = {vector<int>(M), vector<int>(M)};
    REP(i, M - 1){
      sum_mod[0][i + 1] = sum_mod[0][i] + ((!(i & 1)) ? (rope[i + 1] - rope[i]) : 0);
      sum_mod[1][i + 1] = sum_mod[1][i] + (( (i & 1)) ? (rope[i + 1] - rope[i]) : 0);
    }
    ll ans = 0;
    REP(i, N){
      bool rev = (s[i] > t[i]);
      if(rev) swap(s[i], t[i]);
      int b_idx = upper_bound(rope.begin(), rope.end(), s[i]) - rope.begin();
      int e_idx = upper_bound(rope.begin(), rope.end(), t[i]) - rope.begin();
      if(b_idx == e_idx){
        ans += (t[i] - s[i]);
        //if(!rev) printf("%d->%d %lld\n", s[i], t[i], ans - tmp);
        //else printf("%d->%d %lld\n", t[i], s[i], ans - tmp);
        continue;
      }
      assert(b_idx < e_idx);
      e_idx--;
      if(!rev){
        int mod = (b_idx + 1) & 1;
        ans += sum_mod[mod][e_idx] - sum_mod[mod][b_idx];
        ans += (rope[b_idx] - s[i]);
        if((e_idx & 1) == mod){
          ans += (t[i] - rope[e_idx]);
        }
      }else{
        int mod = (e_idx) & 1;
        ans += sum_mod[mod][e_idx] - sum_mod[mod][b_idx];
        ans += (t[i] - rope[e_idx]);
        if(((b_idx + 1) & 1) == mod){
          ans += (rope[b_idx] - s[i]);
        }
      }
      //if(!rev) printf("%d->%d %lld\n", s[i], t[i], ans - tmp);
      //else printf("%d->%d %lld\n", t[i], s[i], ans - tmp);
    }
    cout<<ans<<endl;
  }

  return 0;
}

Measured memory_bytes: 3120
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int n,m,k;
int f(int a,int b){// ue kara a left kara b
	a%=2*m;
	rep(q,3){
		if(a){
			if(b==0&&a%2==0)a--;
			if(b==m-1&&a%2==0)a--;
		}
		int t=m-b-1;
		if(a%2!=b%2){
			if(a-t>=0){
				a-=t;
				b+=t;
			}else return b+a;
			if(a)a--;
		}
		t=b;
		if(a-t>=0){
			a-=t;
			b-=t;
		}else return b-a;
		if(a)a--;
		else return b;
	}
	return -1;
}
int main(){
	cin>>n>>m>>k;
	vi t(m);
	rep(i,m)t[f(n,i)]=i;
//	rep(i,m)cout<<t[i]<<" ";cout<<endl;
	vp in(k);
	rep(i,k){
		int a,b;
		cin>>a>>b;
		in[i]={-a,b};
	}
	sort(all(in));
	rep(i,k){
		int a=-in[i].first,b=in[i].second;
		int A=f(a,b),B=f(a,b-1);
//		cout<<A<<" "<<B<<endl;
		swap(t[A],t[B]);
	}
	rep(i,m)cout<<t[i]+1<<endl;
}
//4 3 2 1
//2 3 4 1

Measured memory_bytes: 5176
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
const ll mod = 1000000007;

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

    Graph to(n), cost(n);
    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        to[a].push_back(b);
        to[b].push_back(a);
        cost[a].push_back(1LL);
        cost[b].push_back(1LL);
    }

    vector<ll> dist0(n, -1LL), distN(n, -1LL);
    queue<ll> Q0, QN;

    dist0[0] = 0;
    Q0.push(0);
    while(!Q0.empty()) {
        
        ll v = Q0.front();
        Q0.pop();

        rep(i, to[v].size()) {
            
            ll u = to[v][i];
            
            if(dist0[u] != -1) {
                continue;
            }
            
            dist0[u] = dist0[v] + cost[v][i];
            Q0.push(u);
        }
    }

    distN[n-1] = 0;
    QN.push(n-1);
    while(!QN.empty()) {
        
        ll v = QN.front();
        QN.pop();

        rep(i, to[v].size()) {
            
            ll u = to[v][i];
            
            if(distN[u] != -1) {
                continue;
            }
            
            distN[u] = distN[v] + cost[v][i];
            QN.push(u);
        }
    }

    int cnt0 = 0, cntN = 0;
    rep(i, n) { 
        if(dist0[i] <= distN[i]) {
            cnt0++;
        }
        else {
            cntN++;
        }
    }

    if(cnt0 > cntN) {
        cout << "Fennec";
    }
    else {
        cout << "Snuke";
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 13824
#include<stdio.h>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>

using namespace std;
long long cnt;
int n;
int R[1000000];
vector<int> G;

void insertionSort(int R[],int n,int g){
	int key,j;
	for (int i = g; i < n; i++){
		key = R[i];
		j = i - g;
		while (j >= 0 && R[j] > key){
			R[j + g] = R[j];
			j -= g;
			cnt++;
		}
		R[j + g]=key;
	}
}

void shellSort(int R[], int n){
	for (int h = 1;;){
		if (h > n){
			break;
		}
		G.push_back(h);
		h = 3 * h + 1;
	}
	for (int i = G.size() - 1; i >= 0; i--){
		insertionSort(R, n, G[i]);
	}
}

int main(){
	cin >> n;
	int j;
	for (int i = 0; i < n; i++){
		scanf("%d", &R[i]);
	}
	int key;
	cnt = 0;
	shellSort(R,n);
	cout << G.size() << endl;
	for (int i = G.size() - 1; i >= 0; i--){
		printf("%d", G[i]);
		if (i)printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	for (int i = 0; i < n; i++){
		printf("%d\n", R[i]);
	}

}

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

int main()
{
    int a, b;
    cin >> a >> b;

    string ans;
    if (a < 0) {
        if (b < 0 && (b - a + 1) % 2) ans = "Negative";
        else if (b < 0) ans = "Positive";
        else ans = "Zero";
    }
    else ans = "Positive";

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
#define ll long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define F first
#define S second
#define ld long double
int const M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e9+10;
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
ll pow(ll a, ll b){ll res = 1;for(int i = 1; i<=b; ++i) res *= a;return res;}
ll isPrime(ll n){for(ll i=2; i<=sqrt(n); i++){if(n%i==0) return 0;}return 1;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll k;
	cin >> k;
	if(k%2) cout << (k/2)*(k/2 + 1);
	else cout << (k*k)/4;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define cst first
#define dur second
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e7 + 5, M = 2 * N + 5;

vector<int> res;
void KMP(const string &s, const string &k){
    res.clear();
    if (k.empty())
        return ;
    vector<int> tmp(k.size(), 0);
    for (int i = 1, j = 0; i < k.size(); ++i){
        while (j && k[j] != k[i])
            j = tmp[j - 1];
        if (k[j] == k[i])
            ++j;
        tmp[i] = j;
    }
    for (int i = 0, j = 0; i < s.size(); ++i){
        while (j && k[j] != s[i])
            j = tmp[j - 1];
        if (k[j] == s[i])
            ++j;
        if (j == k.size())
            res.push_back(i - j + 1);
    }
}

int n, m;

string a, b;

int f(){
    n = res.size();
    int mx = 0;
    int len = a.size();
    vector<int> sum(len, 0);
    for(auto i : res){
        if(i - m >= 0)
            sum[i] = sum[i - m] + 1;
        else sum[i] = 1;
        mx = max(mx, sum[i]);        
    }
    return mx;
}

int awl;

int main(){
    IO;
    cin >> a >> b;
    awl = a.size();
    m = b.size();
    while(a.size() <= m)
        a += a;
    a += a;
    a += a;
    KMP(a, b);
    int hna = f();
    a += a;
    a += a;
    KMP(a, b);
    if(f() > hna)return cout << -1 << endl, 0;
    if(n == 0)return cout << n << endl, 0;
    cout << hna << endl;
}

Measured memory_bytes: 150252
using System;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		string S = Console.ReadLine();
		// スペース区切りの整数の入力
		//出力
		if(S[0] == S[1] && S[2] == S[3] && S[0] == S[2]){
			Console.WriteLine("No");
		} else if(S[0] == S[1] && S[2] == S[3]){
			Console.WriteLine("Yes");
		} else if(S[0] == S[2] && S[1] == S[3]){
			Console.WriteLine("Yes");        
		} else if(S[0] == S[3] && S[1] == S[2]){
			Console.WriteLine("Yes");        
      	} else {
			Console.WriteLine("No");        
      	}
	}
}

Measured memory_bytes: 11092
#include<stdio.h>
#include<math.h>

int main(void)
{
   int n, d, x[200000], y[200000], i, a=0;
   double z;

   scanf("%d%d",&n,&d);
   for(i=0;i<n;i++)
      scanf("%d%d",&x[i],&y[i]);

   for(i=0;i<n;i++){
      z=sqrt(pow(x[i],2.0)+pow(y[i],2.0));
      if(z<=d)
         a++;
   }

   printf("%d\n",a);
   return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#include <stdint.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define int long long
typedef vector<int> vi;
typedef pair<int, int> pii;
const double PI = acos(-1.0);
const int mod = 1e9 + 7;
int pows(int a , int b){int res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
const int N = 1e4+5;
bool vis[N] ;
vector<int> v[N];


/* Iterative Function to calculate (x^y)%p in O(log y) */
int power(int x, unsigned int y, int p)
{
    int res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

void init() {
  ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
}
bool prime(int n)
{
    int c = 0;
    for(int i = 2 ; i*i <= n ; i++){
        if(n%i==0)
            c++;
    }
    if(c>0)
        return false;
    else
        return true;
}
void dfs(int s){
    vis[s]=true;
    for(int i = 0 ; i < v[s].size() ; i++){
        if(!vis[v[s][i]])
            dfs(v[s][i]);
    }
}
void solve(){
    int n ;
    cin >> n ;
    int a[n] ;
    rep(i,0,n)    cin >> a[i] ;
    int dp[n] ;
    dp[0] = 0 ;
    dp[1] = abs(a[1] - a[0]) ;
    rep(i,2,n){
        dp[i] = min((dp[i-2]+abs(a[i]-a[i-2])) , (dp[i-1] + abs(a[i] - a[i-1])));
    }
    cout << dp[n-1] << endl ;
}
int32_t main()
{
    init();
    int t=1;
    //cin>>t;
    clock_t launch=clock();

    while(t--)
    {
        solve();
    }

    clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
}


Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int d;
ll ans;
ll c[20];

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> d;
	for (int i = 1; i < 20; i++)c[i] = c[i - 1] * 10 + 9;
	for (int i = 2; i <= 18; i++) {
		for (int j = 0; j < (1 << (i / 2)); j++) {
			ll cnt = 1;
			ll k = 0;
			for (int l = 0; l < i / 2; l++) {
				int s = d / (ll)pow(10, l) % 10, t = k / (ll)pow(10, l) % 10;
				ll p = 0, q = 0;
				if (s < t)p = s + 10 - t, q = s - t;
				else p = s - t, q = s - t - 10;
				if (j&(1 << l)) {
					if (p)p = 10 - p;
					if (l == 0)cnt *= 10 - p - 1;
					else cnt *= 10 - p;
					k += c[i - 2 * l - 1] * p*(ll)pow(10, l);
				}
				else {
					if (q)q = -10 - q;
					if (p == 0)cnt = 0;
					else if (l == 0)cnt *= 10 - abs(q) - 1;
					else cnt *= 10 - abs(q);
					k += c[i - 2 * l - 1] * q*(ll)pow(10, l);
				}
			}
			if (i % 2)cnt *= 10;
			if (d == k)ans += cnt;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4120
#include<stdio.h>
#include<stdlib.h>

int main(){
  int N, i, j, tmp, minj,  t=0;
  int A[100];

  scanf("%d",&N);
  if( N<1 || 100<N ) exit(1);

  for( i=0 ; i<N ; i++ ){
    scanf("%d",&A[i]);
    if( A[i]<0 || 100<A[i] ) exit(1);
  }

  for( i=0 ; i<N ; i++ ){
    minj = i;

    for( j=i ; j<N ; j++ ){
      if( A[j] < A[minj] ) minj = j;
    }

    if(minj != i){
      tmp = A[i];
      A[i] = A[minj];
      A[minj] = tmp;
      t++;
    }
  }

  for( i=0 ; i<N-1 ; i++ ){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);
  printf("%d\n",t);

  return 0;
}

Measured memory_bytes: 600
// https://atcoder.jp/contests/agc031/tasks/agc031_a

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define MODI (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (const auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// long gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// long lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string str;
    cin >> n;
    cin >> str;
    map<char, int> mp;

    // 文字に重複がなければ、n^(文字数)
    // 文字に重複があれば、abcaの場合はaはなし、先頭、末尾の3通り、bとcは有無の2通り
    for (const auto &x : str) {
        // 見つからない場合
        if (mp.find(x) == mp.end()) {
            mp[x] = 1;
        } else {
            mp[x]++;
        }
    }
    long ans = 1;
    for (const auto &x : mp) {
        ans = (ans * (x.second + 1)) % MODI;
    }

    // 0文字を除外
    cout << ans - 1 << endl;

    return 0;
}


Measured memory_bytes: 512
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto t = readln.split.to!(int[]), s = t.sum;
  auto m = readln.chomp.to!size_t;
  foreach (_; 0..m) {
    auto rd = readln.splitter;
    auto p = rd.front.to!size_t-1; rd.popFront();
    auto x = rd.front.to!int;
    writeln(s - t[p] + x);
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// debug
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}
#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif


int main() {
  ll N; cin >> N;

  ll ans = 1;
  while (N > 0) {
    N /= 2;
    ans *= 2;
  }
  cout << ans-1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int is(string str) 
{ 
    int l = 0; 
    int h = str.length() - 1; 
    while (h > l) 
    { 
        if (str[l++] != str[h--]) 
        { 
            return 0; 
        } 
    } 
   return 1;
}
int main()
{
    string s,x,y;
  int n,m,ans=0;
  cin>>s;
  n=s.length();
  x=s.substr(0,(n-1)/2);
  y=s.substr((n+1)/2,n);
  if(is(s) && is(x) && is(y))
  cout<<"Yes\n";
  else
  cout<<"No\n";

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n,m;
  cin >> n >> m;
  vector<set<ll>> E(n);
  for(ll i=0;i<m;i++) {
    ll a,b;
    cin >> a >> b;a--,b--;
    E[a].insert(b);
    E[b].insert(a);
  }
  deque<ll> q;
  set<ll> cnt;
  q.push_front(0);
  cnt.insert(0);
  while(1) {
    ll f=q.front();
    for(ll t:E[f]) {
      if(cnt.count(t)) continue;
      else {
        cnt.insert(t);
        f=t;
        break;
      }
    }
    if(f==q.front()) break;
    else q.push_front(f);
  }
  while(1) {
    ll f=q.back();
    for(ll t:E[f]) {
      if(cnt.count(t)) continue;
      else {
        cnt.insert(t);
        f=t;
        break;
      }
    }
    if(f==q.back()) break;
    else q.push_back(f);
  }
  cout << q.size() << endl;
  while(q.size()) {
    cout << q.front()+1;
    q.pop_front();
    if(q.size()) cout << " ";
  }
  cout << endl;
}

Measured memory_bytes: 20352
#include<bits/stdc++.h>
using namespace std;
string s;
int a,b;
int main() {
	cin >> s;
	for(int i=0; i<s.length(); i++) {
		if(s[i]=='0') a++;
		else b++;
	}
	printf("%d\n",min(a,b)*2);
	
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
  int n;
  double x,y;
  int cnt = 1;  
  while( cin >> n,n ){
    double sum = 0;
    cin >>  x >> y;
    double oldx = x,oldy = y;
    double fx = x,fy = y;
    for(int i = 1 ; i <= n ; i++ ){
      if(i == n){
    sum+= (oldx - fx)*(oldy + fy);
    break;
      }
      cin >>  x >> y;
      sum += (oldx - x)*(oldy + y);
      oldx = x;
      oldy = y;
    }
    printf("%d %.1f\n",cnt,fabs(sum/2));
    cnt++; 
  }
  return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    bool b=false;
    int cnt=0,ans=0;
    for(int i = 0;i < n;i ++){
        int p;
        cin >> p;
        if(p==i+1){
            b = 1;
            cnt ++;
        }else{
            ans += cnt/2+cnt%2;
            b = 0;
            cnt = 0;
        }
    }
    ans += cnt/2+cnt%2;
    cout << ans << endl;
    return 0;
}

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

using std::pair;
using std::vector;
using std::string;

typedef long long ll;
typedef pair<int, int> pii;

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 10000;

int n;
ll c0, c1;
int a[N + 5], b[N + 5];

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(n);
    for(int i = 1; i <= n; ++i) read(a[i]); 
    for(int i = 1; i <= n; ++i) read(b[i]);
    for(int i = 1; i <= n; ++i) {
        if(a[i] < b[i]) {
            c0 += (b[i] - a[i] + 1) / 2;
            c1 += (b[i] & 1) != (a[i] & 1);
        } else {
            c1 += a[i] - b[i];
        }
    }
    puts(c0 >= c1 ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 int main(){


while(1){
int x, y;
cin>>x>>y;
if(x == 0 && y == 0) break;
 
if(x > y) swap(x, y);
cout<<x<<" "<<y<<endl;
}

return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vll a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (i == n - 1) {
      ans += a[i];
    } else if (a[i] <= 0 && a[i + 1] <= 0) {
      ans -= a[i] + a[i + 1];
      i++;
    } else if (a[i] <= 0 && a[i + 1] > 0) {
      ans += abs(a[i] + a[i + 1]);
      i++;
    } else {
      ans += a[i];
    }
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

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

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> maze(h);
    int cnt = 0;
    for (int i = 0; i < h; ++i) {
        cin >> maze[i];
        for (int j = 0; j < w; ++j) {
            if(maze[i][j] == '.') cnt++;
        }
    }
    int dis[50][50] = {};
    queue<pii> que;
    que.push(pii(0, 0));
    dis[0][0] = 1;
    while(!que.empty()){
        pii p = que.front();
        que.pop();
        for (int i = 0; i < 4; ++i) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if(nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
            if(maze[nx][ny] ==  '#') continue;
            if(dis[nx][ny] > 0) continue;
            dis[nx][ny] = dis[p.first][p.second] + 1;
            que.push(pii(nx, ny));
        }
    }
    if(dis[h-1][w-1] == 0) cout << -1 << endl;
    else cout << cnt - dis[h-1][w-1] << endl;
}

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


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

    string s;
    cin >> s;

    int red = 0;
    for (char c : s) red += c=='R';

    int ans = 0;
    for (int i = 0; i < red; i++) ans += s[i]=='W';

    cout << ans << endl;

//    bool red = false;
//    int answ = 0;
//    for (int i = n-1; i >= 0; i--) {
//        if (s[i]=='R') red = true;
//        else answ += red;
//    }
//
//    bool white = false;
//    int ansr = 0;
//    for (int i = 0; i < n; i++) {
//        if (s[i]=='W') white = true;
//        else ansr += white;
//    }

//    cout << min(answ, ansr) << endl;

    return 0;
}


Measured memory_bytes: 3720