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

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pr(a, b) pair<a, b>
#define si set<int>
#define sl set<long long>
#define pq prioirty_queue
#define all(v) v.begin(),v.end()
#define left (2*idx)+1
#define right (2*idx)+2
#define frt(i,a,b) for(ll i=a; i<b; i++)
#define rew(i,a,b) for(ll i=a; i>=b; i--)
#define fre(i,a,b) for(ll i=a; i<=b; i++)
#define pb push_back

#define test if(true)


int main()
{
    ll l, r;
    cin >> l >> r;

    ll lft = l/2019;
    if(l%2019 == 0)
    {
        lft-=1;
    }
    ll rgt = r/2019;

    if(rgt - lft + 1 > 1)
    {
        cout << 0 << "\n";
        return 0;
    }

    ll mn = 2020;
    frt(i, l, r+1)
    {
        frt(j, i+1, r+1)
        {
            mn = min(mn, (i * j)%2019);
        }
    }

    cout << mn << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main() {
	int mf, df, ms, ds;
	cin >> mf >> df >> ms >> ds;
	if (ms == mf + 1 && ds == 1) {
		cout << '1' << endl;
	}
	else if (mf == 12 && df == 31) {
		cout << '1' << endl;
	}
	else {
		cout << '0' << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N;
	cin >> N;
	vector<LP> ratioa(N);
	rep(i,N)cin >> ratioa[i].first >> ratioa[i].second;
	ll t = 1, a = 1;
	rep(i,N){
		ll need_t = t / ratioa[i].first + (t % ratioa[i].first != 0);
		ll need_a = a / ratioa[i].second + (a % ratioa[i].second != 0);
		t = ratioa[i].first * max(need_t, need_a);
		a = ratioa[i].second * max(need_t, need_a);
		//printf("[%d]->[T = %lld, A = %lld]\n", i+1, t, a);
	}
	cout << t + a << endl;
	return 0;
}


Measured memory_bytes: 3628
a, b, c = map(int, input().split())
res = 'NO'
if a == 5:
    if b==5:
        if c==7:
            res = 'YES'
    if b==7:
        if c==5:
            res = 'YES'
if b == 5:
    if a==5:
        if c==7:
            res = 'YES'
    if a==7:
        if c==5:
            res = 'YES'
if c == 5:
    if a==5:
        if b==7:
            res = 'YES'
    if a==7:
        if b==5:
            res = 'YES'
if res != 'YES':
    print('NO')
else:
    print(res)


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

int main(){
int64_t A,B,C,K; cin >> A >> B >> C>> K;
if(abs(A - B)> pow(10,18)){
  cout << "Unfair" << endl;
}
else{
if(K % 2 ==0){
    cout << A - B << endl;
  }
else{
    cout << B - A <<endl;
  }

}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int INF = 1e9;
int main(){
    int N;
    cin >> N;
    vector<int> P(N);
    for(int i = 0; i < N; i++) {
        cin>> P[i];
    }
    int count = 0;
    int M = N;
    for(int i = 0; i < N; i++){
        if(M >= P[i]) {
            M = P[i];
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 1024
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>
#include <bitset>
#include <chrono>
#include <cstdlib>

using namespace std;
using namespace std::chrono;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()

class solver {
public:
	int D;
	vector<ll> c;
	vector<vector<ll>> s;

	void init() {
		cin >> D;
		c.resize(26);
		s.resize(D);
		rep(i, 26) {
			cin >> c[i];
		}
		rep(j, D) {
			s[j].resize(26);
			rep(i, 26) {
				cin >> s[j][i];
			}
		}
	}

	vector<ll> calc(const vector<int>& t) const {
		vector<int> last(26);
		auto down = [&last, this](int d) {
			d++;
			ll v = 0;
			rep(i, 26) {
				v += c[i] * (d - last[i]);
			}
			return v;
		};
		int N = t.size();
		vector<ll> v(N);
		rep(i, N) {
			if (i > 0)
				v[i] = v[i - 1];
			v[i] += s[i][t[i]];
			last[t[i]] = i + 1;
			v[i] -= down(i);
		}
		return v;
	}

	vector<int> greedy() const {
		vector<pair<ll, int>> cs;
		rep(i, 26) {
			cs.emplace_back(c[i], i);
		}
		sort(all(cs), greater<pair<ll, int>>());

		vector<vector<pair<ll, int>>> ss(D);
		rep(j, D) {
			rep(i, 26) {
				ss[j].emplace_back(s[j][i], i);
			}
			sort(all(ss[j]), greater<pair<ll, int>>());
		}

		vector<int> ans;
		ll score = 0;
		for (auto& i : ss) {
			vector<int> ts(ans);
			ts.push_back(i[0].second);
			auto as = calc(ts);
			vector<int> tc(ans);
			tc.push_back(cs[0].second);
			auto ac = calc(tc);
			if (as.back() > ac.back()) {
				ans.push_back(i[0].second);
				score = as.back();
			}
			else {
				ans.push_back(cs[0].second);
				score = ac.back();
			}
		}

		/*
t[1..D] = 初期解(ランダム生成や、貪欲法で求めたものを利用)
while 時間のある限り:
	d と q をランダムに選ぶ。
	old = t[d] # 後で戻せるように元の値を記憶しておく
	t[d] = q
	if 変形前より解が悪化:
		t[d] = old
		*/
		system_clock::time_point start = system_clock::now();
		auto t = ans;
		for (;;) {
			system_clock::time_point now = system_clock::now();
			double elapsed = duration_cast<milliseconds>(now - start).count();
			if (elapsed > 1900)
				break;

			auto old = t;
			int d = rand() % D;
			int q = rand() % 26;
			t[d] = q;
			auto tmp = calc(t);
			
			if (score < tmp.back()) {
				score = tmp.back();
			}
			else {
				// rollback
				t = old;
			}
		}
		ans = t;
		return ans;
	}
};

int main()
{
	solver solver;
	solver.init();
	auto ans = solver.greedy();
	for (auto t : ans) {
		cout << (t + 1) << endl;
	}
	return 0;
}


Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;
const int maxn = 3e5 + 5;

void go() {
    int n;
    cin >> n;
    f(n) {
        cout << "ACL";
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
}

Measured memory_bytes: 3640
n,m = [int(x) for x in input().split()]
a=[]
b=[]
for i in range(n): a.append([int(x) for x in input().split()])
for j in range(m): b.append(int(input()))
for a_row in a:
    print(sum([x*y for x,y in zip(a_row,b)]))


Measured memory_bytes: 6012
import sys
x,n = map(int,input().split())
if(n == 0):
  print(x)
  sys.exit()
l = [int(v) for v in input().split()]
fl2 = False
for k in range(n):
  if(l[k] == x):
    fl2 = True
if (fl2 == False):
  print(x)
  sys.exit()
x1 = x
x2 = x
for i in range(n):
  flg1 = True
  flg2 = True
  ans1 = x1 - 1
  ans2 = x2 + 1
  for m in range(n):
    if(l[m] == ans1):
      x1 = x1 - 1
      flg1 = False
  if (flg1 == True):
    print(ans1)
    sys.exit()
  for o in range(n):
    if(l[o] == ans2):
      x2 = x2 + 1
      flg2 = False
  if (flg2 == True):
    print(ans2)
    sys.exit()
  
  

Measured memory_bytes: 9240
#include <vector>
#include <iostream>
#include <math.h>

using namespace std;


int main() {

	int n,tmp;
	vector<double> x;
	double y, d1 = 0, d2 = 0, d3 = 0, di = 0;
	cout.precision(15);

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> tmp;
		x.push_back(tmp);
	}

	for (int i = 0; i < n; i++)
	{
		cin >> y;
		d1 += fabs(x[i] - y);
		d2 += pow(fabs(x[i] - y), 2);
		d3 += pow(fabs(x[i] - y), 3);
		if (di < fabs(x[i] - y)) di = fabs(x[i] - y);
	}
	cout << d1 << endl;
	cout << sqrt(d2) << endl;
	cout << pow(d3, (1.0 / 3.0)) << endl;
	cout << di << endl;

	return 0;
}

Measured memory_bytes: 1368
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val D = sc.next().toLong()
        var ans = 0
        repeat(N) {
            val X = sc.next().toLong()
            val Y = sc.next().toLong()
            if (X * X + Y * Y <= D * D) {
                ans++
            }
        }
        pw.println(ans)
    }
}


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

using namespace std;

bool dd[5][5];
int d[5][5];

int main() {
	for (int i=1; i<=3; i++) {
		for (int j=1; j<=3; j++) scanf("%d",&d[i][j]);
	}
	int n; scanf("%d",&n);
	while (n--) {
		int k; scanf("%d",&k);
		for (int i=1; i<=3; i++) {
			for (int j=1; j<=3; j++) {
				if (d[i][j]==k) dd[i][j]=1;
			}
		}
	}
	
	bool istrue=1, istrue2=1;
	for (int i=1; i<=3; i++) {
		istrue=1, istrue2=1;
		for (int j=1; j<=3; j++) {
			if (!dd[i][j]) istrue=0;
			if (!dd[j][i]) istrue2=0;
		}
		if (istrue || istrue2) {
			printf("Yes\n");
			return 0;
		}	
	}
	if (dd[1][1] && dd[2][2] && dd[3][3]) {
		printf("Yes\n");
		return 0;
	}
	if (dd[3][1] && dd[2][2] && dd[1][3]) {
		printf("Yes\n");
		return 0;
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const inputs = input.trim().split('\n');
const adj = inputs.map((s) => s.split(' ').map(Number));

class Edge {
  constructor(dest, weight = 1) {
    this.dest = dest;
    this.weight = weight;
  }
}

class Node {
  constructor() {
    this.list = [];
  }
  addEdge(edge) {
    this.list.push(edge);
  }
  isOdd() {
    return !!(this.list.length % 2);
  }
}

class Graph {
  constructor() {
    this.init();
  }
  init() {
    this.map = new Map();
  }
  getNode(source, edge) {
    if (!this.map.has(source)) {
      this.map.set(source, new Node());
    }
    return this.map.get(source);
  }
  addEdge(source, edge) {
    const node = this.getNode(source);
    node.addEdge(edge);
  }
  countOdd() {
    return Array.from(this.map.values()).map(node => node.isOdd() ? 1 : 0).reduce((a, b) => a + b);
  }
  canPatrol() {
    const totalOddCount = graph.countOdd();
    if (totalOddCount === 0) {
      return false;
    } else if (totalOddCount === 2 && (graph.getNode(1).isOdd() && graph.getNode(2).isOdd())) {
      return true;
    }
    return false;
  }
}

const graph = new Graph();
adj.forEach(([source, dest]) => {
  if (source === 0 && dest === 0) {
    console.log(graph.canPatrol() ? 'OK' : 'NG');
    graph.init();
    return;
  }
  graph.addEdge(source, new Edge(dest));
  graph.addEdge(dest, new Edge(source));
});



Measured memory_bytes: 18612
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#define int long long
using namespace std;
typedef double db;
const int maxn = 3e5+5;
struct line {
	int k,b;
	int gf(int x) {
		return k*x + b;
	}
};
db gj(line a,line b) {
	return 1.0*(a.b-b.b)/(b.k-a.k);
}
int n,m;
int a[maxn];
int QZ[maxn],HZ[maxn],sm[maxn];
int tp; line st[maxn];
void dpit(int *f) {
	sm[0] = 0;
	tp = 1; st[1] = (line){0,0};
	for(int i=1;i<=n;i++) {
		sm[i] = sm[i-1] + a[i];
		while(tp>1&&st[tp].gf(i) <= st[tp-1].gf(i) ) tp--;
		f[i] = max(f[i-1],st[tp].gf(i) + (i*(i+1))/2 - sm[i]);
		line now = (line) { -i , f[i] + i*(i-1)/2 + sm[i] };
		while(tp>1&&gj(st[tp],st[tp-1])<=gj(st[tp-1],now)) tp--;
		st[++tp] = now;
	}
}
int H[maxn];
void DC(int l,int r) {
	if(l==r) {
		H[l] = 1 - a[l];
		return;
	}
	int mid = (l+r)>>1;
	DC(l,mid); DC(mid+1,r);
	tp = 0;
	for(int i=l-1;i<mid;i++) {
		line now = (line) { -i , QZ[i] + i*(i-1)/2 + sm[i] };
		while(tp>1&&gj(st[tp],st[tp-1])<=gj(st[tp-1],now)) tp--;
		st[++tp] = now;
	}
	int mx = -1e18;
	int yo = 1;
	for(int i=r;i>mid;i--) {
		while(yo<tp&&gj(st[yo],st[yo+1])>=i) yo++;
		mx = max(st[yo].gf(i) + (i+1)*i/2 - sm[i] + HZ[i+1] , mx );
		H[i] = max(mx,H[i]);
	}
	tp = 0;
	for(int i=mid+1;i<=r;i++) {
		line now = (line) { -i , HZ[i+1] + i*(i+1)/2 - sm[i] };
		while(tp>1&&gj(st[tp],st[tp-1])<=gj(st[tp-1],now)) tp--;
		st[++tp] = now;
	}
	mx = -1e18;
	yo = tp;
	for(int i=l-1;i<mid;i++) {
		while(yo>1&&gj(st[yo],st[yo-1])<=i) yo--;
		mx = max(st[yo].gf(i) + (i-1)*i/2 + sm[i] + QZ[i] , mx );
		H[i+1] = max(mx,H[i+1]);
	}
}
main() {
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) {
		scanf("%lld",&a[i]);
	}
	dpit(QZ);
	reverse(a+1,a+1+n);
	dpit(HZ);
	reverse(a+1,a+1+n);
	reverse(HZ+1,HZ+1+n);
	cerr<<QZ[3]<<endl;
	for(int i=1;i<=n;i++) {
		sm[i] = sm[i-1] + a[i];
	}
	DC(1,n);
	scanf("%lld",&m);
	for(int i=1;i<=m;i++) {
		int p,x;
		scanf("%lld%lld",&p,&x);
		printf("%lld\n",max(QZ[p-1]+HZ[p+1],H[p]+a[p]-x));
	}
}

Measured memory_bytes: 16896
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
    int a,b;
    vector<int> count(5,0);
    for(int i = 0; i < 3; i++){
        cin >>a >>b;
        count[a]++;
        count[b]++;
    }

    bool solve = true;
    for(int i = 1; i <= 4; i++){
        if(count[i] > 2){
            solve = false;
        }
    }

    if(solve){
        printf("YES\n");
    }else{
        printf("NO\n");
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		long[] arr = new long[N];
		long X = 0;
		long Y = 0;
		for (int i = 0; i < N; i++) {
			arr[i] = reader.nextLong();
		}
		Arrays.sort(arr);
		for (int i = N-1; i > 0; i--) {
			if (X == 0 && arr[i] == arr[i-1]) {
				X = arr[i];
				i--;
			}
			else if (X != 0 && arr[i] == arr[i-1]) {
				Y = arr[i];
				break;
			}
		}

		System.out.println(X*Y);
		reader.close();
	}


}





Measured memory_bytes: 49864
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
	int n,k;
	string s;
	cin>>n>>k>>s;
	if(s[k-1]=='A'){
		s[k-1]='a';
	}else if(s[k-1]=='B'){
		s[k-1]='b';
	}else{
		s[k-1]='c';
	}
	cout<<s<<endl;
	return 0;
}

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

int main() {
  int n;
  int count=0;
  cin >> n;
  int a[200010],b[200010];
  for (int i=1; i<=n; i++) cin >> a[i];
  for (int i=n; i>0; i--){
    int s=a[i];
    for(int j=2; j<=n/i; j++) s += b[i*j];
    s = s%2;
    b[i] = s;
    count += s;
  }
  cout << count << endl;
  for (int i=1; i<=n; i++) {
    if(b[i] == 1) cout << i << " ";
  }
}


Measured memory_bytes: 2432
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#define N 50000
int main() {
	int i, j, cnt, p[N] = { 0 }, n;
	for (i = 2; i <= (int)sqrt((double)N); ++i) if (!p[i]) for (j = 2; j*i < N; j++) p[i*j] = 1;
	while (1) {
		scanf("%d", &n);
		if (n == 0) break;
		cnt = 0;
		for (i = 2; i <= n/2; i++) if (!p[i]&&!p[n - i]) cnt++;
		printf("%d\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 800
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

struct edge{
  ll to, cap, rev;
  edge(){}
  edge(ll a, ll b, ll c){to = a; cap = b; rev = c;}
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, K;
  cin >> N >> K;
  vector<vector<edge>> G(N, vector<edge>(0));
  while(K--){
    ll u, v, c;
    cin >> u >> v >> c;
    G.at(u).push_back(edge(v, c, G.at(v).size()));
    G.at(v).push_back(edge(u, 0, G.at(u).size()-1));
  }
  vll flag(N, 0);
  function<ll(ll, ll, ll)> dfs = [&](ll v, ll goal, ll f){
    if(v == goal) return f;
    flag.at(v) = 1;
    for(int i = 0; i < sz(G.at(v)); i++){
     edge &e = G.at(v).at(i);
     if(flag.at(e.to) || e.cap <= 0) continue;
     ll d = dfs(e.to, goal, min(f, e.cap));
     if(d > 0){
       e.cap -= d;
       G.at(e.to).at(e.rev).cap += d;
       return d;
     }
    }
    return 0LL;
  };
  ll ans = 0;
  while(true){
    fill(ALL(flag), 0);
    ll d = dfs(0, N-1, INF);
    if(d <= 0) break;
    ans += d;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3272
/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-11-4 21:27:34
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
const ll M = 1000000007;

ll H, W, K;

ll cnt[10];
ll S[10];
ll T[10];

ll DP[110][10];

int main()
{
  cin >> H >> W >> K;
  K--;
  cnt[0] = 1;
  cnt[1] = 2;
  for (auto i = 2; i < 10; i++)
  {
    cnt[i] = cnt[i - 1] + cnt[i - 2];
  }
  for (ll i = 0; i < 10; i++)
  {
    S[i] = cnt[max(i - 1, 0ll)] * cnt[max(W - i - 3, 0ll)];
    T[i] = cnt[max(i - 1, 0ll)] * cnt[max(W - i - 2, 0ll)];
  }
  DP[0][0] = 1;
  for (auto i = 1; i < W; i++)
  {
    DP[0][i] = 0;
  }
  for (auto i = 1; i <= H; i++)
  {
    for (auto j = 0; j < W; j++)
    {
      DP[i][j] = DP[i - 1][j] * T[j];
      DP[i][j] %= M;
      if (j - 1 >= 0)
      {
        DP[i][j] += DP[i - 1][j - 1] * S[j - 1];
        DP[i][j] %= M;
      }
      if (j + 1 < W)
      {
        DP[i][j] += DP[i - 1][j + 1] * S[j];
        DP[i][j] %= M;
      }
    }
  }
  cout << DP[H][K] << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;

const double PI  = 3.141592653589793238463;

int main() {
    int n, sum = 0;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
        sum += v[i];
    }
    int m, a, b;
    cin >> m;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        cout << sum - (v[a-1] - b) << endl;
    }
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        long a = in.nextLong();
        long b = in.nextLong();

        long x = calc(a - 1) ^ calc(b);
        out.println(x);
    }

    private long calc (long a) {
        if (a < 0) a = 0;

        long[] ret = new long[] {a, 1, a+1, 0};
        return ret[(int)(a % 4)];
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}


Measured memory_bytes: 21204
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		String s = scanner.next();
		String p = scanner.next();
		
		String out = "No";
		for(int i=0; i<s.length(); i++)
		{
			String str = "";
			for(int j=0; j<p.length(); j++)
			{
				int k = i+j;
				if(k >= s.length())
				{
					k -= s.length(); 
				}
				str += s.substring(k, k+1);
			}
			
			if(p.equals(str))
			{
				out = "Yes";
				break;
			}
		}
		System.out.println(out);
	}
}

Measured memory_bytes: 27232
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line = reader.readLine();
		String[] sarray = line.split(" ", -1);
		int n = Integer.parseInt(sarray[0]);//?????°
		int m = Integer.parseInt(sarray[1]);//?????°
		int matrix[][] = new int[n + 1][m + 1];
		for(int i = 0; i < n; i++){//?????????????????????
			String str = reader.readLine();
			String[] mat = str.split(" ", -1);
			for(int j = 0; j < m; j++){
				matrix[i][j] = Integer.parseInt(mat[j]);
				while(i == 0){
					matrix[n][j] = 0;
					break;
				}
			}
			matrix[i][m] = 0;
		}
		matrix[n][m] = 0;
		for(int k = 0; k < n; k++){
			for(int l = 0; l < m; l++){
				matrix[k][m] += matrix[k][l];//??????????¨?
			}
		}
		for(int p = 0; p < m; p++){
			for(int q = 0; q < n; q++){
				matrix[n][p] += matrix[q][p];//??????????¨?
				while(p == 0){
					matrix[n][m] += matrix[q][m];
					break;
				}
			}
		}
		for(int r = 0; r < n + 1; r++){
			for(int s = 0; s < m; s++){
				System.out.print(matrix[r][s] + " ");
			}
			System.out.println(matrix[r][m]);
		}
	}
}

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

#define endl '\n'

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

    int n, z, w;
    cin >> n >> z >> w;
    vector <int> A(n);
    
    int mn, mx;
    for(int i = 0 ; i < n; i++) {
      cin >> A[i];
    }
    if(n == 1) cout << abs(A[0] - w);
    else cout << max(abs(A[n - 1] - w), abs(A[n - 2] - A[n - 1]));


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;
template<typename T> T factorial(T n){
    if(n==1) return 1;
    else return n*factorial(n-1);
}
template<typename T> T combination(T n, T k){
    vector<vector<T>> v(n+1, vector<T>(n+1, 0)); //dpテーブル
    rep(i, v.size()){
        v[i][0] = 1; v[i][i] = 1;
    }
    for(int j=1; j<v.size(); j++){
        for(int k=1; k<j; k++){
            v[j][k] = v[j-1][k-1] + v[j-1][k];
        }
    }
    return v[n][k];
}
struct edge{
    int to; // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using graph = vector<vector<edge>>;
using Graph = vector<vector<int>>;

int main(){
    int n, m, q; cin >> n >> m >> q;
    vector<vector<int>> city(n+1, vector<int>(n+1, 0));
    int left, right, tmp;
    rep(i, m){
        cin >> left >> right;
        city[left][right] += 1;
    }
    rep(i, n+1){
        rep(j, n){
            city[i][j+1] += city[i][j];
        }
    }
    int q_left, q_right;
    int ans;
    rep(i, q){
        cin >> q_left >> q_right;
        ans = 0;
        for(int j=q_left; j<=q_right; j++){
            ans += city[j][q_right] - city[j][q_left-1];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1920
#include<iostream>
using namespace std;
int main()
{
	int n,x,i;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>x;
		if(x%2==0&&x%3!=0&&x%5!=0)
			break;
	}
	if(i<=n)
		cout<<"DENIED"<<endl;
	else cout<<"APPROVED"<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }

        Arrays.sort(a);
        Arrays.sort(b);
        if (n % 2 == 0) {
            double amed = (double) (a[n/2 - 1] + a[n/2]) / 2;
            double bmed = (double) (b[n/2 - 1] + b[n/2]) /2;
            int ans =(int)( (bmed - amed + 0.5) * 2);
            System.out.println(ans);
        } else {
            int amed = a[(n + 1)/2 - 1];
            int bmed = b[(n + 1)/2 - 1];
            System.out.println(bmed - amed + 1);
        }
    }

}


Measured memory_bytes: 61696
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 1000001

bool is_prime[MAX];

void Sieve() {
  
  is_prime[0] = is_prime[1] = 0;
  for(int i=2; i<MAX; i++) is_prime[i] = 1;
  
  for(int i=2; i*i<MAX; i++) {
    if(is_prime[i]) {
      for(int j=2*i; j<MAX; j+=i) {
	is_prime[j] = 0;
      }
    }
  }
}

int main() {
  
  Sieve();
  
  int n, a, b;
  while(cin >> n >> a, n+a) {
    bool c[MAX] = {};
    c[0] = 1;
    for(int i=0; i<n; i++) {
      cin >> b;
      for(int j=b; j<MAX; j++) {
	c[j] = c[j] | c[j-b];
      }
    }
    
    int mx = -9999;
    for(int i=0; i<=a; i++) {
      if(c[i] && is_prime[i]) mx = max(mx, i);
    }
    if(mx == -9999) cout << "NA" << endl;
    else cout << mx << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3120
// Copyright 2017 Parallelc
#include <bits/stdc++.h>

#include <ext/numeric>
#include <ext/rope>
using namespace __gnu_cxx;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace __gnu_pbds;
template<typename T>
using pbq = priority_queue<T>;
template<typename T>
using rbt = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using namespace std;

#include <tr2/dynamic_bitset>
using namespace tr2;
using db = dynamic_bitset<>;

template <typename T> 
bool in(T& x){
    x = 0; T f = 1; char ch = cin.get();
    while (!isdigit(ch)) {
        if (ch == -1) return false;
        if (ch == '-') f = -1; 
        ch = cin.get();
    }
    while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = cin.get();}
    x *= f; return true;
}
template <typename T, typename... S>
bool in(T& t, S&... s) {if(!in(t)) return false; return in(s...);}

using LL = int64_t;
const int INF = 0x3f3f3f3f;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    vector<LL> s(100005);
    int n;
    LL k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        LL a, b;
        cin >> a >> b;
        s[a] += b;
    }
    for (int i = 0; i < 100005; i++) {
        if (s[i] >= k) {
            cout << i << endl;
            return 0;
        }
        k -= s[i];
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>

using namespace std;

int main(){
    int x, y, z;
    cin >> x >> y >> z;
    std::swap(x, y);
    std::swap(x, z);
    cout << x << " " << y << " " << z << endl;

    return 0;
}


Measured memory_bytes: 768
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------

N, W = map(int, input().split())
WV = [[0,0]]+[ list(map(int, input().split())) for _ in range(N) ]

#p(WV)

dp = [[0 for w in range(W+1)] for _r in range(N+1)]

#print(dp)

for iN in range(1,N+1):
	w,v = WV[iN]
	for iW in range(W+1):
		
		v0 =     dp[iN-1][iW]
		v1 = v + dp[iN-1][iW-w] if iW-w>=0 else 0
		#p("w,v,v0,v1, ",w,v,v0,v1)
		
		dp[iN][iW] = max(v0, v1)

#p(dp)

print(dp[-1][-1])

Measured memory_bytes: 171784
use std::io;
use std::io::{stdout, BufWriter, Write};

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let out = stdout();
    let mut writer = BufWriter::new(out.lock());
    solve(&mut writer);
    writer.flush().unwrap();
}

fn solve<W: Write>(mut writer: W) {
    #[allow(unused_macros)]
    macro_rules! print {
        ($fmt:expr) => {
            write!(writer, $fmt).unwrap()
        };
        ($fmt:expr, $($arg:tt)*) => {
            write!(writer, $fmt, $($arg)*).unwrap()
        };
    }
    #[allow(unused_macros)]
    macro_rules! println {
        ($fmt:expr) => {
            writeln!(writer, $fmt).unwrap()
        };
        ($fmt:expr, $($arg:tt)*) => {
            writeln!(writer, $fmt, $($arg)*).unwrap()
        };
    }

    // Main Code
    let n: usize = read();
    let mut x = Vec::new();
    let mut y = Vec::new();
    let mut p = Vec::new();
    for i in 0..n {
        let data = read_vec::<i64>();
        x.push(data[0]);
        y.push(data[1]);
        p.push(data[2]);
    }
    let mut dist_x = vec![vec![0; 1 << n]; n];
    let mut dist_y = vec![vec![0; 1 << n]; n];
    for i in 0..1 << n {
        let mut b = vec![false; n];
        for j in 0..n {
            if ((1 << j) & i) != 0 {
                b[j] = true;
            }
        }
        for j in 0..n {
            let mut min = i64::abs(x[j]);
            for k in 0..n {
                if b[k] {
                    min = std::cmp::min(min, i64::abs(x[j]-x[k]));
                }
            }
            dist_x[j][i] = min * p[j];
        }
        for j in 0..n {
            let mut min = i64::abs(y[j]);
            for k in 0..n {
                if b[k] {
                    min = std::cmp::min(min, i64::abs(y[j]-y[k]));
                }
            }
            dist_y[j][i] = min * p[j];
        }
    }
    let mut pow = 1;
    for i in 0..n {
        pow *= 3;
    }
    let mut ans = vec![std::i64::MAX; n + 1];
    for i in 0..pow {
        let mut state = vec![0; n];
        let mut m = i;
        for j in 0..n {
            state[j] = m % 3;
            m /= 3;
        }
        let mut count = 0;
        let mut state_x = 0;
        let mut state_y = 0;
        for j in 0..n {
            if state[j] == 1 {
                count += 1;
                state_x += 1 << j;
            }
            else if state[j] == 2 {
                count += 1;
                state_y += 1 << j;
            }
        }
        let mut dist = 0;
        for j in 0..n {
            dist += std::cmp::min(dist_x[j][state_x], dist_y[j][state_y]);
        }
        ans[count] = std::cmp::min(ans[count], dist);
    }
    for i in 0..=n {
        println!("{}", ans[i]);
    }
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    LL a, b, q;cin >> a >> b >> q;
    vector<LL> s(a), t(b), x(q);
    inc(i, 0, a) cin >> s[i];
    inc(i, 0, b) cin >> t[i];
    inc(i, 0, q) cin >> x[i];
    inc(i, 0, q){
        //cout << i << endl;
        int ls = lower_bound(s.begin(), s.end(), x[i]) - s.begin()-1;
        int rs = upper_bound(s.begin(), s.end(), x[i]) - s.begin();
        int lt = lower_bound(t.begin(), t.end(), x[i]) - t.begin()-1;
        int rt = upper_bound(t.begin(), t.end(), x[i]) - t.begin();
        //cout << ls << " " << rs << " " << lt << " " << rt << endl;
        vector<LL> v;
        if(ls != -1 && lt != -1) v.pb(x[i] - min(s[ls], t[lt]));
        //for(auto vv : v) cout << vv << " ";
        //cout << endl;
        if(ls != -1 && rt !=  b) v.pb(min(x[i] - s[ls], t[rt] - x[i]) + (t[rt] - s[ls]));
        //for(auto vv : v) cout << vv << " ";
        //cout << endl;
        if(rs !=  a && lt != -1) v.pb(min(x[i] - t[lt], s[rs] - x[i]) + (s[rs] - t[lt]));
        //for(auto vv : v) cout << vv << " ";
        //cout << endl;
        if(rs !=  a && rt !=  b) v.pb(max(s[rs], t[rt]) - x[i]);
        //for(auto vv : v) cout << vv << " ";
        //cout << endl;


        cout << *min_element(v.begin(), v.end()) << endl;
    }
    return 0;
}


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

typedef long long ll;
typedef double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

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

    ll s;
    cin >> s;

    map <int, int> m;
    for (int i = 0; ; i++) {
        if (m[s]) {
            cout << i + 1 << '\n';
            return 0;
        }
        m[s] = 1;
        if (s & 1) s = 3*s + 1;
        else s = s/2;
    }
    return 0;
}


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

#define MAX 100005
#define NIL -1

struct Node{int parent, left, right; };

Node T[MAX];
int D[MAX];	// Depth

// プロトタイプ宣言
void Print(int u);
void rec(int u, int p);	// 再帰的に深さを求める関数
// ここまでプロトタイプ宣言

int main(){
	int n;	cin>>n;
	for(int i=0;i<n;i++) T[i].parent = T[i].left = T[i].right = NIL;

	int id,k,c,		l,r;
	for(int i=0;i<n;i++){
		cin>>id>>k;
		for(int j=0;j<k;j++){
			cin>>c;
			if(j==0)T[id].left=c;
			else T[l].right=c;
			l=c;	// 右に移動

			T[c].parent=id;
		}
	}

	for(int i=0;i<n;i++){
		if(T[i].parent == NIL) r=i;
			// 親を探す
	}
	rec(r,0);

	for(int i=0;i<n;i++)Print(i);

	return 0;
}





// 関数
void Print(int u){
	int i,c;
	cout<<"node "<<u<<": ";
	cout<<"parent = "<<T[u].parent<<", ";
	cout<<"depth = "<<D[u]<<", ";

	if(T[u].parent == NIL)cout<<"root, ";
	else if(T[u].left == NIL)cout<<"leaf, ";
	else cout<<"internal node, ";

	cout<<"[";

	for(i=0,c=T[u].left;	c!=NIL;		i++, c=T[c].right){
		if(i)cout<<", ";
		cout<<c;
	}
	cout<<"]"<<endl;
}


	// 深さを求める（再帰）
void rec(int u, int p){
	D[u]=p;
	if (T[u].right != NIL)	rec(T[u].right, p);
	if (T[u].left != NIL)	rec(T[u].left, p+1);
}



Measured memory_bytes: 7740
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> L;
	int i;
	for (i = 0; i < N; i++) {
		int l;
		cin >> l;
		L.push_back(l);
	}
	sort(L.begin(), L.end());
	int A = 0;
	for (i = 0; i < N - 1; i++) {
		A += L.at(i);
	}
	if (L.at(N - 1) < A) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

Measured memory_bytes: 256
n,m=map(int, input().split())
ab=[list(map(int,input().split())) for i in  range(n)]
cd=[list(map(int,input().split())) for i in  range(m)]
for i in range(n):
  Min=4*(10**8)+1
  for j in range(m):
    d = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
    #print(d,ab[i][0],cd[j][0])
    if Min > d:
      Min = d
      ans = j+1
  print(ans)

Measured memory_bytes: 8792
import sys
from bisect import bisect

def solve():
    input = sys.stdin.readline
    N = int(input())
    sum = [0] * 41
    for i in range(1, 41):
        sum[i] = sum[i-1] + i
    count = 0
    k = N
    for i in range(2, N + 1):
        if i ** 2 > k: break
        if k % i == 0:
            d = 0
            while k % i == 0:
                d += 1
                k //= i
            count += bisect(sum, d) - 1
    if k > 1: count += 1
    print(count)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9092
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        int sum = 0;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            sum += l + i;
            if(Math.abs(l + i) < Math.abs(min)) min = l + i;
        }
        System.out.println(sum - min);
        sc.close();

    }

}


Measured memory_bytes: 22868
while str=gets
    array=str.split(" ")
    a=array[0].to_i
    b=array[2].to_i
    op=array[1]
    if op =="+" then
        print(a+b,"\n")
    elsif op =="-" then
        print(a-b,"\n")
    elsif op =="*" then
        print(a*b,"\n")
    elsif op =="/" then
        print(a/b,"\n")
    elsif op =="?" then
        exit(0)
   end 
end

Measured memory_bytes: 8656
import java.util.*;

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

        int[] ans = new int[N];

        for (int i = 0; i < N-1; i++) {
            int tmp = sc.nextInt();
            ans[tmp-1]++;
        }

        for (int i = 0; i < N; i++) {
            System.out.println(ans[i]);
        }

    }
}

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

using namespace std;
//fold
#define ll long long
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define Loop(i, a, b) for(int i = a ; i < b ; ++i)
#define loop(i, n) Loop(i, 0, n)
#define ff first
#define ss second
#define mkp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<pii>
#define vvii vector<vii>
#define vl vector<ll>
#define vvl vector<vl>
#define pll pair<ll, ll>
#define vll vector<pll>
#define vvll vector<vll>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define nmbr(c) (int)(c-'0')
#define ltr(c) (int)(c-'a')
#define INF 1e18+5
#define inf 1e9+5
#define M 1000000007 //check
#define _69e27 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

template <typename T> T max(T a, T b, T c){ return max(a, max(b, c));}
template <typename T> T min(T a, T b, T c){ return min(a, min(b, c));}
//endfold

int main() {
	_69e27;
	int n, m;
	cin >> n >> m;
	vi s(n), t(m);
	loop(i, n) cin >> s[i];
	loop(i, m) cin >> t[i];
	vvl dp(n+5, vl (m+5, 1));
	Loop(i, 1, n+1)
	{
		Loop(j, 1, m+1)
		{
			dp[i][j] = dp[i-1][j] + dp[i][j-1];
			if(s[i-1] != t[j-1]) dp[i][j] += M - dp[i-1][j-1];
			dp[i][j] %= M;
		}
	}

	cout << dp[n][m]%M << endl;
	return 0;
}

Measured memory_bytes: 31744
#include <iostream>
#include <string>

using namespace std;

int main() {

	string s;
	cin >> s;

	int n = s.size();
	for (int i = 0; i < n; ++i) {
		if (s[i] == 'A' && s[i+1] == 'C') {
			cout << "Yes" << endl;
			n = 0;
			break;
		}
	}
	if (n != 0) {
		cout << "No" << endl;
	}
}
	

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


int dfs(long long N, long long M, long long Q, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c, std::vector<long long> d, int i, std::vector<long long> e) {
    if (i == N) {
        // for (int k = 0; k < N; k++) {
        //     printf("%lld ", e[k]);
        // }
        int ans = 0;
        for (int k = 0; k < Q; k++) {
            if (e[b[k]-1] - e[a[k]-1] == c[k]) {
                ans += d[k];
            }
        }
        // printf(": %d\n", ans);
        return ans;
    }

    int ans = 0;
    for (int j = (i == 0 ? 1 : e[i-1]); j <= M; j++) {
        e[i] = j;
        ans = max(ans, dfs(N, M, Q, a, b, c, d, i+1, e));
    }
    return ans;
}

void solve(long long N, long long M, long long Q, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c, std::vector<long long> d){
    std::vector<long long> e(N);
    cout << dfs(N, M, Q, a, b, c, d, 0, e) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> a(Q);
    std::vector<long long> b(Q);
    std::vector<long long> c(Q);
    std::vector<long long> d(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
        scanf("%lld",&c[i]);
        scanf("%lld",&d[i]);
    }
    solve(N, M, Q, std::move(a), std::move(b), std::move(c), std::move(d));
    return 0;
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
int main(){
	deque<char> dq;
	bool flag=false;
	string s;
	int q;
	cin>>s>>q;
	for(int i=0;i<s.size();i++)
	    dq.push_back(s[i]);
	for(int i=0;i<q;i++){
		int t; cin>>t;
		if(t==1) flag=!flag;
		else{
			int f; char c;
			cin>>f>>c;
			if(f==1){
				if(!flag) dq.push_front(c);
				else dq.push_back(c);
			}
			else{
				if(!flag) dq.push_back(c);
				else dq.push_front(c);
			}
		}
	}
	int n=dq.size();
	if(flag)
	    for(int i=n-1;i>=0;i--)
	        cout<<dq[i];
	else
	    for(int i=0;i<n;i++)
	        cout<<dq[i];
	return 0;
}

Measured memory_bytes: 896
#include <iostream>

using namespace std;

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

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

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

const ll INF = 1<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int n, x[3];
ll dp[41][1<<17];
int p[1<<17];

ll mod_pow(ll x, ll n, ll mod) {
	if (n == 0) return 1;
	ll res = mod_pow(x * x % mod, n / 2, mod);
	if (n & 1) res = res * x % mod;
	return res;
}

int main() {
	cin >> n;
	REP(i, 3) cin >> x[i];
	int keta = x[0] + x[1] + x[2];
	
	REP(i, 17) p[1<<i] = i;
	
	dp[0][0] = 1;
	
	REP(i, n) {
		REP(j, 1 << keta) {
			if (!dp[i][j]) continue;
			
			FOR(k, 1, 11) {
				int num = j << k | 1 << (k - 1);
				num &= (1 << keta) - 1;
				
				int now = num;
				int pos = 2, sum = 0;
				
				while (now > 0) {
					int last = p[now & -now] + 1;
					
					sum += last;
					if (sum == x[pos]) pos--, sum = 0;
					
					now >>= last;
				}
				if (pos == -1) continue;
				
				(dp[i + 1][num] += dp[i][j]) %= MOD;
			}
		}
	}
	
	ll ans = 0;
	REP(i, 1 << keta) (ans += dp[n][i]) %= MOD;
	ans = (mod_pow(10, n, MOD) - ans + MOD) % MOD;
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 40192
#include <iostream>

using namespace std;

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

    if (R < 1200)
    {
        cout << "ABC" << endl;
    }
    else if (R < 2800)
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "AGC" << endl;
    }
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc153/tasks/abc153_b

read row ; row=($row) ; h=$((row[0])) ; n=$((row[1]))
read row ; A=($row)
sum=$((0))
for v in ${A[@]} ; do
  sum=$((sum + v))
done
if [ $h -le $sum ] ; then
  echo "Yes"
else
  echo "No"
fi


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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  LL r, g, b, n;

  void solve() {
    cin >> r >> g >> b >> n;
    int ans = 0;
    for (int i = 0; i <= n / r; ++i) {
      for (int j = 0; j <= n / b; ++j) {
        int x = n - i * r - j * b;
        if (x >= 0 && x % g == 0) ans++;
      }
    }
    cout << ans << endl;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  Problem::Solver sol;
  sol.solve();
  return 0;
}


Measured memory_bytes: 256
def c(x,y,h,w)
  x == 0 || y == 0 || x == w-1 || y == h-1 ? ?# : ?.
end

loop {
  h, w = gets.split.map(&:to_i)

  break if h == 0 && w == 0
  
  h.times{|y|
    w.times{|x| print c(x,y,h,w) }
    puts
  }
  puts
}



Measured memory_bytes: 6872
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    unordered_set<int> h{2, 4, 5, 7, 9}, p{0, 1, 6, 8}, b{3};
    int n;
    cin >> n;
    n = n % 10;
    if (h.find(n) != h.end())
        cout << "hon" << endl;
    if (p.find(n) != p.end())
        cout << "pon" << endl;
    if (b.find(n) != b.end())
        cout << "bon" << endl;
}


Measured memory_bytes: 3576