akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n + 1);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    uf.unite(a, b);
  }

  set<int> st;
  for (int i = 1; i <= n; ++i) {
    st.insert(uf.find(i));
  }

  cout << (st.size() - 1) << endl;
  return 0;
}


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

int main() {
int n,k;
string s;
cin>>s>>k;
n=s.length();
for(int i=0;i<n-1;i++){
    //cout<<s[i]-'a'<<endl;
    int d=26-s[i]+'a';
    if(d<26&&d<=k){
        k-=d;
        s[i]='a';
    }
}
s[n-1]=(s[n-1]-'a'+k)%26+'a';
cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b>=c){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end() 
using namespace std;

typedef long long ll;

const int N = 1e5 + 5;

vector<int> cnt[4];
int res[N];

int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   for(int i=0; i<n; ++i) {
       int x;
       cin >> x;
       cnt[x%4].push_back(x);
   }
   int p = n-1;
   for(int i=n-1; i>=0; --i) {
       if(cnt[2].empty()) break;
       res[i] = cnt[2].back();
       cnt[2].pop_back();
       p = i;
   }
   for(int i=p-1; i>=0; i-=2) {
       if(cnt[0].empty()) break;
       res[i] = cnt[0].back();
       cnt[0].pop_back();
   }
   for(int i=0; i<n; ++i) {
       if(res[i] == 0) {
           if(cnt[0].empty()) break;
           res[i] = cnt[0].back();
           cnt[0].pop_back();
       }
   }
   for(int i=0; i<n; ++i) {
       if(res[i] == 0) {
           if(!cnt[1].empty()) {
               res[i] = cnt[1].back();
               cnt[1].pop_back();
           }
           else if(!cnt[3].empty()) {
               res[i] = cnt[3].back();
               cnt[3].pop_back();
           } else {
               cout << "No\n";
               return 0;
           }
       }
   }
   for(int i=0; i<n-1; ++i) {
        if((res[i] * res[i+1]) % 4 != 0) {
            cout << "No\n";
            return 0;
        }
   }
   cout << "Yes\n";
   return 0;
} 
// 2 7 1 8 2 8
// 1 8 7 8 2 2


Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int INF = 1001001001;
int n;
vector<int> to[1010];

vector<int> bfs(int sv) {
    vector<int> dist(n, INF), pre(n, -1);
    queue<int> q;
    dist[sv] = 0;
    q.push(sv);
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (int nv: to[v]) {
            if (dist[nv] != INF) continue;
            pre[nv] = v;
            dist[nv] = dist[v] + 1;
            q.push(nv);
        }
    }

    P best(INF, -1);
    rep(v, n) {
        if (v == sv) continue;
        for (int nv: to[v]) {
            if (nv == sv) best = min(best, make_pair(dist[v], v));
        }
    }
    if (best.first == INF) return vector<int>(n+1);
    int v = best.second;
    vector<int> res;
    while (v != -1) {
        res.push_back(v);
        v = pre[v];
    }
    return res;
}

int main() {
    int m;
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
    }

    vector<int> ans(n+1);
    rep(s, n) {
        vector<int> now = bfs(s);
        if (now.size() < ans.size()) ans = now;
    }
    if (ans.size() == n+1) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans.size() << endl;
    for (int v: ans) {
        cout << v+1 << endl;
    }

    return 0;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll K=1000000007;
int MAX=100000;
vector<int> Dis(MAX);
vector<int> Dis2(MAX);

int main (){
    int N;
    int U, V;
    cin>>N>>U>>V;
    U --;
    V --;
    vector<vector<int>> Way(N, vector<int>(0));
    for(int i=0; i<N-1; i++){
        int A, B;
        cin>>A>>B;
        A --;
        B --;
        Way[A].push_back(B);
        Way[B].push_back(A);
    }
    for(int i=0; i<N; i++)Dis[i]=-1;
    Dis[V]=0;
  	queue<int> Q;
    Q.push(V);
    while(!Q.empty()){
        int x=Q.front();
        Q.pop();
        int WSize=Way.at(x).size();
        for(int i=0; i<WSize; i++){
            int to=Way[x][i];
            if(Dis[to]==-1){
                Dis[to]=Dis[x]+1;
                Q.push(to);
            }
        }
    }
    
    for(int i=0; i<N; i++)Dis2[i]=-1;
    Dis2[U]=0;
    queue<int> Q2;
    Q2.push(U);
  	int Ans=0;
    while(!Q2.empty()){
        int x=Q2.front();
        Q2.pop();
        int WSize=Way.at(x).size();
      	Ans=max(Ans, Dis[x] -1);
        for(int i=0; i<WSize; i++){
            int to=Way[x][i];
          	if(Dis2[x]+1>=Dis[to])continue;
            if(Dis2[to]==-1){
                Dis2[to]=Dis2[x]+1;
                Q2.push(to);
            }
        }
    }
    
    int Max=0;
  	if(U==V){
      	cout<<0<<endl;
    }
  	else{
  	for(int i=0; i<N; i++){
        if(Dis[i]>=Dis2[i]){
            Max=max(Max, Dis[i]);
        }
    }
    cout<<Ans;
    }
    
}





Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int MOD=1e9+7;
const int INF=1e20;

signed main(){
    int N,T,A;cin>>N>>T>>A;
    vector<pair<double,int>>vec(N);
    REP(i,N){
        double a;cin>>a;
        double d=T-a*0.006-A;
        vec[i]=make_pair(abs(d),i+1);
    }
    sort(vec.begin(),vec.end());
    cout<<vec[0].second<<endl;
}


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

using namespace std;

int main() {
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double th, tm;
    th = 30 * h + 0.5 * m;
    tm = 6 * m;
    double theta = abs(th - tm) * M_PI / 180;
    double c = sqrt(a * a + b * b - 2 * a * b * cos(theta));
    // printf("%.20lf\n", c);
    cout << fixed << setprecision(10);
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 4192
#include <bits/stdc++.h>
#define maxn 200086

using namespace std;

int n, m;
int ans, sum, x, y;
vector<int> v[maxn];

bool vis[maxn];

void dfs(int i){
	sum++, vis[i] = true;
	for(int j = 0;j < v[i].size();j++){
		int to = v[i][j];
		if(vis[to]) continue;
		dfs(to);
	}
}

int main(){
	scanf("%d%d", &n, &m);
	while(m--){
		scanf("%d%d", &x, &y);
		v[x].push_back(y), v[y].push_back(x);
	}
	for(int i = 1;i <= n;i++){
		if(!vis[i]){
			sum = 0;
			dfs(i);
			ans = max(ans, sum);
		}
	}
	printf("%d", ans);
}

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

const int maxn = 5000 + 7;
const int mod = 1e9 + 7;

vector<int> e[maxn];
int dp[maxn][maxn];
int sz[maxn], tmp[maxn], C[maxn];

void DP(int u, int pre) {
    sz[u] = 1;
    for (auto v : e[u]) {
        if (v == pre) continue;
        DP(v, u);
        sz[u] += sz[v];
    }

    int T = 1;
    dp[u][1] = 1;
    for (auto v : e[u]) {
        if (v == pre) continue;
        for (int j = 0; j <= T + sz[v]; j++) tmp[j] = 0;

        for (int j = 1; j <= T; j++) {
            // case 1: not passing this edge. 
            tmp[j] = (tmp[j] - (long long)dp[u][j] * dp[v][0]) % mod;

            // case 2: passign this edge. 
            for (int k = 1; k <= sz[v]; k++) {
                tmp[j + k] = (tmp[j + k] + (long long)dp[u][j] * dp[v][k]) % mod;
            }
        }

        for (int j = 0; j <= T + sz[v]; j++) dp[u][j] = tmp[j];
        
        T += sz[v];
    }

    for (int i = 2; i <= sz[u]; i += 2) 
        dp[u][0] = (dp[u][0] + (long long)dp[u][i] * C[i]) % mod;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        e[x].push_back(y);
        e[y].push_back(x);
    }
    C[2] = 1;
    for (int i = 4; i <= n; i += 2) {
        C[i] = (long long)C[i - 2] * (i - 1) % mod;
    }
    DP(1, 0);

    printf("%d\n", (dp[1][0] + mod) % mod);
    return 0;
}

Measured memory_bytes: 97408
#include <stdio.h>
   
int v;
int parent[100001];
int sibling[100001];
int degree[100001];
   
int Depth(int i);
int Height(int i);
 
int main(){
  int i,j;
  int id, l, r;
 
  scanf("%d", &v); 
  
  for(i = 0; i < v; ++i) {
    parent[i] = -1;
    sibling[i] = -1;
    degree[i] = 0;
  }
  for(i = 0; i < v; ++i) {
    scanf("%d %d %d", &id, &l, &r);
    if(l != -1){
      parent[l] = id;
      sibling[l] = r;
      ++degree[id];
    }
    if(r != -1){
      parent[r] = id;
      sibling[r] = l;
      ++degree[id];
    }
  }
   
  for(i = 0; i < v; ++i) {
    int depth = Depth(i);
  
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", i, parent[i], sibling[i], degree[i], depth, Height(i));
  
    if(depth == 0) {
      printf("root\n");
    } else if(degree[i] == 0) {
      printf("leaf\n");
    } else {
      printf("internal node\n");
    }
  }                                                                         
  return 0;
}
 
int Depth(int i){
  if(parent[i] == -1) return 0;
  return Depth(parent[i]) + 1;
}
   
int Height(int i){
  int j, h;
  
  h = 0;
  for(j = 0; j < v; ++j){
    if(parent[j] == i){
      int tmp = Height(j) + 1;
      if(tmp > h){
        h = tmp;
      }
    }
  }
  return h;
}

Measured memory_bytes: 620
# ABC_129 C

def stairs(n, a):
    num_list = set(i for i in range(n+1) if i not in a)
    dp = [0 for _ in range(n+1)]
    dp[0] = 1
    if 1 not in a:
        dp[1] = 1
    for i in range(2, n+1):
        if i not in a:
            dp[i] = dp[i-1] + dp[i-2]
            
    result = dp[n] % 1000000007

    print(result)

    
n, m = list(map(int, input().split()))
a = set(int(input()) for _ in range(m))


if __name__ == '__main__':
    stairs(n, a)

Measured memory_bytes: 467304
using System;

namespace _0007
{
    class Program
    {
        static void Main(string[] args)
        {
            double debt = 100000;
            var appointedWeek = int.Parse(Console.ReadLine());

            for (int weekCount = 0; weekCount< appointedWeek; weekCount++)
            {
                debt = debt * (1.05);

                if (debt % 1000 != 0 )
                {
                    debt = debt - (debt % 1000) + 1000;
                }
            }
            Console.Write(debt.ToString()+"\n");
        }
    }
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int x , n ;
  cin >> x >> n ;
  int ans = INF;
  vector<int> d(n);
  rep(i,n) cin >> d.at(i) ;
  
  int now  ;
  int a = 0 ;
  
  while( ans == INF) {
   now = x + a ;
   bool finish = true ; 
   rep(i,n){
     if( now == d.at(i)){ 
       finish = false ;
     }
   }
   if(finish) ans = now ;
   finish = true ;
     
   
   now = x - a ;
   rep(i,n){
     if( now == d.at(i)){ 
       finish = false ;
     }
   }
   if(finish) ans = now ;
   a ++ ;
  }
     
  cout << ans ;
   


}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 99999999999999999
#define MOD 1000000009
 
void func()
{
    ll a,b;
    cin>>a>>b;
    ll ans=a*b;
    cout<<ans<<"\n";
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
 
    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }
}

Measured memory_bytes: 3640
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 15
#define PI 3.141592653589793
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)
#define mem(x, a) memset(x, a, sizeof x)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pcl pair<char, ll>
#define psl pair<string, ll>


ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
unordered_map<ll, ll> mp;
set<ll> s;
string S = "";
ll cases;

int main() {
	go;
	ll cnt = 0;
    cin >> N >> M;
    fei(i, 0, N, 1) {
    	fei(j, 0, N, 1) {
    		ll k = M - (i + j);
    		if(k <= N && k >= 0) {
    			// trace4(i, j, k, N);
    			cnt++;
    		}
    	}
    }
    cout << cnt << "\n";
    
	return 0;
}
/*
	Powered by Buggy Plugin
*/




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

public class Main {

	public static void main(String[] strArgs) throws Exception {
		BufferedReader br = null;

		try {
			br = new BufferedReader(new InputStreamReader(System.in));

			String[] strValues = readValues(br);

			int iEmpCount = toInt(strValues[0]);

			strValues = readValues(br);
			Map<String, Integer> map = new HashMap<String, Integer>();
			for (String strBossEmpNo : strValues) {
				Integer iCount = map.get(strBossEmpNo);
				if (iCount == null) {
					iCount = 0;
				}
				map.put(strBossEmpNo, ++iCount);
			}

			for (int i = 0; i < iEmpCount; i++) {
				Integer iCount = map.get(String.valueOf(i + 1));
				if (iCount == null) { iCount = 0; }
				System.out.println(iCount);
			}

		} finally {
			br.close();
		}
	}

	private static String[] readValues(BufferedReader br) throws IOException {
		return br.readLine().split("\\s");
	}

	private static int toInt(String str) {
		return Integer.parseInt(str);
	}
}


Measured memory_bytes: 79416
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int n,m;cin>>n>>m;){
		vi as(m),bs(m);
		rep(i,m) cin>>as[i]>>bs[i];
		rep(i,m) as[i]--;
		
		vi rs(n);
		int res=0;
		rep(i,n) if(!rs[i]){
			int k=-1;
			rep(j,m){
				if(as[j]>i || bs[j]<=i)
					continue;
				if(k==-1 || bs[j]>bs[k])
					k=j;
			}
			if(k==-1){
				res=-1;
				break;
			}
			repi(j,i,bs[k])
				rs[j]=1;
			res++;
		}
		
		if(res==-1)
			cout<<"Impossible"<<endl;
		else
			cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

int main(){
	int N;
	cin >> N;
	vi A(N),B(N),C(N);
	for(int i=0; i<N; i++){
		cin >> A[i];
		A[i]--;
	}
	for(int i=0; i<N; i++){
		cin >> B[i];
	}
	for(int i=0; i<N; i++){
		cin >> C[i];
	}

	int ans=B[A[0]];
	for(int i=1; i<N; i++){
		ans+=B[A[i]];
		if(A[i]==A[i-1]+1){
			ans+=C[A[i-1]];
		}
	}

	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


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


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

class P{
	int z,y,x;
	P(int z,int y,int x){
		this.z=z;
		this.y=y;
		this.x=x;
	}
}

public class Main {
	int box[][][]=new int[5][5][5];
	Stack<P> bs=new Stack<P>();
	Stack<P> ds=new Stack<P>();
	public static void main(String[] args) {
		//new AOJ1519().run();
		new Main().run();
	}
	void run(){
		Scanner sc=new Scanner(System.in);
		int count=1;
		while(true){
			char ch[][]=new char[5][5];
			int n=sc.nextInt();
			if(n==0) break;

			if(count!=1) System.out.println();
			
			for(int i=0; i<5; i++){
				for(int j=0; j<5; j++){
					ch[j]=sc.next().toCharArray();
					for(int k=0; k<5; k++){
						box[i][j][k]=(ch[j][k]-'0');
					}
				}
			}
			int m1=sc.nextInt();
			int a[]=new int[m1];
			for(int i=0;i<m1;i++){
				a[i]=sc.nextInt();
			}
			int m2=sc.nextInt();
			int b[]=new int[m2];
			for(int i=0;i<m2;i++){
				b[i]=sc.nextInt();
			}
			
			//ここから本番
			for(int day=0; ; day++){
				//誕生
				while(!bs.isEmpty()){
					P p=bs.pop();
					box[p.z][p.y][p.x]=1;
				}
				//死滅
				while(!ds.isEmpty()){
					P p=ds.pop();
					box[p.z][p.y][p.x]=0;
				}
				
				if(n <= day) break;
				
				for(int i=0; i<5; i++){
					for(int j=0; j<5; j++){
						for(int k=0; k<5; k++){
							if(box[i][j][k]==0){
								//誕生するかチェック
								born_check(i, j, k, m1, a);
							}
							else{
								//死ぬかチェック
								death_check(i, j, k, m2, b);
							}
						}
					}
				}
				
			}//day
			System.out.println("Case "+count+":");
			print();
			count++;
		}
	}
	
	void born_check(int z,int y,int x,int m1,int a[]){
		int sum=0;
		for(int i=-1; i<=1; i++){
			for(int j=-1; j<=1; j++){
				for(int k=-1; k<=1; k++){
					if(0<=z+i && 0<=y+j && 0<=x+k && z+i<5 && y+j<5 && x+k<5 && !(i==0 && j==0 && k==0)){
						sum+=box[z+i][y+j][x+k];
					}
				}
			}
		}
		for(int i=0;i<m1;i++){
			if(sum==a[i]){
				bs.add(new P(z, y, x));
				break;
			}
		}
		return;
	}

	void death_check(int z,int y,int x,int m2,int b[]){
		int sum=0;
		for(int i=-1; i<=1; i++){
			for(int j=-1; j<=1; j++){
				for(int k=-1; k<=1; k++){
					if(0<=z+i && 0<=y+j && 0<=x+k && z+i<5 && y+j<5 && x+k<5 && !(i==0 && j==0 && k==0)){
						sum+=box[z+i][y+j][x+k];
					}
				}
			}
		}
		for(int i=0;i<m2;i++){
			if(sum==b[i]){
				return;
			}
		}
		ds.add(new P(z, y, x));
		return;
	}
	void print(){
		for(int i=0; i<5; i++){
			for(int j=0; j<5; j++){
				for(int k=0; k<5; k++){
					System.out.print(box[i][j][k]);
				}
				System.out.println();
			}
			if(i!=4) System.out.println();
		}
	}
}

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

int main() {
    int N; cin >> N;
    vector<vector<int>> G(N);
    for(int i = 0; i < N - 1; ++i) {
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    vector<vector<int>> V(2);
    vector<int> ans(N);
    auto dfs = [&](auto &&dfs, int cur, int pre, int col) -> void {
        V[col].push_back(cur);
        for(auto &to : G[cur]) {
            if(to != pre) dfs(dfs, to, cur, 1 - col);
        }
    };
    vector<queue<int>> que(3);
    for(int i = 1; i <= N; ++i) que[i % 3].push(i);
    dfs(dfs, 0, 0, 0);
    if(V[0].size() > V[1].size()) swap(V[0], V[1]);
    if(V[0].size() <= N / 3) {
        for(auto &v : V[0]) {
            ans[v] = que[0].front(); que[0].pop();
        }
        for(auto &v : V[1]) {
            if(que[0].size()) {
                ans[v] = que[0].front(); que[0].pop();
            } else if(que[1].size()) {
                ans[v] = que[1].front(); que[1].pop();
             } else {
                 ans[v] = que[2].front(); que[2].pop();
             }
        }
    } else {
        for(auto &v : V[0]) {
            if(que[1].size()) {
                ans[v] = que[1].front(); que[1].pop();
            } else {
                ans[v] = que[0].front(); que[0].pop();
            }
        }
        for(auto &v : V[1]) {
            if(que[2].size()) {
                ans[v] = que[2].front(); que[2].pop();
            } else {
                ans[v] = que[0].front(); que[0].pop();
            }
        }
    }
    for(auto &a : ans) cout << a << " ";
    cout << '\n';
    return 0;
}


Measured memory_bytes: 16756
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
ll lr[4010], rr[4010], lg[4010], rg[4010], lb[4010], rb[4010];
int main() {
  ll n;
  char s[4010];
  ll ans = 0LL;
  scanf("%lld", &n);
  scanf("%s", s);
  for (int i = 0; i < n; i++) {
    lr[i + 1] = lr[i];
    lg[i + 1] = lg[i];
    lb[i + 1] = lb[i];
    if (s[i] == 'R') {
      lr[i + 1]++;
    }
    if (s[i] == 'G') {
      lg[i + 1]++;
    }
    if (s[i] == 'B') {
      lb[i + 1]++;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    rr[i] = rr[i + 1];
    rg[i] = rg[i + 1];
    rb[i] = rb[i + 1];
    if (s[i] == 'R') {
      rr[i]++;
    }
    if (s[i] == 'G') {
      rg[i]++;
    }
    if (s[i] == 'B') {
      rb[i]++;
    }
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 1; i + j < n - 1; j++) {
      if (s[i] == 'R') {
        if (s[i + j] == 'G') {
          ans += rb[i + j];
          if (i + 2 * j < n && s[i + 2 * j] == 'B') {
            ans--;
          }
        }
        if (s[i + j] == 'B') {
          ans += rg[i + j];
          if (i + 2 * j < n && s[i + 2 * j] == 'G') {
            ans--;
          }
        }
      } else if (s[i] == 'G') {
        if (s[i + j] == 'R') {
          ans += rb[i + j];
          if (i + 2 * j < n && s[i + 2 * j] == 'B') {
            ans--;
          }
        }
        if (s[i + j] == 'B') {
          ans += rr[i + j];
          if (i + 2 * j < n && s[i + 2 * j] == 'R') {
            ans--;
          }
        }
      } else if (s[i] == 'B') {
        if (s[i + j] == 'G') {
          ans += rr[i + j];
          if (i + 2 * j < n && s[i + 2 * j] == 'R') {
            ans--;
          }
        }
        if (s[i + j] == 'R') {
          ans += rg[i + j];
          if (i + 2 * j < n && s[i + 2 * j] == 'G') {
            ans--;
          }
        }
      }
    }
  }
  printf("%lld\n", ans);
}

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

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

int main() {
  int N;
  cin >> N;
  string S = to_string(N);
  int sum = 0;
  for (int i=0; i<S.size(); i++) {
    sum += ctoi(S.at(i));
  }
  bool divisible = false;
  if (N%sum == 0) {
    divisible = true;
  }
  string answer = "No";
  if (divisible) {
    answer = "Yes";
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct block{
	int color;
	bool pd=true;
};
block a[110][110];
int h,w;
bool checkhang(int x){
	for(int i=1;i<=w;i++){
		if(a[x][i].color==1){
			return false;
		}
	}
	return true;
}
void delhang(int x){
	for(int i=1;i<=w;i++){
		a[x][i].pd=false;
	}
}
bool checklie(int x){
	for(int i=1;i<=h;i++){
		if(a[i][x].color==1){
			return false;
		}
	}
	return true;
}
void dellie(int x){
	for(int i=1;i<=h;i++){
		a[i][x].pd=false;
	}
}
int main(){
	cin>>h>>w;
	char sr;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>sr;
			if(sr=='.'){
				a[i][j].color=0;
			}	
			else{
				a[i][j].color=1;
			}
		}
	}
	for(int i=1;i<=h;i++){
		if(checkhang(i)){
			delhang(i);
		}
	}
	for(int i=1;i<=w;i++){
		if(checklie(i)){
			dellie(i);
		}
	}
	bool scpd=false;
	for(int i=1;i<=h;i++){
		scpd=false;
		for(int j=1;j<=w;j++){
			if(a[i][j].pd==true){
				scpd=true;
				if(a[i][j].color==0){
					cout<<".";
				}
				else{
					cout<<"#";
				}
			}
		}
		if(scpd==true)
		cout<<endl;
	}
}

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

void solve()
{
	ll n;
	cin>>n;
	ll t = n%10;
	if(n%10==3)
		cout<<"bon"<<endl;
	else if(t==0||t==1||t==6||t==8)
		cout<<"pon"<<endl;
	else
		cout<<"hon"<<endl;
}

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

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define min(a,b)	((a)<(b)?(a):(b))
const ll m=100001;
ll l1[m],l2[m],r1[m],r2[m];
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll n;cin>>n;ll arr[n];for(ll i=0;i<n;i++) cin>>arr[i];
	for(ll i=0;i<m;i++) l1[i]=l2[i]=r1[i]=r2[i]=INT_MAX;
	ll c1[m]={0},c2[m]={0};for(ll i=0;i<n;i+=2) c1[arr[i]]++;for(ll i=1;i<n;i+=2) c2[arr[i]]++;
	for(ll i=1;i<m;i++) l1[i]=r1[i]=(n/2-c1[i]),l2[i]=r2[i]=(n/2-c2[i]);
	for(ll i=2;i<m;i++) l1[i]=min(l1[i],l1[i-1]),l2[i]=min(l2[i],l2[i-1]),r1[m-i]=min(r1[m-i],r1[m-i+1]),r2[m-i]=min(r2[m-i],r2[m-i+1]);
	ll ans=INT_MAX;for(ll i=2;i<m-1;i++) ans=min(ans,n/2-c1[i]+min(l2[i-1],r2[i+1])),ans=min(ans,n/2-c2[i]+min(l1[i-1],r1[i+1]));
	ans=min(ans,n/2-c1[1]+r2[2]),ans=min(ans,n/2-c2[1]+r1[2]);
	ans=min(ans,n/2-c1[m-1]+l2[m-2]),ans=min(ans,n/2-c2[m-1]+l1[m-2]);
	cout<<ans<<endl;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,a[200000],ans;

signed main() {
    cin >> n;
    rep(i,n) {
        cin >> a[i];
        if (i) {
            if (a[i] - a[i-1] > 1 && a[i]) {
                cout << -1 << endl;
                return 0;
            }
        } else if (a[i] != 0) {
            cout << -1 << endl;
            return 0;
        }
    }
    rep11(i,n) {
        if (a[i] - a[i-1] == 1) ans++;
        else ans += a[i];
    }
    cout << ans << endl;
}




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

int N, M, L, R, maxL=0, minR=100000, ans;

int main() {
  cin>>N>>M;
  for(int i=0; i<M; i++){
    cin>>L>>R;
    if(L>maxL){
      maxL=L;
    }
    if(R<minR){
      minR=R;
    }
  }
  ans = minR-maxL+1;
  if(ans>0){
    cout<<ans<<"\n";
  }
  else{
    cout<<0<<"\n";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'

int main(){
    double l;cin >> l;
    double ans;
    ans = l/3;
    std::cout << std::fixed;
    cout << std::setprecision(16) << ans*ans*ans << endl;
}

Measured memory_bytes: 256
N, K, Q = map(int, input().split())
P = [0 for _ in range(N)]

for _ in range(Q):
    A = int(input())
    P[A-1] += 1

for i in range(N):
    p = K - Q + P[i]
    if p > 0:
        print("Yes")
    else:
        print("No")


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

#define SSIZE 1024
#define CSIZE 16

void print(int a, int b, char*);
void reverse(int a, int b, char*);
void replace(int a, int b, char*, char*);

int main(void){
  char str[SSIZE] = {0}, command[CSIZE] = {0}, p[SSIZE] = {0};
  int q, a, b, i;

  scanf("%s %d", str, &q);
  for (i = 0; i < q; i++) {
    scanf("%s %d %d", command, &a, &b);
    if (!strcmp(command, "print")) {
      print(a, b, str);
    }
    else if (!strcmp(command, "reverse")) {
      reverse(a, b, str);
    }
    else if (!strcmp(command, "replace")) {
      scanf("%s", p);
      replace(a, b, str, p);
    }
    else
      printf("This command is not available!\n");
  }
  return 0;
}

void print(int a, int b, char *str){
  for ( ; a <= b; a++)
    printf("%c", str[a]);
  printf("\n");
}

void reverse(int a, int b, char *str){
  char strtmp[SSIZE] = {0};
  int i;
  strcpy(strtmp, str);
  for (i = 0; a + i <= b; i++) {
    str[a + i] = strtmp[b - i];
  }
}

void replace(int a, int b, char *str, char *p){
  int i = 0;
  for ( ; a <= b; a++) {
    str[a] = p[i];
    i++;
  }
}

Measured memory_bytes: 588
fn input_one<T: std::str::FromStr> () -> Result<T, T::Err> {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    n.trim().parse()
}

fn main() {
    let n: usize = input_one().unwrap();
    let s: String = input_one().unwrap();
    let cs: Vec<_> = s.chars().collect();
    let mut r = 0;
    for i in 2..n {
        if cs[i] == 'C' && cs[i-1] == 'B' && cs[i-2] == 'A' {
            r += 1;
        }
    }
    println!("{}", r);
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
		int listI[] = splitStringToArrayOfInt(input);
		String result ="No";
		if(listI[0] > listI[2]) {
			if(listI[2] > listI[1] ) {
				result = "Yes";
			}
		}else {
			if(listI[1] > listI[2] ) {
				result = "Yes";
			}
		}
		System.out.println(result);
	}

	private static int[] splitStringToArrayOfInt(String input) {
		return Arrays.stream(input.split(" ")).filter(s -> !s.isEmpty()).mapToInt(Integer::parseInt).toArray();
	}
}

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

int main() {
  int n;
  cin >> n;
  vector<int> dig(100000);
  ll sum = 0;
  rep(i, n) {
    int a;
    cin >> a;
    sum += a;
    dig[a - 1]++;
  }
  vector<ll> sums;
  int q;
  cin >> q;
  rep(i, q) {
    int b, c;
    cin >> b >> c;
    int bnum = dig[b - 1];
    sum += (c - b) * bnum;
    dig[b - 1] = 0;
    dig[c - 1] += bnum;
    sums.push_back(sum);
  }
  rep(i, q) cout << sums[i] << endl;
  return 0;
}


Measured memory_bytes: 4708
from itertools import product


H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
for i in range(H):
    for j in range(W):
        m = product([0, 1, -1], repeat=2)
        if S[i][j] == '.':
            S[i][j] = 0
            for ii, jj in m:
                iii = i + ii
                jjj = j + jj
                if 0 <= iii < H and 0 <= jjj < W:
                    if S[iii][jjj] == '#':
                        S[i][j] += 1
            S[i][j] = str(S[i][j])
for s in S:
    print(('').join(s))

Measured memory_bytes: 3316
num_city,num_road = gets.chomp.split.map(&:to_i)
data = num_road.times.map{gets.chomp.split.map(&:to_i).map{|el| el-1}}

histg = Array.new(num_city, 0)
data.each do |el|
    histg[el[0]] += 1
    histg[el[1]] += 1
end
puts histg

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int K;
bool comp(ll a, ll b) {
	int na = 0, nb = 0;
	ll ta = a, tb = b;
	while(a > 0) {
		na += a % 10; a /= 10;
	}
	while(b > 0) {
		nb += b % 10; b /= 10;
	}
	return ta * nb <= tb * na;
}

ll nex(ll a) {
	ll tmp = 1;
	ll res = a;
	for(int i = 0; i < 15; i++) {
		tmp *= 10;
		ll b = a / tmp * tmp + tmp - 1;
		// debug(res, b);
		if(!comp(res, b)) res = b;
	}
	return res;
}

void solve() {
	cin >> K;
	ll s = 1;
	while(K--) {
		cout << s << "\n";
		s = nex(s + 1);
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] tokuten;
		int kazu = 0;
		double average = 0;
		double hensa2 =0.0;
		double bunsan;
		while (true){
			kazu = sc.nextInt();
			if(0==kazu) break;
			tokuten = new int[kazu];
			for(int i=0;i<tokuten.length;i++){
				tokuten[i]=sc.nextInt();
				//System.out.println();
				//System.out.println(tokuten[i]);
				average += (double)tokuten[i]/tokuten.length;
			}
			//System.out.println("average = "+average);
			for(int i=0;i<tokuten.length;i++){
				hensa2 += (tokuten[i]-average)*(tokuten[i]-average);
				//System.out.println("hensa2[0~"+i+"] = "+hensa2);
			}
			bunsan=hensa2/tokuten.length;
			//System.out.println("bunsan = "+bunsan);
			System.out.println(Math.sqrt(bunsan));

			/* 初期化 */
			average = 0;
			hensa2 = 0;
			kazu =0;
		}
	}
}


Measured memory_bytes: 31096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

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

    if (a + b <= k)
        cout << a - (k - a - b) << endl;
    else if (a <= k)
        cout << a << endl;
    else
        cout << k << endl;
}

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

int main() {
  string s;
  cin >> s;
  int N;
  N = s.size();
  int ss,se;
  for (int i=0; i<N; i++) {
    if(s[i] == 'A') {
      ss = i;
      break;
    }
  }
  for (int i=N-1; i>0; i--) {
    if(s[i] == 'Z') {
      se = i;
      break;
    }
  }
  cout << se - ss + 1 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n , k , x = 1;
    cin >> n >> k;
    for( int i = 0 ; i < n ; i++ ) {
        if( x < k ) x *= 2;
        else x += k;
    }
    cout << x;
}



Measured memory_bytes: 3568
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int

// quoted from beet-aizu
template <typename T,typename E, typename F, typename G, typename H>
struct LazySegmentTree{
    //using F = function<T(T,T)>;
    //using G = function<T(T,E)>;
    //using H = function<E(E,E)>;
    int n,height;
    F f;
    G g;
    H h;
    T ti;
    E ei;
    vector<T> dat;
    vector<E> laz;
    LazySegmentTree(F f,G g,H h,T ti,E ei):
        f(f),g(g),h(h),ti(ti),ei(ei){}

    void init(int n_){
        n=1;height=0;
        while(n<n_) n<<=1,height++;
        dat.assign(2*n,ti);
        laz.assign(2*n,ei);
    }
    void build(const vector<T> &v){
        int n_=v.size();
        init(n_);
        for(int i=0;i<n_;i++) dat[n+i]=v[i];
        for(int i=n-1;i;i--)
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
    }
    inline T reflect(int k){
        return laz[k]==ei?dat[k]:g(dat[k],laz[k]);
    }
    inline void eval(int k){
        if(laz[k]==ei) return;
        laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
        laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
        dat[k]=reflect(k);
        laz[k]=ei;
    }
    inline void thrust(int k){
        for(int i=height;i;i--) eval(k>>i);
    }
    inline void recalc(int k){    
        while(k>>=1)
            dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));
    }
    void update(int a,int b,E x){
        thrust(a+=n);
        thrust(b+=n-1);
        for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
            if(l&1) laz[l]=h(laz[l],x),l++;
            if(r&1) --r,laz[r]=h(laz[r],x);
        }
        recalc(a);
        recalc(b);
    }
    void set_val(int a,T x){
        thrust(a+=n);
        dat[a]=x;laz[a]=ei;
        recalc(a);
    }
    T query(int a,int b){
        thrust(a+=n);
        thrust(b+=n-1);
        T vl=ti,vr=ti;
        for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
            if(l&1) vl=f(vl,reflect(l++));
            if(r&1) vr=f(reflect(--r),vr);
        }
        return f(vl,vr);
    }
};

signed main(){
    
    int n, q; cin >> n >> q;
    using P = pair<int, int>;
    auto f = [](P a, P b){ return P(a.first + b.first, a.second + b.second); };
    auto g = [](P a, int b){ return P(a.second * b, a.second); };
    auto h = [](int a, int b){ return b != INT_MAX ? b : a; };
    LazySegmentTree<P, int, decltype(f), decltype(g), decltype(h)> sg(f, g, h, P(0, 0), INT_MAX);
    sg.build(vector<P>(n, P(0, 1)));
    
    for(int i = 0; i < q; i++){
        int com; cin >> com;
        if(!com){
            int s, t, x; cin >> s >> t >> x;
            sg.update(s, t + 1, x);
        }else{
            int s, t; cin >> s >> t;
            cout << sg.query(s, t + 1).first << endl;
        }   
    }
    return 0;
}



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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007


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

int main(){
	int a,b,k;cin >> a >> b >> k;
	set<int> s;
	for(int i = a;i < min(a + k,b+1);i++){
		s.insert(i);
	}
	for(int i = max(a,b-k+1);i <= b;i++){
		s.insert(i);
	}
	for(auto it = s.begin();it != s.end();it++){
		cout << *it << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
# やるだけ
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
    if a[i] not in d:
        d[a[i]] = 1
    else:
        d[a[i]] += 1
ans = 0
for k, v in d.items():
    if k > v:
        # そもそも足りない場合はまるごとなかったことにしなければいけない（増やせないので
        ans += v
    elif k < v:
        # 多かった場合は差分
        ans += v - k
print(ans)

Measured memory_bytes: 21772
n = STDIN.gets.to_i
input = STDIN.gets.split.map(&:to_i)
@count = 0
def merge_sort(array)
  return array if array.size == 0
  return array if array.size == 1
  mid_index = array.size/2
  left = array[0..mid_index-1]
  right = array[mid_index..-1]
  sorted_left = merge_sort(left)
  sorted_right = merge_sort(right)
  merge(sorted_left, sorted_right)
end
def merge(left, right)
  result = []
  until left.empty? && right.empty? do
    @count += 1
   if left.empty?
     result << right.shift
   elsif right.empty?
     result << left.shift
   elsif left[0] < right[0]
     result << left.shift
   else
     result << right.shift
   end
  end
  result
end
puts merge_sort(input)*" "
p @count



Measured memory_bytes: 70468
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)
	
  sc.Scan()
  N, _ := strconv.Atoi(sc.Text())
  sc.Scan()
  A := []int{}
  for _, s := range strings.Split(sc.Text(), " ") {
    a, _ := strconv.Atoi(s)
    A = append(A, a)
  }
  printSlice(A)
  _ = insertionSort(A, N)
}

func insertionSort(A []int, N int) []int {
  for i := 1; i < N; i++ {
    v := A[i]
    j := i - 1
    for j >= 0 && A[j] > v {
      A[j+1] = A[j]
      j--
    }
    A[j+1] = v
    printSlice(A)
  }
  
  return A
}

func printSlice(A []int) {
  for i, a := range A {
    if i != len(A)-1 {
      fmt.Printf("%d ", a)
    } else {
      fmt.Printf("%d\n", a)
    }
  }
}


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

using namespace std;
typedef long long ll;
ll mod = 1e9+7;

int main(void)
{
  ll N;cin>>N;
  for(ll i=0;i<N;i++){
    int A;
    cin>>A;
    if(A%2==0){
      if(A%3==0 || A%5==0){
        continue;
      }
      else{
        cout<<"DENIED"<<endl;
        return 0;
      }
    }
  }

  cout<<"APPROVED"<<endl;
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
struct vec {
  long num;
  long p;
  long y;
  int id;
  bool operator<(const vec &ano) const{
    return num < ano.num;
  }
};
struct pec {
  string str;
  int id;
  bool operator<(const pec &ano) const{
    return id < ano.id;
  }
};
int main() {
  int n,m;
  cin >> n >> m;
  int N = 1000000001;
  vec* data = new vec[100000];
  for(int i=0;i<m;i++){
    long pi,yi;
    cin >> pi >> yi;
    data[i] = {
      pi * N + yi,
      pi,
      yi,
      i
    };
  }
  sort(data,data+m);
  pec* ans = new pec[100000];
  int counter = 1;
  string preStr = "";
  for(int i=0;i<m;i++){
    string a,b;
    a = "000000" + std::to_string(data[i].p);
    if(preStr=="" || a!=preStr){
      preStr = a;
      counter = 1;
    }
    b = "000000" + std::to_string(counter++);
    ans[i] = {
      a.substr(a.length()-6) + b.substr(b.length()-6),
      data[i].id
    };
  }
  sort(ans,ans+m);
  for(int i=0;i<m;i++){
    cout << ans[i].str << endl;
  }
  return 0;
}


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

const int MAXN = 1e5 + 10;
int a[MAXN];

int main(void){
    int n, sol = 0, x;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x;
        a[x]++;
    }
    for(int i = 1; i < MAXN; i++){
        sol = max(sol, a[i - 1] + a[i] + a[i + 1]);
    }
    cout << sol << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
using namespace std;
const int MAX = 1e5 + 111;
int n, m, h[MAX], d[MAX], c[MAX];
map<pair<int, int>, int> vis;
int main(){
    scanf("%d%d", &n, &m);
    memset(d, 0, sizeof(d));
    memset(c, 0, sizeof(c));
    for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
    for (int i = 0; i < m; i++){
        int a, b;
        scanf("%d%d", &a, &b);
        if (vis[{a,b}]) continue;
        vis[{a,b}] = vis[{b,a}] = 1;
        d[a]++;
        d[b]++;
        if (h[a] > h[b]) c[a]++;
        else if (h[a] < h[b]) c[b]++;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++){
        if (d[i] == c[i]) ans++;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 17496
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;


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

	vector<vector<int>> r(n + 1, vector<int>());

	vector<int> mark(n + 1, -1);
    int clearMarker = 1;

	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		r[a].push_back(b);
		r[b].push_back(a);
	}

	//<goto , from>
	queue<pair<int, int>> a;

	for (int i = 0; i < r[1].size(); i++) {
		a.push(pair<int, int>(r[1][i], 1));
	}

	int num = a.size();

	while (num > 0) {
		for (int i = 0; i < num; i++) {
			if (mark[a.front().first] > 0) {
				a.pop();
				continue;
			}

			for (int j = 0; j < r[a.front().first].size(); j++) {
				a.push(pair<int, int>(r[a.front().first][j], a.front().first));
			}

			mark[a.front().first] = a.front().second;
            clearMarker++;
			a.pop();
		}

		num = a.size();
	}
  
    if(clearMarker == n){
      cout << "No" << endl;
      return 0;
    }

	cout << "Yes" << endl;

	for (int i = 2; i <= n; i++) {

		cout << mark[i] << endl;
	}
}

Measured memory_bytes: 13164