akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

int A[310][310];

signed main() {
	int N, M;
	cin >> N >> M;

	rep(i, N) rep(j, M) {
		cin >> A[i][j];
		A[i][j]--;
	}

	bool flag[310];
	rep(i, 300) flag[i] = true;

	int pt[310];
	int cnt[310];
	memset(pt, 0, sizeof pt);
	memset(cnt, 0, sizeof cnt);

	rep(i, N) {
		cnt[A[i][0]]++;
	}

	int ret = INT_MAX;
	{
		int tmp = 0;
		rep(i, M) {
			tmp = max(tmp, cnt[i]);
		}
		ret = min(ret, tmp);
	}

	rep(i, M - 1) {
		int maxArg;
		{
			int maxVal = 0;
			rep(j, M) {
				if (!flag[j]) continue;
				if (maxVal < cnt[j]) {
					maxVal = cnt[j];
					maxArg = j;
				}
			}
		}

		memset(cnt, 0, sizeof cnt);

		flag[maxArg] = false;
		rep(j, N) {
			while (!flag[A[j][pt[j]]]) pt[j]++;
			cnt[A[j][pt[j]]]++;
		}

		{
			int tmp = 0;
			rep(i, M) {
				tmp = max(tmp, cnt[i]);
			}
			ret = min(ret, tmp);
		}
	}

	cout << ret << endl;

    return 0;
}


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

int main()
{
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		int tmp = 0;
		string mae = s.substr(0, i);
		string ato = s.substr(i);
		set<char> maeChar;
		set<char> atoChar;
		for (char c : mae)
		{
			maeChar.insert(c);
		}
		for (char c : ato)
		{
			atoChar.insert(c);
		}
		for(char c : atoChar){
			if(maeChar.find(c) != maeChar.end()){
				tmp++;
			}
		}
		ans = max(ans, tmp);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
typedef long long ll;
int main(){
  int n,ans=0;
  ll d,x,y;
  scanf("%d%lld",&n,&d);
  d=d*d;
  while(n--){
    scanf("%lld%lld",&x,&y);
    if(x*x+y*y<=d) ans++;
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
#define lor(a,b,c) for(register int a=b;a<=c;++a)
#define ror(a,b,c) for(register int a=c;a>=b;--a)
typedef long long ll;

const int MAXN=105,MAXT=MAXN<<1,INF=0x3f3f3f3f;
const ll MOD=1e9+7;

int n,h[MAXN];
int tot,bor[MAXT][2],son[MAXT][MAXT],top[MAXT],bot[MAXT];
ll dp1[MAXN],dp2[MAXN];

template <typename T> inline T read(){
	char tmp=getchar(); T sum=0; bool flag=false;
	while(tmp<'0'||tmp>'9'){
		if(tmp=='-') flag=true; tmp=getchar();
	}
	while(tmp>='0'&&tmp<='9'){
		sum=(sum<<1)+(sum<<3)+tmp-'0'; tmp=getchar();
	}
	return flag?-sum:sum;
}

template <typename T> inline void inc(T &a,T b){
	(a+=b)>=MOD?a-=MOD:a;
}

inline ll qsm(ll a,ll b){
	ll ans=1ll;
	while(b){
		if(b&1) (ans*=a)%=MOD; (a*=a)%=MOD; b>>=1;
	}
	return ans;
}

int main(){
	n=read<int>(); lor(i,1,n) h[i]=read<int>();

	tot=1; bor[tot][0]=1; bor[tot][1]=n;
	int it=tot;
	while(it<=tot){
		bool same=true; int minn=h[bor[it][0]];
		lor(i,bor[it][0]+1,bor[it][1]){
			if(h[i]!=h[i-1]) same=false; minn=min(minn,h[i]);
		}
		top[it]=minn;
		if(!same){
			int pre=-1;
			lor(i,bor[it][0],bor[it][1]){
				if(h[i]==minn){
					if(pre!=-1) ++tot,son[it][++son[it][0]]=tot,bor[tot][0]=pre,bor[tot][1]=i-1,bot[tot]=minn;
					pre=-1;
				}
				else{
					if(pre==-1) pre=i;
				}
			}
			if(pre!=-1) ++tot,son[it][++son[it][0]]=tot,bor[tot][0]=pre,bor[tot][1]=bor[it][1],bot[tot]=minn;;
		}
		++it;
	}

	ror(k,1,tot){
		ll st1=1ll,st2=1ll;
		ll uncover=bor[k][1]-bor[k][0]+1,h=top[k]-bot[k];
		lor(i,1,son[k][0]){
			int v=son[k][i];
			uncover-=bor[v][1]-bor[v][0]+1;
			(st1*=dp1[v]+dp2[v])%=MOD;
			(st2*=dp1[v])%=MOD;
		}
		dp1[k]=st2*qsm(2,h)%MOD;
		(dp2[k]=qsm(2,uncover)*st1%MOD+(qsm(2,h)+MOD-2)%MOD*st2%MOD)%=MOD;
	}

	printf("%lld\n",dp2[1]);

	return 0;
}

Measured memory_bytes: 384
import sys
 
n = int(input())
 
mlist = [0]*(n+1)
#print(mlist)
mlist[0],mlist[1] = map(int,input().split())
#print(mlist)
for i in range(2,n+1):
    mlist[i] = int(input().split()[1])
    #print(mlist)
dp = [[sys.maxsize]*(n+1) for i in range(n+1)]
 
for i in range(1,n+1):
    dp[i][i] = 0
 
for l in range(2,n+1) :
    for i in range(1,n-l+2):
        j = i +l - 1
        for k in range(i,j):
            dp[i][j] = min(dp[i][j],dp[i][k]+
                           dp[k+1][j]+mlist[i-1]*mlist[k]*mlist[j])
 
print(dp[1][n])



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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for (int a = 0; a <= A; ++a) {
    for (int b = 0; b <= B; ++b) {
      for (int c = 0; c <= C; ++c) {
        int total = 500*a + 100*b + 50*c; // 合計金額
        if (total == X) ++res; // 合計金額が X に一致したら答えをインクリメント
      }
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, T t){return v2<T>(r, vector<T>(c, t));}

double EPS = 1e-3;

void solve(){
    ll a;
    float b;
    cin >> a >> b;
    int c = (b*100.0 + EPS);
    cout << (a*c)/100 << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int a=N%10;
  if(a==2||a==4||a==5||a==7||a==9){
    cout << "hon" << endl;
  }
  if(a==0||a==1||a==6||a==8){
    cout << "pon" << endl;
  }
  if(a==3){
    cout << "bon" << endl;
  }
}

Measured memory_bytes: 3624
//
// C - One-stroke Path
//

#include <iostream>
#include <vector>

using namespace std;

int N;
int V;
int count_ = 0;
vector<int> G[8];

void dfs(int s, int v) {
    if (v == V) {
        count_++;
        return;
    }
    //
    for (int t : G[s]) {
        if (!(v >> t & 1)) {
            dfs(t, v | 1 << t);
        }
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    V = (1 << N) - 1;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0, 1);
    cout << count_ << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define N 100005
#define M 20
#define ll long long

int depth[N];
int anc[N][M];
int a[N],b[N],c[N],d[N];
ll WS[N][M];
vector<int> adj[N];

ll pre[N*3];
int st[N];

vector<pair<int,pair<ll,int> > > v[N];
pair<ll,int> getLca(int u,int v) {
    if(depth[u]<depth[v]) {
        swap(u,v);
    }
    int diff = depth[u] - depth[v];
    ll ret = 0;
    for(int i=0;i<M;++i) {
        if(diff&(1<<i)) {
            ret += WS[u][i];
            u = anc[u][i];
        }
    }
    if(u!=v) {
        for(int i=M-1;i>=0;--i) {
            if(anc[u][i]!=anc[v][i]) {
                ret += WS[u][i] + WS[v][i];
                u = anc[u][i];
                v = anc[v][i];
            }
        }
        ret += WS[u][0] + WS[v][0];
        u = anc[u][0];
    }
    return make_pair(ret,u);
}
void dfs(int node,int p,int w) {
    static int pos = 1;
    anc[node][0] = p;
    WS[node][0] = w;
    for(int i=1;i<M;++i) {
        anc[node][i] = anc[anc[node][i-1]][i-1];
        WS[node][i] = WS[node][i-1] + WS[anc[node][i-1]][i-1];
    }
    int sz = adj[node].size();
    for(int i=0;i<sz;++i) {
        int eid = adj[node][i];
        int ch = a[eid]^b[eid]^node;
        if(ch==p) {
            continue;
        }
        depth[ch] = depth[node] + 1;
        st[ch] = pos;
        pre[pos] = pre[pos-1] + d[eid];
        int color = c[eid];
        
        pair<ll,int> g = v[color].back().second;
        g.first += d[eid];
        g.second += 1;
        v[color].push_back(make_pair(pos,g));
        
        ++pos;
        dfs(ch,node,d[eid]);
        pre[pos] = pre[pos-1] - d[eid];
        g = v[color].back().second;
        g.first -= d[eid];
        g.second -= 1;
        v[color].push_back(make_pair(pos,g));
        ++pos;
    }
}
pair<ll,int> find(int color,int id) {
    pair<ll,int> ret = make_pair(0,0);
    if(v[color][0].first>id) {
        return ret;
    }
    int l = 0,r = v[color].size()-1,mid;
    while(l<r) {
        mid = (l+r+1)/2;
        if(v[color][mid].first<=id) {
            l = mid;
        } else {
            r = mid-1;
        }
    }
    ret = v[color][l].second;
    return ret;
}
void solve() {
    int n,q;scanf("%d %d",&n,&q);
    for(int i=1;i<=n-1;++i) {
        v[i].push_back(make_pair(0,make_pair(0,0)));
    }
    for(int i=0;i<n-1;++i) {
        scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
        adj[a[i]].push_back(i);
        adj[b[i]].push_back(i);
    }
    dfs(1,0,0);
    while(q--) {
        int x,y,u,v;
        scanf("%d %d %d %d",&x,&y,&u,&v);
        pair<ll,int> R = getLca(u,v);
        int lca = R.second;
        ll dist = pre[st[u]] + pre[st[v]] - 2*pre[st[lca]];
        assert(dist == R.first);
        pair<ll,int> tmp = find(x,st[u]);
        pair<ll,int> tmp2 = find(x,st[v]);
        tmp.first += tmp2.first;
        tmp.second += tmp2.second;
        tmp2 = find(x,st[lca]);
        tmp.first -= 2LL*tmp2.first;
        tmp.second -= 2LL*tmp2.second;
        dist -= tmp.first;
        dist += (ll)tmp.second*y;
        printf("%lld\n",dist);
    }
}
int main() {
    solve();
    return 0;
}

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

struct node
{
    int id;
    int parent = -1;
    int left_child = -1;
    int right_child = -1;
    int sibling = -1;
    int height = 0;
    int depth = 0;
};

int findRootId(vector<node> &T)
{
    int root_id;
    for (int i = 0; i < T.size(); i++)
    {
        T[T[i].left_child].parent = T[i].id;
        T[T[i].right_child].parent = T[i].id;
    }
    for (int i = 0; i < T.size(); i++)
    {
        if (T[i].parent == -1)
        {
            root_id = i;
            break;
        }
    }

    return root_id;
}

void calcDepth(vector<node> &T, int id)
{
    // update depth
    if (T[id].parent != -1)
    {
        T[id].depth = T[T[id].parent].depth + 1;
    }

    // calculate childlen's depth
    if (T[id].left_child != -1)
    {
        calcDepth(T, T[id].left_child);
    }
    if (T[id].right_child != -1)
    {
        calcDepth(T, T[id].right_child);
    }
}

int calcHeight(vector<node> &T, int id)
{
    int h1 = 0;
    int h2 = 0;

    if (T[id].left_child != -1)
    {
        h1 = calcHeight(T, T[id].left_child) + 1;
    }
    if (T[id].right_child != -1)
    {
        h2 = calcHeight(T, T[id].right_child) + 1;
    }

    return T[id].height = max(h1, h2);
}

void printNode(vector<node> &T, int id)
{
    cout << "node " << id << ": ";
    cout << "parent = " << T[id].parent << ", ";
    cout << "sibling = " << T[id].sibling << ", ";
    string node_type = "internal node";
    if (T[id].left_child != -1 && T[id].right_child != -1)
    {
        cout << "degree = 2, ";
    }
    else if (T[id].left_child != -1 || T[id].right_child != -1)
    {
        cout << "degree = 1, ";
    }
    else
    {
        cout << "degree = 0, ";
        node_type = "leaf";
    }
    cout << "depth = " << T[id].depth << ", ";
    cout << "height = " << T[id].height << ", ";
    if (T[id].parent == -1)
    {
        cout << "root" << endl;
    }
    else
    {
        cout << node_type << endl;
    }
}

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

    vector<node> T(n);
    for (int i = 0; i < n; i++)
    {
        cin >> T[i].id >> T[i].left_child >> T[i].right_child;
    }
    sort(T.begin(), T.end(), [](node &left, node &right) {
        return left.id < right.id;
    });
    for (int i = 0; i < n; i++)
    {
        T[T[i].left_child].sibling = T[i].right_child;
        T[T[i].right_child].sibling = T[i].left_child;
    }

    int root_id = findRootId(T);
    calcDepth(T, root_id);
    calcHeight(T, root_id);

    for (int i = 0; i < n; i++)
    {
        printNode(T, i);
    }

    return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int gcd(int a, int b) {
    while (b) {
        int c = a % b;
        a = b;
        b = c;
    }
    return a;
}

ll po(ll a, ll b) {
    ll c = 1;
    while (b) {
        if (b % 2) c = c * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return c;
}

int main() {
    ios::sync_with_stdio(false);
    int n, k;
    ll d[100005] = {}, z = 0;
    cin >> n >> k;
    for (int i = 1; i <= k; i++) d[i] = po(k / i, n);
    for (int i = k; i; i--) for (int j = i + i; j <= k; j += i) {
        d[i] -= d[j];
        if (d[i] < 0) d[i] += mod;
    }
    for (int i = 1; i <= k; i++) z = (z + d[i] * i) % mod;
    cout << z;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> cnt(5, 0);
  rep(i, n) {
    string s;
    cin >> s;
    if (s[0] == 'M') cnt[0]++;
    if (s[0] == 'A') cnt[1]++;
    if (s[0] == 'R') cnt[2]++;
    if (s[0] == 'C') cnt[3]++;
    if (s[0] == 'H') cnt[4]++;
  }

  ll ans = 0;
  REP(i, 0, 5) REP(j, i + 1, 5) REP(k, j + 1, 5) {
    ans += cnt[i] * cnt[j] * cnt[k];
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	VE l(n+1), r(n + 1);
	rep(i, n)l[i + 1] = gcd(l[i], a[i]);
	for (int i = n - 1; i >= 0; i--) {
		r[i] = gcd(r[i + 1], a[i]);
	}
	int ans = 0;
	rep(i, n) {
		chmax(ans, gcd(l[i], r[i + 1]));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2560
using System;

namespace ABC103_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var t = Console.ReadLine();
            var f = "No";
            for (int i = 0; i < s.Length; i++)
            {
                s = s[s.Length-1] + s.Substring(0, s.Length - 1);
                if (s == t)
                {
                    f = "Yes";
                }
            }
            Console.WriteLine(f);
        }
    }
}


Measured memory_bytes: 11092
n=int(input())
arr=list(map(int,input().split()))
t=0
for a in arr:
    if a%2==0:
        if a%3==0:
            continue
        elif a%5==0:
            continue
        else:
            t=1
            break
if t==1:
    print("DENIED")
else:
    print("APPROVED")

Measured memory_bytes: 3060
C = [list(map(int, input().split())) for i in range(3)]
for i in range(3):
  C[i] = [C[i][0]-min(C[i]), C[i][1]-min(C[i]), C[i][2]-min(C[i])]
for j in range(3):
  tmp = min(C[0][j], C[1][j], C[2][j])
  C[0][j] = C[0][j] - tmp
  C[1][j] = C[1][j] - tmp
  C[2][j] = C[2][j] - tmp
if C == [[0] *3 for i in range(3)]: print("Yes")
else: print("No")

Measured memory_bytes: 62020
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int64_t N, x;
    cin >> N >> x;
    vector<int64_t> a(N);
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int ans = 0;
    for(int i = 0; i < N; i++) {
        if (a[i] <= x) {
            if(i == N - 1 && a[i] != x) {
                break;
            }
            ans++;
            x -= a[i];
        } else {
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
  int a, b;
  cin >> a >> b;
  if((a + b) %2 == 0)
  	cout << (a + b) / 2 << endl;
  else 
    cout << (a + b + 1) / 2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
using ll=long long;
ll w[110];
int v[110];
ll dp[110][100010];

int main(){ _;
  int n,wMax;cin>>n>>wMax;
  REP(i,n)cin>>w[i]>>v[i];
  REP(j,wMax+1)dp[0][j]=0;

  for(int i=0;i<n;i++){
    REP(j,wMax+1){
      if(j<w[i])
	dp[i+1][j]=dp[i][j];
      else
	dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
    }
  }
  ll result=0;
  REP(j,wMax+1){
    result=max(result,dp[n][j]);
  }
  cout<<result<<endl;
}


Measured memory_bytes: 80128
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,f[100001][5],l=0,r,mid,a[1000001],b[100001],c[100001];
int main()
{
	scanf("%lld",&n);
	for(int j=1;j<=n;++j)
		scanf("%lld",&a[j]);
		for(int j=1;j<=n;++j)
		scanf("%lld",&b[j]);
		for(int j=1;j<=n;++j)
		scanf("%lld",&c[j]);
	sort(a+1,a+1+n);sort(b+1,b+1+n);sort(c+1,c+1+n);
	for(int i=1;i<=n;++i)
	{
		f[i][1]=i;
	}
	for(int j=1;j<=n;++j)
		{
			l=1,r=n;
			while(l<=r)
			{
				mid=(l+r)/2;
				if(b[j]<=a[mid])
				{
					r=mid-1;
				}
				else
				l=mid+1;
			}
			f[j][2]=f[j-1][2]+f[r][1];
		}
	for(int j=1;j<=n;++j)
		{
			l=1,r=n;
			while(l<=r)
			{
				mid=(l+r)/2;
				if(c[j]<=b[mid])
				{
					r=mid-1;
				}
				else
				l=mid+1;
			}
			f[j][3]=f[j-1][3]+f[r][2];
		}
	printf("%lld",f[n][3]);
	return 0;
}

Measured memory_bytes: 9472
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int N, K;
int D[2001];
int E[4001], ne[4001], he[2001];
void dfs(int v, int d) {
	D[v] = d;
	for (int to = he[v]; to; to = ne[to]) {
		if (D[E[to]] < 0) dfs(E[to], d + 1);
	}
}

int dfs2(int v, int prev, int d) {
	if (d > K / 2) return 0;
	int ret = 1;
	for (int to = he[v]; to; to = ne[to]) {
		if (E[to] != prev) ret += dfs2(E[to], v, d + 1);
	}
	return ret;
}

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


	cin >> N >> K;
	int tmp = 1;
	int jisuu[2001] = {};
	rep(i, N - 1) {
		int a, b;
		cin >> a >> b;
		E[tmp] = b;
		ne[tmp] = he[a];
		he[a] = tmp++;
		E[tmp] = a;
		ne[tmp] = he[b];
		he[b] = tmp++;
		jisuu[a]++;
		jisuu[b]++;
	}

	if (K == 1) {
		printf("%d\n", N - 2);
		return 0;
	}

	rep1(j, N) D[j] = -1;
	dfs(1, 0);
	int saidai = 0;
	int doko, doko2;
	rep1(i, N) if (saidai < D[i]) {
		saidai = D[i];
		doko = i;
	}
	rep1(j, N) D[j] = -1;
	dfs(doko, 0);
	saidai = 0;
	bool muri[2001] = {};
	rep1(i, N) {
		if (saidai < D[i]) {
			saidai = D[i];
			doko2 = i;
		}
		if (D[i] < K / 2) {
			muri[i] = 1;
		}
	}
	if (saidai <= K) {
		printf("0\n");
		return 0;
	}
	rep1(j, N) D[j] = -1;
	dfs(doko2, 0);
	rep1(i, N) {
		if (D[i] < K / 2) muri[i] = 1;
		if (jisuu[i] == 1) muri[i] = 1;
	}

	if (K % 2 == 0) {
		int kotae = N;
		rep1(i, N) {
			if (!muri[i]) {
				int kazu = dfs2(i, -1, 0);
				kotae = min(kotae, N - kazu);
			}
		}
		co(kotae);
	}
	else {
		int kotae = N;
		rep1(i, N) {
			for (int to = he[i]; to; to = ne[to]) {
				int j = E[to];
				if (i < j) {
					if (!muri[i] && !muri[j]) {
						int kazu = dfs2(i, j, 0) + dfs2(j, i, 0);
						kotae = min(kotae, N - kazu);
					}
				}
			}
		}
		co(kotae);
	}

	Would you please return 0;
}

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

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

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

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
#[allow(dead_code)]
pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
    let out = stdout();
    let writer = BufWriter::new(out.lock());
    f(writer)
}
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) } ; }
pub const INF: i64 = 10_000;
#[allow(dead_code)]
fn main() {
    input!{
        n: usize,
        k: usize,
        h: [i64; n],
    }
    let mut dp = vec![INF; n];
    dp[0] = 0;
    for i in 0..n {
        for j in 1..k+1 {
            if i + j < n {
                if dp[i+j] == INF {
                    dp[i+j] = dp[i] + (h[i] - h[i+j]).abs();
                } else {
                    dp[i+j] = min(dp[i] + (h[i] - h[i+j]).abs(), dp[i+j]);
                }
            }
        }
    }
    println!("{}", dp[n-1]);
}

Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 998244353;
const int INF = 1e9;
const ll INFLONG = 1e18;
int main(){
  string s,t;
  cin >> s >> t;
  ll len1 = s.size();
  ll len2 = t.size();
  ll ans = INFLONG;
  rep(i,len1-len2+1){
    ll sum = 0;
    rep(j,len2){
      if(s[i+j] != t[j]){
        sum++;
      }
    }
    chmin(ans,sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m;cin>>n>>m;
  vector<lvector> A(n,lvector(m,0));
  rep(i,n)rep(j,m) {cin>>A[i][j];}
  ll ans=1e9,maxnum=0,maxpos=0;
  lvector v(m+1,0);
  while(A[0].size()) {
    rep(i,n) v[A[i][0]]++;
    maxpos=max_element(ALL(v))-v.begin();
    maxnum=v[maxpos];
    ans=min(ans,maxnum);
    rep(i,m+1) v[i]=0;
    for(ll i=0;i<n;++i) A[i].erase(find(ALL(A[i]),maxpos));
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		  ll n,k;
           cin>>n>>k;
           vll a(n);
           rep(i,0,n)cin>>a[i];
           vector<P> cnt(n);
           rep(i,0,n){
            ll now=a[i];
             rep(j,0,n){
               if(i<j&&a[i]>a[j])cnt[i].first++;
               if(a[i]>a[j])cnt[i].second++;
             }
           }
           ll ans=0;
           rep(i,0,n){
              ans+=k*cnt[i].first;
               ans+=k*k%inf*cnt[i].second;
             ans-=k*(k+1)/2%inf*cnt[i].second;
               ans%=inf;
           }
           if(ans<0)ans+=inf;
           cout<<ans<<endl;
          }

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

int bubblesort(vector<int> &A,int N){
    int sw=0;
    bool flag=1;
    while(flag){
        for(int i=0;flag;i++){
            flag=0;
            for(int j=N-1;j>=1;j--){
                if(A.at(j)<A.at(j-1)){
                    swap(A.at(j),A.at(j-1));
                    flag=1;
                    sw++;
                } 
            }
        }
    }
    return sw;
}

int main(void){
    int N;
    cin >> N;
    
vector<int> A(100);
    for(int i=0;i<N;i++){
        cin >> A.at(i);
    }
    
    int sw=bubblesort(A,N);
    
    for(int i=0;i<N-1;i++){
        cout << A.at(i) << " ";
    }
    cout << A.at(N-1) << endl;
    
    cout << sw << endl;
    return 0;
}


Measured memory_bytes: 3112
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let m: usize = read();

    let mut si: Vec<usize> = Vec::new();
    let mut ci: Vec<usize> = Vec::new();

    let mut ans: Vec<i32> = (0..n).map(|_| -1).collect();

    for _ in 0..m {
        si.push(read());
        ci.push(read());
    }

    let mut bad_flag = false;
    for i in 0..m {
        let idx = si[i] - 1;
        if ans[idx] == -1 {
            ans[idx] = ci[i] as i32;
        } else if ans[idx] != ci[i] as i32 {
            bad_flag = true;
            break;
        } 
    }

    if n > 1 && ans[0] == 0 {
        bad_flag = true;
    }

    if bad_flag {
        println!("-1");
    } else {
        for i in 0..n {
            if ans[i] == -1 {
                if i == 0 {
                    if n == 1 {
                        ans[i] = 0;
                    } else {
                        ans[i] = 1;
                    }
                } else {
                    ans[i] = 0;
                }
            }
        }
        let ans: String = ans.into_iter().map(|i| i.to_string()).collect();
        println!("{}", ans);
    }
}


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

int main() {
  int x;
  cin >> x;
  int i = 1;
  while(true) {
    if(x * i % 360 == 0) {
      cout << i << endl;
      break;
    }
    i++;
  }
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>

const int32_t kX = 10000;
const int32_t kY = 5000;
const int32_t kZ = 1000;

int main() {
  int32_t N, Y;
  std::cin >> N >> Y;

  for (int32_t i = 0; i <= N; i++) {
    for (int32_t j = 0; j <= (N - i); j++) {
      for (int32_t k = 0; k <= (N - (i + j)); k++) {
        if (k * kX + j * kY + i * kZ == Y && k + j + i == N) {
          std::cout << k << " " << j << " " << i << std::endl;
          return 0;
        }
      }
    }
  }

  std::cout << "-1 -1 -1" << std::endl;
  return 0;
}

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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 2e5;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
	int a;
	cin >> a;
	cout << a + a * a + a * a * a << "\n";
 	return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

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

int main(){
    int N; cin >> N;
    map<string, int> mpr;
    for(int i=0; i<N; i++){
        string s; cin >> s;
        mpr[s]++;
    }
    int M; cin >> M;
    map<string, int> mpb;
    for(int i=0; i<M; i++){
        string t; cin >> t;
        mpb[t]++;
    }

    int ans=0;
    for(auto p : mpr){
        int sum=p.second;
        if(mpb.count(p.first)) sum-=mpb[p.first];
        chmax(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC115
{
    class Program
    {
        static void Main(string[] args)
        {
            int D;
            

            D = int.Parse (Console.ReadLine());
            if (D == 25)
                Console.WriteLine("Christmas");
            else
                Console.WriteLine(" ");
            if (D == 24)
                Console.WriteLine("Christmas Eve");
            else
                Console.WriteLine(" ");
            if (D == 23)
                Console.WriteLine("Christmas Eve Eve");
            else
                Console.WriteLine(" ");
            if (D == 22)
                Console.WriteLine("Christmas Eve Eve Eve");
            else
                Console.WriteLine(" ");

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
function main()
  
  w = split(chomp(readline()),"")
  
  a2z = [string(i) for i in 'a':'z']
  
  count = 0
  
  for i in a2z
    for j in 1:length(w)
      
      if w[j] == i
        count += 1
      end
      
    end
    
    if count % 2 == 0
      count = 0
    else
      break
    end
    
  end
  
  if count == 0
    println("Yes")
  else
    println("No")
  end
  
end

main()

Measured memory_bytes: 109972
import fractions
a,b,c,d=map(int,input().split())

def lcm(c,d):
	return (c*d)// fractions.gcd(c,d)

aa=a-1-((a-1)//c)-((a-1)//d)+((a-1)//lcm(c,d))
bb=b-(b//c)-(b//d)+(b//lcm(c,d))
print(bb-aa)

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
//#define endl '\n'  
typedef long long ll; 
typedef unsigned long long ull; 
typedef long double ld;
typedef pair< ll , ll > mypair;
typedef priority_queue <ll> max_heap;
typedef priority_queue <ll, vector<ll>, greater<ll> > min_heap;
const ll mod=1e9+7;
const ll inf=1e15+5;
const ll N=3e5+10;
std::vector<int> v[N];
bool visited[N];
int dist[N];
int n,m;
void bfs(int node)
{
	queue<int> qe;
	visited[node]=1;
	qe.push(node);
	while(!qe.empty())
	{
		node=qe.front();
		qe.pop();
		for(auto &i: v[node])
		{
			if(visited[i]==0)
			{
				visited[i]=1;
				dist[i]=dist[node]+1;
				qe.push(i);
			}
		}
	}
}
int main()
{
	boost;
	cin>>n>>m;
	while(m--)
	{
		int x,y;
		cin>>x>>y;
		x--;y--;
		v[x].pb(n+y);
		v[n+x].pb(n+n+y);
		v[n+n+x].pb(y);
	}
	int s,t;
	cin>>s>>t;
	s--;t--;
	bfs(s);
	if(dist[t]) cout<<dist[t]/3;
	else cout<<"-1";

	return 0;
} 


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

#define ll long long 
ll mincost(ll n,ll h[],ll k)
{
	ll dp[n+1],a,b,j;
	
	dp[1]=0;
		
	for(ll step=2;step<=n;step++)
	{

	   dp[step]=INT_MAX;
	   for(j=1;j<=k;j++)
	   {
	   	if(step-j>0)
	   	{
	   		dp[step]=min(dp[step],abs(h[step]-h[step-j])+dp[step-j]);
	   	}
	   	 else
	   	 {
	   	 	break;
	   	 }
	   }
	   
	}
	return(dp[n]);
}
int main()
{
    
    
    ll n;
    cin>>n;
    ll h[n+1],i;

    for(i=1;i<=n;i++)
    {
    	cin>>h[i];
    }
    cout<<mincost(n,h,2)<<endl;
	
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <time.h>

using namespace std;
typedef long long ll;

int N = 0;
int M = 0;
int x = 0;
int y = 0;

//?????????????????

struct UnionFind{
    //ご本体
    vector<ll > tree;
    //高さ
    vector<ll > rank;
    //グループごとのサイズ
    vector<ll > size;
 
    //定義
    UnionFind(ll N) : tree(N), rank(N), size(N){
        for(int i = 0; i < N; i++){
            tree[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }

    //どの根っこに属しているのか？さかのぼり続ける
    int root(int x){
        if(tree[x] == x){
            return x;
        }
        //経路圧縮
        return tree[x] = root(tree[x]);
    }

    //木と木を(高さが低い方に)くっつける
    void unite(int x, int y){
        int tx = root(x);
        int ty = root(y);
        //xとyの根が同じならくっつけない
        if(tx == ty){
            return;
        }

        ll s = size[tx] + size[ty];
        size[tx] = s;
        size[ty] = s;

        //tree[tx] = ty;
        //高くない方にくっつけたい：効果がいまいちわからん
        //下：ランク付けのつもり 
        if(rank[tx] < rank[ty]){
            //小さい方を大きい方
            //txの根が大きい方の根に更新
            tree[tx] = ty; 
        }else{
            tree[ty] = tx;
            //つなげるときに同じ高さだったらつなげた後に高さを＋１する
            if(rank[tx] == rank[ty]){
                rank[tx]++;
            }
        }

        //return s1;

    }

    //同じ木に属しているか？根っこをさかのぼって調べてみる
    bool same(int x, int y){
        int tx = root(x);
        int ty = root(y);
        if(tx == ty){
            return true;
        }else{
            return false;
        }
    }
    //グループのサイズを返す
    int FindSize(int x){
        return size[root(x)];
    }

};

int main(){

    cin >> N >> M;
    vector<int > p(N,0);

    UnionFind u(N);
    
    for(int i = 0; i < N; i++){
        cin >> p[i];
    }
    //グループ分け(連結)
    for(int i = 0; i < M; i++){
        cin >> x >> y;
        u.unite(x - 1, y - 1);
    }
    //確認
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(u.same(i, p[i] - 1)){
            ans++;
        }
        
    }
    cout << ans << endl;

}

Measured memory_bytes: 2944
#include <stdio.h>

int main()
{
    char s[100000+1]; //[]付け忘れないように
    int i;

    scanf("%s", s); //文字列を入力するときは&付けない

    for( i = 0; i < strlen(s); i+=2 ) //文字列の最後の文字までstrlen
        printf("%c", s[i]); //文字列じゃなくて文字を出力するので%c
    
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=j;i<k;i++)
int main(){
    queue<pair<string,int>>Q;
    int n,q,t;cin>>n>>q;
    string s;
    rep(i,0,n){
        cin>>s>>t;
        Q.push(make_pair(s,t));
    }
    int ans=0;
    while(!Q.empty()){
        s=Q.front().first;t=Q.front().second;Q.pop();
        if(t>q){
            t=t-q;
            Q.push(make_pair(s,t));
            ans+=q;
        }
        else if(t<=q){
            ans+=t;
            cout<<s<<" "<<ans<<endl;
        }
    }
    return 0;
}



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

signed main(void)
{
	int n, m, cnt;
	cin >> n >> m;
	int h[n];
	vector<int> v[n];
	rep(i, n) cin >> h[i];
	rep(i, m)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		v[a].push_back(h[b]);
		v[b].push_back(h[a]);
	}
	rep(i, n) sort(v[i].rbegin(), v[i].rend());
	cnt = 0;
	rep(i, n)
	{
		if (v[i].size() == 0 || h[i] > v[i][0])
			cnt++;
	}
	cout << cnt << endl;	
	return 0;
}


Measured memory_bytes: 9124
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
   int N;
   cin >> N;
   vector<float> v(N);
   for(int i=0;i<N;++i) cin >> v[i];

   sort(v.begin(), v.end());
   float temp;

   for(int i=0;i<N-1;++i){
      temp = (v[0] + v[1])/2;
      v.erase(v.begin(),v.begin()+2);
      v.insert(v.begin(),temp);
   }

   cout << v[0]  << endl;

   return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#define MP make_pair
using ll = long long;
using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<ll>A(N);
  vector<ll>B(N);
  ll sum=0;
  for(int i=0; i < N; i++){
    cin >> A[i];
    sum += A[i];
  }
  B[0] = A[0];
  for(int i=1; i < N; i++)
    B[i] = B[i-1] + A[i];
  ll min = 3000000000;
  int mini;
  for(int i=0; i < N-1; i++){
    if(abs(B[i]-(sum-B[i])) < min){
	min = abs(B[i] - (sum-B[i]));
	mini = i;
	}
   }
   cout << min << endl;

  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ll long long
#define EPS 1e-9
#define rank asadf
using namespace std;

const int MAXN = 3e5 + 111;
const int MOD = 1e9 + 7;
const int dx[] = {0, -1, 0, 1};
const int dy[] = {-1, 0, 1, 0};

int h, w, cnt1[MAXN], cnt2[MAXN];

set<pair<int, int> > st;

vector<int> v1, v2;

int main() {
#ifdef LOCAL
    freopen("xxx.in", "r", stdin);
    freopen("xxx.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> h >> w;
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        ++cnt1[x], ++cnt2[y];
        st.insert({x, y});
    }
    int mx1 = -1, mx2 = -1;
    int c1 = 0, c2 = 0;
    for (int i = 0; i < h; ++i) {
        mx1 = max(mx1, cnt1[i]);
    }
    for (int i = 0; i < w; ++i) {
        mx2 = max(mx2, cnt2[i]);
    }
    for (int i = 0; i < h; ++i) {
        if (cnt1[i] == mx1)
            v1.push_back(i);
        c1 += (cnt1[i] == mx1);
    }
    for (int i = 0; i < w; ++i) {
        if (cnt2[i] == mx2)
            v2.push_back(i);
        c2 += (cnt2[i] == mx2);
    }
    if (c1 * 1LL * c2 > m) {
        cout << mx1 + mx2;
    } else {
        bool ok = false;
        for (auto x : v1) {
            for (auto y : v2) {
                if (st.find({x, y}) == st.end())
                    ok = true;
            }
        }
        cout << mx1 + mx2 - !ok;
    }
    return 0;
}

Measured memory_bytes: 23804
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
ll n,k;
ll p[3];
cin >> n;
int i=2;
while(1){
	if(n==0) break;
	k=n%10;
	n/=10;
	if(k==9) p[i]=1;
	else if(k==1) p[i]=9;
	else p[i]=k;
	i--;
}
for(int i=0;i<3;i++){
	cout << p[i];
}
cout << endl;
}


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

using namespace std;

int main()
{
	long int n;
	scanf("%ld", &n);

	bool divisable = false;

	printf("%ld:", n);

	while (n % 2 == 0)
	{
		printf(" 2");
		n /= 2;
	}

	while (n % 3 == 0)
	{
		printf(" 3");
		n /= 3;
	}

	if (n != 1)
	{
		long int ceilodd = (long int)floor(sqrt(n*1.0));

		long int tmp;

		for (long int i = 5; i <= ceilodd; i += 2)
		{
			divisable = false;

			tmp = (long int)floor(sqrt(1.0*i));
			for (long int j = 3; j <= tmp; j += 2)
			{
				if (i%j == 0)
				{
					divisable = true;
					break;
				}
			}

			if (divisable == false)
			{
				while (n%i == 0)
				{
					printf(" %ld", i);
					n /= i;
				}
				if (n == 1)goto goal;
			}

		}

	}
	
	if (n != 1)
		printf(" %ld", n);

	goal:

		printf("\n");
	
	return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>
int main(){
 int n,a,i;
 int ans[100000]={};
 scanf("%d",&n);
 for(i=0;i<n;i++) {
  scanf("%d", &a);
  ans[a-1]=i+1;
 }
 for(i=0;i<n;i++)
  printf("%d ",ans[i]);
 printf("\n");
 return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#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)
#define REPR(i,  n) for (int i  =  n - 1; i >= 0; --i)
using namespace std;
#define int long long int
//------------ATCODER TEMPLATE-------------

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

signed main() {
  int N; cin >> N;
  vector<int> L(N); cin >> L;

  int cnt = 0;
  REP(i, N) {
    REP2(j, i + 1, N) {
      REP2(k, j + 1, N) {
        if (L[i] != L[j] && L[i] != L[k] && L[j] != L[k]) {
          if (L[i] < L[j] + L[k] &&
              L[j] < L[i] + L[k] &&
              L[k] < L[i] + L[j]) ++cnt;
        }
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


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


int main()
{
	int cards[4][13], n, num, idx;
	char s, suit[4] = { 'S', 'H', 'C', 'D' };
	cin >> n;

	for (int i = 0;i < 4;i++) {
		for (int j = 0;j < 13;j++) {
			cards[i][j] = 1;
		}
	}

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

		if (s == 'S') {
			idx = 0;
		}
		else if (s == 'H') {
			idx = 1;
		}
		else if (s == 'C') {
			idx = 2;
		}
		else if (s == 'D') {
			idx = 3;
		}

		cards[idx][num - 1] = 0;
	}

	for (int i = 0;i < 4;i++) {
		for (int j = 0;j < 13;j++) {
			if (cards[i][j] != 0) {
				cout << suit[i] << " " << j + 1 << endl;
			}
		}
	}
    return 0;
}



Measured memory_bytes: 3084
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
    int H, W, D;

    scanf("%d%d%d", &H, &W, &D);

    int **masu;

    masu = (int **) malloc(sizeof(int *) * H);

    int i, j;

    for(i = 0; i < H; i ++){
        masu[i] = (int *) malloc(sizeof(int) * W);

        for(j = 0; j < W; j ++){
            scanf("%d", masu[i] + j);
        }
    }
    int *masu_x = (int *) malloc(sizeof(int) * (H * W + 1));
    int *masu_y = (int *) malloc(sizeof(int) * (H * W + 1));

    for(i = 0; i < H * W + 1; i ++){
        masu_x[i] = 0;
        masu_y[i] = 0;
    }

    for(i = 0; i < H; i ++){
        for(j = 0; j < W; j ++){
            masu_x[masu[i][j]] = i;
            masu_y[masu[i][j]] = j;
        }
    }
    int *sum_sum = (int *) malloc(sizeof(int) * (H * W + 1));

    for(i = 1; i <= D; i ++){
        int sum = 0;

        int cur_R = i;
        int x = masu_x[cur_R];
        int y = masu_y[cur_R];

        sum_sum[i] = 0;

        for(j = i + D; j <= H * W; j += D){
            int x2 = masu_x[j];
            int y2 = masu_y[j];

            sum += abs(x2 - x) + abs(y2 - y);

            x = x2;
            y = y2;
            sum_sum[j] = sum;
        }
    }

    int Q;

    scanf("%d", &Q);

    int *L = (int *) malloc(sizeof(int) * Q);
    int *R = (int *) malloc(sizeof(int) * Q);
    int *sum = (int *) malloc(sizeof(int) * Q);

    for(i = 0; i < Q; i ++){
        scanf("%d%d", L + i, R + i);

        sum[i] = sum_sum[R[i]] - sum_sum[L[i]];
    }
    for(i = 0; i < Q; i ++){
        printf("%d\n", sum[i]);
    }

    return 0;
}

Measured memory_bytes: 3584
#include <stdio.h>
int main(void){
	char s[100001];
	int n,q;
	int ans[100001]={0};
	int ans2[100001];
	scanf("%d%d",&n,&q);
	scanf("%s",s);
	int i,j,l,r;
	//左からACが累計どれだけ存在したかをカウントしてく
	for(i=0;i<n;i++){
		ans[i+1] = ans[i];
		if(s[i]=='A'){
			if(s[i+1]=='C'){
				ans[i+1]++;
			}
		}
	}
	for(i=0;i<q;i++){
		scanf("%d%d",&l,&r);
		ans2[i] = ans[r-1]-ans[l-1];
	}
	for(i=0;i<q;i++){
		printf("%d\n",ans2[i]);
	}
	
	return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cassert>
#include <string.h>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  REP(i,a,b) for(int i=a;i<b;i++)
typedef long long int lld;
typedef vector<lld> vl;
typedef vector<int> vi;
typedef vector<string> vs;



//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());

int main() {
	int h,w,tmp=0;

	string ans;
	cin>>h>>w;
	vi flag_y(w,0),flag_x(h,0);
	vs a(h);
	rep(i,h){
		cin>>a[i];
	}

	rep(i,h){
		tmp=0;
		rep(k,w) {
			if (a[i][k] == '.')
				tmp++;
		}
		if(tmp==w){
			flag_x[i]=1;
		}

	}
	rep(i,w){
		tmp=0;
		rep(k,h) {
			if (a[k][i] == '.')
				tmp++;
		}
		if(tmp==h){
			flag_y[i]=1;
		}
	}

	rep(i,h){
		rep(k,w) {
			if(flag_x[i]!=1 &&flag_y[k]!=1 ){
				cout<<a[i][k];
			}

		}
		if(flag_x[i]!=1 ) {
			cout << "\n";
		}

	}

	/*
	rep(i,w) {
		rep(k, h) {
			cout << flag_x[i] + flag_y[k];
		}
		cout << "\n";
	}
	 */
	return 0;


}


Measured memory_bytes: 256