akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return (rand()<<16|rand())%x;
}
const int N=100005,mod=4000007;
int n,father[N],vis[N];
queue<PI> q;
ll ycl[N];
vector<int> v[N];
struct has_table{
	bool has[mod]; int b[mod];
	ll a[mod],v[mod];
	inline int insert(int xx,int yy){
		ll x=ycl[xx]*n+ycl[yy];
		for(int i=x%mod;;i=i+1==mod?0:i+1){
			if(!has[i]||a[i]==x){
				has[i]=1; a[i]=x; b[i]++; return b[i];
			}
		}
	}
	inline void clear(int xx,int yy){
		ll x=ycl[xx]*n+ycl[yy];
		for(int i=x%mod;;i=i+1==mod?0:i+1){
			if(!has[i]||a[i]==x){
				has[i]=1; a[i]=x; b[i]=0; return;
			}
		}
	}
	inline int find(int xx,int yy){
		ll x=ycl[xx]*n+ycl[yy];
		for(int i=x%mod;;i=i+1==mod?0:i+1){
			if(!has[i]||a[i]==x){
				return b[i];
			}
		}
	}
}Ma;
inline int getfather(int x){
	return father[x]==x?x:father[x]=getfather(father[x]);
}
int main(){
	srand(time(0));
	n=read();
	for(int i=1;i<=n;i++)ycl[i]=(ll)rand()<<32|rand();
    for(int i=1;i<=n*2-2;i++){
        int x=read(),y=read(); 
        v[x].push_back(y); v[y].push_back(x);
        Ma.insert(y,x);
        if(Ma.insert(x,y)==2)q.push(mp(x,y));
    }
    for(int i=1;i<=n;i++)father[i]=i;
    while(!q.empty()){
    	int x=q.front().first,y=q.front().second; q.pop();
		x=getfather(x); y=getfather(y); if(x==y){continue; return 0;}
		if(v[x].size()<v[y].size()) swap(x,y); 
		//cout<<x<<" "<<y<<endl;
		vis[y]=1;
        for(unsigned i=0;i<v[y].size();i++){ 
            int to=v[y][i]; if(vis[to])continue;
            //if(y!=3||to!=3)cout<<x<<" "<<y<<" "<<to<<" "<<er.find(y,to)<<endl;
            v[to].push_back(x);
            Ma.insert(x,to);
            if(Ma.insert(to,x)==2)q.push(mp(to,x));
            v[x].push_back(to);
        }
        father[y]=x; v[y].clear();
    }
    int ans=0;
    for(int i=1;i<=n;i++)ans+=father[i]==i;
    if(ans==1) puts("YES"); else puts("NO");
    return 0;
}

Measured memory_bytes: 67056
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int p[101]={};
int q[101]={};
int r[101]={};
int s[101]={};
int gcd(int a, int b){
	while(b){
		int r=a%b;
		a=b;
		b=r;
	}
	return a;
}
int cal(int i){
	if(i==0){
		return 1;
	}
	int a=cal(r[i]);
	int b=cal(s[i]);
	int g=gcd(a*p[i],b*q[i]);
	int v=a*p[i]/g*b+b*q[i]/g*a;
	//cout << i << ", " << v << endl;
	return v;
}
int main() {
while(1){
	int n;
	cin >> n;
	if(n==0)return 0;
	int hasParent[101]={};
	for(int i=1;i<=n;i++){
		cin >> p[i] >> q[i] >> r[i] >> s[i];
		hasParent[r[i]]=true;
		hasParent[s[i]]=true;
	}
	for(int i=1;i<=n;i++){
		if(!hasParent[i]){
			cout << cal(i) << endl;
		}
	}
}
}

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

int main() {
    int n;
    long long k, m = 0;
    map<int, long long> ar;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        int a, b;
        cin >> a >> b;
        ar[a] += b;
    }
    for(auto i=ar.begin();;i++){
        m += (i->second);
        if(m >= k){
            cout << (i->first) << endl;
            return 0;
        }
    }
	return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main()
{
    int n, W;
    scanf("%d%d", &n, &W);
    vll v(n), w(n), dp(n * 1000 + 10, LLONG_MAX);
    for (int i = 0; i < n; i++){
        scanf("%lld%lld", &w[i], &v[i]);
        // dp[v[i]] = min(dp[v[i]], w[i]);
    }
    dp[0] = 0;
    for (int i = 0; i < n; i++){
        for (int j = n * 1000 - v[i]; j >= 0; j--){
            if (dp[j] != LLONG_MAX)
            dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
        }
    }
    ll ans = 0;
    for (int i = n * 1000; i >= 0; i--) {
        if (dp[i] <= W) {
            printf("%d", i);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 4044
#include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <list>
#include <string>
#include <numeric>
#include <utility>
#include <cfloat>
#include <set>
 
using namespace std;
 
int sqrtN = 512;
struct SqrtDecomposition{
    int N, K;
    vector <long long> data;
    vector <long long> bucketUpdatedLazy;
     
    SqrtDecomposition(int n){
        N = n;
        K = (N + sqrtN - 1) / sqrtN;
        data.assign(N, ((long long) 1 << 31) - 1);
        bucketUpdatedLazy.assign(K, -1);
    }
 
    void propagateLazy(int k){
        if(bucketUpdatedLazy[k] < 0){
            return;
        }
        for(int i = 0; i < sqrtN; i++){
            data[k * sqrtN + i] = bucketUpdatedLazy[k];
        }
        bucketUpdatedLazy[k] = -1;
    }

    long long get(int x){
        propagateLazy(x / sqrtN);
        return data[x];
    }
 
    void update(int x, int y, int a){
        if(y - x < sqrtN){
            propagateLazy(x / sqrtN);
            propagateLazy((y - 1) / sqrtN);
            for(int i = x; i < y; i++){
                data[i] = a;
            }
            return;
        }
        for(int i = x / sqrtN + 1; i < y / sqrtN; i++){
            bucketUpdatedLazy[i] = a;
            //if(bucketUpdatedLazy[i] < 0 && bucketUpdatedLazy[i] != -1){
            //    cerr << "Warning" << endl;
            //}
        }

        propagateLazy(x / sqrtN);
        for(int i = x; i < (x / sqrtN + 1) * sqrtN; i++){
            data[i] = a;
        }
        propagateLazy((y - 1)/ sqrtN);
        for(int i = y / sqrtN * sqrtN; i < y; i++){
            data[i] = a;
        }
    }
     
};

 
int main(){
    int n;
    int q;
    cin >> n >> q;
    SqrtDecomposition sq(n);
    for(int i = 0; i < q; i++){
        int com;
        int s;
        int t;
        int x;
        cin >> com;
        if(com == 0){
            cin >> s >> t >> x;
            sq.update(s, t + 1, x);
        } else {
            cin >> x;
            cout << sq.get(x) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3608
s=input()
ls = len(s)
k= int(input())
for i in range(ls-1):
    tn = ord('z')-ord(s[i])+1
    if k>=tn and s[i]!='a':
        k-=tn
        print('a',end='')
    else:
        print(s[i],end='')
ik = (k + ord(s[-1])-ord('a')) % 26
print(chr(ord('a')+ik))

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

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

int a[110];

int main(){
	int n, tot=0;
	cin >> n;
	rep(i,0,n) {
		cin >> a[i];
		tot += a[i];
	}
	int c=tot/n, d=c>=0?c+1:c-1;	
	int ans1=0, ans2=0;
	rep(i,0,n) {
		ans1+=(a[i]-c)*(a[i]-c);
		ans2+=(a[i]-d)*(a[i]-d);
	}
	cout<< (ans1<ans2?ans1:ans2) <<endl;
	return 0;
}

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

int main(){
  int a[2];
  cin >> a[0] >> a[1];
  for (int i=0; i < 2; i++) {
    if (a[i] ==  1
      | a[i] ==  3
      | a[i] ==  5
      | a[i] ==  7
      | a[i] ==  8
      | a[i] == 10
      | a[i] == 12) a[i] = 0;
    else if (
        a[i] ==  4
      | a[i] ==  6
      | a[i] ==  9
      | a[i] == 11) a[i] = 1;
    else            a[i] = 2;
  }
  if (a[0] == a[1]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> p(N);
  int ans=0;
  
  for (int i=0;i<N;i++){
    cin >> p[i];
  }
  
  sort(p.begin(),p.end());
  ans = p[N/2]-p[N/2-1];
  
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
char a[55];
int main()
{
    int i,j,k;
    scanf("%s",a);
    k=strlen(a);
    for(i=0;i<k-8;i++)
    printf("%c",a[i]);
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int n,a,cnt=0;
    map<int, int>mp;
    cin >> n;
    rep(i, n) {
        cin >> a;
        mp[a]++;
    }
    for (auto p : mp) {
        if (p.first == p.second)continue;
        cnt += p.first > p.second ? p.second : p.second - p.first;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 4736
#include<iostream>
using namespace std;
//Longest Common Prefix(s,s.substr(i)) O(|s|)
#include<vector>
vector<int>Zalgo(const string&s)
{
	vector<int>ret(s.size());
	ret[0]=s.size();
	int i=1,j=0;
	while(i<s.size())
	{
		while(i+j<s.size()&&s[j]==s[i+j])j++;
		ret[i]=j;
		if(j==0)
		{
			i++;
			continue;
		}
		int k=1;
		while(i+k<s.size()&&k+ret[k]<j)ret[i+k]=ret[k],k++;
		i+=k;j-=k;
	}
	return ret;
}
string s,t;
bool ok[5<<17];
int memo[5<<17];
int dfs(int u)
{
	if(memo[u]>=0)return memo[u];
	else if(memo[u]==-2)
	{
		return memo[u]=1e9;
	}
	if(ok[u])
	{
		memo[u]=-2;
		return memo[u]=dfs((u+t.size())%s.size())+1;
	}
	else return memo[u]=0;
}
main()
{
	cin>>s>>t;
	string ss=s;
	while(ss.size()<t.size())ss+=s;
	vector<int>AA=Zalgo(t+ss+ss);
	for(int i=0;i<s.size();i++)
	{
		ok[i]=AA[i+t.size()]>=t.size();
		memo[i]=-1;
	}
	int ans=0;
	for(int i=0;i<s.size();i++)ans=max(ans,dfs(i));
	cout<<(ans<1e9?ans:-1)<<endl;
}


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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

//bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;


int main() {

    int sx = 0, ex, sy = 0, ey;
    cin >> ex >> ey;

    int n;
    cin >> n;

    rep(i, n) {
        int x, y, z;
        cin >> x >> y >> z;
        if (z == 1) {
            cmax(sx, x);
        } else if (z == 2) {
            cmin(ex, x);
        } else if (z == 3) {
            cmax(sy, y);
        } else if (z == 4) {
            cmin(ey, y);
        } else {
            __throw_runtime_error("nai");
        }
    }

    int w = ex - sx;
    int h = ey - sy;
    if (w <= 0 || h <= 0) {
        cout << 0 << endl;
        return 0;
    }

    cout << w * h << endl;

}



Measured memory_bytes: 256
num=raw_input('')
numberdays=num.split(' ')
if int(numberdays[2])-int(numberdays[1])>int(numberdays[0]):
    print 'dangerous'
if 0<int(numberdays[2])-int(numberdays[1])<=int(numberdays[0]):
    print 'safe'
if int(numberdays[2])-int(numberdays[1])<=0:
    print 'delicious'

Measured memory_bytes: 2568
N, H, W = map(int,input().split())
A_list = []
B_list = []
for i in range(N):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)
H_list = [H]*N
W_list = [W]*N
H_div = [x-y for (x,y) in zip(A_list,H_list)]
W_div = [x-y for (x,y) in zip(B_list,W_list)]
count = 0
for i,j in zip(H_div,W_div):
    if i>-1 and j>-1:
        count += 1
print(count)


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<climits>
using namespace std;

int main() {
  int ans=0;
  int N = 0;
  int L = 0;
  int sum =0;

  cin >> N >> L;

  sum = N*L + (N-1)*N/2;
  //  cout << "N*L = " << N*L << endl;
  //  cout << " (N-1)*N/2 = " <<  (N-1)*N/2 << endl;
  //  cout << "sum = " << sum << endl;

  if(L > 0){
    ans = sum - L;
  }else if(L < 0){
    if(N+L >= 1){
      ans = sum;
    }else{
      ans = sum - (L + N -1);
    }
  }else{
    ans = sum;
  }
  
    cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main(){
    fastio;
    ll h, w;
    cin>>h>>w;

    vector<vector<char>> mat(h, vector<char>(w));
    vector<vector<ll>> dp(h, vector<ll>(w));

    for(ll i = 0; i < h; i++)
        for(ll j = 0; j < w; j++)
            cin>>mat[i][j];

    dp[0][0] = 1;

    for(ll i = 1; i < h; i++)
        if(dp[i-1][0] != 0 && mat[i][0] == '.')
            dp[i][0] = 1;

    for(ll i = 1; i < w; i++)
        if(dp[0][i-1] != 0 && mat[0][i] == '.')
            dp[0][i] = 1;

    for(ll i = 1; i < h; i++){
        for(ll j = 1; j < w; j++){
            if(mat[i][j] == '#'){
                dp[i][j] = 0;
                continue;
            }

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

    cout<<dp[h-1][w-1]<<endl;

    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
typedef long long ll;
const int inf = 100100100;


int main(){
  ll k,a,b;
  cin >> k >> a >> b;
  ll ans = k+1;
  if(a+2 < b) {
    ll trade = max(ll(0),(k-(a-1))/2);
    ll res = 1 + k - 2*trade;
    ans = trade*(b-a)+res;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3532
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let p:i32=input();
    let q:i32=input();
    let r:i32=input();
    println!("{}", std::cmp::min(p+q, std::cmp::min(q+r, r+p)))
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, MOD = 998244353;
char A[N], B[N], C[N], D[N];
int L[N], R[N], f[3 * N], rf[3 * N];
int mpow(int x, int n) {
	int res = 1;
	while (n) {
		if (n & 1) res = 1LL * res * x % MOD;
		x = 1LL * x * x % MOD;
		n >>= 1;
	}
	return res;
}
int choose(int n, int m) {
	return 1LL * f[n] * rf[n - m] % MOD * rf[m] % MOD;
}
int work(int n, int m, char AA[N], char BB[N], char CC[N], char DD[N]) {
	static char A[N], B[N], C[N], D[N];
	int nn = 0, mm = 0;
	for (int i = 1; i <= n; ++ i) {
		if (AA[i] == '1' || BB[i] == '1') {
			nn ++;
			A[nn] = AA[i];
			B[nn] = BB[i];
		}
	}
	for (int i = 1; i <= m; ++ i) {
		if (CC[i] == '1' || DD[i] == '1') {
			mm ++;
			C[mm] = CC[i];
			D[mm] = DD[i];
		}
	}
	n = nn, m = mm;
	int rl = 0, rr = 0;
	for (int i = 1; i <= n; ++ i) {
		rl += A[i] == '1';
		rr += B[i] == '1';
	}
	L[0] = 1;
	int x = 0, y = 0;
	for (int i = 1; i <= m; ++ i) {
		x += C[i] == '1';
		y += D[i] == '1';
		L[i] = (rl == 0) ? 0 : choose(x + y + rl - 1, rl - 1);
	}
	x = y = 0;
	R[m + 1] = 1;
	for (int i = m; i >= 1; -- i) {
		x += C[i] == '1';
		y += D[i] == '1';
		R[i] = (rr == 0) ? 0 : choose(x + y + rr - 1, rr - 1);
	}
	int ans = 0, tmp = 1;
	for (int i = 1; i <= m; ++ i) {
		tmp = 1LL * tmp * (C[i] == '1' && D[i] == '1' ? 2 : 1) % MOD;
		(ans += 1LL * tmp * R[i + 1] % MOD) %= MOD;
		tmp = (tmp + L[i]) % MOD;
	}
	return ans;
}
int main() {
	f[0] = 1;
	for (int i = 1; i < 3 * N; ++ i) f[i] = 1LL * f[i - 1] * i % MOD;
	rf[3 * N - 1] = mpow(f[3 * N - 1], MOD - 2);
	for (int i = 3 * N - 2; i >= 0; -- i) rf[i] = 1LL * rf[i + 1] * (i + 1) % MOD;
	int n, m;
	scanf("%d%d", &n, &m);
	scanf("%s%s%s%s", A + 1, B + 1, C + 1, D + 1);
	int tot = 0;
	for (int i = 1; i <= n; ++ i) tot += A[i] == '1';
	for (int i = 1; i <= n; ++ i) tot += B[i] == '1';
	for (int i = 1; i <= m; ++ i) tot += C[i] == '1';
	for (int i = 1; i <= m; ++ i) tot += D[i] == '1';
	if (tot == 0) return 0 * puts("1");
	int ans = work(n, m, A, B, C, D);
	reverse(A + 1, A + 1 + n);
	reverse(B + 1, B + 1 + n);
	(ans += work(m, n, D, C, A, B)) %= MOD;
	printf("%d\n", ans);
}



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

int main(){
  int l,r,n,a;
  cin >> l >> r >> n;
  if(l%n == 0) a=1;
  else a=0;
  r /= n;
  l /= n;
  
  cout << r-l+a << endl;
  
  
  return 0;
}


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

int main()  {
    long long n,x,m=0;
    cin>>n>>x;
    long long  a[1000006];
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>x){
            m+=a[i]-x;
            a[i]=x;
        }
        if(i>0&&a[i]+a[i-1]>x){
            m+=a[i]+a[i-1]-x;
            a[i]-=a[i]+a[i-1]-x;
            if(a[i]<0){
                return 1;
            }
        }
    }
    cout<<m<<endl;
}


Measured memory_bytes: 1024
def resolve():
    n = int(input())
    a = list(map(int,input().split()))
    t = True
    for i in a:
        if i % 2 == 0 and (not (i % 3 == 0 or i % 5 == 0)):
            t = False
    if t:
        print("APPROVED")
    else:
        print("DENIED")
resolve()

Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
int i,j,n,k,count=0;
int a[120],d[120],ans[120]={};
scanf("%d %d",&n,&k);
for(i=1; i<=k; i++){
scanf("%d",&d[i]);

for(j=1; j<=d[i];j++){
scanf("%d",&a[j]);
ans[a[j]]=1;
}
}
for(i=1; i<=n;i++)
if(ans[i]==0){
count++;
}
printf("%d\n",count);
return 0;
}

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

void main_()
{
    ll N;
    vector<ll> As;
    cin >> N;
    copy_n(istream_iterator<ll>(cin), N, back_inserter(As));

    ll ans = 1;
    auto it = begin(As);
    while (it != end(As)) {
        auto start = *it;
        it = adjacent_find(it, end(As), not_equal_to<ll>());
        if (it == end(As)) {
            break;
        }
        it++;
        if (*it > start) {
            it = adjacent_find(it, end(As), greater<ll>());
        } else {
            it = adjacent_find(it, end(As), less<ll>());
        }
        if (it != end(As)) {
            ans++;
            it++;
        }
    }

    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 1400
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        n: usize,
        k: u64,
        a:[Usize1;n],
    }

    const MAX_DBL:usize = 64;
    let mut dbl = vec![vec![0;n];MAX_DBL];

    for i in 0..n {
        dbl[0][i] = a[i];
    }
    for j in 1..MAX_DBL {
        for i in 0..n {
            dbl[j][i] = dbl[j-1][dbl[j-1][i]];
        }
    }

    let mut pos = 0;
    for i in 0..MAX_DBL {
        if k & (1u64<<i) != 0 {
            pos = dbl[i][pos];
        }
    }
    println!("{}", pos+1);
}


Measured memory_bytes: 105084
#include<stdio.h>
int main(){
  int n,i,j,k,a=1,r[100010]={};
  int d[1010][1010];
  scanf("%d",&n);
  for(i=0;i*(i-1)/2<n;i++);
  if(i*(i-1)/2>n){
    printf("No\n");
    return 0;
  }
  printf("Yes\n%d\n",i);
  for(j=0;j<i;j++){
    for(k=j+1;k<i;k++){
      d[j][r[j]++]=a  ;
      d[k][r[k]++]=a++;
    }
  }
  for(j=0;j<i;j++){
    printf("%d",r[j]);
    for(k=0;k<r[j];k++)printf(" %d",d[j][k]);
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	int n,m,p,q,r,x,y;
	vector<int>::iterator u,v,z;
	for(;cin>>n>>m>>p>>q>>r;cout<<x<<endl){
		vector<int> s,t;
		s.push_back(0);
		for(s.push_back(r);m--;t.clear()){
			cin>>x>>y;
			u=upper_bound(s.begin(),s.end(),x);
			v=upper_bound(s.begin(),s.end(),y);
			
			if( v-s.begin()+1 & 1 )t.push_back(0);
			t.push_back(0);
			for(z=v;z!=s.end();++z)
				t.push_back(*z - y);
			
			if(s.end()-u & 1)t.push_back(n-y);
			for(z=u;z!=v;++z)
				t.push_back(*z-x+n-y);
			
			z = s.begin();
			if(v-s.begin() & 1)++z;
			if(!z[1])z+=2;
			if(*z+n-x==t.back()){++z;t.pop_back();}
			for(;z!=u;++z)
				t.push_back(*z+n-x);
			
			s.swap(t);
		}
		s.insert( upper_bound(s.begin(),s.end(),p-1), 2, p-1);
		s.insert( lower_bound(s.begin(),s.end(),q), q );
		s.push_back(n);
		z = upper_bound(s.begin(),s.end(),p-1);
		if(z-s.begin() & 1) --z;
		for(x=0;*z<q;++z)
			m=*z++,x+=*z-m;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc/abc118/b.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> v(m);
    rep(i, m){
        v[i] = 0;
    }
    rep(i, n){
        int k;
        cin >> k;
        rep(j, k){
            int a;
            cin >> a;
            a--;
            v[a]++;
        }
    }
    int ans = 0;
    rep(i, m){
        if(v[i] == n) ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int main() {
    fastio;
    ll ans=0;
    int N,x,y;
    cin >> N >> x >> y;
    vector<int> c(N);
    auto dis = [&](int i, int j) {
        int d = j-i;
        updmin(d, abs(x-i)+1+abs(y-j));
        return d;
    };
    for (int i=1; i<N; ++i) {
        for (int j=i+1; j<=N; ++j)
            c[dis(i,j)]++;
    }
    for (int i=1; i<N; ++i)
        cout << c[i] << endl;
}


Measured memory_bytes: 3584
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> PI;
#define MAX 99999999
int main(){
    int n,m,a;
    while(cin>>n>>m>>a,n+m+a){
        vvi v(1001,vi(1001,INF));
        PI now;
        int h,p,q;
        rep(i,m){
            cin>>h>>p>>q;
            v[h][p]=q;
            v[h][q]=p;
        }
        now.first=1000;now.second=a;
        while(true){
            if(now.first==0)break;
            if(v[now.first][now.second]!=INF){
                now.second=v[now.first][now.second];
            }
          now.first--;
        }
        cout<<now.second<<endl;
    }
}

Measured memory_bytes: 6732
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner in = new Scanner(System.in);
    	String[] nm  = in.nextLine().split(" ");
    	int n, m;
    	n = Integer.parseInt(nm[0]);
    	m = Integer.parseInt(nm[1]);
    	int[] likeFoods = new int[m];
    	
    	for (int i = 0; i < n; i++) {
    		int k = in.nextInt();
    		for (int j = 0; j < k; j++) {
    			likeFoods[in.nextInt()-1]++;
    		}
    	}
    	
    	int counter = 0;
    	for (int foods: likeFoods) {
    		if (foods == n) {
    			counter++;
    		}
    	}
    	
    	System.out.println(counter);
    	
    	
    }
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
int max(int a , int  b){
  if(a > b) return a;
  else return b;

}
int min(int a , int b){
  if(a < b) return a;
  else return b;
}
bool cmp(pair < int , string >   a , pair < int , string >   b){
  if(a.first < b.first ) return true;
  else return false;
}
int a[200005];
map < int , int > sd;
map < int , int > ok;
int32_t main(){  
  int n,k;
  cin >> n >> k;
  for(int i = 0 ; i < n ; i++) cin >> a[i];
  for(int i = 0 ; i < n ; ++i) a[i]--;
  int i = 0 ;
  int ans = -1;
  int cn=0;
  int last;
  while(sd[i] == 0){
      sd[i]++;
      ok[i]=cn;
      if(cn == k) ans = i;
      i = a[i];
      cn++;
      last =i;
      //cout << i << " " << last << "++\n";
      
  }
  //cout << last << "\n";
  if(ans !=-1) cout << ans+1 << "\n";
  else{
      sd.clear();
      i = last;
      cn=0;
      while(sd[i] == 0){
        sd[i]++;
        i = a[i];
        cn++;
      }
      k = k - ok[last];
      int m  = k /cn;
      k = k - m*cn;
      sd.clear();
      i = last;
      cn = 0;
      while(sd[i] == 0){
        sd[i]++;
        if(cn == k) break;
        i = a[i];
        cn++; 
      }
      cout << i+1 << "\n";
  }
  return 0;
} 
/*
10010
01011
11000

16+
*/

Measured memory_bytes: 29900
#include <cstdio>
#include <vector>
using namespace std;
long long cnt;
int A[1000000];
vector<int> G;

template<typename T>
void shellSort(T a[], int n) {
	//生成希尔增量序列
	for (int h = 1; ;) {
		if (h > n) break;
		G.push_back(h);
		h = 3 * h + 1;
	}
	for (int i = G.size() - 1; i >= 0; i--) {//按逆序指定increment = G[i] 
		int increment = G[i];
		for (int j = increment; j < n; j++) {
			T temp = a[j];
			int k;
			for (k = j; k >= increment && a[k - increment] > temp; k -= increment) {
				a[k] = a[k - increment];
				cnt++;
			}
			a[k] = temp;
		}
	}
}

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) 
    	scanf("%d", &A[i]);
	
	shellSort(A, N);
    printf("%d\n", G.size());
    for (int i = G.size() - 1; i >= 0; i--) {
    	printf("%d", G[i]);
    	if (i) printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	for (int i = 0; i < N; i++) printf("%d\n", A[i]);
    	
    return 0;
}



Measured memory_bytes: 6580
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int t; cin >> t;
  while (t--) {
    int n, d; cin >> n >> d;
    int ans = 0;
    if (n % 2 == 0) {
      REP(i, 7) {
        if (d >> i & 1) {
          ans += (1 << i) * (n - 1);
        } else {
          ans += (1 << i) * n;
        }
      }
    } else {
      REP(i, 7) {
        if (d >> i & 1) {
          ans += (1 << i) * n;
        } else {
          ans += (1 << i) * (n - 1);
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
num=[-1]*n

for i in range(m):
    s,c=map(int,input().split())
    if num[s-1]!=-1 and num[s-1]!=c:
        print(-1)
        exit()
    else:
        num[s-1]=c



if n==1 and num[0]<1:
    print(0)
    exit()

if num[0]==-1:
    num[0]=1

if num[0]==0:
    print(-1)
    exit()

st=""
for i in range(n):
    if num[i]!=-1:
        st+=str(num[i])
    else:
        st+="0"

print(st)

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


void solve(std::string s){
    auto it = s.begin();
    auto it2 = s.end();
    it2--;
    ll ans = 0;
    while(it < it2){
        if(*it == *it2){
            it++;
            it2--;
        }else if(*it == 'x' && *it2 != 'x'){
            it++;
            ans++;
        }else if(*it != 'x' && *it2 == 'x'){
            it2--;
            ans++;
        }else{
            cout << -1 << endl;
            return;
        }
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    std::string s;
    std::cin >> s;
    solve(s);
    return 0;
}


Measured memory_bytes: 512
program five_transportations
  implicit none
  integer(8) :: n, a(5) = 0, m, i
  read(*,*) n
  do i = 1, 5
    read(*,*) a(i)
  end do
  m = minval(a)
  write(*,'(i0)') (n+m-1)/m+4
end program five_transportations

Measured memory_bytes: 256
//finally if there is any zero close to a 1 one , I can still remove it
//Let's say you keep on removing numbers at some stage you run out of zeroes or ones
//so answer is min of both * 2
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
  cin>>s;
  int ones=0;
  int zeros=0;
  for(int i=0;i<s.length();i++){
  	if(s[i]=='1')ones++;
    else zeros++;
  }
  cout<<min(ones,zeros)*2;
}

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    int N;
    std::cin >> N;
    std::vector<int> L(N);
    REP(i, N) {
        std::cin >> L[i];
    }

    SORT(L);

    ll ans = 0;
    for(int i = 0; i < N - 1; i++) {
        for(int j = i + 1; j < N; j++) {
            ans += distance(L.begin(), lower_bound(ALL(L), L[i] + L[j])) - j - 1;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
sheet = [list(map(int,input().split())) for j in range(H)]
for i in range(H):
    sheet[i].append(sum(sheet[i]))
sheet.append([0 for i in range(W+1)])
for i in range(W+1):
    tmp = 0
    for j in range(H):
        tmp+=sheet[j][i]
    sheet[H][i] = tmp
for i in range(H+1):
    print(" ".join(map(str,sheet[i])))


Measured memory_bytes: 5704
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, a ;
  cin >> h >> a ;
  if(h%a==0){
    cout << h/a ;
  }
  else{
    cout << h/a+1 ;
  }
  cout <<endl ;
  
  
  
  return 0 ;
}




Measured memory_bytes: 256
my @S;
foreach (split(//o, <STDIN>)) {
        chomp($_);
        push(@S, $_) if ($_ ne '');
}
my $T =  <STDIN>;
chomp ($T);

my $len = $#S;
foreach my $i (0..$len) {
        my $tmp = '';
        foreach ($i+1..$len) {
                $tmp .= $S[$_];
        }
        foreach (0..$i) {
                $tmp .= $S[$_];
        }
        if ($tmp eq $T) {
                print "Yes";
                exit 0;
        }
}
print "No";

Measured memory_bytes: 640
using System;
using System.Linq;

namespace abc136_a
{
    static class Program
    {
        static void Main(string[] args)
        {
            var items = Console.ReadLine().ToIntArray();
            var a = items[0];
            var b = items[1];
            var c = items[2];
            var v = c - (a - b);
            if (v < 0)
            {
                v = 0;
            }
            Console.WriteLine($"{v}");
        }

        static int ToInteger(this string s)
        {
            return int.Parse(s);
        }

        static int[] ToIntArray(this string s, char separator = ' ')
        {
            return s.Split(separator).Select(m => m.ToInteger()).ToArray();
        }
    }
}


Measured memory_bytes: 13396
#include <stdio.h>
#include <math.h>

int main(void){

    int count=0;
    int ans=0;
    int size=2*pow(10,5);
    char S[size];
    char T[size];

    scanf("%s",S);
    scanf("%s",T);

    for(int i=0;i<size;i++){
        if(S[i]!='\0'){
            count++;
        }else{
            break;
        }
    }

    for(int i=0;i<count;i++){
        if(S[i]!=T[i]){
            ans++;
        }
    }

    printf("%d\n",ans);

    return 0;
}

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

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> x,l; //xは座標,lは原点からの距離
    rep(i,n){
        ll a;
        cin >> a;
        x.push_back(a);
        l.push_back(abs(a));
    }

    ll ans=INF;
    for(ll i=0;i+k-1<n;i++){
        ans=min(ans,min(l[i],l[i+k-1])+x[i+k-1]-x[i]);
    }
    cout << ans << endl;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

// Does coordinate compression.
// Arguments:
// - raw_xs: Values to compress.
// Returns:
// - xs: Compressed values.
// - to_raw: A mapping from a compressed value to a raw value.
// Verified: CF573Div1D
tuple<vector<int>, vector<int>> Compress(const vector<int>& raw_xs) {
  unordered_set<int> raw_x_set(raw_xs.begin(), raw_xs.end());
  vector<int> to_raw(raw_x_set.begin(), raw_x_set.end());
  sort(to_raw.begin(), to_raw.end());
  unordered_map<int, int> to_index;
  for (int i = 0; i < to_raw.size(); i++) {
    to_index[to_raw[i]] = i;
  }
  vector<int> xs;
  for (int raw_x : raw_xs) {
    xs.push_back(to_index[raw_x]);
  }
  return make_tuple(xs, to_raw);
}

// Verified: AOJ-DSL1A
class UFSet {
 private:
  vector<int> ranks;
  vector<int> prevs;

 public:
  UFSet(int n) : ranks(n), prevs(n) {
    for (int i = 0; i < n; i++) prevs[i] = i;
  }

  // Returns a root of a tree which x belongs to.
  int Find(int x) {
    if (x != prevs[x]) prevs[x] = Find(prevs[x]);
    return prevs[x];
  }

  // Merges a set which x blongs to and a set which y belongs to.
  void Union(int x, int y) {
    int x_root = Find(x);
    int y_root = Find(y);
    if (ranks[x_root] > ranks[y_root]) {
      prevs[y_root] = prevs[x_root];
    } else if (ranks[x_root] < ranks[y_root]) {
      prevs[x_root] = prevs[y_root];
    } else if (prevs[x_root] != prevs[y_root]) {
      prevs[y_root] = prevs[x_root];
      ranks[x_root]++;
    }
  }
};

struct WEdge {
  int v1, v2;
  int64 weight;
  WEdge(int v1, int v2, int64 weight) : v1(v1), v2(v2), weight(weight) {}
};

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

  int n;
  cin >> n;
  vector<int> raw_xs(n), raw_ys(n);
  for (int i = 0; i < n; i++) {
    cin >> raw_xs[i];
    cin >> raw_ys[i];
  }

  vector<int> xs, xs_to_raw, ys, ys_to_raw;
  tie(xs, xs_to_raw) = Compress(raw_xs);
  tie(ys, ys_to_raw) = Compress(raw_ys);
  vector<vector<int>> x_to_ps(xs_to_raw.size()), y_to_ps(ys_to_raw.size());
  for (int i = 0; i < n; i++) {
    x_to_ps[xs[i]].push_back(i);
    y_to_ps[ys[i]].push_back(i);
  }

  UFSet uf_set(n);
  for (const auto& ps : x_to_ps) {
    for (int i = 1; i < ps.size(); i++) {
      uf_set.Union(ps[0], ps[i]);
    }
  }
  for (const auto& ps : y_to_ps) {
    for (int i = 1; i < ps.size(); i++) {
      uf_set.Union(ps[0], ps[i]);
    }
  }

  vector<WEdge> edges;
  for (int i = 0; i + 1< x_to_ps.size(); i++) {
    edges.push_back(WEdge(x_to_ps[i][0], x_to_ps[i + 1][0], xs_to_raw[i + 1] - xs_to_raw[i]));
  }
  for (int i = 0; i + 1< y_to_ps.size(); i++) {
    edges.push_back(WEdge(y_to_ps[i][0], y_to_ps[i + 1][0], ys_to_raw[i + 1] - ys_to_raw[i]));
  }
  sort(edges.begin(), edges.end(), [](const auto& e1, const auto& e2) {
    return e1.weight < e2.weight;
  });

  int64 ans = 0;
  for (const auto& e : edges) {
    if (uf_set.Find(e.v1) == uf_set.Find(e.v2)) continue;
    ans += e.weight;
    uf_set.Union(e.v1, e.v2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 21480
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <iostream>
#include <iomanip>
#include <map>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
    int N;
    cin >> N;
    vector<LL> D(N);
    REP(i,N)cin>>D[i];
    
    int M;
    cin>>M;
    vector<LL> T(M);
    REP(i,M)cin>>T[i];

    map<LL, int> map_num;
    REP(i,N){
        auto itr = map_num.find(D[i]);
        if(itr != map_num.end()){
            map_num[D[i]] += 1;
        }else{
            map_num[D[i]] = 1;
        }
    }

    REP(i,M){
        auto itr = map_num.find(T[i]);
        if(itr != map_num.end()){
            if(map_num[T[i]]==0){
                cout << "NO" << endl;
                return 0;
            }else{
                map_num[T[i]] -= 1;
            }
        }else{
            cout << "NO" << endl;
            return 0;
        }
    }
    
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 18688
#include <iostream>
using namespace std;
int main(){
  int N,T; cin >> N >> T;
  int min_cost = 9999;
  bool flag = false;
  for(int i = 0; i < N; i++){
    int a,b; cin >> a >>b;
    if(b <= T and a < min_cost){
      flag = true;
      min_cost = a;
    }
  }
  if(flag)
    cout << min_cost << endl;
  else
    cout << "TLE" << endl;

}

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

namespace ABC117D
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var N = ss.Next(int.Parse);
            var K = ss.Next(long.Parse);
            var A = ss.Next(long.Parse, N);

            var ans = new long[2];

            for (var i = 0; i < 40; i++)
            {
                var pc = A.Sum(a => (a >> i) & 1);
                var res0 = pc * (1L << i);
                var res1 = (N - pc) * (1L << i);

                if (((K >> i) & 1) == 1)
                {
                    ans[0] = Math.Max(ans[1] + res0, ans[0] + res1);
                }
                else
                {
                    ans[0] = ans[0] + res0;
                }

                ans[1] = Math.Max(ans[1] + res0, ans[1] + res1);
            }

            sw.WriteLine(ans[0]);
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

Measured memory_bytes: 31196
#include <iostream>
#include <queue>
#include <vector>
#include <utility>
using namespace std;

long long f(vector<pair<int,int>> a){
    priority_queue<int> que;
    int size=a.size();
    vector<vector<int>> in(size+1);
    for(auto p: a){
        if(p.first>=size){
            que.push(p.second);
        }else{
            in[p.first].emplace_back(p.second);
        }
    }
    long long res=0;
    for(int i=size-1;i>=0;i--){
        if(!que.empty()){
            res+=que.top();
            que.pop();
        }
        for(auto p:in[i]){
            que.push(p);
        }
    }
    return res;
}

int main(){
    int T;
    cin>>T;
    long long ans;

    for(int i=0;i<T;i++){
        int N;
        cin>>N;
        int k,l,r;
        vector<pair<int,int>> front;
        vector<pair<int,int>> end;
        ans=0;
        for(int i=0;i<N;i++){
            cin>>k>>l>>r;
            if(k==N){
                ans+=l;
            }else if(l>r){
                ans+=r;
                front.emplace_back(k,l-r);
            }else{
                ans+=l;
                end.emplace_back(N-k,r-l);
            }
        }

        ans+=f(front);
        ans+=f(end);
        cout<<ans<<endl;

    }

    return 0;
}

Measured memory_bytes: 10072
#include <iostream>
using namespace std;
int main() {
	int A, B;
	cin >> A >> B;
	int ans = 0;
	for (int i = A; i <= B; ++i) {
		int r = i, s = 0;
		while (r > 0) {
			s *= 10;
			s += r % 10;
			r /= 10;
		}
		if (i == s) ++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/*
Author : Chandan Agrawal
College : Poornima College of Engg. jaipur, Raj
Mail : chandanagrawal23@gmail.com


" when you are not practicing someone else is ,
 and the day u meet them u will lose "

*/
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX 200050

#define ll long long
#define ld long double
#define lli long long int

#define pb push_back
#define INF 1000000000000
#define mod 1000000007

// trignometric function always give value in Radians only
#define PI acos(-1) //3.1415926535897932384626433832795028
#define dsin(degree) sin(degree*(PI/180.0))
#define dcos(degree) cos(degree*(PI/180.0))
#define dtan(degree) tan(degree*(PI/180.0))

#define rsin(radian) sin(radian)
#define rcos(radian) cos(radian)
#define rtan(radian) tan(radian)

#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))

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

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define makeuniq(v) v.resize(unique(all(v)) - v.begin()); //only uniq element in vector after this
#define sz(x) int(x.size())
#define F first
#define S second

#define mii map<lli,lli>

#define pii pair<lli,lli>

#define vi vector<lli>
#define vvi vector<vi>
#define vpi vector<pii>
#define vbool vector<bool>

#define seti set<lli>

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a/gcd(a,b))*b
#define abs(x) ((x < 0)?-(x):x)

#define endl '\n'

template <typename Head>
void print(Head&& head)
{
    cout<<head<<endl;
}
template <typename Head, typename... Tail>
void print(Head&& head, Tail... tail)
{
    cout<<head<<" ";
    print(tail...);
}

#define scanarr(a,n) for(lli i=0;i<n;i++)    cin>>a[i];
#define scanvec(a,n) for(lli i=0;i<n;i++){ lli x ; cin>>x; a.pb(x);}

#define printarr(a,n) for(lli i=0;i<n;i++)   cout<<a[i]<<" "; cout<<endl;
#define printvec(vec) for(auto xt : vec) cout<<xt<<" ";    cout<<"\n";

#define FD(N) fixed<<setprecision(N)

#define deb(x) cout<<#x<<" "<<x<<endl;

/*
1D vector -  vi dp(n,value);
2D vector -  vvi dp(n,vi(n,value));
*/

// chandan1,2
void chandan1(){int y=1;return;}
void chandan2(){
        loop(i,10){
        lli x=1;
    }
    return(chandan1());
}


int main(){
fastio
lli t=1;
//cin>>t;
chandan2();
while(t--) {
    lli n;
    cin>>n;
    pii a[n];
    loop(i,n)
    {
        cin>>a[i].F>>a[i].S;
    }
    lli cnt = 0;
    lli maxi =-1;
    for(lli i=0;i<n;i++)
    {
        if((a[i].F==a[i].S))
        {
            cnt+=1;
        }
        else
        {
            maxi = max(maxi ,cnt);
            cnt = 0;
        }
    }
    maxi = max(maxi ,cnt);
    if(maxi>=3)
        print("Yes");
    else
        print("No");
  }
return 0;
}



Measured memory_bytes: 3688