akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int main( ) {
        IO;
        #ifdef LOCAL
            //freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        int n;
        cin >> n;
        map <string,LL> cnt;
        for( int i = 1; i <= n; i++ ) {
                string s;
                cin >> s;
                sort( all( s ) );
                cnt[s]++;
        }
        LL ans = 0;
        for( auto x : cnt ) ans += ( x.second * ( x.second - 1 ) / 2 );
        cout << ans << endl;
        return 0;
}










Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
    int N;
    string S;
    cin>>N>>S;
    bool judge=true;
    if(N%2==1){
        cout<<"No"<<endl;
    }
    else{
        rep(i,N/2){
            if(S[i]!=S[N/2+i]){
                judge=false;
                break;
            }
        }
        if(judge==false){
            cout<<"No"<<endl;
        }
        else{
            cout<<"Yes"<<endl;
        }
    }
  
   
}




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

int A,B,C,D,E,F;
int a,b,c,d;
int Sug1,Wat1,Sug,Wat;
float SW1=0.0,SW=0.0;

int main(){
    cin>>A>>B>>C>>D>>E>>F;

    for(a=0;a<31;a++){
        for(b=0;b<31;b++){
            for(c=0;c<301;c++){
                for(d=0;d<301;d++){
                    Sug=C*c+D*d;
                    Wat=100*A*a+100*B*b+Sug;

                    if(Wat>F || Sug>E*(A*a+B*b)){
                        continue;
                    }
                    else{
                        if(Sug*Wat1>=Sug1*Wat){
                            Sug1=Sug;
                            Wat1=Wat;
                        }                                  
                    }
                }
            }
        }
    }
    cout<<Wat1<<" "<<Sug1<<endl;                       
    return 0;     
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}

vector<int> tpl_sort(vector<vector<int>>& r){
	int n= r.size();
	vector<int> rt(n), cnt(n); rt.reserve(n+2);
	for(auto& xl: r) for(auto x: xl) cnt[x]++;
	queue<int> qu;
	for(int i=0; i<n; i++) if(cnt[i]==0){ qu.emplace(i); rt[i] = 0;}
	while(!qu.empty()){
		auto cr = qu.front(); qu.pop();
		//rt.emplace_back(cr);
		for(auto x: r[cr]) if(--cnt[x] == 0){ qu.emplace(x); rt[x] = cr+1;}
	}
	return rt;
}



int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,m;
	cin >>n >>m;
	
	vector<VI> r(n), rr(n);
	VI ct(n);
	rep(i,m+n-1){
		int a,b;
		cin >>a >>b;
		r[a-1].push_back(b-1);
	}
	auto rv = tpl_sort(r);

	rep(i,n) cout<< rv[i] <<"\n";
	
	return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
const int N=10010,mod=1e9+7;
int n,a,b,f[N],g[N],h[N],hh[N],ans;
int power(int x,int y){
    int z=1;
    for(;y;y>>=1,x=1ll*x*x%mod)if(y&1)z=1ll*z*x%mod;
    return z;
}
int main(){
    scanf("%d%d%d",&n,&a,&b);
    if(a>b)swap(a,b);g[a]=g[0]=1;
    for(int i=a+1;i<=b-2;i++){
        g[i]=g[i-1];
        for(int j=i-a-1;~j;j--)(g[i]+=g[j])%=mod;
    }
    f[0]=g[0]=1;for(int i=1;i<=b-2;i++)(g[i]+=g[i-1])%=mod;
    for(int i=1;i<a;i++)
        for(int j=0;j<b;j++)
            j?(h[i+j]+=j>1?g[j-2]:1)%=mod:0,
            (hh[i+j]+=j?g[j-1]:1)%=mod;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=i;j++)
            f[i]=(f[i]+1ll*f[i-j]*(i-j?h[j]:hh[j]))%mod;
    for(int i=n;i>n-b;i--)ans=(ans+1ll*f[i]*(i<n?g[n-i-1]:1))%mod;
    cout<<((power(2,n)-ans)%mod+mod)%mod;
    return 0;
}

Measured memory_bytes: 3832
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    if(y>=2*x && y<=4*x){
        if(y%2==0){
        cout<<"Yes";
        }
        else{
            cout<<"No";
            return 0;
        }
    }
    else
        cout<<"No";
}



Measured memory_bytes: 3636
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
	long long a[200005];
	int n,i;
	long long s(0),min;
	cin>>n;
	a[0]=0;
	for (i=1;i<=n;i++)
	{
		cin>>a[i];
		s+=a[i];
	    a[i]+=a[i-1];
	}
	min=fabs(2*a[1]-s);
	for (i=2;i<n;i++)
	  if (fabs(2*a[i]-s)<min) min=fabs(2*a[i]-s);
	cout<<min<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)
const ll LINF = 1001002003004005006ll;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        --a[i];
    }
    vector<bool> flg(n, false);
    int now = 0;
    int cnt = 0;
    flg[0] = true;
    while(1) {
        // cout << now << " " << a[now] << endl;
        // rep(i, n) cout << flg[i];
        // cout << endl;
        if (now == 1) {
            // cout << "test1" << endl;
            cout << cnt << endl;
            return 0;
        }
        if (now == a[now]) {
            // cout << "test2" << endl;
            cout << -1 << endl;
            return 0;
        }
        if (flg[a[now]]) {
            // cout << "test3" << endl;
            cout << -1 << endl;
            return 0;
        }
        ++cnt;
        flg[a[now]] = true;
        now = a[now];
    }
    return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

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

    ll ans = 0;

    ll m = n-1;
    vector<ll> prime;
    for(ll i = 2; i*i <= m; i++){
        ll count = 0;
        while(m%i == 0){
            m /= i;
            count++;
        }
        if(count > 0) prime.push_back(count);
    }
    if(m != 1) prime.push_back(1);

    ll mm = prime.size();
    ll num = 1;
    rep(i,mm) num *= prime[i]+1;
    ans += num-1;
  
    for(ll i=2; i*i <= n; i++){
        if(n%i != 0) continue;

        ll c = n;
        while(c%i == 0) c /= i;
        if(c%i == 1) ans++;

        ll j = n/i;
      	if(i == j) continue;
      
        ll d = n;
        while(d%j == 0) d /= j;
        if(d%j == 1) ans++;
    }

    cout << ans+1 << endl;

}

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

signed main(){
    string A,B;cin>>A>>B;
    if(A>B)cout<<">"<<endl;
    if(A<B)cout<<"<"<<endl;
    if(A==B)cout<<"="<<endl;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    
    N,K,Q = map(int,input().split())
    from collections import defaultdict
    D = defaultdict(int)
    for i in range(Q):
        A = int(input())
        D[A] += 1
    for i in range(1,N+1):
        p = D[i]
        if K+p-Q>0:
            print("Yes")
        else:
            print("No")
    
    
    
main()

Measured memory_bytes: 61276
#include <bits/stdc++.h>
using namespace std;
#define ri rd<int>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; --i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++i)
const int maxN = 707;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return f ? x : -x;
}

inline void NIE() { puts("-1"); exit(0); }

int n, m;
bool a[maxN][maxN];
int col[maxN], cnt[2];
struct pii{ int a, b; } b[maxN];
bool f[maxN], g[maxN];

void dfs(int x) {
	cnt[col[x]]++;
	rep (y, 1, n) if (a[x][y]) { 
		if (!col[y]) {
			col[y] = 3 - col[x];
			dfs(y);
		}
		else if (col[y] != 3 - col[x]) NIE();
	}
}

int main() {

	n = ri();
	rep (i, 1, n) rep (j, 1, n) if (i != j) a[i][j] = true;
	rep (i, 1, ri()) {
		int x = ri(), y = ri();
		a[x][y] = a[y][x] = false;
	}
	rep (i, 1, n) if (col[i] == 0) {
		cnt[1] = cnt[2] = 0;
		col[i] = 1; dfs(i);
		b[++m] = (pii){cnt[1], cnt[2]};
	}

	f[0] = true;
	rep (t, 1, m) {
		memcpy(g, f, sizeof f);
		memset(f, 0, sizeof f);
		per (i, n, b[t].a) f[i] |= g[i-b[t].a];
		per (i, n, b[t].b) f[i] |= g[i-b[t].b];
	}

	int res = n*n*2;
	rep (i, 0, n) if (f[i]) {
		res = min(res, i*(i-1) + (n-i) * (n-i-1));
	}
	printf("%d\n", res >> 1);

	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <set>
using namespace std;

#define MP make_pair

bool flag[53][53][4];

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

int main(){
	int n,x0,y0,t;
	cin >> n >> x0 >> y0 >> t;
	x0++;
	y0++;
	for(int k=0;k<n;k++){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		a++;b++;c++;d++;
		if(a==c){
			if(b>d)swap(b,d);
			for(int i=b;i<d;i++){
				flag[a][i][0] = 1;
			}
			for(int i=d;i>b;i--){
				flag[a][i][2] = 1;
			}
		}
		if(b==d){
			if(a>c)swap(a,c);
			for(int i=a;i<c;i++){
				flag[i][b][1] = 1;
			}
			for(int i=c;i>a;i--){
				flag[i][b][3] = 1;
			}
		}
	}
	map<int,int> mp;
	int s = 0;
	for(int i=0;i<t;i++){
		int a;
		cin >> a;
		char b;
		cin >> b;
		s += a;
		if(b=='N'){
			mp[s] = 0;
		}else if(b=='E'){
			mp[s] = 1;
		}else if(b=='S'){
			mp[s] = 2;
		}else{
			mp[s] = 3;
		}
	}
	queue<pair<pair<int,int>,pair<int,int> > >q;
	map<pair<pair<int,int>,pair<int,int> >,bool> m;
	if(flag[x0][y0][0]==1){
		q.push(MP(MP(x0,y0),MP(0,0)));
	}
	if(flag[x0][y0][1]==1){
		q.push(MP(MP(x0,y0),MP(0,1)));
	}
	if(flag[x0][y0][2]==1){
		q.push(MP(MP(x0,y0),MP(0,2)));
	}
	if(flag[x0][y0][3]==1){
		q.push(MP(MP(x0,y0),MP(0,3)));
	}
	set<pair<int,int> > ans;
	while(1){
		auto x = q.front();
		q.pop();
		int a,b,c,d;
		a = x.first.first;
		b = x.first.second;
		c = x.second.first;
		d = x.second.second;
		//cout << a <<" " << b << " " <<c << " " << d << endl;
		if(c>s)break;
		if(c==s){
			ans.insert(MP(a-1,b-1));
		}
		if(mp.find(c+1)!=mp.end()){
			if(d==mp[c+1]){
				for(int i=0;i<4;i++){
					if(i!=d&&(i+4-d)%2==0)continue;
					if(flag[a+dx[d]][b+dy[d]][i]==1&&m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,i))]==0){
						m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,i))]=1;
						q.push(MP(MP(a+dx[d],b+dy[d]),MP(c+1,i)));
					}
				}
			}else{
				if((d+4-mp[c+1])%2!=0&&flag[a+dx[d]][b+dy[d]][mp[c+1]]==1&&m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,mp[c+1]))]==0){
					m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,mp[c+1]))]=1;
					q.push(MP(MP(a+dx[d],b+dy[d]),MP(c+1,mp[c+1])));
				}
			}
		}else{
			for(int i=0;i<4;i++){
				if(i!=d&&(i+4-d)%2==0)continue;
				if(flag[a+dx[d]][b+dy[d]][i]==1&&m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,i))]==0){
					m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,i))]=1;
					q.push(MP(MP(a+dx[d],b+dy[d]),MP(c+1,i)));
				}
			}
		}
	}
	for(auto x:ans){
		cout << x.first << " " << x.second << endl;
	}
	return 0;
}


Measured memory_bytes: 52988
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int c = sc.nextInt();
    int count = 0;
    int[] array_b = new int[m];
    for(int i = 0; i < m; i++){
      array_b[i] = sc.nextInt();
    }
    for(int i = 0; i < n; i++){
      int[] array_a = new int[m];
      int ans = 0;
      for(int j = 0; j < m;j++){
        //array_a[i] = sc.nextInt();
        int temp = sc.nextInt();
        ans += array_b[j]*temp;
      }
      ans+=c;
      if(ans>0){
        count++;
      }
    }
    System.out.println(count);
  }
}

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

int main(){
  int go = 0 , siti = 0;
  for(int i = 0; i < 3; i++){
     int a; cin >> a;
    if(a == 5) go++;
    if(a == 7) siti++;
  }
  if(go == 2 && siti == 1) cout << "YES";
  else cout << "NO";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<chrono>
using namespace std;
using namespace chrono;
#define all(a) a.begin(), a.end()
#define sz(x) (int(x.size()))
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef vector<string> vs;
template<class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &P){
	in >> P.first >> P.second;
	return in;
}
template<class T>
istream &operator>>(istream &in, vector<T> &arr){
	for(auto &x: arr) in >> x;
	return in;
}
template<class T>
ostream &operator<<(ostream &out, vector<T> &arr){
	for(auto &x: arr) out << x << ' '; cout << "\n";
	return out;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	const ll INF = 9e18;
	int n;
	cin >> n;
	vl h(n), d(n, INF);
	cin >> h;
	d[0] = 0, d[1] = abs(h[0] - h[1]);
	for(int i = 2; i < n; i ++){
		d[i] = min(d[i - 1] + abs(h[i] - h[i - 1]), d[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << d.back();
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  for(;;){
    int h,w;
    cin >> h >> w;
    if(!h) return 0;
    vector<string> f(h);
    REP(i,h) cin >> f[i];
    map<string,int> spell;
    int di[3]={h-1,0,1},dj[3]={w-1,0,1};
    REP(i,h) REP(j,w){
      REP(k,3) REP(l,3){
	string tmp="";
	int tmpi=i,tmpj=j;
	do{
	  tmp.push_back(f[tmpi][tmpj]);
	  ++spell[tmp];
	  tmpi=(tmpi+di[k])%h;
	  tmpj=(tmpj+dj[l])%w;
	}while(tmpi!=i||tmpj!=j);
      }
    }
    string answer="";
    for(auto x:spell){
      if(x.first.size()<=1 || x.second<2) continue;
      if(x.first.size()>answer.size()) answer=x.first;
      else if(x.first.size()==answer.size()) answer=min(answer,x.first);
    }
    if(answer.size()<2) cout << 0 << endl;
    else cout << answer << endl;
  }
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  
  if(a==5&&b==5&&c==7){
    cout << "YES" << endl;
  }
  else if(a==5&&b==7&&c==5){
    cout << "YES" << endl;
  }
  else if(a==7&&b==5&&c==5){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" <<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
// #pragma GCC optimize("O2")
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef multiset <ll> mms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
typedef complex<double> cd;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define all(v) v.begin(),v.end()
#define deb(x) cout << #x << " " << x << endl;
#define ff first
#define ss second
#define pb(v) push_back(v)
#define lb(v) lower_bound(v)
#define ub(v) upper_bound(v)
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define rev(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b) {
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s) {
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
void pv(mv v) {
	forl(i,v.size()) cout<<v[i]<<" ";
	cout<<"\n";
}
void pa(ll *v, ll size) {
	forl(i,size) cout<<v[i]<<" ";
	cout<<"\n";
}
void removeDups(mv &v) {
	sort(all(v));
	mv::iterator it = unique(v.begin(), v.end());
	v.resize(distance(v.begin(), it));
}
inline ld kthRoot(ld n, ll k) {
	return pow(k, (1.0 / k) * (log(n) / log(k)));
}
ll power(ll x, ll y, ll p) {
	ll res=1;
	x=x%p;
	while(y>0) {
		if(y&1) res = (res*x)%p;
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x, ll mod) {
	if(x>=mod) x%=mod;
}

ll mod = 1e9 + 7;

string n;
void thisIsMain() {
	cin>>n;
	ll ans = 0;
	forl(i,n.size()) ans += (n[i] - '0');
	if(ans % 9 == 0) cout<<"Yes\n" ; else cout<<"No\n";
}

int main(void)
{
	fastio
	ll t = 1;
	// cin>>t;
	while(t--) thisIsMain();
	return 0;
}

Measured memory_bytes: 3784
#include<cstdio>
#include<utility>
#include<vector>
#include<queue>
#include<climits>
#define MAX_V 1000000
#define INF LLONG_MAX
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
struct edge{ll to,cost;};
ll n;
vector<edge> G[MAX_V];
ll d[MAX_V];
void di(ll s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+n, INF);
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        ll v = p.second;
        if (d[v] < p.first) {
          continue;
        }
        for (ll i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}
int main(){
  ll u,v,w;
  
  scanf("%lld",&n);
  for(ll i=0;i<n-1;i++){
    scanf("%lld%lld%lld",&u,&v,&w);
    edge tmp = {v-1,w},tmp2={u-1,w};
    G[u-1].push_back(tmp);
    G[v-1].push_back(tmp2);
  }
  di(0);
  for(ll i=0;i<n;i++){
    if(d[i]%2==0) printf("1\n");
    else printf("0\n");
  }
}


Measured memory_bytes: 31488
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
  int a, b;
  cin >> a >> b;
  
  if(a < b)
  cout << "a < b" << endl;
  
  else if(a > b)
  cout << "a > b" << endl;
  
  else
  cout << "a == b" << endl;
}


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

int main(){
  int N;
  cin>>N;
  int A[100010];
  int sum=0;
  for(int i=0;i<N;i++){
  	cin>>A[i];
    sum+=A[i];
  }
  
 if(sum%2==0)cout<<"YES"<<endl;
 else cout<<"NO"<<endl; 
 return 0;
}

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

using Piece = tuple<double, int>;
constexpr double eps = 1e-10;

Piece merge(Piece lhs, Piece rhs){
    double xg_l, xg_r;
    int m_l, m_r;

    tie(xg_l, m_l) = lhs;
    tie(xg_r, m_r) = rhs;

    xg_r = (m_r * xg_r + m_l * xg_l) / (m_r + m_l);
    m_r += m_l;

    return tie(xg_r, m_r);
}

vector<string> _field;
vector<vector<int>> field;

int h, w;

vector<int> dx = { 1, 0,-1, 0};
vector<int> dy = { 0,-1, 0, 1};

void dfs(int y, int x, char c, int idx){
    if(field[y][x] != -1) return;

    field[y][x] = idx;

    rep(i, 4){
        int ny = y + dy[i], nx = x + dx[i];

        if(ny < 0 or h <= ny or
           nx < 0 or w <= nx or
           _field[ny][nx] != c) continue;

        dfs(ny, nx, c, idx);
    }
}

int main(void){
    for(; cin >> w >> h, w;){
        _field = vector<string>(h);
        for(auto & e : _field){
            cin >> e;
        }

        field = vector<vector<int>>(h, vector<int>(w, -1));
        int num_piece = 0;
        rep(y, h){
            rep(x, w){
                if(_field[y][x] == '.' or field[y][x] != -1) continue;

                dfs(y, x, _field[y][x], num_piece++);
            }
        }

        vector<Piece> piece(num_piece);
        for(auto & e : piece) e = Piece(0.0, 0);

        vector<int> y_bottom(num_piece, -1), xl(num_piece, 10000), xr(num_piece, -10000), i_bottom(num_piece, -1);
        rep(y, h){
            rep(x, w){
                if(field[y][x] == -1) continue;

                int idx = field[y][x];
                piece[idx] = merge(piece[idx], Piece(x, 1));

                if(y + 1 < h and field[y + 1][x] != -1 and field[y + 1][x] != field[y][x]){
                    i_bottom[idx] = field[y + 1][x];
                    y_bottom[idx] = y;
                    xl[idx] = min(xl[idx], x);
                    xr[idx] = max(xr[idx], x);
                }
            }
        }

        rep(x, w){
            if(field[h - 1][x] == -1) continue;

            int idx = field[h - 1][x];
            xl[idx] = min(xl[idx], x);
            xr[idx] = max(xr[idx], x);
            y_bottom[idx] = h - 1;
        }

        string res = "STABLE";
        [&]{
            rep(y, h){
                rep(i, num_piece){
                    if(y_bottom[i] != y) continue;

                    double xg;
                    tie(xg, ignore) = piece[i];
                    if(xg - eps <= xl[i] - 0.5 or xr[i] + 0.5 <= xg + eps){
                        res = "UNSTABLE";
                        return;
                    }

                    if(i_bottom[i] != -1){
                        piece[i_bottom[i]] = merge(piece[i_bottom[i]], piece[i]);
                    }
                }
            }
        }();

        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 3024
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll N, M, L, R, maxL = 0, minR = 100000;

int main() {
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		cin >> L >> R;
		maxL = max(maxL, L);
		minR = min(minR, R);
	}
	if (minR - maxL + 1 > 0) {
		cout << minR - maxL + 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll k;
  cin >> k;
  vs lun = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
  ll n = 9;
  ll i = 1;
  while(n < k) {
    if(lun[i].back() == '0') {
      lun.push_back(lun[i] + '0');
      lun.push_back(lun[i] + '1');
      n += 2;
    } else if(lun[i].back() == '9') {
      lun.push_back(lun[i] + '8');
      lun.push_back(lun[i] + '9');
      n += 2;
    } else {
      lun.push_back(lun[i] + char(lun[i].back() - 1));
      lun.push_back(lun[i] + char(lun[i].back()));
      lun.push_back(lun[i] + char(lun[i].back() + 1));
      n += 3;
    }
    i++;
  }
  cout << lun[k] << endl;
}

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

int main()
{
	string s;

    int a, b;

    cin >> a >> b;
    cin >> s;

    for(int i=0; i<s.size(); i++)
    {
    	if(i==a)
    	{
    		if(s[i]!='-')
    		{
    			cout << "No";
    			return 0;
    		}
    	}
    	else if(!isdigit(s[i]))
    	{
    		cout << "No";
    		return 0;
    	}
    }
    
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct Node{
  int key;
  struct Node *next;
  struct Node *prev;
}Node;

Node *sen;

Node* listsearch(int key){
  Node *cur=sen->next;
  while(cur!=sen && cur->key!=key){cur=cur->next;}
  return cur;
}

void init(){
  sen=(Node *)malloc(sizeof(Node));
  sen->next=sen;
  sen->prev=sen;
}

void listprint(){
  Node *cur=sen->next;
  int i=0;
  while(1){
    if(cur==sen)break;
    if(i>0)printf(" ");
    printf("%d",cur->key);
    cur=cur->next;
    i++;
  }
  printf("\n");
}

void deleteNode(Node *t){
  if(t==sen)return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deletefirst(){
  deleteNode(sen->next);
}
void deletelast(){
  deleteNode(sen->prev);
}

void deletekey(int key){
  deleteNode(listsearch(key));
}

void insert(int key){
  Node *a=(Node *)malloc(sizeof(Node));
  a->key=key;
  a->next=sen->next;
  sen->next->prev=a;
  sen->next=a;
  a->prev=sen;
}

int main(){
  int key,n,i;
  int size=0;
  char com[20];
  int p=0,d=0;
  scanf("%d",&n);
  init();
  for(i=0;i<n;i++){
    scanf("%s%d",com,&key);
    if(com[0]=='i'){
      insert(key);
      p++;
      size++;
    }
    else if(com[0]=='d'){
      if(strlen(com)>6){
	if(com[6]=='F')deletefirst();
	else if(com[6]=='L')deletelast();
      }
      else{
	deletekey(key);
	d++;
      }
      size--;
    }
  }
  listprint();
  return 0;
}



Measured memory_bytes: 32980
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if (e - a > k) cout << ":(" << endl;
    else cout << "Yay!" << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
w_arr = [0]
r_arr = [0]

w_acc = 0
r_acc = 0
for i in range(n):
    if s[i] == 'W':
        w_acc += 1
    else:
        r_acc += 1

    w_arr.append(w_acc)
    r_arr.append(r_acc)


min_r = 999999999999
for i in range(n+1):
    w_1, r_1 = w_arr[i], r_arr[i]
    w_2, r_2 = w_arr[n] - w_arr[i], r_arr[n] - r_arr[i]

    if w_1 >= r_2:
        r = w_1
    else:
        r = r_2

    if r < min_r:
        min_r = r

print(min_r)


Measured memory_bytes: 19124
use std::io::Read;
use std::collections::HashMap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();

    let mut map: HashMap<usize, usize> = HashMap::new();
    for _i in 0..m {
        let s: usize = iterator.next().unwrap().parse().unwrap();
        let c: usize = iterator.next().unwrap().parse().unwrap();
        if n != 1 && s == 1 && c == 0 {
            return "-1".to_string();
        }

        let old = map.insert(s, c);
        if let Some(x) = old {
            if x != c {
                return "-1".to_string();
            }
        }
    }

    let mut ans: usize = 0;
    for i in 1..(n + 1) {
        ans *= 10;

        let value = map.get(&i);
        ans += match value {
            Some(&x) => x,
            _ => if i == 1 && n != 1 { 1 } else { 0 }
        };
    }

    return ans.to_string();
}


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

using namespace std;
const int MOD = 1000000007,MAX = 510000;
long int pow107 = (int)pow(10, 9) + 7,llimit = LONG_MAX,fac[MAX], finv[MAX], inv[MAX];
int ilimit = INT_MAX;

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long int COM(long int n,long int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

//long intの最大llimit
//intの最大ilimit
//10^9+7    pow107
//素数pn
//n乗jou
//階乗factorial
//コンビネーションFunc2
//コンビネーションCOMinit(),COM(n,m)

int main(){
    int s[100000] = {};
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> s[i];
    }
    sort(s,s+n);
    int r,l = 0,c = 0;
    for(int i = 0;i < n; ++i){
        if(s[l] != s[i]){
            if((i - l) % 2 == 1){
                c++;
            }
            l = i;
        }
        if(i == n - 1 && (i - l + 1) % 2 == 1){
                c++;
        }
    }

    cout << c << endl;
}

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

const int MX = 100005;

int main() {
    int n;
    cin >> n;
    vector<ll> cnt(MX);
    rep(i,n) {
        int a;
        cin >> a;
        cnt[a]++;
    }
    ll tot = 0;
    rep(i,MX) tot += i*cnt[i];

    int q;
    cin >> q;
    rep(i,q) {
        int b, c;
        cin >> b >> c;
        tot += (c-b)*cnt[b];
        cnt[c] += cnt[b]; cnt[b] = 0;
        cout << tot << endl;
    }
    return 0;
}

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

static char S[100000];
static int N;
int main(void) {
  scanf("%s", S);
  N = strlen(S);

  int Zero = 0;
  int One  = 0;
  for(int i = 0; i < N; i++) {
    if(S[i] == '0') {
      Zero++;
    } else {
      One++;
    }
  }

  int Min = (Zero < One) ? Zero : One;
  printf("%d\n", Min*2);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
int main()
{
	cin >>n;
	for (int i=1;i<10;i++)
	{
		for (int j=i;j<10;j++)
		{
			if (i*j==n)
			{
				cout <<"Yes";
				return 0;
			}
		}
	}
	cout <<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    x=(x+11)%13;
    y=(y+11)%13;
    if (x>y)
    cout<<"Alice";
    if (x==y)
    cout<<"Draw";
    if (x<y)
    cout<<"Bob";
    system ("pause");
    return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int a, b;
  cin >> a >> b;
  
  cout << a*b << endl;
return 0;
}

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

int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; ++i) cin >> A[i];
  int flag = 1;
  int ans;
  while (flag) {
    for (int i = 0; i < N; ++i) {
      if (A[i]%2 != 0) flag = 0;
      A[i] /= 2;
    }
    ++ans;
  }
  cout << ans-1 << endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

struct point {
	ll x, y, d;
};

char a[1002][1002];
ll dif[1002][1002];

int main() {
	IOS();
	ll h, w;
	queue<P> que;
	Fill(dif, INF);
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
			if (a[i][j] == '#') {
				que.push(P(i, j));
				dif[i][j] = 0;
			}
		}
	}
	ll ans = 0;
	while (!que.empty()) {
		P p  = que.front();
		ll x = p.first, y = p.second;
		que.pop();
		for (int i = 0; i < 4; i++) {
			ll nx = p.first + dx[i];
			ll ny = p.second + dy[i];
			if (nx >= 0 && nx < h && ny >= 0 && ny < w && dif[nx][ny] > dif[x][y] + 1) {
				dif[nx][ny] = dif[x][y] + 1;
				que.push(P(nx, ny));
				ans = max(ans, dif[nx][ny]);
			}
		}
	}

	dump(ans);

	return 0;
}

Measured memory_bytes: 25396
k = gets.to_i
a = [1,2,3,4,5,6,7,8,9]
ans = 0
k.times do
  ans = a[0]
  a.shift
  a.push(10*ans+(ans%10)-1) if ans%10 != 0
  a.push(10*ans+(ans%10))
  a.push(10*ans+(ans%10)+1) if ans%10 != 9
end
puts ans

Measured memory_bytes: 3964
#include<iostream>
#include<cstring>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;
#define MAX 500000
#define INF 2e9
int L[MAX/2+2],R[MAX/2+2];
long long  cnt=0;
long long merge(int A[],int n,int left,int mid,int right)
{
	long long cnt=0;
    int n1=mid-left;
    int n2=right-mid;
    for(int i=0;i<n1;i++)
    {
        L[i]=A[left+i];
    }
    for(int i=0;i<n2;i++)
    {
        R[i]=A[mid+i];
    }
    L[n1]=INF;
    R[n2]=INF;
    int i=0,j=0;
    for(int k=left;k<right;k++)//合并
    {
     if(L[i]<=R[j])
     A[k]=L[i++];
     else
     {
	 A[k]=R[j++];
	 cnt=cnt+(n1-i);
}
}
return cnt;
}
long long  mergeSort(int A[],int n,int left,int right)
{
	long long v1,v2,v3;
    if(left+1<right)
    {
        int mid=(left+right)/2;
        v1=mergeSort(A,n,left,mid);
        v2=mergeSort(A,n,mid,right);
        v3=merge(A,n,left,mid,right); 
        return (v1+v2+v3); 
    }
    else
    return 0;
}
int main()
{
int A[MAX],n;
cnt=0;
cin>>n;
for(int i=0;i<n;i++)
cin>>A[i];
cnt=mergeSort(A,n,0,n);
cout<<cnt<<endl;
return 0;
 }


Measured memory_bytes: 4648
#include <iostream>
#include <vector>
using namespace std;
typedef long long int lli;

lli popcount(lli n)
{	
	if(n==0) return 0;
	if(n&1) return 1+popcount(n>>1);
	else return popcount(n>>1);
}
lli MOD=1e9+7;
int main()
{
	lli n; cin>>n;
	lli a[100][100];vector<lli> dp; dp.resize((1<<n)+1);
	for(lli i=0;i<n;i++) for(lli j=0;j<n;j++) cin>>a[i][j];
	dp[0]=1;
	for(lli i=0;i<(1<<n);i++)
	{	
		lli x=popcount(i);
		for(lli j=0;j<n;j++)
		{
			if(a[x][j] and !((1<<j)&i))
			{
				dp[i ^ (1<<j)] += (dp[i])%MOD;
				dp[i ^ (1<<j)] %= MOD;
			}
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
}
















Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define int long long
#define inf (int)(3e18)
#define mod (int)(1e9+7)
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,a[333333];
int sum[333333],sum2[333333];
signed main(){
	cin>>n;
	rep(i,3*n)cin>>a[i];
	{
		multiset<int>st;
		rep(i,n){
			st.insert(a[i]);
			sum[n-1]+=a[i];
		}
		for(int i=n;i<2*n;i++){
			sum[i]=sum[i-1];
			auto it=st.lower_bound(a[i]);
			if(it!=st.begin()){
				sum[i]-=*st.begin();sum[i]+=a[i];
				st.erase(st.begin());st.insert(a[i]);
			}
		}
	}
	{
		multiset<int>st;
		for(int i=3*n-1;i>=2*n;i--){
			st.insert(a[i]);
			sum2[2*n]+=a[i];
		}
		for(int i=2*n-1;i>=n;i--){
			sum2[i]=sum2[i+1];
			auto it=st.lower_bound(a[i]);
			if(it!=st.end()){
				auto it2=st.end();it2--;
				sum2[i]-=*it2;sum2[i]+=a[i];
				st.erase(it2);st.insert(a[i]);
			}
		}
	}
	int ans=-inf;
	for(int i=n-1;i<2*n;i++){
		ans=max(ans,sum[i]-sum2[i+1]);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 11264
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    lint N,K;
    cin >> N >> K;
    plint A[N];
    rep(i,N) cin >> A[i].fi >> A[i].se;
    sort(A,A+N);
    lint now=0;
    rep(i,N){
        now+=A[i].se;
        if(now>=K){
            cout << A[i].fi << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 1792
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

char a[8];

int main() {
    scanf("%s", a);
    for (int i = 0; i < 3; i++)
        if (a[i] == a[i+1]) {
            printf("Bad\n");
            return 0;
        }
    printf("Good\n");

    return 0;
}


Measured memory_bytes: 256
import sys,math,copy,queue,itertools,bisect
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(0,1),(-1,0),(0,-1))
N,K,C = LI()
S = input()
dp = [0 for _ in range(N)]
j = 0
last = -INF
for i in range(N):
    if S[i] == 'o':
        if i - last > C:
            j += 1
            last = i
        dp[i] = j

if j != K:
    exit(0)

last = INF

j = K+1
for i in range(N-1,-1,-1):
    if 0 < dp[i] < j :
        if last - i <= C:
            dp[i] = 0
        else:
            j = dp[i]
            last = i

last = -1
cnt = 0
for i in range(N):
    if dp[i] > 0:
        if dp[i] != last:
            if cnt == 1:
                print (last_i + 1)
            cnt = 0
            last = dp[i]
            last_i = i
        cnt += 1
if cnt == 1: print (last_i + 1)

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

int main() {

	int a, b, c;

	cin >> a >> b >> c;

	if (a+b==c||a+c==b||b+c==a) {
		cout << "Yes" << endl;
	}

	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    m = 10 ** 9 + 7
    x = n - k + 1
    c = [x]
    a, b = n - k, k - 1

    for i in range(2, k + 1):
        x = x * a * b // (i * (i - 1))
        c.append(x % m)
        a -= 1
        b -= 1

    print('\n'.join(map(str, c)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>
// #include <bits/std++.h>

#include <algorithm>
#include <string.h>
using namespace std;
#define MAX_V 1005

#define MOD 1000000007

int dp[MAX_V][MAX_V];
char grid[MAX_V][MAX_V];
int h,w;


int main(int argc,char* argv[]){

    scanf("%d %d",&h,&w);
    
    for(int i = 0; i < h; i++)
    {
        scanf("%s", grid[i]);
    }
    
    dp[h-1][w-1] = 1;
    for(int i = h-1;i >= 0;i --){
        for(int k = w-1;k >= 0;k--){
            if(grid[i][k] == '#'){
                continue;
            }else 
            {
                dp[i][k] =( dp[i][k] + (dp[i + 1][k] + dp[i][k + 1]) % MOD)%MOD;
            }
            
        }
    }
    
    // for(int i = 0; i <= h; i++)
    // {
    //     for(int j = 0; j <= w; j++)
    //     {
    //         printf("[%d]",dp[i][j]);
    //     }
    //     printf("\n");
    // }


    printf("%d",dp[0][0]);
    return 0;
}



Measured memory_bytes: 5120
a, b = map(str, input().split())

tmp = b.split('.')
b = ''.join(tmp)
ans = []
for i in reversed(range(len(b))):
   x = 0
   cnt = 0
   for j in reversed(range(len(a))):
      x += int(a[j]) * int(b[i]) * pow(10, cnt)
      cnt += 1
   ans.append(x)

tmp = [ans[i] * pow(10, i) for i in range(len(ans))]
print(sum(tmp)//100)


Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int h, w, n; cin >> h >> w >> n;
  V<> x(n), y(n); for (int i = 0; i < n; ++i) cin >> x[i] >> y[i], --x[i], --y[i];
  VV<> xs(w);
  set< pair<int, int> > s;
  for (int i = 0; i < n; ++i) {
    xs[y[i]].push_back(x[i]);
    s.emplace(x[i], y[i]);
  }
  for (auto&& v : xs) sort(begin(v), end(v));
  int res = h;
  int i = 0, j = 0;
  while (true) {
    if (i == h - 1) break;
    auto itr = lower_bound(begin(xs[j]), end(xs[j]), i + 1);
    if (itr != end(xs[j])) {
      res = min(res, *itr);
    }
    if (s.count({i + 1, j})) break;
    else ++i;
    if (j != w - 1 and !s.count({i, j + 1})) ++j;
  }
  cout << res << '\n';
}

Measured memory_bytes: 19712
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<P,ll>;

int main(){
	int h, w, ans = 0;
	scanf("%d %d", &h, &w);
	std::vector<std::vector<bool>> fie(h+2, std::vector<bool>(w+2, true));
	for(int i=1; i<=h; i++){
		char s[w+1];
		scanf("%s", s);
		for(int j=1; j<=w; j++){
			fie[i][j] = (s[j-1]=='#');
			ans += (s[j-1]=='.');
		}
	}
	
	int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};	

	int dist = INT_MAX;
	std::queue<PP> que;
	que.push(PP(P(1,1), 0));
	while(!que.empty()){
		P p = que.front().first;
		int x=p.first, y=p.second, d=que.front().second;
		que.pop();
		if(x==h && y==w) dist = d;
		if(fie[x][y]) continue;
		fie[x][y] = true;
		for(int i=0; i<4; i++){
			int nx = x + dx[i], ny = y + dy[i];
			if(!fie[nx][ny]) que.push(PP(P(nx,ny), d+1));
		}
	}

	if(dist==INT_MAX) puts("-1");
	else printf("%d\n", ans-dist-1);
	return 0;
}


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

int main(){
  int n, k, q;
  cin >> n >> k >> q;

  int a[q];

  for(int i=0; i<q; ++i){
    cin >> a[i];
    --a[i];
  }

  int num[n];
  for(int i=0; i<n; ++i){
    num[i] = k;
  }
  for(int i=0; i<q; ++i){
    num[a[i]]++;
  }
  for(int i=0; i<n; ++i){
    if(num[i] > q) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 1408
unittest
{
	assert( [ "atcoder" ].parse.expand.solve == "acdr" );
	assert( [ "aaaa" ].parse.expand.solve == "aa" );
	assert( [ "z" ].parse.expand.solve == "z" );
	assert( [ "fukuokayamaguchi" ].parse.expand.solve == "fkoaaauh" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.strip;
	return tuple( s );
}

auto solve( string s )
{
	auto t = "";
	for( auto i = 0; i < s.length; i += 2 )
	{
		t ~= s[ i ];
	}
	return t;
}


Measured memory_bytes: 664
#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100010;

int a[MAXN];

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i ++)
    {
        scanf("%d", &a[i]);
    }
    a[n + 1] = 0;
    long long ans = 0;
    for (int i = 1; i <= n; i ++)
    {
        if (a[i] + a[i + 1] > m)
        {
            int tmp = a[i] + a[i + 1] - m;
            ans += (long long) tmp;
            if (a[i + 1] >= tmp)
            {
                a[i + 1] -= tmp;
            }
            else
            {
                a[i] -= tmp - a[i + 1];
                a[i + 1] = 0;
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 640
N,M=map(int,input().split())
cakes=[None]*N
for i in range(N):
  x,y,z=map(int,input().split())
  cakes[i]=[x,y,z]
  
ans=0
for i in range(2**3):
  plus_or_minus=[1]*3
  for j in range(3):
    if (i>>j)&1:
      plus_or_minus[j]=1
    else:
      plus_or_minus[j]=-1
  dp=[None for j in range(M+1)]
  dp[0]=[0,0,0]
  
  for c in range(len(cakes)):
    for j in range(c+1,-1,-1):
      if j<len(dp)-1 and dp[j]!=None:
        if dp[j+1]==None:
          dp[j+1]=[None]*3
          for k in range(3):
            dp[j+1][k]=dp[j][k]+cakes[c][k]
        else:
          diff=0
          for k in range(3):
            diff+=((dp[j][k]+cakes[c][k])*plus_or_minus[k])-(dp[j+1][k]*plus_or_minus[k])
          if diff>0:
            for k in range(3):
              dp[j+1][k]=dp[j][k]+cakes[c][k]
  if abs(dp[-1][0])+abs(dp[-1][1])+abs(dp[-1][2])>ans:
    ans=abs(dp[-1][0])+abs(dp[-1][1])+abs(dp[-1][2])

print(ans)


Measured memory_bytes: 52956