akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repd(a,b,c) for(int a=c;a>=b;a--)
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define pb push_back
#define pbb pop_back
const int N = 5e5+100;
const int mod=1e9+7;
const int inf=1e18;
int power(int a,int b)
{
  int ans=1;
  while(b)
  {
    if(b&1)ans*=a;
    a*=a;
    b/=2;
  }
  return ans;
}
struct node
{
  int h,p;
};
int arr[4000][4000];
/*void printPascal(int n) 
{ 
      
    // An auxiliary array to store  
    // generated pscal triangle values 
    //int arr[n][n];  
  
    // Iterate through every line and  
    // print integer(s) in it 
    for (int line = 1; line <= n; line++) 
    { 
        // Every line has number of integers  
        // equal to line number 
        for (int i = 1; i <= line; i++) 
        { 
        // First and last values in every row are 1 
        if (line == i || i == 1) 
            arr[line][i] = 1; 
        // Other values are sum of values just  
        // above and left of above 
        else
            arr[line][i] = arr[line - 1][i - 1] +  
                            arr[line - 1][i]; 
       // cout << arr[line][i] << " "; 
        } 
       // cout << "\n"; 
    } 
} */
int add(int a, int b){return (a%mod + b%mod + mod)%mod;}
int sub(int a, int b){return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b){return ((a%mod)*(b%mod) + mod)%mod;}
signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int T=1;
    //cin>>T;
    while(T--)
    {
      int n,m;
      cin>>n>>m;
      int a[n+1]={0};
      bool red[n+1];
      rep(i,1,n+1)
      {
        a[i]=1;
        red[i]=false;
      }
      red[1]=true;
      rep(i,0,m)
      {
        int x,y;
        cin>>x>>y;
        if(a[x])
        {
          a[y]++;
          if(red[x])
          {
            red[y]=true;
          }
          a[x]--;
          if(a[x]==0)red[x]=false;
        }
      }
      int ans=0;
      rep(i,1,n+1)
      {
        if(red[i])ans++;
      }
      cout<<ans<<"\n";
    }
  
    
    
               

                

     

        
        
      
      
      
    
    

    
    
}

Measured memory_bytes: 1152
H, W = map(int,input().split())

hw = []
hw.append('.'*(W+2))
for _ in range(H):
    edited = input()
    edited = '.' + edited + '.'
    hw.append(edited)
hw.append('.'*(W+2))
#四方を白に囲まれた黒がある場合に達成不可能
for i in range(1,H+1):
    for j in range(1,W+1):
        if hw[i][j] == '#':
            #探索
            if hw[i+1][j] == '.' and hw[i-1][j] == '.' and hw[i][j+1] == '.' and hw[i][j-1] == '.':
                print('No')
                quit()

print('Yes')

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

int main(){
  string S;
  long long int sum = 0;
  cin >> S;
  int n = S.size() - 1;
  
  for(int bit = 0; bit < (1<<n); bit++){
    long long int a = 0;
    for(int i=0; i < n+1;i++){
      a = a*10 + (int)S[i] - 48;
  	  //cout << a << endl;
      
      if(i==n)
        sum += a;
      else if((bit & (1 << i))){
        sum += a;
        a = 0;
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3628
#include<stdio.h>
int main(void){

int W;
int H;
int x;
int y;
int r;
int a;
int b;
int c;
int d;

scanf("%d",&W);
scanf("%d",&H);
scanf("%d",&x);
scanf("%d",&y);
scanf("%d",&r);

a=x+r;
b=x-r;
c=y+r;
d=y-r;

if(H<c) puts("No");
else if(d<0) puts("No");
else if(W<a) puts("No");
else if(b<0) puts("No");
else puts("Yes");
return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <queue>
#include <vector>
#include <climits>
using namespace std;

/*
 * ??\??????warshallfloyd??????????????°??????
 * ??°?????????[?????????i] - [?????????j]????????????????????¢????±?????????¢??°
 * ??\?????¨?????????weight[NODE_NUM][NODE_NUM]?????¨??????
 * ?????????????????????????????¢???weight[i][i]??????0?????\??£????????????
 * [?????????i] - [?????????j]???????????\?¶?????????????????????´??????INF???????´??????????
 */

#define NODE_NUM 101
#define INF INT_MAX

int weight[NODE_NUM][NODE_NUM];

/*
 * ??????????????????????????????????????´?????????-1?????????
 * n:?????????????????°
 */
int WarshallFloyd(int n){
    
    for(int k=0; k < n; k++) {
        for(int i=0; i < n; i++) {
            for(int j=0; j < n; j++) {
                if(weight[i][k] != INF && weight[k][j] != INF)
                    weight[i][j] = min(weight[i][j], weight[i][k] + weight[k][j]);
            }
        }
    }
    
    //????????????????????????0??????????????????????????´??????????????????????????????????????????
    for(int v = 0; v < n; v++){
        if(weight[v][v] < 0) return -1;
    }
    
    return 1;
}

int main( ){
    
    int i, V, E, u, v, c;
    int rtn;
    cin >> V >> E;
    
    //????????????????????????0???????????\??????INF??¨??????
    for (int i = 0; i < V; i++) {
        for (int j =0; j < V; j++) {
            if(i == j) weight[i][j] = 0;
            else weight[i][j] = INF;
        }
    }

    for (i = 0; i < E; i++) {
        cin >> u >> v >> c;
        weight[u][v] = c;
    }
    
    rtn = WarshallFloyd(V);
    if (rtn == -1) {
        cout << "NEGATIVE CYCLE" << endl;
        return 0;
    }
    
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < V; j++) {
            if(weight[i][j] == INF){
                cout << "INF";
            }else{
                cout << weight[i][j];
            }
            if (j < V-1) {
                 cout << " ";
            }
            else{
                cout << endl;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>

int main(void){
  int n,k,i;
  int ans = 0;
  scanf("%d%d", &n, &k);
  int L[n];
  for (i = 0; i < n; i++){
    scanf("%d", &L[i]);
  }
  for (i = 0; i < n; i++){
    if (L[i] >= k){
      ans++;
    }
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
#ABC45 B

from collections import deque

sa = deque(input())
sb = deque(input())
sc = deque(input())

x = 'a'
while 1:
    if x == 'a':
        if len(sa) == 0:
            print('A')
            quit()
        x = sa.popleft()
    elif x == 'b':
        if len(sb) == 0:
            print('B')
            quit()
        x = sb.popleft()
    elif x == 'c':
        if len(sc) == 0:
            print('C')
            quit()
        x = sc.popleft()


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

int main() {
    int K; int X;
    cin>>K>>X;
    if(500*K>=X){
        cout<<"Yes";return 0;
    }
    else{
        cout<<"No";return 0;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

int main(){
	double W, H, x, y;
	cin >> W >> H >> x >> y;
	double ans = W * H / 2;
	cout << ans << endl;
	if(x == W / 2 && y == H / 2){
		cout << 1 << endl;
	}
	else{
		cout << 0 << endl;
	}
}

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


int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>b(100010);
  rep(i,n){
    cin>>a.at(i);
    b.at(a.at(i))++;
  }
  bool ch=true;
  rep(i,n){
    if(n%2==0){
      if(i%2==0){
        if(b.at(i)!=0){
          ch=false;
        }
      }
      else{
        if(b.at(i)!=2){
           ch=false;
        }
      }
    }
    else{
      if(i==0){
        if(b.at(i)!=1){
          ch=false;
        }
      }
      else if(i%2==0){
        if(b.at(i)!=2){
          ch=false;
        }
      }
      else{     
        if(b.at(i)!=0){
          ch=false;
        }
      }
    }
  }
  long ans=1;
  int c=n/2;
  while(c--){
    ans*=2LL;
    ans%=1000000007;
  }
    
    
  if(ch){
    cout<<ans<<endl;
  }
  else{
    cout<<0<<endl;
  }
 
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 1e18
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	//cin>>t;
	t=1;
	while(t--)
	{
        ll x,k,d,ans;
        cin>>x>>k>>d;
        if(x<0)
        {
        	x=x*(-1);
		}
		ll temp=x/d;
		if(temp<k)
		{
			temp=k-temp;
			//cout<<temp<<endl;
			if(temp%2==0)
			{
				ans=x%d;
				cout<<ans<<endl;
				continue;
			}
			else
			{
				ans=x%d;
				ans=ans-d;
				ans=abs(ans);
				cout<<ans<<endl;
				continue;
			}
		}
		else
		{
			temp=k*d;
			x=x-temp;
			ans=abs(x);
			cout<<ans<<endl;
		}
	}
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream> 
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <cassert>
using namespace std;

#define assert_range(x,a,b) assert((a) <= (x) and (x) <= (b))
using ll = long long;

ll minimum_cost_merge(const vector<int>& a) {
    int n = a.size();
    vector<vector<ll>> dp(n, vector<ll>(n));
    vector<ll> pref_sum(n+1);
    for (int i = 0; i < n; ++i) {
        pref_sum[i+1] = pref_sum[i] + a[i];
    }
    const ll INF = 1e18;
    for (int d = 2; d <= n; ++d) {
        for (int i = 0; i+d-1 < n; ++i) {
            int j = i+d-1;
            dp[i][j] = INF;
            for (int k = i; k < j; ++k) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + pref_sum[j+1] - pref_sum[i]);
            }
        }
    }
    return dp[0][n-1];
}
int main() {
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    auto res = minimum_cost_merge(a);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1536
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=[(int(input()),i) for i in range(n)]
    A.sort()
    d=0
    for i,tup in enumerate(A):
        a,j=tup
        d+=abs(j-i)%2

    print(d//2)
resolve()

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

#define N 100010
#define pii pair <int, int>
#define fi first
#define se second
int n;
vector <int> a, b;

int main() {
	while (scanf("%d", &n) != EOF) {
		a.clear(); b.clear(); 
		for (int i = 1, x; i <= n; ++i) {
			scanf("%d", &x);
			if (x <= 0) {
				a.push_back(x); 
			} else {
				b.push_back(x);
			}
		}
		vector <pii> vec;
		if (a.empty()) { //只有正数
			sort(b.begin(), b.end(), [&](int x, int y) {
				return x > y;		
			});
			int x = b.back(); b.pop_back(); 
			int y = b.back(); b.pop_back(); 
			vec.push_back(pii(x, y));
			a.push_back(x - y);
		} else if (b.empty()) { //只有负数
			sort(a.begin(), a.end(), [&](int x, int y) {
				return x < y;		
			});
			int x = a.back(); a.pop_back();
			int y = a.back(); a.pop_back();
			vec.push_back(pii(x, y));
			b.push_back(x - y);
		}
		//有正右负
		if (!a.empty() && !b.empty()) {
			while ((int)b.size() > 1) {
				int x = a.back(), y = b.back();
				vec.push_back(pii(x, y));  
				a.pop_back(); b.pop_back();
				a.push_back(x - y);  
			}	
			for (auto it : a) {
				int x = it, y = b.back();
				vec.push_back(pii(y, x));
				b.pop_back();
				b.push_back(y - x);
			}
		}
		printf("%d\n", vec.back().fi - vec.back().se);
		for (auto it : vec) {
			printf("%d %d\n", it.fi, it.se);
		}
	}
	return 0;
}


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
 
struct edge{int to,cap,rev;};
struct Maxflow{//ant book p.194
    vector<vector<edge> > G;
    vector<int> level,iter;
    void initsize(int nv){
        G.resize(nv);
        level.resize(nv);
        iter.resize(nv);
    }
    void add_edge(int from,int to,int cap){
        G[from].push_back((edge){to,cap,(int)G[to].size()});
        G[to].push_back((edge){from,0,(int)G[from].size()-1});
    }
    void bfs(int s){
        fill(level.begin(),level.end(),-1);
        //memset(level,-1,sizeof(level));
        queue<int> que;
        level[s]=0;
        que.push(s);
        while( !que.empty() ){
            int v = que.front();que.pop();
            for(int i=0;i<G[v].size();i++){
                edge &e = G[v][i];
                if(e.cap > 0 && level[e.to]<0){
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }
    int dfs(int v,int t,int f){
        if(v==t)return f;
        for(int &i = iter[v];i<G[v].size();i++){
            edge &e = G[v][i];
            if(e.cap>0 && level[v]<level[e.to]){
                int d = dfs(e.to,t,min(f,e.cap));
                if(d>0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    int max_flow(int s,int t){
        int flow=0;
        for(;;){
            bfs(s);
            if(level[t]<0)return flow;
            fill(iter.begin(),iter.end(),0);
            //memset(iter,0,sizeof(iter));
            int f;
            while((f=dfs(s,t,INT_MAX))>0){
                flow += f;
            }
        }
    }
};
  
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    Maxflow mf;
    int X,Y,E;
    cin>>X>>Y>>E;
    mf.initsize(X+Y+2);
    FOR(i,0,E){
        int x,y;
        cin >> x >> y;
        mf.add_edge(x+1,y+X+1,1);
    }
    FOR(i,1,X+1){
      mf.add_edge(0,i,1);
    }
    FOR(i,1,Y+1){
      mf.add_edge(i+X,X+Y+1,1);
    }
    cout<<mf.max_flow(0,X+Y+1)<<endl;
    return 0;
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define ll long long
using namespace std;
const int N=1e6+6,P=1e9+7;
int inv[N],x[N];
int main(){
    int n; cin>>n;
    inv[1]=1; rep(i,2,n) inv[i]=(ll)inv[P%i]*(P-P/i)%P;
    rep(i,2,n) inv[i]=(inv[i-1]+inv[i])%P;
    rep(i,1,n) cin>>x[i];
    int ans=0;
    rep(i,1,n-1) ans=(ans+(ll)inv[i]*(x[i+1]-x[i]))%P;
    rep(i,1,n-1) ans=(ll)ans*i%P;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4736
#include "bits/stdc++.h"
using namespace std;

//template
typedef long long int ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define repr(i,n) for(ll i=n;i>0;i--)
#define all(v) v.begin(),v.end()
#define in cin>>
#define out cout<<
#define en <<endl
const ll INF = 10000000000000;

int main()
{
	ll h,n;
	in h >> n;
	vector<ll> A(n);
	ll plus = 0;
	rep(i, n)
	{
		in A.at(i);
		plus += A.at(i);
	}
	if (plus >= h)
	{
		out "Yes" en;
	}
	else
	{
		out "No" en;
	}
}


Measured memory_bytes: 1024
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()
#pragma endregion

ll dp[51][51][2501];

int main()
{
	int n, a; cin >> n >> a;
	vector<int> x(n);
	rep(i, n)cin >> x[i];
	rep(i, 51)rep(j, 51)rep(k, 2501)dp[i][j][k] = 0;
	dp[0][0][0] = 1;
	rep(i, n)rep(j, i + 1)rep(k, 2501)
	{
		dp[i + 1][j][k] += dp[i][j][k];
		if (k - x[i] >= 0)dp[i + 1][j + 1][k] += dp[i][j][k - x[i]];
	}
	ll res = 0;
	for (int i = 1; i <= n; ++i)res += dp[n][i][i * a];
	cout << res << endl;
}

Measured memory_bytes: 51072
#include <bits/stdc++.h> 
using namespace std;
#define ll long long 
#define f(i, a, b) for(ll i=a;i<b;i++)
#define fi(i, a, b) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define ml map<ll,ll> 

void solve()
{
   ll n;
   cin>>n;
   ll dp[n][3]={0};
   ll a,b,c;
   cin>>a>>b>>c;
   dp[0][0] = a;
   dp[0][1] = b;
   dp[0][2] = c;
   f(i,1,n)
   {
      cin>>a>>b>>c;
      dp[i][0] = a + max(dp[i-1][1],dp[i-1][2]);
      dp[i][1] = b + max(dp[i-1][0],dp[i-1][2]);
      dp[i][2] = c + max(dp[i-1][0],dp[i-1][1]);

   }
   cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

int main()
{
   ll t;
   t=1;
//    cin>>t;
   while (t--)
   {
       solve();
   }  
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF=1e18+10;
const int inf=1e9+10,dx[]= {0,0,1,-1,1,-1,1,-1},dy[]= {1,-1,0,0,1,1,-1,-1};
ll MOD=1e9+7;
ld eps=1e-7,pi=acos(-1);

ll n,w,wv[110][2];

ll mem[110][100010];

ll solve(int i,int sz)
{
if(sz<=0)return 0;
if(i>=n)return 0;
if(mem[i][sz]!=-1)return mem[i][sz];

ll a=0;
if(sz>=wv[i][0])
a=solve(i+1,sz-wv[i][0])+wv[i][1];///add this

a=max(a,solve(i+1,sz));/// don't add this

return mem[i][sz]=a;
}

int main()
{

scanf("%lld %lld",&n,&w);
for(int i=0;i<n;i++)
scanf("%lld %lld",&wv[i][0],&wv[i][1]);

memset(mem,-1,sizeof mem);

printf("%lld",solve(0,w));

return 0;
}


Measured memory_bytes: 86144
#include <iostream>
#include <queue>
using namespace std;

#define REP(i,p,n) for(int i=0;i<n;++i)
#define rep(i,n) REP(i,0,n)

struct Node { int cost,x,y,left,right,oxigen; Node(int a,int b,int c,int d,int e,int f):cost(a),x(b),y(c),left(d),right(e),oxigen(f){} };
bool operator<(const Node& a,const Node& b){ return a.cost>b.cost; }
const int MAXN=16,MAXO=64;
const int INF=1<<28;
int T[MAXN][MAXN];
int W,H,F,M,O;

bool visited[MAXN][MAXN][MAXN][MAXN][MAXO];
inline int ox(int x,int y,int o){ return min( o+(T[y][x]>0?T[y][x]:0)-1, M ); }
inline int cs(int x,int y,int c){ return c+(T[y][x]<0?-T[y][x]:0); }

int dk()
{
        if(O<2) return INF;
        rep(x,MAXN) rep(y,MAXN) rep(l,MAXN) rep(r,MAXN) rep(o,MAXO) visited[x][y][l][r][o]=false;

        priority_queue<Node> Q;
        rep(i,W) Q.push(Node( cs(i,0,0), i, 0, i, i, ox(i,0,O) ));

        while(!Q.empty())
        {
                const Node node = Q.top(); Q.pop();
                if(node.oxigen==0) continue;
                if(node.y==H-1){ return node.cost; }
                if(visited[node.x][node.y][node.left][node.right][node.oxigen]) continue;
                visited[node.x][node.y][node.left][node.right][node.oxigen]=true;

                if(node.oxigen==1) continue;
                const int dx[] = { 1, -1 };
                rep(i,2)
                {
                        const int x = node.x+dx[i], y = node.y;
                        if(x<0||x>=W) continue;

                        const int left = min(x,node.left), right = max(x,node.right);
                        const int cost   = ((node.left==left&&node.right==right)?node.cost:cs(x,y,node.cost));
                        const int oxigen = ((node.left==left&&node.right==right)?node.oxigen-1:ox(x,y,node.oxigen));
                        //if(oxigen<=0) continue;
                        Q.push(Node(cost,x,y,left,right,oxigen));
                }

                {
                        const int x = node.x, y = node.y+1;
                        const int cost   = cs(x,y,node.cost);
                        const int oxigen = ox(x,y,node.oxigen);
                        //if(oxigen<=0) continue;
                        Q.push(Node(cost,x,y,x,x,oxigen));
                }
        }

        return INF;
}

int main()
{
        while(cin>>W>>H&&(W|H))
        {
                cin>>F>>M>>O;
                rep(y,H) rep(x,W) cin>>T[y][x];

                int res = dk();
                if(res>F){ cout<<"NA"<<endl; } else { cout<<res<<endl; }
        }

        return 0;
}

Measured memory_bytes: 5516
#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 k,a,b,counts=0;
  cin >> k >> a >> b;
  for(int i = a; i<b+1; i++){
   if(i%k == 0) counts++; 
  }
 if(counts != 0) cout << "OK" << endl;
  else cout << "NG" << endl;
}

Measured memory_bytes: 3624
def main():

    T = int(input())

    def dfs(i, A, B, C, D):
        if i not in memo:
            v = i * D
            if i % 2 == 0:
                v = min(v, A + dfs(i//2, A, B, C, D))
            else:
                v = min(v, D + A + dfs((i-1)//2, A, B, C, D))
                v = min(v, D + A + dfs((i+1)//2, A, B, C, D))
            if i % 3 == 0:
                v = min(v, B + dfs(i//3, A, B, C, D))
            else:
                v = min(v, D*(i%3) + B + dfs((i-i%3)//3, A, B, C, D))
                v = min(v, D*(3-i%3) + B + dfs((i+3-i%3)//3, A, B, C, D))
            if i % 5 == 0:
                v = min(v, C + dfs(i//5, A, B, C, D))
            else:
                v = min(v, D*(i%5) + C + dfs((i-i%5)//5, A, B, C, D))
                v = min(v, D*(5-i%5) + C + dfs((i+5-i%5)//5, A, B, C, D))
            memo[i] = v
        return memo[i]

    for _ in range(T):
        N, A, B, C, D = map(int, input().split())
        memo = dict()
        memo[0] = 0
        memo[1] = D

        print(dfs(N, A, B, C, D))

if __name__ == '__main__':
    main()

Measured memory_bytes: 10972
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int a[3];
int main()
{
	for(int i=0;i<3;i++)
		scanf("%d",&a[i]);
	for(int i=0;i<3;i++)
		if(!(a[i]&1))
		{
			printf("0");
			return 0;
		}
	sort(a,a+3);
	printf("%lld",(long long)a[0]*a[1]);
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  string s1 = s.substr(0, 4);
  string s2 = s.substr(5, 2);
  int a = stoi(s1);
  int b = stoi(s2);
  if (a >= 2019 && b >= 5) {
    cout << "TBD" << endl;
  } else {
    cout << "Heisei" << endl;
  }
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())
count = 0
for i in range(int(n) + 1):
  c = len(str(i))
  d = 0
  for j in range(c):
    d += int(str(i)[j])
  if int(a) <= d and d <= int(b):
    count += i
print(count)

Measured memory_bytes: 9036
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

#define REP(i,n) for(int64_t i=0;i<(int64_t)(n);i++)

using namespace std;

bool is_valid(const vector<int>& fct, int64_t n) {
  int64_t old_h = 0;
  for (int p : fct) {
    int cnt = 0;
    while((n % p) == 0){
      n /= p;
      ++cnt;
    }
    if (cnt < old_h) return false;
    old_h = cnt;
  }
  return true;
}

int main() {
  int64_t a, b;
  cin >> a >> b;
  int64_t beg = max(a - b, int64_t(2));
  int64_t ed = a + b;
  vector<vector<int>> pl2(1000001);
  vector<int> ps(1100001,1);
  ps[0] = ps[1] = 0;
  int64_t i;
  for (i = 2; i * i * i * i <= ed; ++i) {
    if (ps[i] == 1) {
      int64_t offset = (i - (beg % i)) % i;
      for (int64_t k = offset; k <= 1000000; k += i) {
        pl2[k].push_back(i);
      }
      for (int64_t j = i * 2; j * j <= ed; j += i) {
        ps[j] = i;
      }
    }
  }
  for (; i * i <= ed; ++i) {
    if (ps[i] == 1) {
      int64_t offset = (i - (beg % i)) % i;
      for (int64_t k = offset; k <= 1000000; k += i) {
        pl2[k].push_back(i);
      }
      for (int64_t j = i * 2; j * j <= ed; j += i) {
        ps[j] = i;
      }
    }
  }
  int64_t cnt = 0;
  for (int64_t i = 0; i <= ed - beg; ++i) {
    auto fct = pl2[i];
    sort(begin(fct),end(fct),greater<int64_t>());
    if (is_valid(fct, beg+i)) {
      ++cnt;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 63608
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int

ans = false
N.to_s.length.times do |i|
  if N.to_s[i] == '7'
    ans = true
  end
end

puts ans ? 'Yes' : 'No'


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


int main(){
    int x;
    cin >> x;
    int i=1;
    while(true){
        int ans = pow(i,5)-pow(i-1,5);
        if(ans >= x) break;
        i++;
    }
    // iは最大の数

    for(int k=-i+1;k<=i;k++){
        for(int t =-i;t<i;t++){
            int ans = pow(k,5)-pow(t,5);
            if(ans == x){
                cout << k <<" "<< t << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 4100
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <map>
#include <queue>
#include <tuple>
#include <math.h>
#include <iomanip>

using namespace std;

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


int main(){
    int N,M;
    cin >> N >> M;
    vector<int> cnt(N,0),flag(N,0);
    for(int i=0; i<M; i++){
        int p;string s;
        cin >> p >> s;
        p--;
        if(s=="WA" && flag[p]==0){
            cnt[p]++;
        }else{
            flag[p]=1;
        }
    }

    int wa=0,ac=0;
    for(int i=0; i<N; i++){
        if(flag[i]==1){
            ac++;
            wa+=cnt[i];
        }
    }

    cout << ac << ' ' << wa << endl;




    return 0;
}

Measured memory_bytes: 4028
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;
const int N = 1e5+5;

int main(){
	ll a,b,g;
	scanf("%lld%lld", &a, &b);
	g = __gcd(a, b);
	int ans = 1;
	if(g%2==0){
		++ans;
		while(g%2==0) g>>=1LL;
	}
	for(ll i=3;i*i<g;i+=2){
		if(g%i==0){
			++ans;
			while(g%i==0) g/=i;
		}
	}
	if(g>1) ++ans;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static const int MAX= 2e5;

int main()
{
    int R[MAX],N;
    cin >> N;
    for(int i=0;i<N;i++)cin>>R[i];

    int maxv = -2e9;
    int minv = R[0];

    for(int i=1;i<N;i++){
        maxv = max(maxv,R[i]-minv);
        minv = min(minv,R[i]);
    }
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 3892
/*
	Name:
	Author: xiaruize
	Date:
*/
#pragma GCC optimize(2)
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cerrno>
#include<clocale>
#include<cmath>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<vector>
#include<cwchar>
#include<cwctype>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second
#define sz(a) int((a).size())

inline int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
}

int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ll a,b,n;
	cin>>a>>b>>n;
	ll x;
	if(b>n)
	{
		x=n;
	}
	else
	{
		x=b-1;
	}
	cout<<(a*x)/b-a*(x/b)<<endl;
	return 0;
}

Measured memory_bytes: 3636
//--------------------------------------------------template----------------------------------------//
//c
#include <stdio.h>
#include <time.h>
#include <math.h>
//c++
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <complex>
#include <cmath>
//c++11
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
//#define sort(v,n) sort(v,v+n)
//#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.rbegin(),v.rend())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//


int main() {
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			cout << i << "x" << j << "=" << i*j << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2936
#include<stdio.h>
#include<string.h>

int main(void){

	char a[20],b[20],c[20];	
	int an,bn;
	
	scanf("%s",a);
	scanf("%s",b);
	scanf("%s",c);

	an=strlen(a);
	bn=strlen(b);

	if(a[an-1]==b[0] && b[bn-1]==c[0]){
		printf("YES\n");
	}else{
		printf("NO\n");
	}

	return 0;

}



	
	

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    string s;cin >> s;
    while(n--){
      string buf="";
      int i,j,k;
      char c=s[0];bool f=false;k=1;
      for(i=1;i<s.size();i++){
	if(c==s[i]) k++;
	else{
	  stringstream ss;
	  ss<<k;
	  buf+=ss.str();
	  buf+=c;
	  c=s[i];
	  k=1;
	}
      }
      stringstream ss;
      ss<<k;
      buf+=ss.str();
      buf+=c;
      s=buf;
    }
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 1364
N = int(input())
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
mdn = make_divisors(N)

aa = []
for x in mdn:
  aa.append(x+N//x)
print(min(aa)-2)

Measured memory_bytes: 66012
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    string w;
    cin >> w;
    vector<char> s;
    s.push_back('A');
    for(int i=0;i<w.size();i++){
        for(int j=0;j<s.size();j++){
            if(s[j] == w[i]){
                s.erase(s.begin() + j);
                break;
            }
            else if(j == s.size()-1){
                s.push_back(w[i]);
                break;
            }
        }
    }
    if(s.size() == 1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;

}

Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        s: chars,
    }
    let n = s.len();
    if n == 1 {
        println!("1");
        return;
    }
    let mut dp1 = vec![0; n];
    let mut dp2 = vec![0; n];
    dp1[0] = 1;
    dp2[1] = 1;
    dp1[1] = if s[1] == s[0] {0} else {2};
    for i in 2..n {
        if s[i] == s[i - 1] {
            dp1[i] = dp2[i - 1] + 1;
        } else {
            dp1[i] = std::cmp::max(dp1[i - 1], dp2[i - 1]) + 1;
        }
        if i >= 3 && s[i] == s[i - 2] && s[i - 1] == s[i - 3] {
            dp2[i] = dp1[i - 2] + 1;
        } else {
            dp2[i] = std::cmp::max(dp2[i - 2], dp1[i - 2]) + 1;
        }
    }
    println!("{}", std::cmp::max(dp1[n - 1], dp2[n - 1]));
}

fn main() {
    run();
}


Measured memory_bytes: 6524
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		String ans = capitalize(sc.nextLine());
		System.out.println(ans);
	}

	public static String capitalize(String text) {
		char[] ca = text.toCharArray();

		int shift = 'A' - 'a';
		for (int i=0; i < ca.length; i++) {
			if ('a' <= ca[i] && ca[i] <= 'z') {
				ca[i] = (char) (ca[i] + shift);
			}
		}
		return String.valueOf(ca);
	}
}

Measured memory_bytes: 26048
while True:
    x, y=map(int,input().split())
    if x==0 and y==0:
        break
    if x>y:
        print('{0} {1}'.format(y,x))
    elif x<y:
        print('{0} {1}'.format(x,y))
    else:
        print('{0} {1}'.format(x,y))


Measured memory_bytes: 5608
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << a*b - (c*b + a*d -c*d) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <chrono>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

struct edge {
    int u, v, cost;
    edge() {}
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    int n, m, p;
    cin >> n >> m >> p;
    vector<edge> g(m);
    for (int i = 0; i < m; i++) {
        cin >> g[i].u >> g[i].v >> g[i].cost;
        g[i].u--;
        g[i].v--;
        g[i].cost -= p;
    }
    vector<int> d(n, -INF);
    d[0] = 0;
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        for (auto e : g) {
            if (d[e.v] < d[e.u] + e.cost && d[e.u] != -INF) {
                d[e.v] = d[e.u] + e.cost;
            }
        }
        ans = max(ans, d[n - 1]);
    }
    int lst = ans;
    for (int i = 0; i < n - 1; i++) {
        for (auto e : g) {
            if (d[e.v] < d[e.u] + e.cost && d[e.u] != -INF) {
                d[e.v] = d[e.u] + e.cost;
                d[e.v] = INF;
            }
        }
        ans = max(ans, d[n - 1]);
    }
    if (lst < ans || d[n - 1] == INF) {
        cout << -1;
        return 0;
    }
    cout << ans;
}
/*

*/


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <climits>
#include <iomanip>

using namespace std;

long long dp[101][101];
vector<pair<int, int> > cards;
int n;

/*void print_table(){
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      if(dp[i][j] == INT_MAX){
	cout << "INF";
      }else{
	cout << setw(3) << dp[i][j];
      }
      cout << ' ';
    }
    cout << endl;
  }
  cout << endl;
  }*/

main(){
  cin>>n;
  for(int i=0;i<n;i++){
    int a, b;
    cin >> a >> b;
    cards.push_back(make_pair(a, b));
  }
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      dp[i][j] = INT_MAX;
    }
    dp[i][i] = 0;
  }
  //print_table();
  for(int i=1;i<n;i++){
    for(int j=0;j<=n-i;j++){
      for(int k=j;k<j+i;k++){
	//cout << cards[j].first << ' ' << cards[k].second << ' ' << cards[k+1].first << ' ' << cards[j+i].second << endl;
        long long cost = cards[j].first * cards[k].second * cards[k+1].first * cards[j+i].second;
        dp[j][j+i] = min(dp[j][j+i],cost+dp[j][k]+dp[k+1][j+i]);
	//print_table();
      }
    }
  }
  cout<< dp[0][n-1] <<endl;
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  int color[10] = {};
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    if (tmp >= 3200) tmp = 3200;
    color[tmp/400]++;
  }
  int ma, mi;
  ma = mi = 0;
  for (int i = 0; i < 8; i++) {
    if (color[i] > 0) {
      ma++;
      mi++;
    }
  }
  if (mi == 0) mi = 1;
  ma += color[8];
  cout << mi << " " << ma << endl;
  return 0;
}


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


int main() {
	int A = 10, B = 11, C = 12, D = 13, E = 14, F = 15;
	string  X, Y;
	cin >> X >> Y;
	

	if (X == Y) {
		cout << "=" << endl;
	}
	else if(X>Y){
		cout << ">" << endl;
	}
	else {
		cout << "<" << endl;
	}
	system("pause");
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
const ll mod = 1e9 + 7;

int main()
{
    ll n;
    cin >> n;
    cout << (n + 1) * n / 2 - n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

#include <iostream>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll n;
vector<ll> s, ans;
int main() {
	cin >> n;
	REP(i, n) {
		ll a;
		cin >> a;
		s.push_back(a);
	}
	while (s.size() > 0) {
		bool ok = false;
		REPR(i, s.size() - 1) {
			if (i + 1 == s[i]) {
				ans.push_back(i + 1);
				s.erase(s.begin() + i);
				ok = true;
				break;
			}
		}
		if (!ok) {
			cout << -1 << endl;
			return 0;
		}
	}
	reverse(ALL(ans));
	REP(i, ans.size())cout << ans[i] << endl;
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
X = list(map(int, input().split()))

evens = Counter(X[::2]).most_common()
odds = Counter(X[1::2]).most_common()

evens.append((0, 0))
odds.append((0, 0))

if evens[0][0] != odds[0][0]:
    print(N - evens[0][1] - odds[0][1])
else:
    print(min(N - evens[0][1] - odds[1][1], N - evens[1][1] - odds[0][1]))


Measured memory_bytes: 95552
// problem: "https://atcoder.jp/contests/keyence2020/tasks/keyence2020_c"

#include<bits/stdc++.h>
#define ll long long

using namespace std;

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

    vector<ll>V;
    while(k-- && n--)
        V.push_back(s);

    if(s != (ll)(1e9))
        while(n--)
            V.push_back(s+1);

    else
        while(n--)
            V.push_back(1);

    ll i;
    for(i=0;i!=V.size();i++)
        cout<<V[i]<<' ';

    return 0;
}


Measured memory_bytes: 2164
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <algorithm>
using namespace std;

int main() {
  int N;
  cin >> N;
  int t[N];
  int x[N];
  int y[N];
  for(int i = 0;i < N;i++)
    cin >> t[i] >> x[i] >> y[i];
  bool b[N];
  for(int i = 0;i < N;i++)
  {
    b[i] = false;
    if(t[i] >= x[i] + y[i]){
      if(((x[i] + y[i]) % 2 == 0) && (t[i] % 2 == 0))
        b[i] = true;
      if(((x[i] + y[i]) % 2 != 0) && (t[i] % 2 != 0))
        b[i] = true;
      }
  }
  for(int i = 0;i < N;i++)
    if(b[i] == false){
      cout << "No" <<'\n';
      return 0;
    }
  cout << "Yes" <<'\n';
  return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
 
 
 
 
 
 
 




vector<pair<int,int>> adj[100005];
ll dist[100005];
int n;
void dfs(int node,int par){
     for(auto ch:adj[node]){
          if(ch.fi==par)continue;
          dist[ch.fi]=dist[node]+ch.se;
          dfs(ch.fi,node);
     }
}



const int maxn1=100005;
int pos[maxn1];
bool type[maxn1];
int main()
{
     int n;
     cin>>n;
     int ans=0;
     for(int i=0;i<n;i++){
          int a,b;
          cin>>a>>b;
          type[a]=true;
          pos[a]=b;
     }
     for(int i=0;i<n;i++){
          int a,b;
          cin>>a>>b;
          type[a]=false;
          pos[a]=b;
     }
     set<int> st;
     for(int i=0;i<2*n;i++){
          if(type[i]){
               st.insert(pos[i]);
          }
          else{
               set<int>::iterator itr=st.lower_bound(pos[i]);
               if(itr==st.begin())continue;
               itr--;ans++;
               st.erase(itr);
          }
     }
     cout<<ans;
}






















Measured memory_bytes: 5976
#include <stdio.h>
#include <string.h>

char str[1234];

int main()
{
	int n = 0, e = 0, w = 0, s = 0;
	scanf("%s",str);
	for (int i = 0; i < strlen(str); ++i)
	{
		switch (str[i])
		{
		case 'N':++n; break;
		case 'E':++e; break;
		case 'W':++w; break;
		case 'S':++s; break;
		}
	}
	if (((bool)n ^ (bool)s) || ((bool)w ^ (bool)e))
	{
		printf("No\n");
	}
	else
	{
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h> 
using namespace std;
///////////////////////////////////////////
const long long int INF = INT32_MAX;
const long long int Mod = 1000000007;
const long long int mod = 100000;//10^5
using ll = long long int; //long long int は64bit
using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using pii = pair<int,int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
#define np nullptr
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define fill(x,num) memset(x,num,sizeof(x));
typedef vector<vector<ll> > matrix;
//       cin.tie(0);ios::sync_with_stdio(false);
void cinit(){cin.tie(0);ios::sync_with_stdio(false);}
//////////////////////////^^ *Emile ^^^//////////////////////////////////////////////////////

struct edge{//重み付き//有向
    int to;//toは接続先
    edge(int t){to=t;};
};

typedef vector<vector<edge>> graph;//graph

graph g(100001);

bool used[100001] = {0};
vi ts;

void dfs(int rt){
	used[rt] = true;
	rep(i,g[rt].size()){
		if(!used[g[rt][i].to])dfs(g[rt][i].to);
	}
	ts.pb(rt);
}

int main(){
	ll n,m;
	cin>>n>>m;ll a,b;
	rep(i,n+m-1){
		cin>>a>>b;
		g[a].pb(edge(b));
	}
	rep(i,n){
		if(!used[i+1])dfs(i+1);
		//cout<<"ya"<<endl;	
	}
	reverse(ts.begin(),ts.end());
	ll index[100001]={0};
	rep(i,ts.size()){
		index[ts[i]]=i;
	}
	//cout<<"aaa"<<endl;
	ll ans[100001]={0};
	rep(i,n){
		rep(j,g[i+1].size()){
			if(ans[g[i+1][j].to]==0){
				ans[g[i+1][j].to]=i+1;
			}else{
				if(index[ans[g[i+1][j].to]]<index[i+1])ans[g[i+1][j].to]=i+1;
			}
		}
	}
	
	rep(i,n)cout<<ans[i+1]<<endl;
	return 0;
}

Measured memory_bytes: 10612
# coding: utf-8
# Your code here!
from math import factorial as f
def ncr(n,r):
    if n<r:
        return 0
    return f(n)//((f(n-r))*(f(r)))
n,m=map(int,input().split())
x=(ncr(n+m,n))
y=ncr(m,2)
z=(ncr(n,2))
print((y+z))

Measured memory_bytes: 3060
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

char mp[13][13];


void dfs(int y,int x){
  if(0<=x&&x<12&&0<=y&&y<12&&mp[y][x]=='1'){
    mp[y][x]='0';
    for(int i=0;i<4;i++){
      dfs(y+dy[i],x+dx[i]);
    }
  }else return ;
}

signed main(){

  while(cin>>mp[0][0]){
    rep(i,12)rep(j,12){
      if(i==j&&i==0)continue;
      else cin>>mp[i][j];
    }
    int ans=0;
    rep(i,12)rep(j,12){
      if(mp[i][j]=='1'){
        dfs(i,j);
        ans+=1;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3044