akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <numeric>
#include <tuple>

using namespace std;

using lint = long long;
using ldouble = long double;

bool solve() {
    int N, D;
    cin >> N >> D;
    if (N == 0) return false;

    vector<vector<int>> C(N);
    for (auto& v : C) {
        int m;
        cin >> m;
        v.resize(m);
        for (auto& c : v) cin >> c;
    }

    vector<int> sum(N);
    for (int i = 0; i < N; ++i) {
        sum[i] = accumulate(C[i].begin(), C[i].end(), 0);
    }

    bool update = true;
    while (update) {
        update = false;
        for (int i = 0; i < N; ++i) {
            if (C[i].empty()) continue;

            sum[i] -= C[i].back();
            int minsum = *min_element(sum.begin(), sum.end());
            int maxsum = *max_element(sum.begin(), sum.end());
            if (maxsum - minsum <= D) {
                update = true;
                C[i].pop_back();
            } else {
                sum[i] += C[i].back();
            }
        }
    }

    cout << (*max_element(sum.begin(), sum.end()) == 0 ? "Yes" : "No") << endl;
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}



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

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define xx first
#define yy second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;

void solve()
{   
    string s;
    int n;
    cin >> s >> n;

    deque<char> dq;

    for (int i = 0; i < s.length(); i++)
        dq.push_back(s[i]);

    bool flip = false;

    for (int i = 0; i < n; i++)
    {
        int t;
        cin >> t;

        if (t == 1)
            flip = !flip;
        else
        {
            int f;
            string c;
            cin >> f >> c;
            f--;

            if (flip ^ f)
                dq.push_back(c[0]);
            else
                dq.push_front(c[0]);
        }
    }

    while (!dq.empty())
    {
        if (!flip)
        {
            cout << dq.front();
            dq.pop_front();
        }
        else
        {
            cout << dq.back();
            dq.pop_back();
        }
    }

    cout << '\n';
} 

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

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

    return 0;
}

Measured memory_bytes: 976
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main(){
    while(true){
        string s1,s2;
        cin>>s1;
        if(s1==".")
            break;
        cin>>s2;
        if(s1==s2) 
            cout<<"IDENTICAL"<<endl;
        else{
            vector <string> Vs1;
            vector <string> Vs2;
            vector <string> s1copy;
            vector <string> s2copy;
            for(int i=0;i<s1.size();i++){
                if(s1[i]=='\"'){
                    i++;
                    string s="";
                    while(s1[i]!='\"'){
                        s+=s1[i];
                        i++;
                    }
                    Vs1.push_back(s);
                }else{
                    string s="";
                    while(i<s1.size() && s1[i]!='\"'){
                        s+=s1[i];
                        i++;
                    }
                    i--;
                    s1copy.push_back(s);
                }
            }
            for(int i=0;i<s2.size();i++){
                if(s2[i]=='\"'){
                    i++;
                    string s="";
                    while(s2[i]!='\"'){
                        s+=s2[i];
                        i++;
                    }
                    Vs2.push_back(s);
                }else{
                    string s="";
                    while(i<s2.size() && s2[i]!='\"'){
                        s+=s2[i];
                        i++;
                    }
                    i--;
                    s2copy.push_back(s);
                }
            }
            if(Vs1.size()!=Vs2.size() || s1copy.size()!=s2copy.size()){
                cout<<"DIFFERENT"<<endl;
                continue;
            }
            bool continueflag=false;
            for(int i=0;i<s1copy.size();i++){
                if(s1copy[i]!=s2copy[i]){
                    cout<<"DIFFERENT"<<endl;
                    continueflag=true;
                    break;
                }
            }
            if(continueflag)continue;
            int wrongcount=0;
            for(int i=0;i<Vs1.size();i++){
                if(Vs1[i]!=Vs2[i])
                    wrongcount++;
            }
            if(wrongcount==1){
                cout<<"CLOSE"<<endl;
            }else{
                cout<<"DIFFERENT"<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


ll dp[302][302][302];
void chmin(ll &a, ll b) {
	a = min(a, b);
}

int main() {
	int n, k; cin >> n >> k;
	vector<ll> h(n + 2);
	for (int i = 1; i <= n; i++) cin >> h[i];
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			for (int s = 0; s <= n; s++) {
				dp[i][j][s] = 1e18;
			}
		}
	}
	map <ll, int> mp;
	mp[0] = 0;
	int cnt = 1;
	for (int i = 1; i <= n; i++) {
		if (mp.count(h[i])) continue;
		mp[h[i]] = cnt++;
	}
	vector<int> mp2(n + 2);
	for (int i = 0; i <= n; i++) {
		mp2[i] = mp[h[i]];
	}
	dp[0][0][0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= k; j++) {
			for (int t = 0; t <= n; t++) {
				chmin(dp[i][j][mp2[i]], dp[i - 1][j][mp2[t]] + max(0LL, h[i] - h[t]));
			}
			if (j == 0) continue;
			for (int s = 0; s <= n; s++) {
				chmin(dp[i][j][mp2[s]], dp[i - 1][j - 1][mp2[s]]);
			}
		}
	}
	ll ans = 1e18;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= n; j++) {
			chmin(ans, dp[n][i][mp2[j]]);
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<long double> x(n);
  vector<string> u(n);
  long double ans = 0;
  rep(i,n){
    cin >> x[i] >> u[i];
    if(u[i] == "BTC") x[i] *= 380000.0;
    ans += x[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3720
#include<iostream>
#include<map>
#include<string>
using namespace std;

int main()
{
    map<string,int> m;                  //通常のmapはkeyに対して1つの値を持つ。multimapになると、keyにいくつもの値を持たせることが出来る。
    int n, q, x;
    string k;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> q >> k;

        if( q == 0 )
        {
            cin >> x;
            m[k] = x;
        }
        else if( q == 1 )
            cout << m[k] << endl;
        else
            m[k] = 0;
    }
    return 0;
}


Measured memory_bytes: 27864
#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;

int fast(){
	int res=0,fl=1;
	char c=getchar();
	while(c<48||c>57){
		if(c=='-')fl=-1;
		c=getchar();
	}while(c>=48&&c<=57)res=res*10+c-48,c=getchar();
	return res*fl;
}

void write(int x){
	if(x>9)write(x/10);
	putchar(x%10+48);
}

int main(){
	char c;
	scanf("%c",&c);
	printf("%c",c+1); 
	return 0;
}

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

using namespace std;

const int N = 2e3 + 5;
int n, x, y, cnt[N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n >> x >> y;
    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
                int ans1 = j - i;
                int ans2 = abs(i - x) + 1 + abs(j - y);
                cnt[min(ans1, ans2)]++;
        }
    }
    for(int i = 1; i <= n - 1; i++){
        cout << cnt[i] << '\n';
    }

    return 0;
}

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


int main(){
    string s;cin>>s;
    ll countb = 0;
    ll ans = 0;
    int n = s.size();
    for(int i = 0;i<n;i++){
        if(s[i]=='W') ans+=countb;
        else countb++;


    }
    cout<<ans<<endl;

}


Measured memory_bytes: 3724
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var A = input[1].split(" ").map(i => parseInt(i));
  var sum = A[N-1];
  for(var i=0;i<N-1;i++){
    if(i%2==0){
      sum+=A[i];
    }else{
      sum-=A[i];
    }
  }
  var anssub=[sum];
  for(var i=0;i<N-1;i++){
    sum=A[i]*2-sum;
    anssub.push(sum);
  }
  var ans = anssub.join(" ");
  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 38196
#include<iostream>
#define N 32768
long a[N],b[N],n,k,i=N;int main(){for(std::cin>>n>>k;--i;b[i]=i<n?i:n)a[i]=n/i;while(--k){for(std::swap(a,b);++i<N;)b[i]+=b[i-1];for(*b=b[n/--i];*a=--i;)*b=a[i]=(*b+a[i]*(n/i-n/(i+1)))%0x3B9ACA07;}std::cout<<*b;}


Measured memory_bytes: 896
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]

A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = I()
print(A[K - 1])


Measured memory_bytes: 38256
n = int(input())
XYH = list(tuple(map(int, input().split())) for _ in range(n))

# h != 0であるデータを取得
for x, y, h in XYH:
    if h != 0:
        x_, y_, h_ = x, y, h
        break

for cx in range(0, 101):
    for cy in range(0, 101):

        H = abs(x_ - cx) + abs(y_ - cy) + h_

        if all([max(H - abs(x - cx) - abs(y - cy), 0) == h for x, y, h in XYH]):
            print(cx, cy, H)
            exit()

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

int n;
int c[500],s[500],f[500];

int solve(int start){
	int arrive=0;
	int lag;
	arrive=s[start]+c[start];
	for(int lp=start+1;lp<n-1;lp++){
		int x=arrive-s[lp];
		if(x>=0){
			lag=f[lp]-((x)%f[lp]);
			if(lag==f[lp]) lag=0;
			arrive=arrive+lag+c[lp];
		}else{
			arrive=s[lp]+c[lp];
		}
	}
	return arrive;
}



int main(void){

	cin >> n;
	
	for(int lp=0;lp<n-1;lp++){
		scanf("%d %d %d",&c[lp],&s[lp],&f[lp]);
	}
	for(int lp=0;lp<n-1;lp++){
		printf("%d\n",solve(lp));
	}
	printf("0\n");
	
	return 0;
		
	
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
int main()
{
	int m,n,i,t,j,k;
	int a[100005],b[100005];
	scanf("%d%d%d",&m,&n,&k);
	int mina=100005,minb=100005;
	for(i=1;i<=m;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]<mina) mina=a[i];
	}
	for(i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		if(b[i]<minb) minb=b[i];
	}
	int min=mina+minb;
	for(i=0;i<k;i++)
	{
		int x,y,c;
		scanf("%d%d%d",&x,&y,&c);
		int sum=a[x]+b[y]-c;
		if(sum<min) min=sum;
	}
	printf("%d",min);
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int N;
    cin >> N;
    string S;
    cin >> S;
    
    if(N%2!=0){
        cout << "No"<<endl;
        return 0;
    }
    
    if(S.substr(0,S.size()/2) == S.substr(S.size()/2,S.size()/2)){
        cout << "Yes"<<endl;
        return 0;
    }else{
        cout << "No"<<endl;
        return 0;
    }

}


Measured memory_bytes: 256
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define set0(x) memset(x,0,sizeof(x))
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();int f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
int mod = 1000000007;
inline int sq(int x){return 1ll*x*x%mod;}
inline int sub(int a,int b){return a<b?a-b+mod:a-b;}
inline int add(int a,int b){return a+b>=mod?a+b-mod:a+b;}
inline int mul(int a,int b){return 1ll*a*b%mod;}
inline int pow(int a,int b){if(b == 0)return 1;return b&1?mul(sq(pow(a,b/2)),a):sq(pow(a,b/2));}
inline int inv(int a){return pow(a,mod-2);}
int n,a[200010],dp[200010],last[200010];
int main() {
	read(n);
	dp[0] = 1;
	for(int i=1;i<=n;i++){
		read(a[i]);
		dp[i] = add(dp[i],dp[i-1]);
		if(last[a[i]] && last[a[i]]!=i-1)dp[i] = add(dp[i],dp[last[a[i]]]);
		last[a[i]] = i;
		//cout<<i<<' '<<dp[i]<<endl;
	}
	cout<<dp[n]<<endl;
	return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <algorithm>
#include <vector>

typedef long long LL;
const int MN = 100005;

int N, M;
std::vector<int> G[MN];

int a, b, vis[MN], par[MN], dep[MN], num1[MN], num2[MN], kval[MN];
void DFS(int u, int fr) {
	vis[u] = 1;
	dep[u] = dep[par[u] = fr] + 1;
	num1[u] = dep[u] & 1;
	num2[u] = ~dep[u] & 1;
	for (int v : G[u]) if (v != fr) {
		if (!vis[v]) DFS(v, u), num1[u] += num1[v], num2[u] += num2[v];
		else a = u, b = v;
	}
}

int main() {
	scanf("%d%d", &N, &M);
	if (N & 1) return puts("-1"), 0;
	for (int i = 1; i <= M; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	DFS(1, 0);
	if (M == N - 1) {
		if (num1[1] != num2[1]) return puts("-1"), 0;
		LL Ans = 0;
		for (int i = 2; i <= N; ++i) {
			int x = num2[i] - num1[i];
			Ans += x < 0 ? -x : x;
		}
		printf("%lld\n", Ans);
	} else {
		if ((dep[a] ^ dep[b]) & 1) {
			if (num1[1] != num2[1]) return puts("-1"), 0;
			for (int x = a; x; x = par[x]) ++kval[x];
			for (int x = b; x; x = par[x]) --kval[x];
			LL Ans = 0;
			static int seq[MN], cnt;
			seq[cnt = 1] = 0;
			for (int i = 2; i <= N; ++i) {
				if (!kval[i]) {
					int x = num2[i] - num1[i];
					Ans += x < 0 ? -x : x;
				} else
					seq[++cnt] = kval[i] * (num2[i] - num1[i]);
			}
			std::sort(seq + 1, seq + cnt + 1);
			int mid = seq[cnt / 2 + 1];
			for (int i = 1; i <= cnt; ++i)
				Ans += seq[i] < mid ? mid - seq[i] : seq[i] - mid;
			printf("%lld\n", Ans);
		} else {
			int k = N / 2 - num1[1];
			for (int x = a; x; x = par[x]) num1[x] += k;
			for (int x = b; x; x = par[x]) num1[x] += k;
			LL Ans = 0;
			for (int i = 2; i <= N; ++i) {
				int x = num2[i] - num1[i];
				Ans += x < 0 ? -x : x;
			}
			printf("%lld\n", Ans + (k < 0 ? -k : k));
		}
	}
	return 0;
}

Measured memory_bytes: 14720
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int x, y, a, b, c, p[MAXN], q[MAXN], r[MAXN];
vector<int> res;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> x >> y >> a >> b >> c;
    FOR(i,1,a) cin >> p[i];
    FOR(i,1,b) cin >> q[i];
    FOR(i,1,c) cin >> r[i];
    sort(p+1, p+a+1);
    sort(q+1, q+b+1);
    sort(r+1, r+c+1);
    FORE(i,a,a-x+1) res.push_back(p[i]);
    FORE(i,b,b-y+1) res.push_back(q[i]);
    sort(ALL(res));
    ll kq = 0;
    FOR(i,0,SZ(res)-1) kq += res[i];
    int I = 0, J = c;
    while (1) {
        if (r[J] > res[I]) {
            kq += r[J] - res[I];
            I++;
            J--;
            if (I >= SZ(res)) break;
            if (J <= 0) break;
        }
        else break;
    }
    cout << kq;
    return 0;
}


Measured memory_bytes: 2552
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, b, n) for (int i = b; i < n; ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;
const string YES = "Yes";
const string NO = "No";

void solve(string S, string T) {
  cout << (S == T.substr(0, S.length()) ? YES : NO) << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  string S;
  cin >> S;
  string T;
  cin >> T;

  solve(S, T);

  return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecstr vector<string>
#define vecch vector<char>
#define vecpii vector<pii>
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}

string strin(){string s;cin>>s;return s;}
char chin(){char c;cin>>c;return c;}
ll lin() {ll x;scanf("%lld",&x);return x;}

int main(){
    ll x=lin(),y=lin(),z=lin(),k=lin();
    vecll a(x),b(y),c(z),ab(min(x,k)*min(y,k)),abc(min(x*y,k)*min(z,k));
    rep(i,x)a[i]=lin();
    rep(i,y)b[i]=lin();
    rep(i,z)c[i]=lin();
    sort(ALL(a),greater<ll>());
    sort(ALL(b),greater<ll>());
    sort(ALL(c),greater<ll>());
    int ida=0,idb=0;
    rep(i,min(k,x)*min(k,y)){
        ab[i]=a[ida]+b[idb];
        if(idb<min(k,y)-1)idb++;
        else{
            ida++;
            idb=0;
        }
    }
    sort(ALL(ab),greater<ll>());
    int idab=0,idc=0;
    rep(i,min(k,x*y)*min(k,z)){
        abc[i]=ab[idab]+c[idc];
        if(idc<min(k,z)-1)idc++;
        else{
            idab++;
            idc=0;
        }
    }
    sort(ALL(abc),greater<ll>());
    rep(i,k)cout<<abc[i]<<endl;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    string s, t;
    cin >> s >> t;
    int ans = 0;
    if(s[0] == t[0]) ans++;
    if(s[1] == t[1]) ans++;
    if(s[2] == t[2]) ans++;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <iostream>

#define IN(x) scanf("%d",&(x));
#define IN2(x,y) IN((x));IN((y));
#define IN3(x,y,z) IN2((x),(y));IN((z);

#define OUT(x) printf("%d\n",x);
#define OUT2(x,y) printf("%d %d\n",x,y);
#define OUT3(x,y,z) printf("%d %d %d\n",x,y,z);

#define X first
#define Y second
#define MP make_pair
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair < int, int> pii;
typedef vector < int > vi;
typedef pii pt;

const int N = 1e5 + 500;
const int M = 1e6 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOG = 20;
const int OFF = (1 << LOG);
const double EPS = 1e-9;
const double PI = 3.1415926535;

string s;

int main(){
    cin >> s;
    if(s.size() != 26){
        for(char c = 'a';c<='z';c++){
            int cnt = 0;
            for(int j = 0;j<s.size();j++)
                cnt += int(s[j] == c);
            if(!cnt){
                s.PB(c);
                cout << s << endl;
                return 0;
            }
        }
    }
    int j = s.size() - 1;
    set < char  > st;
    while(j > 0 && s[j - 1] > s[j]){
        st.insert(s[j]);
        j--;
    }
    st.insert(s[j]);
    if(j == 0){
        cout << -1 << endl;
        return 0;
    }
    //cout << st.size() << endl;
    char to = *st.upper_bound(s[j - 1]);
    s.erase(s.begin() + j - 1,s.end());
    s.PB(to);
    cout << s << endl;
}


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

using namespace std;
 
int main() {

    int times;
    cin >> times;

    string name1, name2;

    int point1 = 0;
    int point2 = 0;

    for (int i=0; i<times; i++)
    {
        cin >> name1;
        cin >> name2;

        if (name1 < name2)
        {
            point2 += 3;
        }
        else if (name1 > name2)
        {
            point1 += 3;
        }
        else
        {
            point1++;
            point2++;
        }
    }
    cout << point1 << " " << point2 << endl;
    return 0;
}


Measured memory_bytes: 3212
package main

import "fmt"

const M = 13
const MOD = int64(1000000000 + 7)

func main () {
	var s string
	fmt.Scan(&s)

	dp := make([][]int64, len(s)+1)
	dp[0] = make([]int64, M)
	dp[0][0] = 1

	ru := 1

	for i := 0; i < len(s); i++ {
		idx := len(s) - i - 1
		r := s[idx]

		dp[i+1] = make([]int64, M)

		if r == '?' {
			for j := 0; j <= 9; j++ {
				d := (j * ru) % M
				for di, prev := range dp[i] {
					k := (di + d) % M
					dp[i+1][k] = (dp[i+1][k] + prev) % MOD
				}
			}
		} else {
			d := int(r) - '0'
			rem := (d * ru) % M
			for di, prev := range dp[i] {
				k := (di + rem) % M
				dp[i+1][k] = prev
			}
		}

		ru = (ru * 10 % M) % M
	}

	fmt.Println(dp[len(s)][5])
}


Measured memory_bytes: 14592
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define endl '\n'
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

void solve(){
    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i = 0; i < n; ++i){
        cin >> arr[i];
    }
    sort(arr.rbegin(), arr.rend());
    ll sum = arr[0];
    int two = 0;
    int id = 1;
    for(int i = 2; i < n; ++i){
        sum += arr[id];
        two++;
        if(two == 2){
            two = 0;
            id++;
        }
    }
    cout << sum << endl;
}

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

    int t;
    t = 1;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 4028
/*
注意范围！
short范围：-32768~32767
unsigned short范围：0~65535
int范围：-2147483648~2147483647
uint范围：0~4294967295
INT范围：-9223372036854775808~9223372036854775807
UINT范围：0~18446744073709551615
float范围：-3.4e38~3.4e38，精度：6~7位
double范围：-1.7e308~1.7e308，精度：15~16位
ldouble范围：-1.2e4932~1.2e4932，精度：18~19位
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define LL long long
#define pb push_back
#define pob pop_back
#define mp make_pair
#define FILL(a,v) memset((void*)a,v,sizeof(a))
#define FILL0(a) FILL(a,0)
#define FILL1(a) FILL(a,-1)
#define ALL(a) (a).begin(),(a).end()
#define Inf 1e9
#define Mod 1000000007
#define foreach(it,x) for(typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define FOR(i,x) for(int i=0;i<x;i++)
#define RFOR(i,x) for(int i=x-1;i>=0;i--)
#define FFOR(i,a,b) for(int i=a;i<b;i++)
#define FRFOR(i,a,b) for(int i=a-1;i>=b;i--)
#define SZ(a) ((int)(a).size())
#define FI first
#define SE second
#define OVER(a) return puts(a),0
#define fastio ios::sync_with_stdio(0)
#define filei(f) freopen(f,"r",stdin)
#define fileo(f) freopen(f,"w",stdout)
using namespace std;
void avoid(){}
typedef pair<int,int> pii;
typedef unsigned long long UINT;
typedef unsigned int Uint;
typedef long long INT;
typedef pair<INT,INT> PII;
typedef stringstream sst;
typedef istringstream iss;
typedef vector<int> vint;
typedef vector<INT> VINT;
typedef vector<pii> vpii;
typedef vector<PII> VPII;
typedef priority_queue<int> pqi;
typedef priority_queue<INT> PQI;
typedef priority_queue<pii> pqp;
typedef priority_queue<PII> PQP;
typedef priority_queue<int,vint,greater<int> > xqi;
typedef priority_queue<INT,VINT,greater<INT> > XQI;
typedef priority_queue<pii,vpii,greater<pii> > xqp;
typedef priority_queue<PII,VPII,greater<PII> > XQP;

int n,m,a,b;

//Can calculate a^(Mod-2) quickly(O(log a)).
inline INT mitsfun(int di,int zhi)
{
	if(zhi==0)return 1;
	INT num=mitsfun(di,zhi/2);
	num=num*num%Mod;
	if(zhi%2)num=num*di%Mod;
	return num;
}

INT c1[100007];

int main()
{
	scanf("%d%d%d%d",&n,&m,&a,&b);
	INT cdi=n-a-1,num=1;
	for(int i=1;i<m;i++)
	{
		num=num*(i+cdi)%Mod*mitsfun(i,Mod-2)%Mod;
		if(i>=b)c1[i]=num;
	}
	cdi=a-1;
	num=1;
	INT cnt=c1[m-1];
	for(int i=m-2,j=1;i>=b;i--,j++)
	{
		num=num*(j+cdi)%Mod*mitsfun(j,Mod-2)%Mod;
		cnt=(cnt+(num*c1[i]%Mod))%Mod;
	}
	printf("%I64d\n",cnt);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
string a;
int main()
{
    cin >> a;
    for(int i=0;i<a.length();i++)
        if(a[i]=='C')
            for(int j=i+1;j<a.length();j++)
                if(a[j]=='F')
                {
                    puts("Yes");
                    return 0;
                }
    puts("No");
    return 0;
}

Measured memory_bytes: 256
/******************************************
* AUTHOR : HRITIK AGGARWAL *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define int ll
ll po(ll a, ll x, ll m) { if (x == 0) {return 1;} ll ans = 1; ll k = 1;  while (k <= x) {if (x & k) {ans = ((ans * a) % m);} k <<= 1; a *= a; a %= m; } return ans; }
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE
int n, m, x;
int mat[100][100];
int rec(int pos, int *arr) {
  if (pos == n) {
    forr(i, m) {
      if (arr[i] < x) {
        return INT_MAX;
      }
    }
    return 0;
  }
  int ans   = 0;
  int tmp[m];
  forr(i, m) {
    tmp[i] = arr[i] + mat[pos][i + 1];
  }
  ans  = min(rec(pos + 1, arr), mat[pos][0] + rec(pos + 1, tmp));
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  cin >> n >> m >> x;
  forr(i, n + 1) {
    forr(j, m + 1) {
      cin >> mat[i][j];
    }
  }
  int a[m];
  forr(i, m)
  a[i] = 0;
  int ans = rec(0, a);
  ans  = (ans >= INT_MAX) ? -1 : ans;
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3664
#include <stdio.h>
#include <stdlib.h>
#define N 100000

int partition(int *,int,int);

int i,j,A[N];

int main(){
  int n,P;

  scanf("%d",&n);


 for(i=0 ; i<n ; i++){
    scanf("%d",&A[i]);
  }

 P=partition(A,0,n-1);

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

   return 0;
}

int partition(int *A,int p,int r){
  int x,a;
  x=A[r];
  i=p-1;
  for(j=p ; j<r ; j++){
    if(A[j]<=x){
      i++;
      a=A[i];
      A[i]=A[j];
      A[j]=a;
    }
  }
    a=A[i+1];
    A[i+1]=A[r];
    A[r]=a;

    return i+1;
}

Measured memory_bytes: 992
import java.util.*;
import java.io.*;

class Main
{
	public static void main(String[] args)
	{
		FastReader reader = new FastReader();
		PrintWriter writer = new PrintWriter(System.out);

		int n = reader.nextInt();
		long[] array = new long[n];
		for (int i=0; i<n; i++)
			array[i] = reader.nextLong();

		int count=0;
		for (int i=0; i<n; i++)
		{
			while (array[i]%2 == 0)
			{
				array[i] /= 2;
				count++;
			}
		}

		writer.println (count);
		writer.close();
	}

	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}
}


Measured memory_bytes: 25300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////


int main(){fastio
    ll n;cin>>n;
    string s[n];rep(i,0,n-1)cin>>s[i];
    ll c[3];memset(c,0,sizeof(c));
    ll ans=0;
    rep(i,0,n-1){
        rep(j,0,s[i].size()-2){
            if(s[i][j]=='A'&&s[i][j+1]=='B')ans++;
        }
        if(s[i][0]=='B'&&s[i][s[i].size()-1]=='A')c[0]++;
        else if(s[i][0]=='B')c[1]++;
        else if(s[i][s[i].size()-1]=='A')c[2]++;
    }
   // cout<<ans<<endl;
    //rep(i,0,2)cout<<c[i]<<" ";cout<<endl;
    if(c[2]>=1){
        ans+=c[0];
        c[0]=0;
    }
    if(c[1]>=1){
        ans+=c[0];
        c[0]=0;
    }
    if(c[0]>=2){
        ans+=c[0]-1;
    }
    ans+=min(c[1],c[2]);
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 768
h,w,n=map(int,input().split())
dic={}
dx=[-2,-1,0]
dy=[-2,-1,0]
ans=[0]*10
for _ in range(n):
  a,b=map(int,input().split())
  for x in dx:
    for y in dy:
      if 1<=a+y and a+y+2<=h and 1<=b+x and b+x+2<=w:
        if (a+y,b+x) not in dic:
          dic[(a+y,b+x)]=1
        else:
          dic[(a+y,b+x)]+=1
ans[0]=(h-2)*(w-2)-len(dic)
for v in dic.values():
  ans[v]+=1
for i in range(10):
  print(ans[i])

Measured memory_bytes: 166516
#include<cstdio>
#include<iostream>
using namespace std;
int n;
char s[10001];
bool M,MM;
int main(){
	scanf("%d",&n);
	puts("0");
	fflush(stdout);
	scanf("%s",s);
	if(s[0]=='V') return 0;
	if(s[0]=='M') M=1;
	else M=0;
	int l=0,r=n;
	while(l<r){
		int m=(l+r)>>1;
		printf("%d\n",m);
		fflush(stdout);
		scanf("%s",s);
		if(s[0]=='V') return 0;
		if(s[0]=='M') MM=1;
		else MM=0;
		int d=m-l;
		if(d&1){
			if(M==MM) r=m;
			else l=m,M=MM;
		}
		else{
			if(M==MM) l=m;
			else r=m;
		}
	}
	fflush(stdout);
	return 0;
}

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

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

    vector<int> x(n,0);
    rep(i,k) {
        int d;
        cin >> d;
        vector<int> a(d,0);
        rep(j,d) {
            int a;
            cin >> a;
            x[a-1]++;
        }
    }

    int ans = 0;
    rep(i,n) {
        if (x[i] == 0) ans++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 3612
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Ribhav
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ASumOfInteriorAngles solver = new ASumOfInteriorAngles();
        solver.solve(1, in, out);
        out.close();
    }

    static class ASumOfInteriorAngles {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            int n = s.nextInt();
            out.println((n - 2) * 180);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21460
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int x,y;
        while(true){
            x=sc.nextInt();
            y=sc.nextInt();
            if(x==0 && y==0) break;
            else{
                if(x<y){
                    System.out.println(x+" "+y);
                }else{
                    System.out.println(y+" "+x);
                }
            }
        }
    }
}


Measured memory_bytes: 35816
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)(1e9)+7)
#define MAX ((ull)(1e9)+1)

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> cnt(n+1, 0);
	for(int i=0; i<n; i++){
		int a;
		cin >> a;
		cnt[a]++;
	}
	sort(cnt.begin(), cnt.end(), greater<int>());
	int ans=0;
	for(int i=k; i<n; i++) ans+=cnt[i];
	cout << ans << endl;
 	return 0;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

template<typename T> void maxUpdate(T& a, T b) { a = max(a, b); }

int N, Q, V[300005], W[300005], dp[20][100005];

vector<int> ch[300005];
vector<int> L[300005];
vector<int> q[300005];
vector<int> ans[300005];

const int DEP = 9;
const int MAX_L = 100000;

int solve(vector<int>& tar, int C) {
    int n = tar.size();

    function<int(int, int, int)> rec = [&](int i, int sum_v, int sum_w) {
        if (i == n) return sum_v + dp[DEP][C - sum_w];
        int ret = 0, v = tar[i];
        ret = max(ret, rec(i + 1, sum_v, sum_w));
        if (sum_w + W[v] <= C) {
            ret = max(ret, rec(i + 1, sum_v + V[v], sum_w + W[v]));
        }
        return ret;
    };

    return rec(0, 0, 0);
}

void dfs(int v, int d, vector<int>& tar) {
    if (d >= DEP) {
        tar.push_back(v);
    }
    else {
        INIT(dp[d + 1], 0);
        for_(x,0,MAX_L+1) {
            maxUpdate(dp[d  + 1][x], dp[d][x]);
            if (x > 0) maxUpdate(dp[d + 1][x], dp[d + 1][x - 1]);
            int nx = x - W[v];
            if (nx >= 0) maxUpdate(dp[d + 1][x], dp[d][nx] + V[v]);
        }
    }

    int K = L[v].size();
    for_(i,0,K) {
        int C = L[v][i];
        if (d < DEP) ans[v].push_back(dp[d + 1][C]);
        else ans[v].push_back(solve(tar, C));
    }

    for (int u : ch[v]) dfs(u, d + 1, tar);

    if (d >= DEP) {
        tar.pop_back();
    }
}

int main() {
    cin >> N;
    for_(i,1,N) {
        int p = (i - 1) / 2;
        ch[p].push_back(i);
    }
    for_(i,0,N) cin >> V[i] >> W[i];

    cin >> Q;
    for_(i,0,Q) {
        int vi, Li;
        cin >> vi >> Li;
        --vi;
        L[vi].push_back(Li);
        q[vi].push_back(i);
    }

    INIT(dp, 0);
    vector<int> tar;
    dfs(0, 0, tar);

    vector<int> out(Q);
    for_(v,0,N) {
        int K = L[v].size();
        for_(k,0,K) {
            int i = q[v][k];
            out[i] = ans[v][k];
        }
    }

    for (int o : out) cout << o << endl;
}

Measured memory_bytes: 54992
import sys
input=sys.stdin.readline
from functools import lru_cache

def solve(n,a,b,c,d):
    @lru_cache(None)
    def f(n):
        if n==0:
            return 0
        if n==1:
            return d
        ans=d*n
        q,r=divmod(n,2)
        if r==0:
            ans=min(ans,f(q)+a)
        else:
            ans=min(ans,f(q)+a+d,f(q+1)+a+d)
        q,r=divmod(n,3)
        if r==0:
            ans=min(ans,f(q)+b)
        elif r==1:
            ans=min(ans,f(q)+b+d)
        else:
            ans=min(ans,f(q+1)+b+d)
        q,r=divmod(n,5)
        if r==0:
            ans=min(ans,f(q)+c)
        elif r==1:
            ans=min(ans,f(q)+c+d)
        elif r==2:
            ans=min(ans,f(q)+c+d*2)
        elif r==3:
            ans=min(ans,f(q+1)+c+d*2)
        else:
            ans=min(ans,f(q+1)+c+d)
        return ans
    return f(n)

def main():
    t=int(input())
    for _ in range(t):
        n,a,b,c,d=map(int,input().split())
        print(solve(n,a,b,c,d))

if __name__=='__main__':
    main()

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

#define MAX_NUMBER 1000001
int main(void) {
	bool sosu[MAX_NUMBER];

	for (int i = 1; i < MAX_NUMBER; i++) {
		sosu[i] = true;
	}

	sosu[1] = false;
	for (int i = 2; i < MAX_NUMBER/2; i++) {
		for (int j = 2; i*j < MAX_NUMBER; j++) {
			sosu[i*j] = false;
		}
	}

	for (;;) {
		int a, d, n;
		cin >> a >> d >> n;
		if (a == 0 && d == 0 && n == 0)
			break;

		int cnt = 0;
		for (int i = 1; a+(i-1)*d < MAX_NUMBER; i++) {
			int num = a + (i - 1)*d;
			if (sosu[num]) {
				cnt++;
			}
			if (cnt == n) {
				printf("%d\n", num);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2116
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}


int main(){
	int n,y;
	cin>>n>>y;
	y/=1000;
	rep(i,2001){
		rep(j,2001){
			if( ( (y-10*i-5*j) == (n-i-j) ) && (n-i-j>=0) ){
				cout<<i<<" "<<j<<" "<<n-i-j<<endl;
				return 0;
			}
			if(n-i-j<0){
				break;
			}
		}
	}
	cout<<"-1 -1 -1"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=2e5+5;

int f(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int ans = 0;
	int tot = 0;
	for(auto it:s){
		if(it == 'R') tot++;
	}
	for (int i = 0; i < tot; ++i)
	{
		if(s[i] == 'W') ans++;
	}
	return ans;
}

int32_t main(){
    fast_io;
    int t=1;
    // cin>>t;
    while(t--){
    	show(f());

    	// f();

    	// if(f()){
    	// 	cout<<"Yes"<<endl;
    	// }
    	// else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <unordered_map>
using namespace std;
using ll = long long;

int main() {
    // input
    ll N, A_i, sum = 0, res = 0;
    cin >> N;
    unordered_map<ll, ll> mp;
    mp[0] = 1;
    
    for (ll i = 0; i < N; ++i) {
        cin >> A_i;
        sum += A_i;
        res += mp[sum];  // key がなければ 0 を返す
        mp[sum]++;
    }
    
    cout << res << "\n";
    
    return 0;
}


Measured memory_bytes: 8520
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	int C; cin >> C;
	int K; cin >> K;

	vector<int>T(N); rep(i, 0, N) { cin >> T[i]; }
	sort(all(T));

	int ans = 0;
	int i = 0;
	while (i < N) {
		int j = 1;
		ans++;
		while (i + j < N and T[i+j] <= T[i] + K and j + 1 <= C) {
			j++;
		}
		i += j;
		dump(j);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define CONCAT_(x,y) x##y
#define CONCAT(x,y) CONCAT_(x,y)
#define _v1 CONCAT(qyw1, __LINE__) // unique name in same line (otherwise use __COUNTER__)
#define _v2 CONCAT(qyw2, __LINE__)
#define forbits(i, m) for (int _v1 = m, i = __builtin_ctz(_v1); _v1 != 0; _v1 ^= _v1 & -_v1, i = __builtin_ctz(_v1))
#define forsubm(s, m) for (int s = m; s >= 0; s = !s ? -1 : m & (s - 1))
int __nextXZW(int v){int t=v|(v-1);int w=(t+1)|(((~t&-~t)-1)>>(__builtin_ctz(v)+1));return w;}
#define ksets(i, n, k) for (int i = (1u << k) - 1, max = i << (n - k); i <= max; i = __nextXZW(i))
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll N = 5e5+5, inf = 1e9+5000;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <atcoder/lazysegtree>
#include <atcoder/modint>
using namespace atcoder; 
using mint = modint998244353;

struct S { mint a; int size; };
S op(S x, S y) { return {x.a + y.a, x.size + y.size}; }
S e() { return {0, 0}; }
struct F { mint b; mint c; };
S mapping(F f, S x) { return {f.b * x.a + f.c * x.size, x.size}; }
F composition(F f, F g) { return { f.b*g.b, f.b*g.c + f.c }; }
F id() { return {1, 0}; }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n, q; cin >> n >> q;
  vector<S> a(n); 
  rep (i, n) {
    int x; cin >> x;
    a[i].a = x;
    a[i].size = 1;
  }

  lazy_segtree<S, op, e, F, mapping, composition, id> st(a);

  while (q--) {
    int type, l, r; cin >> type >> l >> r;
    if (type == 0) {
      int b, c; cin >> b >> c;
      st.apply(l, r, {b, c});
    } else {
      cout << st.prod(l, r).a.val() << '\n';
    } 
  }
  
  return 0;
}

Measured memory_bytes: 19468
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top,S[1000];

void push(int x)
{
  S[++top]=x;
}

int pop()
{
  top--;
  return S[top+1];
}

int main (){
  int a,b;
  top=0;
  char s[100];
  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(s[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }
    else if(s[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    else push(atoi(s));
  }

  printf("%d\n",pop());

  return 0;
}



Measured memory_bytes: 1992