akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define mod 1000000007
class unionfind{
    public:
    ll treecnt,colorcnt;
    unordered_map<ll,ll> p,vcnt;
    unordered_set<ll> jiko;
    vector<ll> as,bs;
    void init(){
	as.clear();
	bs.clear();
	p.clear();
	vcnt.clear();
	jiko.clear();
	treecnt=0;
	colorcnt=0;
    }
    ll par(ll x){
	if(p.find(x)==p.end()){
	    p[x]=x;
	    vcnt[x]=1;
	    treecnt++;
	    colorcnt++;
	    return x;
	}
	return p[x]=(x==p[x]?x:par(p[x]));
    }
    void unite(ll a,ll b){
	as.push_back(a);
	bs.push_back(b);
	if(a==b){
	    if(jiko.find(a)!=jiko.end())return;
	    jiko.insert(a);
	    a=par(a);
	    if(vcnt[a]==1)treecnt--;
	    vcnt[a]--;
	    if(vcnt[a]==1)treecnt++;
	    return;
	}
	a=par(a),b=par(b);
	if(a==b){
	    if(vcnt[a]==1)treecnt--;
	    vcnt[a]--;
	    if(vcnt[a]==1)treecnt++;
	}
	else{
	    if(vcnt[a]==1)treecnt--;
	    if(vcnt[b]==1)treecnt--;
	    p[b]=a;
	    vcnt[a]+=vcnt[b]-1;
	    if(vcnt[a]==1)treecnt++;
	}
    }
    ll qry(){
	return colorcnt-treecnt;
    }
};
unionfind uf[100010];
ll n,k;
vector<ll> g[100010];
ll c[100010],d[100010];
ll id[100010];
ll ans[100010];
void dfs(ll x,ll from){
    ll ma=-1,pnt=-1;
    for(auto y:g[x])if(y!=from){
	dfs(y,x);
	if(uf[id[y]].colorcnt>ma){
	    ma=uf[id[y]].colorcnt;
	    pnt=y;
	}
    }
    if(pnt==-1)id[x]=x;
    else id[x]=id[pnt];
    uf[id[x]].unite(c[x],d[x]);
    for(auto y:g[x])if(y!=from&&y!=pnt){
	for(int i=0;i<uf[id[y]].as.size();i++){
	    ll a=uf[id[y]].as[i];
	    ll b=uf[id[y]].bs[i];
	    uf[id[x]].unite(a,b);
	}
	uf[id[y]].init();
    }
    ans[x]=uf[id[x]].qry();
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin>>n>>k;
  for(int i=0;i<n-1;i++){
      ll a,b; cin>>a>>b;
      g[a].push_back(b);
      g[b].push_back(a);
  }
  for(int i=1;i<=n;i++){
      cin>>c[i]>>d[i];
      uf[i].init();
  }
  dfs(1,0);
  for(int i=1;i<=n;i++){
      cout<<ans[i]<<endl;
  }
  return 0;
}



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

int main() {
	int a, b;
	cin >> a >> b;
	if (a%3==0||b%3==0||(a+b)%3==0)
	{
		cout << "Possible";
	}
	else
	{
		cout << "Impossible";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

//閉路やばそう
//閉路の総和がPより大きいとヤバそう
//小さい場合は閉路を回る必要がないが

//閉路判定以外やるだけでは？

struct edge {
	int to; ll cost;
};
vector<edge> G[2500];
vector<int> rG[2500];
ll score[2500];

bool cangoal[2500];
bool canstart[2500];
void solve() {
	int n, m; cin >> n >> m; ll p; cin >> p;
	rep(i, m) {
		int a, b, c; cin >> a >> b >> c; a--; b--;
		G[a].push_back({ b,c });
		rG[b].push_back(a);
	}
	fill(score, score + n, -INF);
	score[0] = 0;

	//頂点0から行けてかつN-1に到達するやつを列挙
	queue<int> q; q.push(n - 1); cangoal[n - 1] = true;
	while (!q.empty()) {
		int id = q.front(); q.pop();
		rep(j, rG[id].size()) {
			int to = rG[id][j];
			if (cangoal[to])continue;
			cangoal[to] = true; q.push(to);
		}
	}
	//rep(i, n)cout << i << " " << cangoal[i] << endl;
	q.push(0); canstart[0] = true;
	while (!q.empty()) {
		int id = q.front(); q.pop();
		rep(j, G[id].size()) {
			int to = G[id][j].to;
			if (canstart[to])continue;
			canstart[to] = true; q.push(to);
		}
	}
	rep(i, n) {
		if (!canstart[i])cangoal[i] = false;
	}

	//とりあえず5000回更新
	rep(aa, 5000) {
		rep(i, n) {
			if (!cangoal[i])continue;
			rep(j, G[i].size()) {
				int to = G[i][j].to;
				if (!cangoal[to])continue;
				ll ns = score[i] + G[i][j].cost - p;
				//cout << i << " " << to << " " << ns << endl;
				if (score[to] < ns) {
					score[to] = ns;
				}
			}
		}
	}

	//まだ更新されるなら無限に回ってる
	rep(i, n) {
		if (!cangoal[i])continue;
		rep(j, G[i].size()) {
			int to = G[i][j].to;
			if (!cangoal[to])continue;
			ll ns = score[i] + G[i][j].cost - p;
			if (score[to] < ns) {
				//cout << i << " " << to << endl;
				cout << -1 << endl; return;
				score[to] = ns;
			}
		}
	}
	if (score[n - 1] < 0)score[n - 1] = 0;
	cout << score[n - 1] << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
	//stop
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>

using namespace std;

#define int_ int64_t
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int N=110;
int n,a[N];

int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",a+i);
    int ans=0;
    for (int i=1;i<=n;) {
        int j=i;
        while (j<=n&&a[j]==a[i]) j++;
        ans+=(j-i)/2;
        i=j;
    }
    printf("%d\n",ans);
}



Measured memory_bytes: 256
#! /usr/bin/python3
# 白昼夢 / Daydream

S = input()

def main(s):
    s = s.replace('eraser', '')
    s = s.replace('erase', '')
    s = s.replace('dreamer', '')
    s = s.replace('dream', '')
    if s == '':
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main(S)


Measured memory_bytes: 3188
#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: 3636
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
using namespace std;
long long actionFunction(vector<int> &weights, vector<long long> &values, int maxWeightCapacity) {
    if(weights.size()==0 || maxWeightCapacity<0)return 0;
    vector<vector<long long>> dp(weights.size()+1,vector<long long>(maxWeightCapacity+1,0));
    for(int i=1;i<=weights.size();i++) {
        for(int k=0;k<=maxWeightCapacity;k++) {
            dp[i][k]=(long long)max((long long)dp[i-1][k],(long long)(weights[i-1]<=k)?(long long)values[i-1]+(long long)dp[i-1][k-weights[i-1]]:0);
        }
    }
    return dp[weights.size()][maxWeightCapacity];
}
int main(void){
    vector<int> weights;
    vector<long long> values;
    int n,k,tmp;
    long long tmpl;
    cin>>n>>k;
    for(int i=0;i<n;i++) {
        cin>>tmp;cin>>tmpl;
        weights.push_back(tmp);
        values.push_back(tmpl);
    }
    cout<<actionFunction(weights,values,k)<<endl;
}


Measured memory_bytes: 80256
from math import hypot
x1, y1, x2, y2 = map(int, input().split())
dx, dy = x2-x1, y2-y1
vector_a = hypot(dx, dy)
q = int(input())

for x3, y3 in (map(int, input().split()) for _ in [0]*q):
    d = ((x3-x1)*dx + (y3-y1)*dy) / (vector_a**2)
    print(x1+dx*d, y1+dy*d)


Measured memory_bytes: 5700
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, N, sum;
  cin >> A >> B;
  sum=0;

  for(int i=A;i<=B;i++){
    N=i;
    int x1, x2;
    x1=((N%100)%10)*10+(N%100)/10;
    x2=N/1000;
    if(x1==x2) sum++;
  
  }

  cout << sum << endl;

}

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

using namespace std;

int main() {
	int n;
	int res = 0;
	cin >> n;
	vector<int> H(n), V(n, 0);
	for (int& h: H) {
		cin >> h;
	}
	for (int i = n - 2; i >= 0; --i) {
		if (H[i + 1] <= H[i]) {
			V[i] = V[i + 1] + 1;
		} else {
			V[i] = 0;
		}
		res = max(res, V[i]);
	}

	cout << res;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef double ld;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
const ll MOD = 4000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

ll digit(ll n){
	string s=to_string(n);
	ll ret=0;
	for(int i=0;i<s.size();i++){
		ret+=(s[i]-'0');
		
	}
	
	return ret;
}


int main(){
	init();
	ll N;cin>>N;
	cout<<48-N<<endl;
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.math;

void main(){

    while(true){
	int n = to!int(chomp(readln()));
	if(n == 0) break;
	int ans = 0;
	int nf=8;
	while(nf>0){
	    ans += n / pow(5,nf) ;
	    nf--;
	}
	writeln(ans);
    }
}

Measured memory_bytes: 2368
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pl>    vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
  uniform_int_distribution<int> uid(0,lim-1);
  return uid(rang);
}
int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

void solve() {
  int i, j, n, m, t;
  cin >> n >> m;
  vpl c;
  fo(i,n){
    ll int a,b;
    cin >> a >> b;
    c.pb(mp(a,b));
  }
  sortall(c);
  unsigned ll int cost = 0, can = 0;
  for(i=0; i<n; i++){
    if(can>m) break;
    if(can+c[i].S<=m){
      cost+=(c[i].S*c[i].F);
      can+=c[i].S;
    }
    else{
      cost+=((m-can)*c[i].F);
      can+=(m-can);
      break;
    }
  }
  cout << cost;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

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

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}


Measured memory_bytes: 5256
H,W,M=map(int,input().split())
h,w=map(list,zip(*[list(map(int,input().split())) for i in range(M)]))
from collections import Counter
hc,wc=Counter(h),Counter(w)
hx,wx=hc.most_common()[0][1],wc.most_common()[0][1]
hl,wl=set([k for k,v in hc.items() if v==hx]),set([k for k,v in wc.items() if v==wx])
x=sum([1 for i in range(M) if h[i] in hl and w[i] in wl])
print(hx+wx if len(hl)*len(wl)-x else hx+wx-1)

Measured memory_bytes: 115448
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
string s;
int a[1000001];
int b[1000001];

int c[1000001];
LL num[1000011];

void init(){
	num[0]=0;
	REP(i,1000011){
		if(i==0)continue;
		num[i]=num[i-1];
		int temp=i;
		while(temp%2==0){
			temp/=2;
			num[i]++;
		}
	}
}
int main(){
	cin>>N;
	cin>>s;
	REP(i,N){
		if(s[i]=='1'){
			c[i]=1;
		}else if(s[i]=='2'){
			c[i]=2;
		}else if(s[i]=='3'){
			c[i]=3;
		}
	}
	REP(i,N-1){
		c[i]=abs(c[i]-c[i+1]);
	}
	N--;
	if(N==1){
		cout<<c[0]<<endl;
		return 0;
	}
	bool check=false;
	REP(i,N){
		if(c[i]==1){
			a[i]=0;
			b[i]=1;
			check=true;
		}else if(c[i]==2){
			a[i]=1;
			b[i]=0;
		}else{
			a[i]=0;
			b[i]=0;
			//check=true;
		}
	}
	init();
	LL aa=0;
	REP(i,N){
		if(a[i]==1){
			if(num[N-1]-num[i]-num[N-1-i]==0){
				aa++;
			//					cout<<"+"<<i<<endl;
			}
		}
		
		//cout<<num[N-1]-num[i]-num[N-1-i]<<endl;
	}
	LL bb=0;
	REP(i,N){
		if(b[i]==1){
			if(num[N-1]-num[i]-num[N-1-i]==0){
				bb++;
			}
		}
		//cout<<num[N-1]-num[i]-num[N-1-i]<<endl;
	}
	aa%=2;
	bb%=2;
	if(check){
		aa=0;
	}
	cout<<aa*2+bb<<endl;
}

Measured memory_bytes: 20868
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int E[4010] = {};
	bool F[4010] = {};
	for (int n; cin >> n&&n;) {
		memset(E, 0, sizeof(E));
		memset(F, 0, sizeof(F));
		bool flag = true;
		rep(i, 0, n) {
			int e, p, q; cin >> e >> p >> q;
			E[e] += p*q;
			if (E[e] >= 1000000 && !F[e]) {
				flag = false;
				F[e] = true;
				cout << e << endl;
			}
		}
		if (flag)cout << "NA" << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
const int mod = 1e9+7;

int dp[2005][2005][2];
int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    if(n == 1){
        printf("1\n");
        return 0;
    }
    dp[n+1][0][0] = 1;
    for(int i=n;i>=2;i--){
        for(int j=n;j>=0;j--){
            dp[i][j][0] = (dp[i][j][0] + dp[i+1][j][0])%mod;
            dp[i][j][0] = (dp[i][j][0] + dp[i+1][j][1])%mod;

            dp[i][j+1][1] = (dp[i][j+1][1] + dp[i+1][j][0])%mod;
            dp[i][j+1][1] = (dp[i][j+1][1] + dp[i+1][j][1])%mod;

            dp[i][j][0] = (dp[i][j][0] + dp[i][j+1][0])%mod;
        }
    }

    int ans = (dp[2][n-k][0] + dp[2][n-k][1])%mod;
    for(int i=1;i<=n-k-1;i++) ans = ans*2%mod;
    printf("%d\n", ans);
}

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

#define x first
#define y second

const int N = 100005;
typedef long long LL;
typedef std::pair<int, int> point;

point operator + (point a, point b) { return point(a.x + b.x, a.y + b.y); } 
point operator - (point a, point b) { return point(a.x - b.x, a.y - b.y); }
point T(point a) { return point(a.y, a.x); }
int n, a, b, d;
LL ans;

point pos[N], lu, ld, ru, rd;



struct dsu {
	int f[N]; std::pair<point, int> p[N];
	void init() { std::sort(p + 1, p + n + 1); for (int i = 1; i <= n + 1; ++i) f[i] = i; }
	int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
	void remove(int x) { f[x] = x + 1; }
} h, v;

inline bool cmp0(point a, std::pair<point, int> b) {return a < b.first;}
inline bool cmp1(std::pair<point, int> a, point b) {return a.first < b;}

bool vis[N];
void solve() {
	h.init(), v.init();
	std::queue<int> q; q.push(a), vis[a] = 1;
	while (q.size()) {
		int x = q.front(), L, R; q.pop();
		L = std::lower_bound(h.p + 1, h.p + n + 1, T(pos[x] + lu), cmp1) - h.p;
		R = std::lower_bound(h.p + 1, h.p + n + 1, T(pos[x] + ru), cmp1) - h.p;
		ans += R - L;
		for (; (L = h.find(L)) < R; h.remove(L++)) {
			int id = h.p[L].second; if (!vis[id]) vis[id] = 1, q.push(id);
		}
		//
		L = std::upper_bound(h.p + 1, h.p + n + 1, T(pos[x] + ld), cmp0) - h.p;
		R = std::upper_bound(h.p + 1, h.p + n + 1, T(pos[x] + rd), cmp0) - h.p;
		ans += R - L;
		for (; (L = h.find(L)) < R; h.remove(L++)) {
			int id = h.p[L].second; if (!vis[id]) vis[id] = 1, q.push(id);
		}
		//
		L = std::upper_bound(v.p + 1, v.p + n + 1, pos[x] + rd, cmp0) - v.p;
		R = std::upper_bound(v.p + 1, v.p + n + 1, pos[x] + ru, cmp0) - v.p;
		ans += R - L;
		for (; (L = v.find(L)) < R; v.remove(L++)) {
			int id = v.p[L].second; if (!vis[id]) vis[id] = 1, q.push(id);
		}
		//
		L = std::lower_bound(v.p + 1, v.p + n + 1, pos[x] + ld, cmp1) - v.p;
		R = std::lower_bound(v.p + 1, v.p + n + 1, pos[x] + lu, cmp1) - v.p;
		ans += R - L;
		for (; (L = v.find(L)) < R; v.remove(L++)) {
			int id = v.p[L].second; if (!vis[id]) vis[id] = 1, q.push(id);
		}
	}
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> a >> b;
	for (int i = 1; i <= n; ++i) {
		point p; std::cin >> p.x >> p.y, p = point(p.x + p.y, p.x - p.y);
		pos[i] = p, v.p[i] = {p, i}, std::swap(p.x, p.y), h.p[i] = {p, i};
	}
	point q = pos[a] - pos[b]; d = std::max(std::abs(q.x), std::abs(q.y));
	lu = {-d, d}, ld = {-d, -d}, ru = {d, d}, rd = {d, -d};
	solve(), std::cout << ans / 2 << '\n';
	return 0;
}

Measured memory_bytes: 5120
n = int(input())
s = input()

seen = {}

for i in range(n):
    if s[i] in seen:
        seen[s[i]].append(i)
    else:
        seen[s[i]] = [i]

cnt = 0

for a, ai in seen.items():
    for b, bi in seen.items():
        if ai[0] >= bi[-1]:
            continue

        lower = ai[0]
        upper = bi[-1]

        for c, ci in seen.items():
            search = ci
            if a == c:
                search = search[1:]
            if b == c:
                search = search[:-1]

            #binary search
            l = 0
            r = len(search)-1
            found = False

            while l <= r:
                mid = (l+r)//2

                if lower < search[mid] < upper:
                    found = True
                    break
                elif search[mid] >= upper:
                    r = mid-1
                else:
                    l = mid+1

            if found:
                cnt += 1

print(cnt)

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

using namespace std;

int main(){
    string s;
    cin>>s;
    string ans="AC";
    int cnt=0;
    
    for(int i=0;i<s.size();i++){
        if(i==0){
            if(s.at(i)!='A') ans="WA";
        }else if(s.at(i)=='C'){
            cnt++;
            if(i<2 || i==s.size()-1) ans="WA";
        }else if(s.at(i)>='A' && s.at(i)<='Z'){
            ans="WA";
        }
    }
    
    if(cnt!=1) ans="WA";
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**5
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    s = sys.stdin.readline().rstrip()
    n = len(s)
    ans = 0
    for i in range(n):
        if i % 2 == 0:
            if s[i] == 'p': ans -= 1
        else:
            if s[i] == 'g': ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 41580
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()

ll A[7];

void solve(){
	rep(i, 7)scanf("%lld", A+i);
	ll ans = 0;
	ll a = A[0], b = A[3], c = A[4];
	if(a > 0 && b > 0 && c > 0)ans = max(ans, 3 + (a-1) / 2 * 2 + (b-1) / 2 * 2 + (c-1) / 2 * 2);
	ans = max(ans, a/2 * 2 + b/2 * 2 + c/2 * 2);
	printf("%lld", ans + A[1]);
}

int main(){
	int Tc = 1; //scanf("%d", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	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 n = Integer.parseInt(sc.next());
		int[] mt = new int[n];
		
		for(int i=0;i<n;i++) {
			mt[i] = Integer.parseInt(sc.next());
			
		}
		
		int count = 1;
		int max = mt[0];
		for(int i=1;i<n;i++) {
			if(mt[i]>max) {
				count++;
				max = mt[i];
			}else if(mt[i] == max) {
				count++;
			}
			
			
			
		}
		
		System.out.println(count);
	}
}


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

namespace ConsoleApp43 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int a = st[0];
            int b = st[1];
            int c = st[2];

            if (b - a == c - b) {
                Console.WriteLine("YES");
            } else {
                Console.WriteLine("NO");
            }

            
            
        }

    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S,False(1,-1);
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

template<typename A,size_t N,typename T>
void Fill(A(&array)[N],const T &val){
    fill((T*)array,(T*)(array+N),val);
}

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



int main(){
    ll h, w;
    cin >> h >> w;
    ll res;
    if( h == 1 || w == 1 ){
        res = 1;
    }
    else if( h % 2 == 0 || w % 2 == 0 ){
        res = h * w / 2;
    }
    else {
        res = h * w / 2 + 1;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  for(int i=1;i<=n;i++){
    int ans=0;
    for(int x=1;x*x+2*x+3<=i;x++){
      for(int y=1;x*x+y*y+1+x*y+y+x<=i;y++){
        for(int z=1;x*x+y*y+z*z+x*y+y*z+z*x<=i;z++){
          if(x*x+y*y+z*z+x*y+y*z+z*x==i) ans++;
        }
      }
    }
    cout << ans << endl;
  }      
  return 0;
}


Measured memory_bytes: 3588
/*
    ##############################
    #  Author: Pratyush Gaurav   #
    #  College: NIT ROURKELA     #
    ##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

lli dx[]={0,0,-1,1,-1,-1,1,1};
lli dy[]={1,-1,0,0,1,-1,-1,1};

void solve() {
    lli x;
    cin >> x;
    if (x == 7 or x == 5 or x == 3)
        cout << "YES\n";
    else
        cout << "NO\n";
}

int main()
{
    opt;
    lli t = 1;
    //cin >> t;

    while(t--)
        solve();
    return 0;
}

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

typedef long long ll;

static const ll INF = 1ll<<60;
static const int MOD = 1e9+7;

int main(){
    map<string,int> cnt;
    int N;
    cin>>N;

    for(int i=0; i<N; i++){
        string s;
        cin>>s;
        cnt[s]++;
    }

    cout<<"AC x "<<cnt["AC"]<<endl;
    cout<<"WA x "<<cnt["WA"]<<endl;
    cout<<"TLE x "<<cnt["TLE"]<<endl;
    cout<<"RE x "<<cnt["RE"]<<endl;
    
    return 0;
}

Measured memory_bytes: 3632
n=int(input())
#print(n)                                                                                                     
#a=input().split()                                                                                            
a=[int(x) for x in input().split()]
#a=map(int,input().split())                                                                                   
#print(a)                                                                                                     
#print(a[0]+a[1])                                                                                             
count=0
while True:
    flag=0
#    print(a)                                                                                                 
    for i in range(n):
        if((a[i] % 2)==0):
#        if((a[i]!=1) and (a[i] % 2)==0):                                                                     
            flag+=0
            a[i]=a[i]/2
        else:
            flag+=1
#    print(flag)                                                                                              
    if(flag!=0):
        break
    else:
        count+=1
#        print(count)                                                                                         

print(count)


Measured memory_bytes: 3060
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[]  aa = new int[n], bb = new int[n], dif = new int[n], sum = new int[n];
        Pair[] p = new Pair[n];
        ArrayList<Pair> al = new ArrayList<>();
        for(int i = 0; i < n; i++){
            aa[i] = sc.nextInt();
            bb[i] = sc.nextInt();
            sum[i] = aa[i] + bb[i];
            al.add(new Pair(aa[i], bb[i]));
        }
        Collections.sort(al);
        long ans = 0;

        for(int i = n-1; i >= 0; i--){
            if((n - i) % 2 == 1){
                ans += al.get(i).a;
            }
            else{
                ans -= al.get(i).b;
            }
        }
        System.out.println(ans);
    }

}

class Pair implements Comparable<Pair>
{
    int a, b, sum;
    Pair(int x, int y)
    {
        a = x; b = y; sum = a + b;
    }
    @Override
    public int compareTo( Pair p ){
      return this.sum - p.sum;
    }
}

Measured memory_bytes: 95756
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define max(l,r) ((l)>(r)?l:r)
#define min(l,r) ((l)<(r)?l:r)
#define swap(l,r) {ll tp=l;l=r;r=tp;}
const ll MOD = 1000000007;

int main(){
    //input
    ll k;
    scanf("%lld", &k);

    //solve
    ll ans = 1;
    if(k % 2 == 0){
        puts("-1");
        return 0;
    }
    ll tmp = 7 % k;
    bool ch[1010101] = {0};
    ch[tmp] = true;
    if(tmp == 0){
        puts("1");
        return 0;
    }
    while(tmp != 0){
        tmp = (tmp*10+7) % k;
        ans++;
        if(ch[tmp]){
            puts("-1");
            return 0;
        }
        ch[tmp] = true;
    }

    //output
    printf("%lld", ans);
}

Measured memory_bytes: 2712
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n =sc.nextInt();
		int[] a=new int[n];
		int[] ans=new int[n];
		for(int i=0; i<n; i++){
			a[i]=sc.nextInt();
		}
		int count=0;
		for(int i=n-1; i>=0; i--){
			int k=i+1;
			int sum=0;
			while(n>=k){
				sum+=ans[k-1];	
				k+=i+1;
			}
			if(sum%2==1){
				if(a[i]==1){
					ans[i]=0;
				}else{
					ans[i]=1;
					count++;
				}
			}else{
				if(a[i]==1){
					ans[i]=1;
					count++;
				}else{
					ans[i]=0;
				}
			}
		}
		System.out.println(count);
		for(int i=0; i<n; i++){
			if(ans[i]==1){
				System.out.println(i+1);
			}
		}
	}
}




Measured memory_bytes: 69532
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
#define all(v) v.begin(),v.end()
using namespace std;
const int N=1005;
int n,a[N],s,ans[N],top,vis[N];
void getv(int &v1,int &v2){
	v1=1e9,v2=0;
	For(i,1,n){
		v1=min(v1,a[i]);
		v2=max(v2,a[i]);
	}
}
void construct1(){
	int v1,v2,p=0;
	For(i,1,n){
		--a[ans[top+i-n]];
		getv(v1,v2);
		if (v1>=0&&v1*2>=v2) p=i;
		else if (v1*2+1==v2&&v1>=0){
			int p1=1e9,p2=0;
			For(j,top+i-n+1,top+i){
				if (a[ans[j]]==v1) p1=min(p1,j);
				if (a[ans[j]]==v2) p2=max(p2,j);
			}
			if (p1>p2) p=i;
		}
	}
	For(i,p+1,n) ++a[ans[top+i-n]];
	assert(p);
	memset(vis,0,sizeof(vis));
	For(i,1,p) vis[ans[top+i-n]]=1;
	getv(v1,v2);
	if (v1*2>=v2){
		For(i,1,n) if (vis[i]) ans[++top]=i;
	}
	else{
		int p=0;
		For(i,1,n) if (vis[i]&&a[i]==v2) p=i;
		For(i,1,p) if (vis[i]&&a[i]!=v1) ans[++top]=i;
		For(i,1,p) if (vis[i]&&a[i]==v1) ans[++top]=i;
		For(i,p+1,n) if (vis[i]) ans[++top]=i;
	}
	int v=n,pp=top;
	memset(vis,0,sizeof(vis));
	Rep(i,top,top-p+2){
		v-=(vis[ans[i]]==0);
		v-=(vis[ans[i-n]]==0);
		--vis[ans[i]];
		++vis[ans[i-n]];
		v+=(vis[ans[i]]==0);
		v+=(vis[ans[i-n]]==0);
		if (v==n) pp=i-1;
	}
	for (;top>pp;top--)
		++a[ans[top]];
	/*cout<<p<<' '<<pp<<' '<<top<<endl;
	For(i,1,n) cout<<a[i]<<' '; cout<<endl;
	For(i,1,top) cout<<ans[i]<<' '; cout<<endl;*/
}
void construct2(){
	int v1=1e9,v2=0;
	For(i,1,n) v1=min(v1,a[i]-1),v2=max(v2,a[i]-1);
	assert(v1*2+1>=v2);
	For(i,1,n) a[i]--;
	if (v1*2>=v2){
		For(i,1,n) ans[++top]=i;
	}
	else{
		int p=0;
		For(i,1,n) if (a[i]==v2) p=i;
		For(i,1,p) if (a[i]!=v1) ans[++top]=i;
		For(i,1,p) if (a[i]==v1) ans[++top]=i;
		For(i,p+1,n) ans[++top]=i;
	}
	//For(i,1,n) cout<<ans[i]<<' '; cout<<endl;
	//For(i,1,n) cout<<a[i]<<' '; cout<<endl;
}
int main(){
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&a[i]);
	For(i,1,n) s+=a[i];
	int v1=1e9,v2=0;
	For(i,1,n) v1=min(v1,a[i]),v2=max(v2,a[i]);
	if (v1*2<v2) return puts("-1"),0;
	construct2();
	for (;top!=s;) construct1();
	For(i,1,s) cout<<ans[i]<<' '; cout<<endl;
}
/*
1 2 3 4 5 6 2 1 3 4 5 6 2 1
*/

Measured memory_bytes: 3704
#include <iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>

using namespace std;

int main(){
    int N,K;
    cin >> N >> K;
    vector<long long> tree(N,0);
    for(int i=0;i<N;i++){
        cin >> tree[i];
    }
    sort(tree.begin(),tree.end());
    vector<long long> tree_dif(N-K+1,0);
    for(int i=0;i<N-K+1;i++){
        tree_dif[i]=max(tree[i],tree[i+K-1])-min(tree[i],tree[i+K-1]);
    }
    sort(tree_dif.begin(),tree_dif.end());
    cout << tree_dif[0] << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int a;
    cin>>a;
    if(a<1200)
        cout<<"ABC"<<endl;
    else
        cout<<"ARC"<<endl;

    return 0;
}


Measured memory_bytes: 3612
ENV[A='RUBY_THREAD_VM_STACK_SIZE']||exec({A=>?5*8},'ruby',$0)
F=->c{H[c].all?{|e|Z[e]?Z[c]^Z[e]>0:(Z[e]=1^Z[c];F[e])}}
N,M=gets.split.map &:to_i;H=Hash.new{|h,k|h[k]=[]};Z={1=>0}
$<.map{|e|a,b=e.split.map &:to_i;H[a]<<b;H[b]<<a}
p (F[1]?(x,y=Z.partition{|k,v|v>0};x.size*y.size):N*~-N/2)-M

Measured memory_bytes: 111048
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;

int main(){
    cout << fixed << setprecision(6);
    vector<string> scs{"Sunny","Cloudy","Rainy"};
    string s; cin >> s;
    auto itr = find(scs.begin(),scs.end(),s);
    int i =itr-scs.begin();
    int out ;
    if(i==2) out = 0;
    else out = i+1;
    cout << scs[out] << endl;
    return 0;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define sort stable_sort
using namespace std; 
 
int _;

int n,cnt,ans;
string s;

int main()
{	
	//for(scanf("%d",&_);_;_--)
	scanf("%d",&n);
	cin >> s;
	for(int i=0;i<n;i++)
		if(s[i] == 'R')
			cnt++;
	for(int i=0;i<cnt;i++)
		if(s[i] == 'W')
			ans++;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3964
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int A, P;
	cin >> A >> P;

	P += A * 3;
	cout << P / 2 << endl;



	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 100000

int parent(int i)
{
    return i / 2;
}
int left(int i)
{
    return 2 * i;
}
int right(int i)
{
    return 2 * i + 1;
}

int main()
{
    int H, i, A[MAX + 1];

    cin >> H;
    for (i = 1; i <= H; i++)
        cin >> A[i];

    for (i = 1; i <= H; i++)
    {
        cout << "node " << i << ": key = " << A[i] << ", ";
        if (parent(i) >= 1)
            cout << "parent key = " << A[parent(i)] << ", ";
        if (left(i) <= H)
            cout << "left key = " << A[left(i)] << ", ";
        if (right(i) <= H)
            cout << "right key = " << A[right(i)] << ", ";
        cout << endl;
    }

    return 0;
}


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

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
int a[13][13];
int c[13];
int main(){
    int n,m,x;
    cin >> n >> m >> x;
    rep(i,n){
        cin >> c[i];
        rep(j,m){
            int s;
            cin >> s;
            a[i][j] = s;
        }
    }
    int mi = inf;
    rep(bits,(1<<n)){
        vector<int> b(m);
        int cs = 0;
        rep(j,n){
            if((bits>>j)&1){
                cs += c[j];
                rep(k,m){
                    b[k] += a[j][k];
                }
            }
        }
        bool flag = 0;
        rep(j,m){
            if(b[j]<x){
                flag = 1;
            }
        }
        if(flag)continue;
        chmin(mi,cs);
            
    }
    if(mi==inf){
        cout << -1 << endl;
    }else{
        cout << mi << endl;
    }
    return 0;
}

Measured memory_bytes: 3192
#include <chrono>
#include <iostream>

using namespace std;
using namespace std::chrono;

int main() {
  auto start = high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;
  int val = 1;
  for (int i = 0; i < n; ++i)
    val = min(val * 2, val + k);
  cout << val << endl;

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define Max 100000
#define S 1000000000

typedef struct Card{
  char suit;
  int value;
}Card;

Card L[Max / 2 + 2], R[Max / 2 + 2];

void merge(Card a[], int n, int l, int m, int r){
  int i, j, k, n1, n2;
  n1 = m - l;
  n2 = r - m;
  
  for(i = 0 ; i < n1 ; i++) L[i] = a[l + i];
  for(i = 0 ; i < n2 ; i++) R[i] = a[m + i];
  
  L[n1].value = R[n2].value = S;
  i = j = 0;
  
  for(k = l ; k < r ; k++){
    if(L[i].value <= R[j].value){
      a[k] = L[i++];
    }
    else{
      a[k] = R[j++];
    }
  }
}

void mergeSort(Card a[], int n, int l, int r){
  int m;
  if(l + 1 < r){
    m = (l + r) / 2;
    mergeSort(a, n, l, m);
    mergeSort(a, n, m, r);
    merge(a, n, l, m, r);
  }
}

int partition(Card a[], int n, int p, int r){
  int i, j;
  Card t, x;
  x = a[r];
  i = p - 1;

  for(j = p ; j < r ; j++){
    if(a[j].value <= x.value){
      i++;
      t = a[i];
      a[i] = a[j];
      a[j] = t;
    }
  }

  t = a[i + 1];
  a[i + 1] = a[r];
  a[r] = t;

  return i + 1;
}

void quickSort(Card a[], int n, int p, int r){
  int q;
  if(p < r){
    q = partition(a, n, p, r);
    quickSort(a, n, p, q - 1);
    quickSort(a, n, q + 1, r);
  }
}


int main(){
  int n, i, v, stable = 1;
  Card a[Max], b[Max];
  char s[10];

  scanf("%d", &n);

  for(i = 0 ; i < n ; i++){
    scanf("%s %d", s, &v);
    a[i].suit = b[i].suit = s[0];
    a[i].value = b[i].value = v;
  }

  mergeSort(a, n, 0, n);
  quickSort(b, n, 0, n - 1);
  
  for(i = 0 ; i < n ; i++){
    if(a[i].suit != b[i].suit) stable = 0;
  }

  if(stable == 1) printf("Stable\n");
  else printf("Not stable\n");
  for(i = 0 ; i < n ; i++){
    printf("%c %d\n", b[i].suit, b[i].value);
  }

  return 0;
}


Measured memory_bytes: 4040
ll = lambda: list(map(int, input().split()))
testcases = 1
# testcases = int(input())
for testcase in range(testcases):
    [n,m]=ll()
    broken=[1]*(n+1)
    # print(broken)
    for i in range(m):
        [ai]=ll()
        broken[ai]=0
    ans=[0]*(n+1)
    ans[0]=1
    ans[1]=1*broken[1]
    for i in range(2,n+1):
        ans[i] = (ans[i-1]*broken[i-1] + ans[i-2]*broken[i-2])%(10**9+7)
    # print(ans)
    print(ans[n])

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

typedef long long ll;
typedef struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
} UnionFind;

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind tree(N);
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        --A; --B;
        tree.unite(A, B);
    }
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (tree.par[i] == i) cnt++;
    }
    cout << cnt-1 << endl;
    return 0;
}

Measured memory_bytes: 3740
#include <iostream>
using namespace std;
int main()
{
  int N;
  scanf("%d",&N);
  int t[N],x[N],y[N];
  int n;
  for(n = 0;n < N;n++){
    scanf("%d %d %d",&t[n],&x[n],&y[n]);
  }
  int flag = -1;
  for(n = 0;n < N;n++){
    if( !( (0 == (t[n] - (x[n] + y[n]) ) % 2) && (x[n] + y[n] <= t[n]) ) ) flag\
 = flag + 1;
  }
  if(-1 == flag) printf("Yes\n");
  else printf("No\n");
  return 0;
}

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

int main()
{
  string N;
  cin >> N;
  bool ok = false;
  if(N[0] == N[1] && N[1] == N[2])
    ok = true;
  if(N[1] == N[2] && N[2] == N[3])
    ok = true;

  if(ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define Fori(g) for(int i=0;i<g;i++)
#define	Forj(g) for(int j=0;j<g;j++)
#define min(a,b) return (a<b)?a:b
#define max(a,b) return (a<b)?b:a
#define gcd(a,b) return (!b)?a:gcd(b,a%b)

int main(){
	int n,k,count=0;
	scanf("%d%d",&n,&k);
	int h[n];
	Fori(n)scanf("%d",&h[i]);

	Fori(n)if(h[i]>=k)count++;

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

Measured memory_bytes: 512
#include <stdio.h>

int main(void){
  long n,i,x,j;
  long R[200000],max=-1000000000,min;

  scanf("%ld",&n);

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

min=R[0];

for(i=1;i<n;i++){
  x=R[i]-min;
  if(max<x)max=x;
  if(min>R[i])min=R[i];
}

  printf("%ld\n",max);

  return 0;
}

Measured memory_bytes: 3356
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int a[2][110];

int solve() {
    for (int i = 0; i < 2; i++) {
        for (int j = 1; j <= n; j++) {
            a[i][j] += a[i][j-1];
        }
    }

    int res = 0;
    for (int i = 1; i <= n; i++) {
        res = max(res, a[0][i] + a[1][n] - a[1][i-1]);
    }
    return res;
}

void input() {
    cin >> n;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j+1];
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
rl = [input() for _ in range(H)]

result = []
for i, r in enumerate(rl):
    result_r = ""
    pre_r = rl[i - 1] if i - 1 >= 0 else ""
    next_r = rl[i + 1] if i + 1 < H else ""
    for j, p in enumerate(r):
        if p == "#":
            result_r += "#"
            continue
        pre_j = j - 1 if j - 1 >= 0 else 0
        next_j = j + 2
        around_str = pre_r[pre_j:next_j] + r[pre_j:next_j] + next_r[pre_j:next_j]
        result_r += str(around_str.count("#"))
    result.append(result_r)

print("\n".join(result))



Measured memory_bytes: 68064
A = [[[0 for r in range(10)] for f in range(3)] for b in range(4)] # A[b][f][r]
n = int(input())
for i in range(n):
    b, f, r, v = map(int, input().split())
    A[b-1][f-1][r-1] += v
for b in range(4):
    for f in range(3):
        for r in range(10):
            print(' %d' %(A[b][f][r]), end='')
        print('')
    if b < 3:
        print('#'*20)

Measured memory_bytes: 7808
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;


int main(){
  ll n,k;
  cin >> n >> k;
  ll a[n];
  ll x;
  rep(i,n){
    cin >> x;
    x--;
    a[i] = x;
  }
  queue<ll> q;
  set<ll> s;
  ll cnt = 0;
  s.insert(0);
  q.push(0);
  ll now = 0;
  bool flag = false;
  if(k <= n){
    for(int i = 0; i < k; i++){
      if(s.count(a[now]) != 0){
        flag = true;
        break;
      }
      q.push(a[now]);
      s.insert(a[now]);
      now = a[now];
      // printf("%lld\n", now);
    }
    if(!flag){
      printf("%lld\n", now+1);
      return 0;
    }
    while(q.front() != a[now]){
      cnt++;
      q.pop();
    }
    ll size = q.size();
    if(cnt>0) k -= cnt;
    k %= size;
    rep(i,k){
      q.pop();
    }
    ll ans = q.front()+1;
    printf("%lld\n", ans);
    return 0;
  }else{
    queue<ll> qa;
    set<ll> sa;
    ll cnta = 0;
    sa.insert(0);
    qa.push(0);
    ll nowa = 0;

    for(int i = 0; i < n; i++){
      if(sa.count(a[nowa]) != 0){
        break;
      }
      qa.push(a[nowa]);
      sa.insert(a[nowa]);
      nowa = a[nowa];
    }
    while(qa.front() != a[nowa]){
      cnta++;
      qa.pop();
    }
    ll sizea = qa.size();
    if(cnta>0) k -= cnta;
    k %= sizea;
    rep(i,k){
      qa.pop();
    }
    ll ansa = qa.front()+1;

    printf("%lld\n", ansa);

  }


  return 0;
}


Measured memory_bytes: 14088