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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve()
{
    ll x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vll ap(a), bp(b), cp(c);
    for(ll i=0;i<a;i++) {
        cin >> ap[i];
    }
    for(ll i=0;i<b;i++) {
        cin >> bp[i];
    }
    for(ll i=0;i<c;i++) {
        cin >> cp[i];
    }
    sort(all(ap));
    sort(all(bp));
    sort(all(cp));
    ll i = a-x;
    ll j = b-y;
    ll k = c-1;
    while(k >= 0 && i < a && j < b) {
        if(ap[i] <= bp[j]) {
            if(cp[k] >= ap[i]) {
                ap[i] = cp[k];
                i++;
                k--;
            } else {
                break;
            }
        } else {
            if(cp[k] >= bp[j]) {
                bp[j] = cp[k];
                j++;
                k--;
            } else {
                break;
            }
        }
    }
    while(k >=0 && i < a) {
        if(cp[k] >= ap[i]) {
            ap[i] = cp[k];
            k--;
            i++;
        } else {
            break;
        }
    }
    while(k >= 0 && j < b) {
        if(cp[k] >= bp[j])  {
            bp[j] = cp[k];
            j++;
            k--;
        } else {
            break;
        }
    }
    ll sum = 0;
    for(ll i=a-x;i<a;i++) {
        sum += ap[i];
    }
    for(ll j=b-y;j<b;j++) {
        sum += bp[j];
    }
    cout << sum << "\n";
}

int main()
{
    // FAST_IO;
    // #ifndef ONLINE_JUDGE 
    //   OC;
    // #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}   

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <chrono>
#include <string>
#include <assert.h>

using namespace std;

#define endl '\n'

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

    int n, m;
    cin >> n >> m;

    vector<vector<int>> adj(n);

    for (int i = 0; i < m; ++i)
    {
        int u, v;
        cin >> u >> v;
        u--;
        v--;

        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    vector<int> col(n);
    vector<int> vis(n);

    long long bip = 0, one = 0, oth = 0;
    bool ok;

    function<void(int)> is_bipartite = [&](int u) {
        vis[u] = 1;

        for (auto v : adj[u])
        {
            if (vis[v])
            {
                if (col[u] == col[v])
                    ok = false;
            }
            else
            {
                col[v] = col[u] ^ 1;
                is_bipartite(v);
            }
        }
    };

    for (int i = 0; i < n; ++i)
    {
        if (vis[i])
            continue;

        if (adj[i].empty())
        {
            one++;
            continue;
        }

        ok = true;
        is_bipartite(i);

        if (ok)
        {
            bip++;
        }
        else
        {
            oth++;
        }
    }

    long long answer = 2 * n * one - one * one;

    answer += (bip + oth) * (bip + oth) + bip * bip;

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 11264
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

int main(){
	
	int A, B, C;
	cin >> A >> B >> C;
	
	if(A == C){
		cout << B << endl;
	}else if(B == C){
		cout << A << endl;
	}else{
		cout << C << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
double a,ans;
int main()
{
	cin>>n;
	int k=n;
	k++;
	k/=2;
	double b;
	a=n;
	b=k;
	ans=(b/a);
	printf("%.10f\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
	if(b<=0){
		return a;
	}else{
		return gcd(b,a%b);
	}
}
int lcm(int a,int b){
	return (a/gcd(a,b))*b;
}	
int main() {
	long long int a,b;
	while(cin>>a>>b){
		cout<<gcd(a,b)<<" "<<lcm(a,b)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3064
//ABC109A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int k;
	cin >> k;
	int ans = k/2 * (k-k/2);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a;
  vector<int>v1(a);
  for(int i=0;i<a;i++)
  cin>>v1[i];
  cin>>b;
  vector<int>v2(b);
   for(int i=0;i<b;i++)
  cin>>v2[i];
  cout<<includes(v1.begin(),v1.end(),v2.begin(),v2.end())<<endl;

}



Measured memory_bytes: 4424
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int a[100001];
vector<int> vec;
int cnt[100001];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		vec.push_back(a[i]);
	}
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());
	for(int i=0;i<n;i++){
		a[i]=lower_bound(vec.begin(),vec.end(),a[i])-vec.begin();
	}
	int now=0;
	bool po=false;
	for(int i=0;i<n;i++){
		cnt[a[i]]++;
		if(cnt[a[i]]==1)now++;
		if(cnt[a[i]]==0)now--;
		cnt[a[n-1-i]]--;
		if(cnt[a[n-1-i]]==-1)now++;
		if(cnt[a[n-1-i]]==0)now--;
		if(now==0){
			if(po)printf(" ");
			po=true;
			printf("%d",i+1);
		}
	}
	printf("\n");
	return 0;
}


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

int main(void){
    set<int> st;
    rep(i,3){
        int x;
        cin>>x;
        st.insert(x);
    }
    cout<<st.size()<<endl;
    
    return 0;
}


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


int main() {
  int k;
  cin >> k;
  int odd, evn;
  if (k % 2 == 0) { odd = k / 2; } 
  else { odd = k / 2 + 1; }
  evn = k / 2;

  int ans = odd * evn;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main() {
	int a;
	string s;
	cin >> a >> s;
	if (a >= 3200) {
		cout << s << endl;
	}
	else {
		cout << "red" << endl;
	}

}

Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = list(input())
    sub_ts = [[] for i in range(K)]
    for index, t in enumerate(T):
        sub_ts[index % K].append(t)

    total = 0
    for sub_t in sub_ts:
        total += sub(sub_t, R, S, P)
    print(total)

def sub(T, R, S, P):
    point = 0
    last_te = None
    for t in T:
        if last_te is None or can_win(last_te, t):
            te, p = win(t, R, S, P)
            last_te = te
            point += p
        else:
            last_te = 'o'
    return point

def win(enemy_t, R, S, P):
    if enemy_t == 'r':
        return 'p', P
    elif enemy_t == 's':
        return 'r', R
    else:
        return 's', S

def can_win(last_te, enemy_t):
    win_t = None
    if enemy_t == 'r':
        win_t = 'p'
    elif enemy_t == 's':
        win_t = 'r'
    else:
        win_t = 's'
    return last_te != win_t

main()


Measured memory_bytes: 14116
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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

#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
//#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
ll ceil(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 1000000000;
const ll INF64 = 9223372036854775807ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//mapは、if関数などで覗いただけで構成されるので注意しよう！
int main(){
    int n;
    std::cin >> n;
    string s;
    std::cin >> s;
    itn ans=0;
    rep(i,n-1){
        if(s[i]!=s[i+1])ans++;
    }
    std::cout << ans+1 << std::endl;
}

Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <ctime>
#include <cstring>
using namespace std;

int cross[100];
int a, b;
bool ans;

int main(void){

	for(int i = 0; i < 100; i++){
		cross[i] = 0;
	}

	while (cin >> a >> b) {
		
		if (a == 0) {

			ans = true;

		if(cross[0] % 2 == 1 && cross[1] % 2 == 1){
			for(int i = 2; i < 100; i++){
				if(cross[i] % 2 == 1){
					ans = false;
				}
			}
		}else{
			ans = false;
		}

		if(ans){
			cout << "OK" << endl;
		}else{
			cout << "NG" << endl;
		}


		for(int i = 0; i < 100; i++){
			cross[i] = 0;
		}

		}else{
			
			cross[a - 1]++;
			cross[b - 1]++;
		}
	}
	
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <typeinfo>
#define _USE_MATH_DEFINES
#include <cmath>
#include <stack>
#include <queue>

using namespace std;


int main(){

    int n, q;
    cin >> n;
    vector<int> seq1(n);
    for(int i=0; i<n; i++){
        cin >> seq1[i];
    }
    cin >> q;
    vector<int> seq2(q);
    for(int i=0; i<q; i++){
        cin >> seq2[i];
    }

    sort(seq1.begin(), seq1.end());
    // seq1内のかぶり数の削除 うまく行ってない
    vector<int>::iterator itr = seq1.begin();
    while(itr!=seq1.end()){
        if(*itr==*(itr+1)){
            seq1.erase(itr);
            itr--;
        }
        itr++;
    }


    sort(seq2.begin(), seq2.end());
    vector<int>::iterator itr2 = seq2.begin();
    while(itr2!=seq2.end()){
        if(*itr2==*(itr2+1)){
            seq2.erase(itr2);
                itr2--;
        }
        itr2++;
    }

    int both_num = 0;
    int size1 = seq1.size();
    int size2 = seq2.size();
    for(int i=0; i<size1; i++){
        for(int j=0; j<size2; j++){
            if(seq1[i]==seq2[j]){
                both_num += 1;
                break;
            }
        }
    }

    cout << both_num << endl;

    return 0;
}



Measured memory_bytes: 3172
#pragma warning (disable: 6031)
#pragma warning (disable: 26451)

#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <map>


//const int mod = 1000000007;
const int mod = 998244353;
template <class T> T maximum(T a, T b) { return a < b ? b : a; }
template <class T> T minimum(T a, T b) { return a > b ? b : a; }
template <class T> void swap(T& a, T& b) { T c = a; a = b; b = c; }
template <class T> T abs_(T a) { return a < 0 ? -a : a; }
using std::pair;
using std::vector;

long long size[31]{ 1 };

long long rec(long long, long long, long long, long long, long long, bool);
long long sq(long long a, long long b, long long c, long long d, long long s) {
	s /= 3;
	long long aa = a / s;
	long long bb = b / s;
	long long cc = c / s;
	long long dd = d / s;
	if (bb == dd) {
		swap(a, b);
		swap(c, d);
		swap(aa, bb);
		swap(cc, dd);
	}
	if (aa != cc)return abs_(a - c) + abs_(b - d);
	if (bb == dd) return sq(a % s, b % s, c % s, d % s, s);
	return rec(a % s, b, c % s, d, s, aa == 1);
}

long long rec(long long a, long long b, long long c, long long d, long long w, bool bl) {
	if (!bl) {
		if (w == 1)return abs_(a - c) + abs_(b - d);
		w /= 3;
		long long aa = a / w;
		long long cc = c / w;
		if (aa == cc)return rec(a % w, b, c % w, d, w, aa == 1);
		return abs_(a - c) + abs_(b - d);
	}
	else {
		if (abs_((b / w) - (d / w)) == 1)return rec(a, b, c, d, w, false);
		return abs_(b - d) + minimum(a + c + 2, 2 * w - a - c);
	}
}

int main() {
	for (int i = 0; i < 30; i++) {
		size[i + 1] = size[i] * 3;
	}
	int Q;
	scanf("%d", &Q);
	auto res = new long long[Q];
	for (int i = 0; i < Q; i++) {
		long long a, b, c, d;
		scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
		res[i] = sq(a - 1, b - 1, c - 1, d - 1, size[30]);
	}
	for (int i = 0; i < Q; i++)printf("%lld\n", res[i]);
	return 0;
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

int C1[200001], C2[200001], D[200001];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int N, cnt=0, t1=0, t2=0;
	string s;
	cin>>N>>s;
	for(auto c: s) cnt+=c-'0';
	for(int i=1;i<=200000;i++) D[i]=D[i%__builtin_popcount(i)]+1;
	C1[N-1]=C2[N-1]=1;
	t1=t2=s.back()-'0';
	for(int i=N-2;i>=0;i--) {
		if(cnt>1) {
			C1[i]=(C1[i+1]*2)%(cnt-1);
			if(s[i]=='1') t1=(t1+C1[i])%(cnt-1);
		}
		if(cnt<N) {
			C2[i]=(C2[i+1]*2)%(cnt+1);
			if(s[i]=='1') t2=(t2+C2[i])%(cnt+1);
		}
	}
	for(int i=0;i<N;i++) {
		if(s[i]=='1') {
			if(cnt==1) cout<<"0\n";
			else cout<<D[(t1+cnt-1-C1[i])%(cnt-1)]+1<<'\n';
		}
		else cout<<D[(t2+C2[i])%(cnt+1)]+1<<'\n';
	}
	return 0;
}

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

using namespace std;

int a[100];

int main()
{
	//freopen("input14.txt","r",stdin);freopen("output14.txt","w",stdout);
	int i,n,s1=0,s2=0,t;
	cin>>n;
	for (i=0;i<n;i++){
		cin>>a[i];
		s1+=a[i];
	}
	t=s1/n;
	s1=0;
	for (i=0;i<n;i++){
		s1+=(a[i]-t)*(a[i]-t);
		s2+=(a[i]-t-1)*(a[i]-t-1);
	}
	cout<<min(s1,s2);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair < int , int > pii;
#define mpr make_pair
#define FS first
#define SC second
#define PB push_back
template < typename T > void UMAX(T &a,T b){a=(a>b?a:b);}
template < typename T > void UMIN(T &a,T b){a=(a<b?a:b);}
LL readint(){
	char c=getchar();
	LL ret=0ll;
	bool neg=0;
	while(!(c>='0' && c<='9')){
		if(c=='-') neg=1;
		c=getchar();
	}
	while(c>='0' && c<='9'){
		ret=ret*10ll+(LL)(c-'0');
		c=getchar();
	}
	return neg?-ret:ret;
}
void putint(LL v){
	if(v<0){
		putchar('-');
		v=-v;
	}
	if(!v){
		putchar('0');
		return;
	}
	if(v>=10ll) putint(v/10ll);
	putchar('0'+(v%10ll));
}
int n,D,x[200005],q;
struct tree{
	int fa[20][200005],val[200005],sum[200005];
	tree(){
		memset(fa,-1,sizeof(fa));
		memset(val,0,sizeof(val));
	}
	void prec(bool rev){
		int i,j,k;
		for(i=1;i<20;++i){
			for(j=0;j<n;++j){
				if(~fa[i-1][j])
					fa[i][j]=fa[i-1][fa[i-1][j]];
				else
					fa[i][j]=-1;
			}
		}
		if(rev){
			for(i=n-1;i>=0;--i){
				sum[i]=val[i]+(~fa[0][i]?sum[fa[0][i]]:0);
			}
		}
		else{
			for(i=0;i<n;++i){
				sum[i]=val[i]+(~fa[0][i]?sum[fa[0][i]]:0);
			}
		}
	}
	int qry(int v,int tv){
//		printf("qry %d %d\n",v,tv);
		int ret=sum[v],i;
		for(i=19;i>=0;--i){
			if(~fa[i][v] && val[fa[i][v]]>=tv)
				v=fa[i][v];
		}
//		printf("got to %d\n",v);
		return ret-(~fa[0][v]?sum[fa[0][v]]:0);
	}
}R2L,L2R;
int main(){
	int i,j,k;
	n=readint();D=readint();
	for(i=0;i<n;++i) x[i]=readint();
	for(i=0;i<n;++i) R2L.val[i]=i,L2R.val[i]=-i+1;
	for(i=j=0;i<n;++i){
		while(x[i]-x[j]>=D) ++j;
		R2L.fa[0][i]=j-1;
	}
	for(i=j=n-1;i>=0;--i){
		while(x[j]-x[i]>=D) --j;
		L2R.fa[0][i]=(j==n-1?-1:j+1);
	}
	R2L.prec(0);
	L2R.prec(1);
	q=readint();
	while(q--){
		int l=readint()-1,r=readint()-1;
		printf("%d\n",R2L.qry(r,l)+L2R.qry(l,-r+1));
	}
	return 0;
}
/*
 * 代码框架
 * 1. 实现树结构体，自行设置父亲、权值，支持定位祖先并求权值和
 * 2. 向左走->下标，向右走->下标相反数
*/

Measured memory_bytes: 38924
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
using namespace std;
int main(){
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            cout << s[i];
        }
    }
    cout << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  ll s=0;
  rep(i,n){
    cin >> a.at(i);
    s=s^a.at(i);
  }
  rep(i,n)
    cout << (s^a.at(i)) << ' ';
}

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

int main()
{
	int k, n;
	cin >> k >> n;
	vector< int > a(n);
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];	
	}
	int mini = 0;
	for(int i = 0; i < n - 1; i++)
	{
		if(a[i + 1] - a[i] > mini)
		{
			mini = a[i + 1] - a[i];
	//cout << "min is: " << mini << "\n";
		}
	}
	int diff = (k - a[n - 1]) + a[0];
	//cout <<"diff: "<<diff <<" ";
	
	if(mini < diff)
	{
		cout << k - diff;
	}
	else{cout << k - mini;}
	
	
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <map>

using namespace std;

int main()
{
    int N, M;
    long long int ans = 0;
    cin >> N >> M;

    std::map<long long int, int> ab;

    long long int a, b;
    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        auto it = ab.find(a);
        if (it != ab.end()) {
            it->second += b;
        }
        else {
            ab[a] = b;
        }
    }

    for (auto it = ab.begin(); it != ab.end() && M > 0; it++) {
        long c = min(M, it->second);
        ans += c * it->first;
        M -= c;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6528
import sys


sys.setrecursionlimit(100000)


def main():
    N = int(input())

    E = {i:{} for i in range(N)}
    for _ in range(N-1):
        u, v, w = map(int, input().split())
        E[u-1][v-1] = w % 2
        E[v-1][u-1] = w % 2
    
    ans = [-1] * N
    def dfs(x):
        for y in E[x]:
            del E[y][x]
            ans[y] = ans[x] if E[x][y] == 0 else 1 - ans[x]
            if len(E[y]) > 0:
                dfs(y)
    
    ans[0] = 0
    dfs(0)
    for a in ans:
        print(a)


main()


Measured memory_bytes: 100976
#include <stdio.h>

int main(void){
  int a,b,c,i,x;
  scanf("%d %d %d",&a,&b,&c);
  x = 0;
 
  for( i=a ; i<=b; i++){
   if( c % i == 0){
    x++;
   }
 }
 printf("%d\n",x);
 return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define scan(x) scanf("%lld",&x);
#define inf 5555555555555555555
#define mod 1000000007
#define pi 3.14159265358979323846
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool ok, flag;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111

ll mo = 998244353;

ll fac[MAX*3];

ll mpow(ll x, ll y) {
  ll ret = 1;
  while (y > 0) {
	if (y & 1) ret = (x*ret) % mo;
	x = (x*x) % mo;
	y >>= 1;
  }
  return ret;
}

ll comb(ll x, ll y) {
  if (x < y) return 0;
  ll fac1 = fac[x];
  ll fac2 = fac[y];
  ll fac3 = fac[x - y];
  return ((fac1 *mpow(fac2, mo - 2)) % mo * mpow(fac3, mo - 2)) % mo;
}

void fac_set() {
  fac[0] = 1;
  FOR(i, 1, MAX*3) {
	(fac[i] = fac[i - 1] * i) %= mo;
  }
}

int main(void) {
  ll r, b, k, g, a1, a2, r1, b1;
  vll re, bu;
  cin >> n >> r >> b >> k;
  fac_set();
  rep(i, 3*10e5+1) {
	if (((double)k - i * r) / b == (k - i * r) / b) {
	  tmp = (k - i * r) / b;
	  if (tmp < 0) continue;
	  if (i > n || tmp > n) continue;
	  re.pb(i);
	  bu.pb(tmp);
	}
  }

  rep(i, re.size()) {
	(ans += (comb(n, re[i])*comb(n, bu[i]))) %= mo;
  }

  cout << ans << endl;

  return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define r_rep(i,n) for(int i=n-1;i>=0;i--)
#define ll long long

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

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int i;
	int n;
	int a, b, c;
	scanf("%d", &n);
	for(i=0;i<n;i++) {
		scanf("%d %d %d", &a, &b, &c);
		if(a > b && a > c) {
			if(a*a == b*b+c*c) {
				puts("YES");
			} else {
				puts("NO");
			}
		} else if(b > a && b > c) {
			if(b*b == a*a+c*c) {
				puts("YES");
			} else {
				puts("NO");
			}
		} else if(c > a && c > b) {
			if(c*c == a*a+b*b) {
				puts("YES");
			} else {
				puts("NO");
			}
		} else {
			puts("NO");
		}
	}
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

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

    if (n == 2) {
        double dx = x[0] - x[1];
        double dy = y[0] - y[1];
        printf("%.12f\n", sqrt(dx * dx + dy * dy) * 0.5);
        exit(0);
    }

    double pi = acos(-1);
    auto f = [&](int i, int j, int k) {
        double x0 = x[j] - x[i];
        double y0 = y[j] - y[i];
        double x1 = x[k] - x[i];
        double y1 = y[k] - y[i];
        double z0 = atan2(y0, x0);
        double z1 = atan2(y1, x1);
        double z = z1 - z0;
        if (z < 0) z *= -1;
        if (z > pi) z = pi * 2 - z;
        return z;
    };

    double r = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                if (i == j || j == k || k == i) continue;
                double t = 0;
                double dx = x[j] - x[k];
                double dy = y[j] - y[k];
                double l = sqrt(dx * dx + dy * dy);
                double z = f(i, j, k);
                if (z < 0) z *= -1;
                if (z > pi) z = pi * 2 - z;
                if (z < 1e-9) continue;
                if (z >= pi * 0.5 || f(j, k, i) >= pi * 0.5 || f(k, i, j) >= pi * 0.5) {
                    t = l;
                } else {
                    t = l / sin(z);
                    //if (t > 80) {
                    //    cout << z << ' ' << sin(z) << endl;
                    //}
                }
                r = max(r, t);
            }
        }
    }
    printf("%.12f\n", r * 0.5);

    return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second
#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second

vi u, v;
ll ans;

class DSU
{
private:
    int n;
    vector<ll> vel, rod;
public:
    DSU(int n) : n(n)
    {
        vel.assign(n,1);
        rod.resize(n);
        for(int i = 0; i < n; ++i)
            rod[i] = i;        
    }

    int dobiRod(int a)
    {
        while(a!=rod[a])
        {
            rod[a] = rod[rod[a]];
            a = rod[a];
        }
        
        return a;
    }
    
    void unite(int a, int b)
    {
        a = dobiRod(a), b = dobiRod(b);

        if(a == b)
            return;
        
        ans -= 1LL * vel[a] * vel[b];
        if(vel[a] > vel[b])
            swap(a,b);

        vel[b] += vel[a];
        rod[a] = rod[b];
    }
};


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

    int n, m;
    cin >> n >> m;
    DSU pov(n);
    
    u.resize(m);
    v.resize(m);
    ans = n * 1LL * (n-1) / 2LL;

    for(int i = 0; i < m; ++i)
    {
        cin >> u[i] >> v[i], --u[i], --v[i];
    }

    vector<ll> kon;

    for(int i = m-1; ~i; --i)
    {
        kon.pb(ans);
        pov.unite(u[i],v[i]);
    }

    reverse(all(kon));
    
    for(auto z : kon)
        cout << z << '\n';
}


Measured memory_bytes: 6640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int H,W;
  char c[110][110];
  int res=0;
  cin >> H >> W;

  rep(i,H) {
    cin >> c[i];
  }

  rep(i,H){
    cout << c[i] << endl;
    cout << c[i] << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <sstream>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;

int N, a;
int m;
int idx = 1;

int main() {

  cin >> N;
  for(int i = 1; i <= N; i++) {
    cin >> a;
    if (abs(a) > abs(m)) {
      m = a;
      idx = i;
    }
  }

  cout << 2 * N - 2 << endl;
  for(int i = 1; i <= N; i++) {
    if (i == idx) {
      continue;
    }
    cout << idx << " " << i << endl;
  }

  for(int i = 1; i < N; i++) {
    if (m >= 0) {
      cout << i << " " << i + 1 << endl;
    } else {
      cout << N - i + 1 << " " << N - i << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

void solve() {
    int N;
    cin >> N;
    map<string, int> cnt;
    rep(i, N) {
        string s;
        cin >> s;
        sort(all(s));
        cnt[s]++;
    }
    ll ans = 0;
    each(p, cnt) {
        ll group = p.second;
        ans += group * (group - 1) / 2;
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  ll n;
  ll a[300009];
  cin>>n;
  rep(i,n)cin>>a[i];
  mint ans=0;
  rep(i,60){
    ll x=0;
    rep(j,n)x+=a[j]>>i&1;
    mint now=(mint)x*(n-x);
    rep(j,i)now*=2;
    ans+=now;
  }
  cout<<ans.x<<endl;
  return(0);
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int a[6]= {100,101,102,103,104,105},n,dp[1000002];
int main()
{
    scanf("%d",&n);
    dp[0]=1;
    for(int i=0; i<6; i++)
        for(int j=a[i]; j<=n; j++)
            dp[j]=dp[j]+dp[j-a[i]];
    if(dp[n])
        printf("1");
    else
        printf("0");
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
     
using namespace std;
     
#define FOR(i,a,b)		for(int i=(a),_b=(b);i<(_b);++i)
#define FORD(i,a,b)		for(int i=(a),_b=(b);i>(_b);--i)
#define pb			push_back
#define mp			make_pair
#define	all(c)			(c).begin(),(c).end()
#define	present(c,x)		((c).find(x) != (c).end())
#define	cpresent(c,x)		(find(all(c),x) != (c).end())
#define	endl			'\n'
     
typedef long long		ll;
typedef unsigned long long	ull;
typedef unsigned char	 	byte;
typedef vector<int>		vi;
typedef pair<int, int>		pii;
typedef pair<ll, ll>		pll;
typedef vector<pii>		vpii;
     
const int MX = 25;
     
int main(int argc, char *argv[])
{
#ifdef	HTRINH_UNIT_TEST
   freopen(argv[1],"r",stdin);
   ifstream cin(argv[1]);
#endif
#if 0
   ofstream cout(argv[2]);
#endif
   ios :: sync_with_stdio(false);
   cin.tie(NULL);
     
   	int n,a,b,c;
	cin >> n;
	int dp[3];
	cin >> dp[0] >> dp[1] >> dp[2];
	FOR(i,1,n) {
		cin >> a >> b >> c;
		int A,B,C;
		A = max(dp[1]+a,dp[2]+a);
		B = max(dp[0]+b,dp[2]+b);
		C = max(dp[0]+c,dp[1]+c);
		dp[0] = A, dp[1] = B, dp[2] = C;
	}
    cout << max(dp[0],max(dp[1],dp[2])) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

//ここから編集 
int cnt[110];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N; cin >> N;

  vector<int> a(N);
  set<int> st;
  int mi = INT_MAX;
  REP(i,N) {
    cin >> a[i];
    cnt[a[i]]++;
    mi = min(mi, a[i]);
    st.insert(a[i]);
  }
  if(cnt[mi] == 1){
    //mi~mi*2まで存在
    bool f = true;
    for(int i=mi+1; i<=mi*2; i++){
      if(cnt[i] < 2) f = false;
    }
    for(int i=mi*2+1; i<=N; i++){
      if(cnt[i]) f = false;
    }
    if(f){
      cout << "Possible" << endl;
    }else{
      cout << "Impossible" << endl;
    }
  }else if(cnt[mi] == 2){
    //mi~mi*2-1まで存在
    bool f = true;
    for(int i=mi+1; i<=mi*2-1; i++){
      if(cnt[i] < 2) f = false;
    }
    for(int i=mi*2; i<=N; i++){
      if(cnt[i]) f = false;
    }
    if(f){
      cout << "Possible" << endl;
    }else{
      cout << "Impossible" << endl;
    }
  }else{
    cout << "Impossible" << endl;
  }


  return 0;
}


Measured memory_bytes: 3680
N = input()
a=int(N[0])
b=int(N[1])
c=int(N[2])
d=int(N[3])
if a+b+c+d==7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a-b+c+d==7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a+b-c+d==7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a+b+c-d==7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a-b-c+d==7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a-b+c-d==7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a+b-c-d==7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
elif a-b-c-d==7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')

Measured memory_bytes: 3064
/*
 Sarthak Jain
*/
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
int mod=1e9+7;
int min(int a,int b){
  return (a<b)?a:b;
}
int max(int a,int b){
  return (a>b)?a:b;
}
int fp(int a,int b){
  if(b==0) return 1;
  int x=fp(a,b/2);
  x=(x*x)%mod;
  if(b&1) x=(x*a)%mod;
  return x;
}


signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
 int n,m,x;
 cin>>n>>m;
 for(int i=1;i<=m;i++)
 {
  cin>>x;
  n-=x;
 }
 if(n<0)
  n=-1;
cout<<n;

}

Measured memory_bytes: 3644
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#define ll long long int
#define MOD 1000000007LL
using namespace std; 
ll dis[201][201];
void WF(int v){
    for(int k=1;k<=v;k++){
        for(int i=1;i<=v;i++){
            for(int j=1;j<=v;j++){
                dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
            }
        }
    }
}
int main() {
    int n,m,r;
    cin>>n>>m>>r;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(i==j){
                dis[i][j]=0;
            }else{
                dis[i][j]=MOD*MOD;
            }
        }
    }
    vector<int>rr;
    for(int i=0;i<r;i++){
        int a;
        cin>>a;
        rr.push_back(a);
    } 
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        if(dis[a][b]>c){
            dis[a][b]=c;
            dis[b][a]=c;
        }
    }
    WF(n);
    ll ans=MOD*MOD;
    sort(rr.begin(),rr.end());
    do{
        ll d=0;
        for(int i=1;i<r;i++){
            d+=dis[rr[i-1]][rr[i]];
        }
        if(d<ans){
            ans=d;
        }
    }while(next_permutation(rr.begin(),rr.end()));
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#line 1 "main_f.cpp"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */

using i64=std::int_fast64_t;
using u64=std::uint_fast64_t;
 
#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, u64 b,Num id=1) {
  if(b==0)return id;
  Num x = id;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

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

  i64 n;
  std::cin>>n;

  i64 ans=0;

  rep(i,1,n+1)ans+=i*(n+1-i);

  rep(i,0,n-1){
    i64 u,v;
    std::cin>>u>>v;
    if(u>v)std::swap(u,v);
    v--;
    ans-=u*(n-v);
  }

  std::cout<<ans<<"\n";
  
  return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rept(i,k,n) for(ll i = (k); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;
typedef tuple<int,int,int> Tii;

template <typename T>
ostream& operator<<(ostream& s, const vector<T> &vec){
    for(int i=0;i<vec.size();i++){
        if(i) s << ',';
        else s << '{';
        s <<setw(2)<< vec[i];
    }
    s << '}' << endl;
    return s;
}

//素因数分解　(key:素因数　value:次数)
map<ll,ll> pf(ll n){
    map<ll,ll> mp;
    int i=2;
    while(i<=sqrt(n)){
        if(n%i==0){
            mp[i]++;
            n/=i;
            continue;
        }
        i++;
    }
    mp[n]++;
    return mp;
}

int main(){
    ll n;cin>>n;
    auto mp = pf(n);
    ll ans=0;
    for(auto x:mp){
        ll p=x.first,e=x.second;
        if(p==1) continue;
        ll n=(-1+sqrt(1+8*e+1))/2;
        if(n*(n+1)>2*e) n--;
        ans+=n;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <cstring>
#include <iostream>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i, s, n) for(int i=(s); i<=(n); ++i)
#define outl(x) cout<< (x) << '\n'
const int INF = 0x7f7f7f7f;
using namespace std;

typedef long long ll;
int L[100005], R[100005];

ll merge(int* left, int* mid, int* right)
{
   const int hl = mid - left;
   const int hr = right - mid;
   L[hl] = R[hr] = INF;

   memcpy( L, left, sizeof(int) * hl );
   memcpy( R, mid,  sizeof(int) * hr );

   int i = 0, j = 0;
   ll cnt = 0;
   for(int* k = left; k != right; ++k)
      *k = (L[i] <= R[j])? (L[i++]) : (cnt += hl-i, R[j++] );
   return (cnt);
}

ll inversion(int* a, int* end)
{
   ll ret = 0;
   if ( a + 1 < end ) {
      int* mid = a + (end - a) / 2;
      ret += inversion(a, mid);
      ret += inversion(mid, end);
      ret += merge(a, mid, end);
   }
   return (ret);
}

signed main()
{
   ios::sync_with_stdio(false), cin.tie(0);
   int N;
   static int a[200005];

   cin >> N;
   rep(i, N)cin >> a[i];

   outl( inversion(a, a+N) );
}



Measured memory_bytes: 4672
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int const MAXN=110000;
int N;
int a[MAXN];
int b[MAXN];
map<int,vector<int>> posB;
bool was[MAXN];

void dfs(int v) {
	was[v]=true;
	for (int u:posB[a[v]]) if (!was[u]) dfs(u);
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	cin>>N;
	rep(i,0,N) cin>>a[i];
	rep(i,0,N) cin>>b[i];
	
	rep(i,0,N) a[N]^=a[i];
	rep(i,0,N) b[N]^=b[i];
	
	vector<int> vA(a,a+N+1);
	vector<int> vB(b,b+N+1);
	
	if (vA==vB) {
		cout<<"0\n";
		return 0;
	}
	
	sort(vA.begin(),vA.end());
	sort(vB.begin(),vB.end());
	
	if (vA!=vB) {
		cout<<"-1\n";
		return 0;
	}
	
//~ cerr<<a[N]<<endl;
//~ cerr<<b[N]<<endl;
	
	int res=0;
	rep(i,0,N+1) if (a[i]!=b[i]) {
		res++;
		posB[b[i]].push_back(i);
	}
	
	if (a[N]!=b[N]) res--;
	
	int cc=0;
	rep(i,0,N+1) if (a[i]!=b[i] && !was[i]) {
		cc++;
		dfs(i);
	}
	
	res+=cc;
	
	if (a[N]!=b[N] || posB.count(b[N])) {
		res--;
	}

	cout<<res<<"\n";
}


Measured memory_bytes: 19072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 1e9+7;
ll qpow(ll a,ll b){ll res=1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
struct graph
{
    int head[maxn],nxt[maxn<<1],to[maxn<<1],w[maxn<<1],sz;
    void init(){memset(head,-1,sizeof(head));}
    graph(){init();}
    void push(int a,int b,int c){nxt[sz]=head[a],to[sz]=b,w[sz]=c,head[a]=sz++;}
    int& operator[](const int a){return to[a];}
}g;
int n,a[maxn],b[maxn],m;
struct BIT
{
    int bit[maxn];
    vector<pair<int,int> > update(int x,int k){
        vector<pair<int,int> >v;
        while(x<=m){
            if(bit[x]<k){
                v.push_back(make_pair(x,bit[x]));
                bit[x]=k;
            }
            x+=x&-x;
        }
        return v;
    }
    int query(int x){
        int tmp = 0;
        while(x){
            tmp=max(tmp,bit[x]);
            x-=x&-x;
        }
        return tmp;
    }
}bit;
int ans[maxn];
void dfs(int now,int pre)
{
    ans[now]=bit.query(a[now]-1)+1;
    vector<pair<int,int> >v=bit.update(a[now],ans[now]);;
    ans[now]=max(ans[now],ans[pre]);
    for(int i = g.head[now];~i;i = g.nxt[i]){
        if(g[i]==pre)continue;
        dfs(g[i],now);
    }
    for(int i = 0;i < v.size();++i){
        bit.bit[v[i].first]=v[i].second;
    }
}
int main()
{
    scanf("%d",&n);
    for(int i = 1;i <= n;++i)scanf("%d",&a[i]),b[i]=a[i];
    sort(b+1,b+1+n);
    m = unique(b+1,b+1+n)-b-1;
    for(int i = 1;i <= n;++i)a[i]=lower_bound(b+1,b+1+m,a[i])-b;
    for(int i = 1;i < n;++i){
        int c,d;
        scanf("%d%d",&c,&d);
        g.push(c,d,0),g.push(d,c,0);
    }
    dfs(1,0);
    for(int i = 1;i <= n;++i)printf("%d\n",ans[i]);
    return 0;
}


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

signed main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int n, a, b;
    std::string s;

    std::cin >> n >> a >> b >> s;

    int qualified = 0;
    int foreign = 0;

    for (char &c : s) {
        if (c == 'c') {
            goto No;
        }
        else if (c == 'a') {
            if (qualified < a + b) {
                ++qualified;
                goto Yes;
            }
        }
        else {
            if (qualified < a + b && foreign < b) {
                ++foreign;
                ++qualified;
                goto Yes;
            }
        }

        No:
            std::cout << "No\n";
            continue;
        Yes:
            std::cout << "Yes\n";
    }

    return 0;
}

Measured memory_bytes: 3776