akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  I n,m;
  cin >> n >> m;
  V p(n);
  VIN(p);
  UnionFind xy(n+1);
  REP(i,m){
    I x,y;
    cin >> x >> y;
    xy.unite(x,y);
  }
  I t=0;
  REP(i,n+1){
    if (i == 0) continue;
    I x = p.at(i-1);
    if (x == i){
      t++;
    }else{
      if (xy.find(x) == xy.find(i)){
        t++;
      }
    }
  }
  cout << t << endl;
  return 0;
}



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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int N,M;
    string s;
    cin >> N >> M >> s;
    vector<set<int>> graph(N);
    rep(i,0,M){
        int a,b;
        cin >> a >> b;
        --a;
        --b;
        graph[a].insert(b);
        graph[b].insert(a);
    }

    vector<bool> erased(N);
    set<int> st;
    rep(i,0,N){
        bool a=false,b=false;
        for(int j:graph[i]){
            if(s[j]=='A') a=true;
            else b=true;
        }
        if(!a or !b){
            erased[i]=true;
            st.insert(i);
        }
    }

    while(!st.empty()){
        int u=*st.begin();
        st.erase(u);
        for(int v:graph[u])
        {
            graph[v].erase(u);
        }
        for(int v:graph[u]){
            if(erased[v]) continue;
            bool a=false,b=false;
            for(int w:graph[v]){
                if(s[w]=='A') a=true;
                else b=true;
                if(a and b) break;
            }
            if(!a or !b){
                erased[v]=true;
                st.insert(v);
            }
        }
    }

    int cnt=0;
    rep(i,0,N) if(erased[i]) ++cnt;
    cout << (cnt==N?"No":"Yes") << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 32592
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() { 
   string s,t;
   cin>>s>>t;
   cout<<t+s<<endl;

   
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>

using namespace std;


int main()
{

  int N;
  cin >> N;

  if(N == 1)  cout << 1 << endl;
  else cout << N*N*N << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
 
using namespace std;

void deleteBlankRow(vector<vector<char>>& grid);
void deleteBlankColumn(vector<vector<char>>& grid);
  
int main() {
    int numOfRows = 0;
    int numOfColumns = 0;
    cin >> numOfRows >> numOfColumns;
    
    vector<vector<char>> grid(numOfRows, vector<char>(numOfColumns));
    for (int i = 0; i < numOfRows; ++i) {
        for (int j = 0; j< numOfColumns; ++j) {
            cin >> grid.at(i).at(j);
        }
    }
    
    deleteBlankRow(grid);
    deleteBlankColumn(grid);

    for (size_t i = 0U; i < grid.size(); ++i) {
        for(size_t j = 0U; j < grid.at(i).size(); ++j) {
            cout << grid.at(i).at(j);
        }
        cout << endl;
    }
}

void deleteBlankRow(vector<vector<char>>& grid) {
    stack<int> blankRowNum;
    for (size_t i = 0U; i < grid.size(); ++i) {
        bool isBlankRow = true;
        for(size_t j = 0U; j < grid.at(i).size(); ++j) {
            if(grid.at(i).at(j) == '#') {
                isBlankRow = false;
                break;
            }
        }
        if (isBlankRow) {
            blankRowNum.push(i);
        }    
    }
    
    while (!blankRowNum.empty()) {
        grid.erase(grid.begin() + blankRowNum.top());
        blankRowNum.pop();
    }
}

void deleteBlankColumn(vector<vector<char>>& grid) {
    stack<int> blankColumnNum;
    for (size_t i = 0U; i < grid.at(0).size(); ++i) {
        bool isBlankColumn = true;
        for(size_t j = 0U; j < grid.size(); ++j) {
            if (grid.at(j).at(i) == '#') {
                isBlankColumn = false;
                break;
            }
        }
        if (isBlankColumn) {
            blankColumnNum.push(i);
        }    
    }
    
    while(!blankColumnNum.empty()) {
        for (size_t i = 0U; i < grid.size(); ++i) {
            grid.at(i).erase(grid.at(i).begin() + blankColumnNum.top());
        }
        blankColumnNum.pop();
    }
}

Measured memory_bytes: 3644
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>

using namespace std;
typedef long long LL;
typedef pair<LL, LL> LLLL;

const int MAX_W = 100000;
const int THRESHOLD = 1 << 9;

vector<LL> v;
vector<LL> w;

vector<LLLL> calc(int node, LL max_weight) {
	int init_node = node;
	vector<LLLL> dp;
	dp.emplace_back(LLLL(0, 0));
	while (node > 0 && (init_node < THRESHOLD || node >= THRESHOLD)) {
		vector<LLLL> next = dp;
		for (auto kv : dp) {
			if (kv.first + w[node] > max_weight) continue;
			next.emplace_back(LLLL(kv.first + w[node], kv.second + v[node]));
		}
		dp = next;
		node /= 2;
	}
	return dp;
}

int main(int argc, char* argv[]) {
	int n, q, x, y;
	cin >> n;
	v.resize(n + 1);
	w.resize(n + 1);
	for (LL i = 1; i <= n; ++i) {
		cin >> v[i] >> w[i];
	}
	vector<vector<LL>> lower;
	if (n >= THRESHOLD) {
		lower.resize(THRESHOLD);
		vector<vector<LLLL>> dp(THRESHOLD);
		dp[0].emplace_back(LLLL(0, 0));
		for (int i = 1; i < THRESHOLD; ++i) {
			vector<LLLL> next = dp[i / 2];
			for (auto kv : dp[i / 2]) {
				if (kv.first + w[i] > MAX_W) continue;
				next.emplace_back(LLLL(kv.first + w[i], kv.second + v[i]));
			}
			if (i >= THRESHOLD / 2) {
				next.emplace_back(LLLL(MAX_W + 1, 0));
				sort(next.begin(), next.end());
				LL filled_index = 0, prev_max_value = 0;
				lower[i].resize(MAX_W + 1);
				for (auto kv : next) {
					for (LL j = filled_index; j < kv.first; ++j) {
						lower[i][j] = prev_max_value;
					}
					filled_index = kv.first;
					prev_max_value = max(prev_max_value, kv.second);
				}
			} else {
				dp[i] = next;
			}
		}
	}
	cin >> q;
	for (LL tt = 0; tt < q; ++tt) {
		cin >> x >> y;
		LL ans = 0;
		vector<LLLL> r = calc(x, y);
		if (x < THRESHOLD) {
			for (auto kv : r) {
				ans = max(ans, kv.second);
			}
		} else {
			while (x >= THRESHOLD) {
				x /= 2;
			}
			for (auto kv : r) {
				ans = max(ans, kv.second + lower[x][y - kv.first]);
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 208924
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;

int main(){

	int n, a[10000], ans=0;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	for(int i=0; i<n; i++){
		while(a[i]%2==0){
			ans++;
			a[i]/=2;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
using namespace std; typedef long long ll; const int INF=1e9+7;
typedef pair<ll,ll> P;

int main() {
  ll n,p; cin>>n>>p;
  map<ll,ll> mp;
  for(ll i=2;i*i<=p;i++) {
    while(p%i==0) p/=i, mp[i]++;
  }
  mp[p]++;

  ll an=1;
  for(P x:mp) {
    for(ll i=0;i<x.second/n;i++) {
      an*=x.first;
    }
  }
  cout<<an<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

	int a[100];
	int b,c,i,j;
	
	scanf("%d",&b);
		
	for(i=0;i<b;i++){
		scanf("%d",&a[i]);
	}
	
	for(i=0;i<b;i++){
		for(j=i+1;j<b;j++){
			c=a[i];
			a[i]=a[j];
			a[j]=c;
		}
	}
	
	for(i=0;i<b;i++){
		if(i!=0){
			printf(" ");
		}
		printf("%d",a[i]);
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int main() 
{
	long long int a,b;
	cin>>a>>b;
	bool flag;
	if(a<=1 && b<=1)
	 flag=false;
	else
  	{
   	  if(a==0 || b==0)
	   flag=true;
   	  else
	  {
          if(a==b)
           flag=false;
          else
          { 
            if(llabs(a-b)==1)
             flag=false;
            else
             flag=true;
          }
	  }
	}
    if(flag)
     cout<<"Alice";
    else
     cout<<"Brown";
     return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
char c[100][101];
int h,w;
void del(int a,int b,char t){
	c[a][b]='.';
	if(a>0&&c[a-1][b]==t)del(a-1,b,t);
	if(b>0&&c[a][b-1]==t)del(a,b-1,t);
	if(a<h-1&&c[a+1][b]==t)del(a+1,b,t);
	if(b<w-1&&c[a][b+1]==t)del(a,b+1,t);
	return;
}
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		h=a;
		w=b;
		for(int i=0;i<a;i++){
			scanf("%s",c[i]);
		}
		int ret=0;
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				if(c[i][j]!='.'){
					ret++;
					del(i,j,c[i][j]);
				}
			}
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9+7;

vector<ll> fact;

ll m_pow(ll p, ll n){
    if(n==0) return 1;
    else if(n%2){
        ll now = m_pow(p,(n-1)/2);
        return (now*now%MOD)*p%MOD;
    }
    else{
        ll now = m_pow(p,n/2);
        return now*now%MOD;
    }
}

ll m_comb(ll n, ll k){
    fact.resize(n+1);
    fact[0] = 1;
    rep(i,n) fact[i+1] = fact[i]*(i+1)%MOD;
    ll ans;
    ans = (fact[n]*m_pow(fact[k],MOD-2)%MOD)*m_pow(fact[n-k],MOD-2)%MOD;
    return ans;
}

int main(){
    int x,y;
    cin >> x >> y;
    if( (2*x-y)%3!=0 ||  (2*y-x)%3!=0 || (2*y-x)<0 || (2*x-y)<0 ) {
        cout << 0 << endl;
        return 0;
    }

    int l = (2*x-y)/3, k = (2*y-x)/3;
    //calc n+kCk
    cout << m_comb(k+l,k) << endl;
    return 0;
}

Measured memory_bytes: 8480
#include <iostream>
#include <stack>
#include <cstdio>
using namespace std;
int main(){
  stack<int>st;
  int a;
  cin >> a;
  st.push(a);
  while(scanf("%d",&a) != EOF){
    if(!a){
      cout << st.top() << endl;
      st.pop();
    }else{
      st.push(a);
    }
  }
  return(0);
}

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

using namespace std;

typedef long long ll;

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

	ll x;
	cin >> x;

	ll ans = x / 500 * 1000;
	ll q = x / 500;
	x -= q * 500;

	ans += x / 5 * 5;

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int R;

  cin >> R;

  cout << 3 * R * R << endl;

  return 0;
}


Measured memory_bytes: 256
while True:
    s = input()
    if s == "-":
        break
    l = list(s)
    m = int(input())
    top = 0
    for i in range(m):
        h = int(input())
        top = (top+h) % len(l)
    for i in range(top, top+len(l)):
        print(l[i%len(l)],end="")
    print("")

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

int n;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	if(n % 1000 == 0) cout<<0<<endl;
	else cout<< 1000 - n % 1000 <<endl;
}


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

typedef long long ll;

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

    int n,m,a,b;
    cin >> n >> m;
    int cnt[200050] = {0};
    for(int i=0;i<m;i++){
        cin >> a >> b;
        if(a==1) cnt[b]++;
        if(b==n) cnt[a]++;
    }
    for(int i=0;i<200050;i++){
        if(cnt[i]==2){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {FIN
	
	int d;
	string num;
	cin >> num;
	d = num[(int)num.size() - 1] - '0';
	if (d == 2 or d == 4 or d == 5 or d == 7 or d == 9)
		cout << "hon\n";
	else if (d == 0 or d == 1 or d == 6 or d == 8)
		cout << "pon\n";
	else
		cout << "bon\n";
	return 0;
}


Measured memory_bytes: 3636
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ll int
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
const ll mod = 1000000007;
const ll mod9 = 1000000009;

signed main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> a2(n);
    map<ll,ll> MP;
    vector<map<ll,ll>> MP2(n);
    vector<vector<ll>> mp3(n);
    rep(i,n) {
        scanf("%d",&a[i]);
        MP[a[i]]++;
    }
    sort(a.begin(),a.end());

    rep(i,n) a2[i]=a[i];
    a2.erase(unique(a2.begin(),a2.end()),a2.end());
    ll sz2 = a2.size();
    ll sz1 = a.size();
    rep(i,sz2){
        rep(j,(int)sqrt(a2[i])+1){
            if(a2[i]%(j+1)==0){
                    mp3[i].push_back(j+1);
                    // cout<<j+1<<" ";
                
                    mp3[i].push_back(a2[i]/(j+1));
                    // cout<<a2[i]/(j+1)<<" ";
                
            }
        }
    }
    ll ct=0;
    bool f=0;
    //rep(i,sz2) cout<<a2[i]<<endl;
    ll sz3;
    rep(i,sz2){
        f=0;
        if(MP[a2[i]]>=2) {
            continue;
            f=1;
        }
        sz3 = mp3[i].size();
        rep(j,sz3){
            if(mp3[i][j]!=a2[i]){
                if(binary_search(a2.begin(),a2.end(),mp3[i][j])==true){
                    f=1;
                    //cout<<" "<<a2[i]<<endl;
                    break;
                }
            }
        }
        if(!f) {
            ct++;
            //cout<<"<>"<<a2[i]<<endl;
        }
    }
    printf("%d\n",ct);
}


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

#define MAX 100

int main() {
	int H, W, N;
	vector<int> cols;
	cin >> H >> W >> N;
	int c[MAX][MAX];
	for (int i = 1; i <= N; i++) {
		int a;
		cin >> a;
		for (int j = 0; j < a; j++) {
			cols.push_back(i);
		}
	}
	for (int h = 0; h < H; h++) {
		for (int w = 0; w < W; w++) {
			c[h][w] = cols.back();
			cols.pop_back();
		}
		h++;
		if (h == H)
			break;
		for (int w = W - 1; w >= 0; w--) {
			c[h][w] = cols.back();
			cols.pop_back();
		}
	}
	for (int h = 0; h < H; h++) {
		for (int w = 0; w < W; w++) {
			cout << c[h][w] << " ";
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_set>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long

int a, b;
bool cell[100][100];

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

    int blackRowCount = ((a+49)/50)*2;
    int whiteAreaCount = 0;
    rep(i, blackRowCount)
    {
        if(i % 2 == 0)
        {
            rep(j, 100)
            {
                if(j % 2 == 0)
                {
                    if(whiteAreaCount < a - 1)
                    {
                        cell[i][j] = false;
                        whiteAreaCount++;
                    }
                    else
                    {
                        cell[i][j] = true;
                    }
                }
                else
                {
                    cell[i][j] = true;
                }
            }
        }
        else
        {
            rep(j, 100)
            {
                cell[i][j] = true;
            }
        }
    }

    int whiteRowCount = ((b+49)/50)*2;
    int blackAreaCount = 0;
    loop(i, blackRowCount, blackRowCount + whiteRowCount)
    {
        if(i % 2 == 0)
        {
            rep(j, 100)
            {
                cell[i][j] = false;
            }
        }
        else
        {
            rep(j, 100)
            {
                if(j % 2 == 0)
                {
                    if(blackAreaCount < b - 1)
                    {
                        cell[i][j] = true;
                        blackAreaCount++;
                    }
                    else
                    {
                        cell[i][j] = false;
                    }
                }
                else
                {
                    cell[i][j] = false;
                }
            }
        }
    }

    int h = blackRowCount + whiteRowCount;
    int w = 100;
    cout << h << " " << w << endl;
    rep(i, h)
    {
        rep(j, w)
        {
            if(cell[i][j])
                cout << "#";
            else
                cout << ".";
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
	public static void main(String[] args) throws IOException {
		String str="";
		BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));

		str=bfr.readLine();
		int kaisu=Integer.parseInt(str);
		int[] balls=new int[10];
		int[] case1=new int[10];
		int[] case2=new int[10];
		String[] matome;


		int counter=0;
		int cnt1=0;
		int cnt2=0;
		boolean c1_jun=true;
		boolean c2_jun=true;
		boolean said=false;
		String str1="";
		String str2="";

		for(int h=0; h<kaisu; h++) {
			str=bfr.readLine();
			matome=str.split(" ");
			for(int i=0; i<10; i++) {
				case1[i]=0;
				case2[i]=0;
				balls[i]=Integer.parseInt(matome[i]);
			}
			for(int i=0; i<1024; i++) {
				counter=i;
				for(int j=0; j<10; j++) {
					if(counter%2==0) {
						case1[cnt1]=balls[j];
						cnt1++;
					}

					else if(counter%2==1) {
						case2[cnt2]=balls[j];
						cnt2++;
					}
					counter=counter/2;
				}

				for(int j=1; j<cnt1; j++) {
					if(case1[j-1]<case1[j] && c1_jun==true) {
						c1_jun=true;
					}
					else {
						c1_jun=false;
						break;
					}
				}

				for(int j=1; j<cnt2; j++) {
					if(case2[j-1]<case2[j] && c2_jun==true) {
						c2_jun=true;
					}
					else {
						c2_jun=false;
						break;
					}
				}

				if(c1_jun==true && c2_jun==true) {
					System.out.println("YES");
					said=true;
					c1_jun=true;
					c2_jun=true;
					cnt1=0;
					cnt2=0;
					for(int j=0; j<10; j++) {
						case1[j]=0;
						case2[j]=0;
					}
					break;
				}
				c1_jun=true;
				c2_jun=true;
				cnt1=0;
				cnt2=0;
				for(int j=0; j<10; j++) {
					case1[j]=0;
					case2[j]=0;
				}
			}
			if(said==false)System.out.println("NO");
			said=false;
		}
	}
}


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

int main ()
{
	char c;
	cin >> c;
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') puts ("vowel");
	else puts ("consonant");
	return 0;
}

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

int n, x, ans = 0, a[100];

int main() {
    cin >> n >> x;
    rep(i, n) cin >> a[i];
    sort(a, a + n);
    rep(i, n) {
        if (a[i] <= x) {
            x -= a[i];
            ans++;
            if (i == n-1 && x > 0) ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define Set(a, b) memset(a, b, sizeof (a))
#define For(i, j, k) for (register int i = j; i <= k; ++ i)
#define Forr(i, j, k) for (register int i = j; i >= k; -- i)

using namespace std;

inline void File() {
	freopen("speech.in", "r", stdin);
	freopen("speech.out", "w", stdout);
}

const int N = 2e3 + 5; char str[N][N];
int n, m, t[N][N], s[N][N], ans, sta[N], tp, len, l[N];

inline int mul(int a, int b) { return (a + 1) * (b + 1); }

inline void solve(int *h) {
	sta[tp = 0] = 0, len = 0;

	For(i, 1, m) {
		if (h[i] >= sta[tp]) 
			sta[++ tp] = h[i], l[tp] = 1;
		else {
			for (len = 0; tp && sta[tp] > h[i]; -- tp)
				len += l[tp], ans = max(ans, mul(len, sta[tp]));
			sta[++ tp] = h[i], l[tp] = len + 1;
		}
	}

	for (len = 0; tp; -- tp) 
		len += l[tp], ans = max(ans, mul(len, sta[tp]));
}

int main() {

	scanf("%d%d", &n, &m);

	For(i, 1, n) scanf("%s", str[i] + 1);

	For(i, 1, n) For(j, 1, m) t[i][j] = str[i][j] == '#';

	For(i, 1, n - 1) For(j, 1, m - 1) {
		int sum = t[i][j] + t[i + 1][j] + t[i][j + 1] + t[i + 1][j + 1];
		if (!(sum & 1)) s[i][j] = 1;
	}
	-- n, -- m, Set(t, 0);

	For(i, 1, n) For(j, 1, m)
		if (s[i][j] == 1) t[i][j] = t[i - 1][j] + 1;

	For(i, 1, n) solve(t[i]);

	ans = max(max(n + 1, m + 1), ans);

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


Measured memory_bytes: 35584
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <ios>
#include <vector>
#include <cmath>
using namespace std;
int main(void){
  int a,b,c;
  cin >> a >> b >> c;
  
  cout << min({a + c,c + b,b + a}) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    char ch1, ch2, arry = 'A';
    
    while(scanf("%c,%c", &ch1, &ch2) != EOF){
        if (arry == ch1 || arry == ch2){
            if (arry == ch1) arry = ch2;
            else             arry = ch1;
        }
    }
    printf("%c\n", arry);
    
    return 0;
}

Measured memory_bytes: 544
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto xy = readln.split.to!(int[]);
    auto X = xy[0];
    auto Y = xy[1];
    foreach (i; 0..X+1) {
        auto j = X-i;
        if (i*2 + j*4 == Y) {
            writeln("Yes");
            return;
        }
    }
    writeln("No");
}

Measured memory_bytes: 2716
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 100000
int a[N+2];

int main(){
    int n;
    scanf("%d",&n);
    int sum = 0;
    for(int i=1;i<n+1;i++){
        int num;
        scanf("%d",&num);
        sum += abs(a[i-1]-num);
        a[i]=num;
    }
    sum +=abs(a[n]-a[n+1]);
    for(int i=1;i<=n;i++){
        int t=abs(a[i-1]-a[i])+abs(a[i]-a[i+1])-abs(a[i-1]-a[i+1]);
        printf("%d\n",sum-t);
    }
    return 0;
}

Measured memory_bytes: 1536
#include <iostream>

using namespace std;

int main() {
	int N, M,L[100001],R[100001],max,min;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> L[i] >> R[i];
	}
	min = L[0];
	max = R[0];
	for (int i = 0; i < M; i++) {
		if (L[i] > min)min = L[i];
		if (R[i] < max)max = R[i];
	}
	if (max - min < -1) {
		max = 1;
		min = 2;
	}
	cout << max - min + 1 << endl;
		return 0;
}


Measured memory_bytes: 1024
import sys
class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = self.right = None

root = None

def insert(key):
    global root
    x, y = root, None
    while x:
        y = x
        if key < x.key:
            x = x.left
        else:
            x = x.right

    if y is None:
        root = Node(key)
    elif key < y.key:
        y.left = Node(key)
    else:
        y.right = Node(key)

def find(key):
    global root
    x = root
    while x:
        if key < x.key:
            x = x.left
        elif key == x.key:
            return "yes"
        else:
            x = x.right
    return "no"
            
def inorder(node):
    return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
def preorder(node):
    return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''

n = int(input())
for e in sys.stdin:
    if e[0] == 'i':
        insert(int(e[7:]))
    elif e[0] == "f":
        print(find(int(e[5:])))
    else:
        print(inorder(root))
        print(preorder(root))


Measured memory_bytes: 53640
N, K = map(int, input().split())
a = list(map(int, input().split()))

dp = [0] * (K + 1)

for i in range(1, K + 1):
    for j in range(N):
        if i - a[j] >= 0 and dp[i - a[j]] == 0:
            dp[i] = 1

print('First' if dp[K] else 'Second')


Measured memory_bytes: 74240
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    N = int(input())
    stones = input()

    count = 0
    visited = 0
    r = stones[::-1]
    for i in range(N):
        if stones[i] == "W":
            j = r.find('R', visited, N-i)
            if j > -1:
                visited = j + 1
                count += 1

    return count


def main():
    print(solve())


if __name__ == "__main__":
    main()


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

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

    //good luck kittu!
    int k, x; cin>>k>>x;
    if(k*500 >= x) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
ll f(ll n){
    return (n*n + 4) / 8;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll N = S.size();
    ll c1 = 0, c2 = 0;
    rep(i,0,N){
        if(S[i] == 'A'){
            c1 = i;
            break;
        }
    }
    rrep(i,N-1,0){
        if(S[i] == 'Z'){
            c2 = i;
            break;
        }
    }
    print(c2 - c1 + 1);
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(long long i=0;i<(n);i++)
#define rep2(i,m,n) for(long long i=(m);i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back




int main(){


    int n;
    cin>>n;

    vi ans(n+1,0);


    for (int i=1;i<=99;i++){
        for (int j=1;j<=99;j++){
            for (int k=1;k<=99;k++){
                int tmp;
                tmp=i*i+j*j+k*k+i*j+j*k+k*i;
                if (1<=tmp and tmp<=n){
                    ans.at(tmp)++;
                }


            }
        }
    }


    for (int i=1;i<=n;i++){
        cout<<ans.at(i)<<endl;
    }


    









}








            






Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
using ll = long long;


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

    // sのi番目までとtのj番目までの結果がdp[i][j]
    vector<vector<int>> dp (s.size() + 1, vector<int>(t.size() + 1));
    for (int i = 0; i < s.size(); ++i) {
        for (int j = 0; j < t.size(); ++j) {
            if(s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j] + 1;
            }else{
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }
    }

    string ans;
    int i=s.size(), j=t.size();

    while (i && j) {
        if(dp[i-1][j]==dp[i][j]) {
            --i;
        }else if(dp[i][j-1]==dp[i][j]){
            --j;
        }else {
            ans = s[i-1] + ans;
            --i;
            --j;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 35584
#include <stdio.h>


int gcd(int a, int b){
	return b ? gcd(b, a % b) : a;
}

int main(){
	int n, x, ans = 0;
	scanf("%d%d", &n, &x);
	for(int i = 0; i < n; ++i){
		int tmp;
		scanf("%d", &tmp);
		ans = gcd(ans, x - tmp);
	}
	printf("%d\n", ans > 0 ? ans : -ans);
}


Measured memory_bytes: 128
#include<bitset>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
int A[2011];
bitset<4000064> B;

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%d", A+i);

    B.set(0);
    int s = 0;
    REP (i, N) {
	B |= B << A[i];
	s += A[i];
    }

    int ans = 0;
    REP (i, s+1) if (i <= s-i && B.test(i) && B.test(s - i)) {
	ans = s-i;
    }
    printf("%d\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
struct edge{int to,cost;};
#define INF (1<<28)
#define MAX_N 6005
#define MAX_M 2005

struct state{
  int pos,cost;
  bool operator < ( const state &p)const{
    return cost > p.cost;
  }
};

int n,m,l,cnt;
string si,ti,str;
vector<edge> G[MAX_N];
map<string,int> change;
int T[MAX_M][MAX_M];
int d[MAX_N];

int A[MAX_M];
int B[MAX_M];

void solve(int si){
  for(int i=0;i<MAX_N;i++)d[i]=INF;
  priority_queue< state > Q;
  d[si]=0;
  Q.push((state){si,0});
  while(!Q.empty()){
    state s=Q.top();Q.pop();
    if(s.cost>d[s.pos])continue;
    if(s.cost>l)break;
    for(int i=0;i<(int)G[s.pos].size();i++){
      edge e=G[s.pos][i];
      if(s.cost+e.cost<d[e.to]){
        d[e.to]=s.cost+e.cost;
        Q.push((state){e.to,d[e.to]});
      }
    }
  }
}

void init(){
  change.clear();
  for(int i=0;i<MAX_N;i++){
    G[i].clear();
  }
}

int main(){
  while(1){
    cin>>n>>m>>l;
    if(n==0&&m==0&&l==0)break;
    l*=10;
    
    cin>>si>>ti;
    init();
    cnt=1;
    for(int i=0;i<n;i++){
      cin>>str;
      if(change[str]==0)
        change[str]=cnt++;
      int a=change[str];
      cin>>str;
      if(change[str]==0)
        change[str]=cnt++;
      int b=change[str];
      int c;
      cin>>c;
      G[a].push_back((edge){b,c});
      G[b].push_back((edge){a,c});
    }
    vector<int> vec;
    for(int i=0;i<m;i++){
      cin>>str;
      vec.push_back(change[str]);
    }

    for(int i=0;i<m;i++){
      solve(vec[i]);
      for(int j=0;j<m;j++){
        T[i][j]=d[vec[j]];
      }
    }


    int ans=INF;
    solve(change[si]);
    for(int i=0;i<m;i++)A[i]=d[vec[i]];
    if(d[change[ti]] <= l)ans=d[change[ti]];
    
    
    solve(change[ti]);
    for(int i=0;i<m;i++)B[i]=d[vec[i]];
    
    priority_queue< state > Q;
    for(int i=0;i<m;i++){
      d[i]=INF;
      if(A[i]>l)continue;
      d[i]=A[i];
      Q.push((state){i,A[i]});
    }

    while(!Q.empty()){
      state s=Q.top();Q.pop();
      if(s.cost>d[s.pos])continue;
      for(int i=0;i<m;i++){
        if(T[s.pos][i]>l)continue;
        if(s.cost+T[s.pos][i]<d[i]){
          d[i]=s.cost+T[s.pos][i];
          Q.push((state){i,d[i]});
        }
      }
    }
    


    
    for(int i=0;i<m;i++){
      if(B[i]>l)continue;
      ans=min(ans,d[i]+B[i]);
    }

    if(ans==INF)cout<<-1<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 5704
/* ex3_2
   masaaki52	*/
#include <stdio.h>
int main(void){
  int number;
  int ichi;
  scanf("%d",&number);//numberに値を入力
  ichi = number % 10;//numberを10で割った余りをichiに代入
  if(ichi == 3){//ichiが3の場合
    printf("bon\n");//bonを出力
  }
  else if(ichi == 0 || ichi == 1 || ichi == 6 || ichi == 8){//ichiが0,1,6,8の場合
    printf("pon\n");//ponを出力
  }
  else{//上記以外の場合
    printf("hon\n");//honを出力
  }
  return 0;
}


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

#define ll              long long
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x, y)      cout << #x << "=" << x << " , " << #y << "=" << y << endl

typedef pair<int, int>ii;
typedef pair<ll, ll>pl;
typedef vector<int>vi;
typedef vector<ll>vl;
typedef vector<ii>vii;
typedef vector<pl>vll;
typedef vector<vi>vvi;
typedef vector<vl>vvl;


const int mod = 1000000007;
const int N = 1e5+5, M = N;


void solve()
{
    ll n,m;
    
    scanf("%lld",&n);
    if(n) printf("0\n");
    else printf("1\n");
}


int main()
{
    int t = 1, n, m, b, p;

    //scanf("%d",&t);

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

    return 0;
}




Measured memory_bytes: 3684
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

int main(){
    int n;
    cin >> n;
    rep(i,60000){
        if(i*108/100 == n){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;

}

Measured memory_bytes: 888
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class E
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (H, W, M) = Scanner.Scan<int, int, int>();
            var height = new int[H];
            var width = new int[W];
            var bombs = new HashSet<(int h, int w)>();
            for (var i = 0; i < M; i++)
            {
                var (h, w) = Scanner.Scan<int, int>();
                height[--h]++;
                width[--w]++;
                bombs.Add((h, w));
            }

            var hMax = 0;
            var wMax = 0;
            var hHash = new HashSet<int>();
            var wHash = new HashSet<int>();
            for (var i = 0; i < height.Length; i++)
            {
                if (hMax < height[i])
                {
                    hMax = height[i];
                    hHash.Clear();
                    hHash.Add(i);
                }
                else if (hMax == height[i])
                {
                    hHash.Add(i);
                }
            }

            for (var i = 0; i < width.Length; i++)
            {
                if (wMax < width[i])
                {
                    wMax = width[i];
                    wHash.Clear();
                    wHash.Add(i);
                }
                else if (wMax == width[i])
                {
                    wHash.Add(i);
                }
            }

            var answer = hMax + wMax;
            var ok = false;
            foreach (var h in hHash)
            {
                foreach (var w in wHash)
                {
                    if (!bombs.Contains((h, w))) ok = true;
                    if (ok) break;
                }
                if (ok) break;
            }

            if (!ok) answer--;

            Console.WriteLine(answer);
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
        }
    }
}


Measured memory_bytes: 72772
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    a = root(a);
    return -Parent[a];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(a < b) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }

  bool issame(int a, int b){
    return root(a) == root(b);
  }
};

int main(){
  string s; cin >> s;
  char dir[] = {'N','W','S','E'};
  vi c(4);
  rep(i,s.size()) {
    rep(j,4) {
      if(s[i] == dir[j]) c[j]++;
    }
  }

  bool ok = true;
  if((c[0] == 0) != (c[2] == 0)) ok = false;
  if((c[1] == 0) != (c[3] == 0)) ok = false;
  
  cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef pair<int,int> pii;
typedef pair<pii, int> piii;

int main() {
  int n;
  while(cin>>n,n) {
    set<piii> se;               // piii(pii(a, b), c) -> [a,b) É c ªÍ¢ÁÄéB
    REP(i,n) {
      char c;
      cin >> c;
      if (c=='W') {
        int a,m;
        cin>>a>>m;
        vector<piii> tmp;
        int pre = 0;
        FOR(it, se) {
          if (m == 0) break;
          pii p=it->first;
          if (p.first > pre) {
            int hoge = min(m, p.first-pre);
            tmp.push_back(piii(pii(pre, pre+hoge), a));
            m -= hoge;
          }
          pre = p.second;
        }
        if (m) {
          tmp.push_back(piii(pii(pre, pre+m), a));
        }
        se.insert(ALL(tmp));
      } else if (c == 'D') {
        int a;
        cin >> a;
        set<piii> tmp;
        FOR(it, se) {
          if(it->second != a)
            tmp.insert(*it);
        }
        se = tmp;
      } else {
        int m;
        cin >> m;
        int ans = -1;
        FOR(it, se) {
          pii p = it->first;
          if (p.first<=m && m<p.second) {
            ans = it->second;
            break;
          }
        }
        cout << ans << endl;
      }
       // cout << "i = " << i << endl;
       // FOR(it, se) {
       //   pii p =  it->first;
       //   printf("(%d,%d),%d ", p.first,p.second,it->second);
       // }
       // cout << endl;
    }
    cout << endl;
  }
}

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

int main() { 
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) {
  	cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  int sum = 0;
  rep(i, k){
  	sum += p[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <string>

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

    std::string S;
    std::cin >> S;

    std::vector<int> ints(4);
    for (int i = 0; i < 4; ++i) {
        ints[i] = S[i] - '0';
    }

    std::vector<int> sign(4, 1);
    int i = 0;
    int j = 0;
    int k = 0;
    bool found = false;
    for (i = 0; i < 2; ++i) {
        for (j = 0; j < 2; ++j) {
            for (k = 0; k < 2; ++k) {
                sign[1] = ((i == 0) ? 1 : -1);
                sign[2] = ((j == 0) ? 1 : -1);
                sign[3] = ((k == 0) ? 1 : -1);

                // inner product
                int sum = 0;
                for (int l = 0; l < 4; ++l) {
                    sum += sign[l] * ints[l];
                }
                if (sum == 7) found = true;
                if (found) break;
            }
            if (found) break;
        }
        if (found) break;
    }

    std::string ans(9, '7');
    for (int i = 0; i < 4; ++i) {
        ans[i*2   ] = S[i];
    }
    for (int i = 0; i < 3; ++i) {
        ans[i*2 +1] = ((sign[i+1] == 1) ? '+' : '-');
    }

    ans[7] = '=';

    std::cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 100000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;

pii add(const pair<int,int>& obj1, const pair<int,int>& obj2) { 
    int x = obj1.first + obj2.first;
    int y = obj1.second + obj2.second;
    pii ret = { x,y };
    return ret;
}

template<typename T>
int BFS(vector<vector<T>> & table, pii start) { // {(distance from Start, x-coordinate of max_dist,y-coordinate of max_dist}
    queue<pii> q;
    vector<pii> move = {{1, 0}, { -1, 0 }, { 0,1 }, { 0,-1 } };
    vvi dp(table.size(), vi(table[0].size(), pint_INF));
    dp[start.first][start.second] = 0;
    q.push(start);
    int max = 0;
    pii ret;

    while (!q.empty()) {
        pii u = q.front(); q.pop();
        for (int i = 0; i < move.size(); i++) {
            pii temp = add(u,move[i]);
            if (0 <= temp.first and temp.first < table.size() and 0 <= temp.second and temp.second < table[0].size()) {
                if (table[temp.first][temp.second] == '.' and dp[temp.first][temp.second] == pint_INF) {
                    dp[temp.first][temp.second] = dp[u.first][u.second] + 1;
                    if (dp[temp.first][temp.second] > max) {
                        max = dp[temp.first][temp.second];
                        ret = { temp.first,temp.second };
                    }
                    q.push(temp);
                }
            }
        }
    }

    //vi vec = { max, ret.first, ret.second };
    return max;
}

int main() {
    int H, W; cin >> H >> W;
    vector<vector<char>> table(H, vector<char>(W));
    int dist = 0;
    rep(i, H)rep(j, W) cin >> table[i][j];
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (table[i][j] == '.') {
                BFS(table, { i,j }) > dist ? dist = BFS(table, { i,j }) : 1;
            }
        }
    }
    cout << dist << endl;

}

Measured memory_bytes: 256