akhauriyash/Code-Regression huggingface dataset:
#include<vector>
#include<map>
#include<iostream>
using namespace std;

#define MOD (1000000007)

pair<int, int> pl(int a , int N){
    int mp = N/2;
    return make_pair(mp -a/2 , mp + a/2);
}

int main(){
    int N;
    cin >> N;
    map<int, int> mp;
    for (int i=0; i<N; i++){
        int a;
        cin >> a;
        //printf("a %d \n",a);
        pair<int, int> pr = pl(a, N);
        bool single_point = (pr.first == pr.second);
        //printf("a %d , %d, %d\n",a , pr.first, pr.second);
        // cout << "MP" << endl;
        // for(auto x: mp){
        //     cout << x.first << ", " << x.second << endl;
        // }
        // cout << "/MP" << endl;
        if(!mp.count(a)){
            mp[a]=1;
        } else {
            auto it = mp.find(a);
            // printf("a %d, it %d, %d\n",a, it->first, it->second);
            if ((single_point && N%2==1) || (!single_point && it->second>2)){
                printf("0\n"); // single point duplicated or two people must be in same spot
                return 0;
            }
            mp[a]+=1;
        }
            
    }

    long long sol = 1;
    for(map<int,int>::iterator it = mp.begin(); it!=mp.end(); it++){
        if(it->second==2){
            sol <<=1;
            sol%=MOD;
        }
    }
    printf("%llu\n", sol);

}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main(void)
{
	int p,q,r,ans;
	cin>>p>>q>>r;
	ans=p+q;
	if(ans>=r+q){
		ans=r+q;
	}
	if(ans>=p+r){
		ans=p+r;
	}
	if(ans>=q+r){
		ans=q+r;
	}
	if(ans>=r+p){
		ans=r+p;
	}
	if(ans>=q+p){
		ans=q+p;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main{
  static int n;
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    dfs("", 'a');
  }
  public static void dfs(String s, char mx){
    if(s.length()==n){
      System.out.println(s);
    } else {
      for(char c = 'a'; c <= mx; c++){
        dfs(s+c, ((c == mx) ? (char)(mx+1) : mx));
      }
    }
  }
}

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

int main() {
    char s[4];
    cin >> s;
    sort(s, s+4);
    s[0] == s[1] && s[1] != s[2] && s[2] == s[3] ? cout << "Yes" << endl : cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 3005
using namespace std;
int n,m,dp[M][M],dx[M][M],dy[M][M];
char in1[M], in2[M];
int main()
{
    while (~scanf("%s%s",in1+1,in2+1)) {
        n = strlen(in1+1);
        m = strlen(in2+1);
        REP(i,1,n) REP(j,1,m) {
            if (in1[i]==in2[j]) {
                dp[i][j] = dp[i-1][j-1] + 1;
                dx[i][j] = dy[i][j] = -1;
            } else if (dp[i-1][j] > dp[i][j-1]) {
                dp[i][j] = dp[i-1][j];
                dx[i][j] = -1;
                dy[i][j] = 0;
            } else {
                dp[i][j] = dp[i][j-1];
                dx[i][j] = 0;
                dy[i][j] = -1;
            }
        }

        string ans = "";
        int x=n, y=m;
        while (x&&y) {
            if (dx[x][y]==-1 && dy[x][y]==-1) {
                ans += in1[x];
            }

            int tx=x, ty=y;
            x += dx[tx][ty];
            y += dy[tx][ty];
        }

        reverse(ans.begin(), ans.end());
        printf("%s\n", ans.c_str());
    }
    
    return 0;
}




Measured memory_bytes: 105984
for i in range(int(input())):
    a,b,c=map(int,input().split())
    if a**2+b**2==c**2:
        print("YES")
    elif b**2+c**2==a**2:
        print("YES")
    elif c**2+a**2==b**2:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pi acos(-1)
#define mod 1000000007
#define show(x, y); cout << x << " " << y << endl;
using namespace std;

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

    int n, m;
    cin >> n >> m;
    char grid[n][m];
    for(int i = 0; i < n; i++){
        cin >> grid[i];
    }
    if(grid[n-1][m-1] == '#'){
        cout << 0;
        return 0;
    }
    int dp[n][m];
    memset(dp, 0, sizeof dp);
    for(int i = n - 2; i >= 0; i--){
        if(grid[i][m-1] == '#'){
            break;
        }else{
            dp[i][m-1]  = 1;
        }
    }
    for(int j = m - 2; j >= 0; j--){
        if(grid[n-1][j] == '#'){
            break;
        }else{
            dp[n-1][j]  = 1;
        }
    }
    for(int i = n - 2; i >= 0; i--){
        for(int j = m - 2; j >= 0; j--){
            if(grid[i][j] == '.'){
                dp[i][j] = (dp[i+1][j] + dp[i][j+1]) % mod;
            }
        }
    }
    cout << dp[0][0];
    return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e10;

int main(){
    string s;
    while(getline(cin, s)){
        stringstream buf(s);
        double w;
        buf >> w;
        vector<double> r;
        double in;
        while(buf >> in){
            r.push_back(in);
        }
        int n = r.size();

        vector<vector<double> > dp(n, vector<double>(1<<n, INF));
        for(int i=0; i<n; i++){
            dp[i][1<<i] = r[i];
        }
        for(int i=0; i<(1<<n); i++){
            for(int j=0; j<n; j++){
                if((1<<j & i) == 0) continue;
                for(int k=0; k<n; k++){
                    if((1<<k & i) != 0) continue;
                    double x = sqrt((r[j]+r[k]) *(r[j]+r[k]) - (r[j]-r[k]) *(r[j]-r[k]));
                    dp[k][i | 1<<k] = min(dp[k][i | 1<<k], dp[j][i] +x);
                }
            }
        }

        double MIN = INF;
        for(int i=0; i<n; i++){
            MIN = min(MIN, dp[i][(1<<n)-1] +r[i]);
        }
        if(MIN < w +EPS){
            cout << "OK" << endl;
        }else{
            cout << "NA" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  if( S.at(K-1)=='A'){
    S.at(K-1) = 'a';}
  else if( S.at(K-1)=='B'){
    S.at(K-1) = 'b';}
  else if( S.at(K-1)=='C'){
    S.at(K-1) = 'c';}
  cout << S << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
 

void solve(){
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); ++i) {
        if(s[i] == '7') {
            cout << "Yes";
            return;
        }
    }
    cout << "No";
} 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 3652
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
using namespace std;
#define ll long long
#define INF 1000000007
using P = pair<int, int>;
int main(){
    int n,k;
    cin>>n>>k;
    int x[114514];
    int ans=INF;
    for(int i=0;i<n;i++)cin>>x[i];
    for(int i=0;i<n-k+1;i++){
        if(x[i]<0&&x[i+k-1]<0)ans=min(ans,abs(x[i]));
        else if(x[i]<0&&x[i+k-1]>=0)ans=min(x[i+k-1]-x[i]+min(abs(x[i]),x[i+k-1]),ans);
        else ans=min(ans,x[i+k-1]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n,p[200100],v[200100];
struct node{
	long long c0,c1,inv;
};
bool operator <(node a,node b){
	return a.c1*b.c0<a.c0*b.c1;
}
multiset<node> a[200100];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<n;i++) cin>>p[i],p[i]--;
	for(int i=0;i<n;i++) cin>>v[i];
	for(int i=n-1;i>=0;i--){
		node s={(v[i]==0),(v[i])==1,0};
		while(!a[i].empty()&&*a[i].begin()<s){
			node t=*a[i].begin();
			a[i].erase(a[i].begin());
			s.inv+=t.inv+s.c1*t.c0;
			s.c0+=t.c0;
			s.c1+=t.c1;
		}
		a[i].insert(s);
		if(i>0){
			if(a[i].size()>a[p[i]].size())
				swap(a[i],a[p[i]]);
			for(node t:a[i]) a[p[i]].insert(t);
			a[i].clear();
		}
	}
	node s={0,0,0};
	while(!a[0].empty()){
		node t=*a[0].begin();
		a[0].erase(a[0].begin());
		s.inv+=t.inv+s.c1*t.c0;
		s.c0+=t.c0;
		s.c1+=t.c1;
	}
	cout<<s.inv<<endl;
	return 0;
}


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

int main()
{
    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(n-1));
    rep(i,n) rep(j,n-1) { cin >> a[i][j]; a[i][j]--; }

    vector<int> d(n,0);
    vector<int> p(n,0);
    queue<pair<int,int>> que;

    rep(i,n) {
        if(a[a[i][0]][0] == i)
            que.push({i,p[i]});
    }

    int ans = 0;
    while(!que.empty()) {
        int player = que.front().first;
        int pp = que.front().second;
        que.pop();
        if(p[player] > pp) continue;

        int opponent = a[player][pp];
        int po = p[opponent];
        if(po >= n-1 || a[opponent][po] != player) 
            continue;

        int nd = max(d[player], d[opponent]) + 1;
        d[player] = d[opponent] = nd;
        p[player]++;
        p[opponent]++;

        if(p[player] < n-1) que.push({player,p[player]});
        if(p[opponent] < n-1) que.push({opponent,p[opponent]});

        ans = max(ans, nd);
    }

    rep(i,n) {
        if(p[i] < n-1) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>

using namespace std;

const int maxn = 20005;
pair<int, pair<int, int> > p[maxn];
// s, w, v

int n;


typedef long long LL;

LL dp[maxn];
LL c[maxn];

void add(int pos, LL val){
    for(int i = pos;i < maxn;i += i & -i){
        c[i] = max(c[i], val);
    }
} 

LL sum(int pos){
    LL res = 0;
    for(int i = pos;i > 0;i -= i & -i){
        res = max(res, c[i]);
    }
    return res;
}

int main(){
    cin >> n;
    for(int i = 1;i <= n;i++){
        scanf("%d%d%d", &p[i].second.first, &p[i].first, &p[i].second.second);
        p[i].first += p[i].second.first;
    }
    sort(p + 1, p + 1 + n);
    for(int i = 1;i <= n;i++){
        //cout << i << endl;
        for(int j = 1;j < maxn;j++){
            add(j, dp[j]);
        }
        int w = p[i].second.first;
        int s = p[i].first - w;
        int v = p[i].second.second;
        //cout << w << " " << s << " " << v << endl;
        dp[w] = max(dp[w], 1LL * v);
        //cout << i << endl;
        for(int j = w;j < maxn;j++){
            //int rb = max(0, min(s, j - w));
            int rb = min(s, j - w);
            dp[j] = max(dp[j], sum(rb) + v);
        }
        //for(int j = 0;j <= 5;j++){
        //    cout << j << " " << dp[j] << endl;
        //}
    }
    cout << dp[maxn - 1] << endl;
    return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int M = cin.nextInt();

        int[] num = new int[N];
        for (int i = 0; i < M; i++)
        {
            int a = cin.nextInt() - 1;
            int b = cin.nextInt() - 1;
            num[a]++;
            num[b]++;
        }

        for (int i = 0; i < N; i++)
        {
            if(num[i] % 2 == 1)
            {
                Console.WriteLine("NO");
                return;
            }
        }
        Console.WriteLine("YES");


    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 17328
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] c = sc.next().toCharArray();
        Arrays.sort(c);
        System.out.println(
                c[0] == c[1] && c[2] == c[3] && c[0] != c[2] ? "Yes" : "No");
    }
}

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

int main() {
  int a,b,c,d,l,r;
  cin >> a >> b >> c >> d;
  l = a+b;
  r = c+d;
  if(l > r){
    cout << "Left" << endl;
  }
  else if(l == r){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

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

int main()
{
    ll n;
    cin>>n;
    ll arr[n+1];
    ll dp[n+1] = {0};

    for(ll i=1;i<=n;i++)
    {
        cin>>arr[i];
        dp[i] = 10e15;
    }

    dp[0] = 0;
    dp[1] = 0;
    dp[2] = abs(arr[2]-arr[1]);
    for(ll i=3;i<=n;i++)
    {
        dp[i] = min(dp[i-1] + abs(arr[i]-arr[i-1]),dp[i-2] + abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    int n, m, flag;
    char before[100000]={}, after[100000]={}, c;
    
    while(1){
        cin >> n;
        if(n==0) break;
        for(int i=0; i<n; i++){
            cin >> before[i] >> after[i];
        }
    
        cin >> m;
        for(int j=0; j<m; j++){
            cin >> c;
            flag=0;
            for(int i=0; i<n; i++){
                if(c==before[i]){
                    cout << after[i];
                    flag=1;
                }
            }
            if(flag==0) cout << c;
        }
        cout << endl;
    }
    return 0;
}



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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define mp make_pair
#ifndef MY
    #define endl '\n'
#endif
//#define int long long
#define sz(x) (int)x.size()

typedef long long ll;
typedef long double db;
typedef long double ldb;
typedef pair < int, int > pii;

ostream & operator << (ostream & out, vector < int > & lst) {
    for (auto a : lst)
        out << a << ' ';
    out << endl;
    return out;
}


signed main() {
#ifdef MY
    freopen("f.in", "r", stdin);
    //freopen("f.out", "w", stdout);
#endif // MY
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    n %= 10;
    if (n  == 3) {
        cout << "bon";
    } else if (n == 0 || n == 1 || n == 6 || n == 8) {
        cout << "pon";
    } else {
        cout << "hon";
    }
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pii pair<ll,ll>
#define F first
#define S second
#define pb push_back
struct triplet{ll a,b,c;};bool operator < (const triplet &t1,const triplet &t2){   if(t1.a<t2.b)return true;if(t1.a==t2.a && t1.b <t2.b)return true;if(t1.a==t2.a && t1.b ==t2.b && t1.c<t2.c)return true;return false;}
ll mod1=998244353;
ll power(ll n,ll k){ll ans=1; while(k>0){if(k&1)ans=(ans*n);n=(n*n);k>>=1;}return ans;}
int main()
{
    fio;
    ll n;
    cin>>n;
    vector <pii> v;
    for(int i=0;i<n;i++)
    {
        ll a,b;
        cin>>a>>b;
        v.pb({a,b});
    }
     if(n<=2)
    {
        cout<<1;
        return 0;
    }
    sort(v.begin(),v.end());
    multiset<pii> ms(v.begin(),v.end());
    vector<pii> diff;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            diff.pb({v[j].F-v[i].F,v[j].S-v[i].S});
        }
    }
    int maxi=51;

    for(int i=0;i<diff.size();i++)
    {
        multiset<pii> temp=ms;
        int c=0;
        for(int j=0;j<n;j++)
        {
            int k=1;
            if(temp.find(make_pair(v[j].F ,v[j].S))==temp.end())
                {
                    continue;
                }
            while(1)
            {
                if(temp.find({v[j].F +k*diff[i].F,v[j].S+k*diff[i].S})==temp.end())
                    break;
                temp.erase(temp.find({v[j].F +k*diff[i].F,v[j].S+k*diff[i].S}));
                k++;
            }
            //cout<<v[j].F<<" "<<v[j].S<<"\n";
            temp.erase(temp.find({v[j].F ,v[j].S}));
            c++;

        }

        maxi=min(maxi,c);

    }
    cout<<maxi;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){
	double n,k;cin>>n>>k;
	double ans=0;
	for(double i=1;i<=n;i+=1){
		if(i>=k){
			ans += 1.0/n;
		}
		else {
			double t=1.0/n;
			int cur = i;
			while(cur<k){
				cur*=2;
				t/=2.0;
			}
			ans += t;
		}
	}
	cout<<fixed<<setprecision(15)<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,a,b;
    cin>>n>>a>>b;
    ll t;
    t = a+b;
    ll y = n/t;
    y = y*a;
    ll r = n%t;
    if(r<a)
        y+=r;
    else
        y+=a;
    cout<<y<<endl;
    return 0;
}


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

int N;
vector <int> a, p;

int main() {
	scanf("%d", &N);
	a.resize(N + 1);
	p.resize(N + 1);
	for (int i = 1; i <= N; i++) {
		scanf("%d", &a[i]);	
		p[i] = i;
	}
		
	vector <int> ans(N + 1, 0);
	for (int k = 0; k < N; k++) {
		int pos = 1;
		for (int i = 1; i < a.size(); i++)
			if (a[i] >= a[pos])
				pos = i;
		int where = (int)p.size() - 1 - pos + a[pos];
		if (where < 0 || where >= p.size()) {
			puts("-1");
			return 0;
		}
		ans[p[where]] = a[pos];
		a.erase(a.begin() + pos);
		p.erase(p.begin() + where); 
	}
	
	for (int i = 1; i <= N; i++)
		printf("%d\n", ans[i]);
	
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import java.util.stream.Collectors;
import java.util.stream.Stream;

import java.util.Set;
import java.util.HashSet;

public class Main{

    public static void main(String[] args) {
	try {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    List<String> lines = new ArrayList<String>();
	    String line = "";

	    while((line = br.readLine()) != null){
		lines.add(line);
	    }
	    br.close();

	    //lines.add("4 5");
	    //lines.add("1 1 3 4 5");
	    //lines.add("2 2 2 4 5");
	    //lines.add("3 3 0 1 1");
	    //lines.add("2 3 4 4 6");

	    Integer row = Integer.parseInt(lines.get(0).split(" ")[1]);
	    List<String> newLines = new ArrayList<String>();

	    Integer[] rows = Collections.nCopies(row+1, 0).toArray(new Integer[row+1]);

	    for (int i = 1; i < lines.size(); i++) {
		String[] columns = lines.get(i).split(" ");
		List<Integer> list = new ArrayList<Integer>();
		for (int j = 0; j < columns.length; j++) {
		    Integer c = Integer.parseInt(columns[j]);
		    rows[j] = rows[j] + c;
		    list.add(c);
		}
		Integer sum = list.stream().mapToInt(x -> x).sum();
		rows[row] = sum + rows[row];
		newLines.add(lines.get(i) + " " + sum);
	    }

	    for (String e: newLines) {
		System.out.println(e);
	    }

	    String[] alpha = new String[row+1];
	    for (int i = 0; i < row+1; i++) {
		alpha[i] = String.valueOf(rows[i]);
	    }
	    String s = Arrays.stream(alpha).collect(Collectors.joining(" "));
	    System.out.println(s);

	    System.exit(0);

	} catch (Exception e) {
	    System.out.println(e.getMessage());
	    System.out.println(Arrays.toString(e.getStackTrace()));
	    System.exit(0);
	}
    }
}

Measured memory_bytes: 32476
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
 
#define int __int128
#define long __int128
 
ostream &operator<<(ostream &os, __int128_t value) {
    if (ostream::sentry(os)) {
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[64];
        char *d = end(buffer);
        do {
            --d;
            *d = "0123456789"[tmp % 10];
            tmp /= 10;
        } while (tmp != 0);
        if (value < 0) {
            --d;
            *d = '-';
        }
        int len = end(buffer) - d;
        if (os.rdbuf()->sputn(d, len) != len) {
            os.setstate(ios_base::badbit);
        }
    }
    return os;
}
 
istream &operator>>(istream &is, __int128_t &value) {
    string in;
    is >> in;
    value = 0;
    for (const char &c : in) {
        if ('0' <= c && c <= '9') value = 10 * value + (c - '0');
    }
    if (in[0] == '-') value *= -1;
    return is;
}

signed main(){
    int N;
    cin >> N;
    vector<bool> sieve_of_primes(1e5, true);
    for(int i = 2; i * i < 1e5; i++){
        if(sieve_of_primes[i]){
            for(int j = i * 2; j < 1e5; j += i){
                sieve_of_primes[j] = false;
            }
        }
    }
    vector<long> primes;
    for(int i = 2; i < 1e5; i++){
        if(sieve_of_primes[i]){
            primes.push_back(i);
        }
    }
    map<long, int> nums;
    bool is_in_1 = false;
    for(int i = 0; i < N; i++){
        long num;
        cin >> num;
        for(long j = 0; primes[j] * primes[j] * primes[j] <= num; ){
            if(num % (primes[j] * primes[j] * primes[j]) == 0){
                num /= primes[j] * primes[j] * primes[j];
            }else{
                j++;
            }
        }
        if(num == 1){
            is_in_1 = true;
        }else{
            nums[num]++;
        }
    }
    long ans = 0;
    for(auto item: nums){
        pair<long, int> i = item;
        long i_tmp = i.first;
        long cube_pair_another = 1;
        for(long j = 0; primes[j] * primes[j] * primes[j] <= i.first; j++){
            if(i.first % (primes[j] * primes[j]) == 0){
                cube_pair_another *= primes[j];
                i_tmp /= primes[j] * primes[j];
            }else if(i.first % primes[j] == 0){
                cube_pair_another *= primes[j] * primes[j];
                i_tmp /= primes[j];
            }
        }
        cube_pair_another *= i_tmp * i_tmp;
        ans += max(i.second, nums[cube_pair_another]);
        nums[i.first] = 0;
        if(nums[cube_pair_another]){
            nums[cube_pair_another] = 0;
        }else{
            nums.erase(cube_pair_another);
        }
    }
    cout << ans + is_in_1 << endl;
}

Measured memory_bytes: 11464
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 200001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

int visited[10001];
int N;
vector<int>c;
vector<int>adj[10001];
int vertex[10001];

void dfs(int cur)
{
    visited[cur] = true;
    
    for(int i = 0; i < adj[cur].size(); i++)
    {
        auto next = adj[cur][i];
        if(visited[next]) continue;
        vertex[next] = c.back(); c.pop_back();
        dfs(next);
    }
    
}

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    cin >> N;
    ll ret = 0;
    for(int i = 0; i < N - 1; i++)
    {
        int a, b; cin >> a >> b;
        adj[a].push_back(b); adj[b].push_back(a);
    }
    for(int i = 0; i < N; i++)
    {
        int t; cin >> t; c.push_back(t);
        ret += t;
    }
    sort(c.begin(), c.end());
    ret -= c.back();
    
    vertex[1] = c.back(); c.pop_back();
    dfs(1);
    
    cout << ret << endl;
    for(int i = 1; i <= N; i++)
        cout << vertex[i] << " ";
    
    
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>a
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    ll N, M, s, t;
    cin >> N >> M;
    if(N>1 && M == 0){
        string ans = "1";
        rep(i, N-1){
            ans += '0';
        }
        cout << ans <<endl;
    }else if(N==1 && M == 0){
        cout << "0" <<endl;
    }else{
        map<ll,ll> q;
        vector<char> ans(N, '0');
        ans[0] = '1';
        bool is_ok = true;
        rep(i, M){
            cin >> s >> t;
            if(q.find(s) != q.end() && q[s] != t){
                is_ok = false;
            }
            q[s] = t;
        }
        if(is_ok){
            string a = "";
            for(auto p:q){
                ans[p.first-1] = '0' + p.second;
            }
            for(auto s:ans){
                a += s;
            }
            if(a[0] == '0' && N > 1){
                cout << "-1" <<endl;
            }else{
                cout << a <<endl;
            }
        }else{
            cout << "-1" <<endl;
        }
    }
}

int main(){
    Main();
}

Measured memory_bytes: 3108
#include<cstdio>
int main()
{
  int K, A, B;
  int i=1;
  scanf("%d", &K);
  scanf("%d%d", &A, &B);
  if(K==1||A<=K&&K<=B) {
         printf("OK");
         return 0;
     }
     for(int i=A;i<=B;i++){
     	if(i%K==0)
     	{
     		printf("OK");
     		break;
		 }
		 if(i==B)
		 {
		 	printf("NG");
		 }
	 } 

  return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    vector<string> vec;
    string tmp;
    for(int i=0;i<n;i++){
        cin >> tmp;
        vec.push_back(tmp);
    }
    
    int ans[26] = {}, size = vec[0].size();
    multiset<char> alphabet;
    // 一つ目の文字列を基準とする
    for(int i=0;i<size;i++)
        alphabet.insert(vec[0][i]);
    char a;
    for(int i=0;i<26;i++){
        a = 'a' + i;
        ans[i] = alphabet.count(a);
    }
    // S2 ~ Sn
    for(int i=1;i<n;i++){
        size = vec[i].size();
        for(int j=0;j<size;j++)
            alphabet.insert(vec[i][j]);
        // アルファベット全探索
        for(int j=0;j<26;j++){
            a = 'a' + j;
            ans[j] = min( ans[j], (int)(alphabet.count(a)) );
        }
        alphabet.clear();   // 忘れない
    }  
    
    // 辞書順に出力
    for(int i=0;i<26;i++){
        for(int j=0;j<ans[i];j++){
            a = 'a' + i;
            cout << a;
        }
    }
    cout << endl;

    return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n,m;
  cin >> n >> m;
  vector<vector<bool>> adj(n, vector<bool>(n,false));
  REP(i,m){
    int32 a,b;
    cin >> a >> b;
    a--;b--;
    adj[a][b] = adj[b][a] = true;
  }
  vector<int32> perm;
  FOR(i,1,n)perm.pb(i);
  int32 ans = 0;
  do{
    bool flg = adj[0][perm[0]];
    REP(i,n-2){
      if(!adj[perm[i]][perm[i+1]]){
        flg = false;
        break;
      }
    }
    if(flg){
      // REP(i,n-1)cout << perm[i]+1;
      // cout << endl;
      ++ans;
    }
  }while(next_permutation(ALL(perm)));
  ANS(ans);
  return 0;
}

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

int m = 0, t = 0, w, u = 1;
string s;
int a[2020];

int main()
{
	cin >> s;

	w = s.size();
	a[0] = 1;

	for (int i = 0; i < w; i++) {
		t = (t + (s[w - 1 - i] - '0') * u) % 2019;
		a[t]++;
		u = u * 10 % 2019;
	}

	for (int i = 0; i < 2019; i++)
		m += a[i] * (a[i] - 1) / 2;

	cout << m << endl;
}

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

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

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let d: Vec<char> = read::<String>().chars().collect();

    for i in 0..s.len() {
        let si = s[i];
        let di = d[i];
        if si != di {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


Measured memory_bytes: 2120
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

typedef long long int lli;

void swap(int* a, int* b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

void ll_swap(lli* a, lli* b)
{
    lli tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

int gcd(int a, int b)
{
    if (a < b)
        swap(&a, &b);

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

int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

long power(long x, int n) {
    long ans = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
		printf("res:%lld a:%lld\n", res,a);
	}
	return res;
}


lli comb(lli n, lli r)
{
    if (n == 0)
        return 0;

    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (comb(n - 1, r - 1) + comb(n - 1, r));
}

/*
#define MAX 100000
long long fac[MAX], finv[MAX], inv[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 long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*/


int main()
{
    int X;

    scanf("%d", &X);

    for (int i = -1000; i <= 1000; i++)
    {
        for (int j = -1000; j <= 1000; j++)
        {
            if (pow(i, 5) - pow(j, 5) == X)
            {
                printf("%d %d", i, j);
                return 0;
            }
        }
    }
}



Measured memory_bytes: 4224
#include<iostream>
#include<cstdio>
const int N=1e4+5;
int a[N],b[N],n;
typedef long long ll;
int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",a+i);
    for(int i=1;i<=n;i++) scanf("%d",b+i);
    ll l=0,r=0;
    for(int i=1;i<=n;i++) {
        if(a[i]>=b[i]) r+=a[i]-b[i];
        else l+=(b[i]-a[i])>>1;
    }
    if(l>=r) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double

int main(){
	/*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
	#endif*/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n; 
	cin>>n;
	int a[n];
	int l=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>=0) l++;
	}
	if(l==0){
		sort(a,a+n);
		int ans=0;
		for(int i=0;i<n-1;i++) ans+=abs(a[i]);
		ans+=a[n-1];
		cout<<ans<<"\n";
		int pre=a[n-1];
		for(int i=n-2;i>=0;i--){
			cout<<pre<<" "<<a[i]<<"\n";
			pre-=a[i];
		}
		return 0;
	}
	if(l==n){
		sort(a,a+n);
		reverse(a,a+n);
		int ans=0;
		for(int i=0;i<n-1;i++) ans+=abs(a[i]);
		ans-=a[n-1];
		cout<<ans<<"\n";
		int pre=a[n-1];
		for(int i=n-2;i>=1;i--){
			cout<<pre<<" "<<a[i]<<"\n";
			pre-=a[i];
		}
		cout<<a[0]<<" "<<pre<<"\n";
		return 0;
	}
	int ans=0;
	vector<int> v1,v2;
	for(int i=0;i<n;i++){
		if(a[i]>=0) v1.push_back(a[i]);
		else v2.push_back(a[i]);
		ans+=abs(a[i]);
	}
	cout<<ans<<"\n";
	int pre=v2.back();
	v2.pop_back();
	for(int i=v1.size()-1;i>=1;i--){
		cout<<pre<<" "<<v1[i]<<"\n";
		pre-=v1[i];
	}
	cout<<v1[0]<<" "<<pre<<"\n";
	pre=v1[0]-pre;
	for(int i=v2.size()-1;i>=0;i--){
		cout<<pre<<" "<<v2[i]<<"\n";
		pre-=v2[i];
	}
}

Measured memory_bytes: 2808
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    set<int> se;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        se.insert(a);
    }
    cout << (se.size() == n ? "YES" : "NO") << endl;
}

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

int main() {

    int N;

    int X;

    cin >> N ;

     X = N / 1.08;

    // // X * 1.08 = N
    //  cout << "---" << N << endl;
    //  cout << "---" << X << endl;
    //  cout << "(X + 1) * 1.08 : " << (X + 1) * 1.08  << endl;

   

    if (X * 1.08 == N){

        cout << X << endl;
    }
    else if (int((X + 1) * 1.08) == N){

        cout << (X + 1) << endl;
    }
    else{

        cout << ":(" << endl;
    }








}

Measured memory_bytes: 3608
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define EPS 1e-14
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define PI 2*acos(0.0)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x <<": "<< x << "\n"
#define DEBUG_ARR(a) REP(i, size(a)){ cout << #a << "[" << i << "]: " << a[i] << "\n"; }
const int VX[] = { 0, 1, 0, -1 };
const int VY[] = { 1, 0, -1, 0 };
const long MOD = 1000000007;

int main()
{
	//	--- I/O 高速化 ---
	cin.tie(0);
	ios::sync_with_stdio(false);
	// --- ここまで ---

	int N;
	cin >> N;
	vector<int> a(N);
	vector<bool> used(N, false);
	REP(i, N) cin >> a[i];

	int i = 0, count = 0;
	while (i != 1)
	{
		count++;
		used[i] = true;
		i = a[i] - 1;
		if (used[i])
		{
			cout << "-1\n";
			return 0;
		}
	}

	cout << count << "\n";

	return 0;
}


Measured memory_bytes: 640
// aoj-5000.cpp

#include <cstdio>

int main() {
	int i;
	int cards, a, b, scoreA = 0, scoreB = 0;

	while (1) {
		// read number of cards
		scanf("%d", &cards);
		if (cards == 0) break;
		scoreA = 0;
		scoreB = 0;
	
		for (i=0; i<cards; ++i) {
			scanf("%d %d", &a, &b);
			if (a > b) {
				scoreA += (a + b);
			} else if (b > a) {
				scoreB += (a + b);
			} else {
				scoreA += a;
				scoreB += b;
			}
		}
		printf("%d %d\n", scoreA, scoreB);
	}

	return 0;
}

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

using namespace std;

typedef long long ll;

const ll INF = 1LL << 60;

ll N,M;  vector<pair<ll,ll>> to[1010];

vector<ll> dist;

int main(){
cin >> N >> M; 
  dist = vector<ll> (N,INF);
  
  for(ll i = 0; i < M; i++){
    ll a,b,c; cin >> a >> b >> c; a--; b--; c *= -1;
    to[a].push_back(make_pair(b,c));}
  
  bool closed = false;
  
  dist[0] = 0;
  
  for(ll i = 0; i < 2 * N; i++){
    for(ll v = 0; v < N; v++){
      if( dist[v] == INF){ continue;}//
      else{
        if( to[v].empty()){ continue;}
        for( ll k = 0; k < to[v].size(); k++){
          ll p =  to[v][k].first; //vから繋がる先
          ll q =  to[v][k].second; // v- p間のコスト
          if( dist[p] > dist[v] + q){
            dist[p] = dist[v] + q;
            if( i >= N && p == N - 1){ closed = true;}}
        }}
    }}
  
  if( closed){ cout << "inf" << endl;}
  else{
    cout << -dist[N-1] << endl; } return 0;}
            

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <typeinfo>
using namespace std;
int main(){
	int n/*kaisuu*/,k/*tasukazu*/,c=1;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		if(c*2>c+k)c+=k;
		else c*=2;
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys

n=int(input())
A=list(map(int,input().split()))

s=0
for i in A:
    s+=i

S=[]
for i in range(n+1):
    S.append(s)
    s-=A[i]


if n==0:
    if A[0]==1:
        print(1)
    else:
        print(-1)
    sys.exit()

if A[0]!=0:
    print(-1)
    sys.exit()


ans=1
temp=1
for i in range(n-1):
    #print(ans,temp)
    if A[i+1]>=2*temp:
        print(-1)
        sys.exit()
    else:
        temp=min(S[i+1],2*temp)
        ans+=temp
        temp-=A[i+1]
        

if temp<=A[n]<=2*temp:
    ans+=A[n]
    print(ans)
else:
    print(-1)



    

Measured memory_bytes: 20028
from itertools import permutations

N, C = map(int, input().split())

d = [list(map(int, input().split()))  for i in range(C)] 
c = [list(map(int, input().split()))  for i in range(N)] 

# 3行にまとめる
c_listed = [{},{},{}]

for i in range(N):
    for j in range(N):
        index = (i + j) % 3
        c_listed[index][c[i][j]] = c_listed[index].get(c[i][j], 0) + 1

# 色の選び方
color_seq = permutations(range(C), 3)

ret = N * N * 1000
for color in color_seq:
    count = 0
    for line, line_color in zip(c_listed, color):
        for f, v in line.items():
            # f to line_color
            count += d[f-1][line_color] * v

    # 
    if count < ret:
        ret = count

print(ret)



Measured memory_bytes: 5620
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

vector<vector<int>> G;
vector<int> colors;
LL N, M;

bool dfs(int v, int c) {
  colors[v] = c;
  for (const auto& n : G[v]) {
    if (colors[n] == c) return false;
    if (colors[n] == 0 && !dfs(n, -c)) return false;
  }
  return true;
}

bool is_bipartite_graph() {
  for (int i = 1; i <= N; ++i) {
    if (colors[i] == 0) {
      if (!dfs(i, 1)) {
        return false;
      }
    }
  }
  return true;
}

int main() {
  cin >> N >> M;
  G.resize(N+1);
  colors.resize(N+1, 0);

  for (int i = 0; i < M; ++i) {
    int A, B; cin >> A >> B;
    G[A].push_back(B);
    G[B].push_back(A);
  }

  if (is_bipartite_graph()) {
    LL cnta = 0, cntb = 0;
    for (int i = 1; i <= N; ++i) {
      if (colors[i] < 0) ++cnta;
      else       ++cntb;
    }
    cout << cnta*cntb - M << endl;
  } else {
    cout << N*(N-1LL)/2LL - M << endl;
  }
}


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

int main(){
    int n;cin>>n;
    vi a(n);
    int s=0;
    rep(i,n){
        cin>>a[i];
        s^= a[i];
    }
    rep(i,n){
        printf("%d%s", (s^a[i]), i==n-1?"\n":" ");
    }
    return 0;
}

Measured memory_bytes: 3968
N=int(input())
a=[int(i) for i in input().split()]
x=a[0]
y=sum(a)-a[0]
ans=abs(x-y)
for i in range(1,N-1):
        x+=a[i]
        y-=a[i]
        ans=min(ans,abs(x-y))
print(ans)

Measured memory_bytes: 24668
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<long long> a(n+1),b(n);
  for(int i=0;i<n+1;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    cin >> b[i];
  }
  long long ans=0;
  for(int i=n-1;i>=0;i--){
    if(a[i+1]+a[i]<=b[i]){
      ans+=a[i+1]+a[i];
      a[i+1]=0;
      a[i]=0;
    }
    else if(a[i+1]>=b[i]){
      a[i+1]-=b[i];
      ans+=b[i];
    }
    else{
      a[i]-=b[i]-a[i+1];
      a[i+1]=0;
      ans+=b[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int t; cin >> t; cin.ignore(); while(t--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
 
vector <ll> p(1005);
vector <ll> g(1005, 0);
ll dp[1005][1<<13];
bool vis[1005][1<<13];
ll n, m;
 
ll solve(ll ind, ll x){
    if (ind==m) {
        int temp = 1<<n;
        if (x==(temp-1)) return 0ll;
        return (ll)1e9;
    }
    if (vis[ind][x]) return dp[ind][x];
    vis[ind][x] = true;
    ll val = p[ind];
    dp[ind][x] = solve(ind+1, x);
    return dp[ind][x] = min(dp[ind][x], val+solve(ind+1, x | g[ind]));

}
 
int main(){
    fast();
 
/* you get what you work for not what you wish for */
    scanf("%lld%lld", &n, &m);
    for(int i=0; i<m; i++){
        scanf("%lld", &p[i]);
        ll sz;
        scanf("%lld", &sz);
        for(int j=0; j<sz; j++){
            ll x;
            scanf("%lld", &x);
            x--;
            g[i]+=1<<x;
        }
    }
    ll y = solve(0, 0);
    if(y>=1e9){
        out(-1);
    }
    else{
        out(y);
    }
}


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

int main() {
		int A, B, C;
		std::cin >> A >> B >> C;

		if(A > B) std::swap(A, B);
		if(B > C) std::swap(B, C);
		if(A > B) std::swap(A, B);

		int cnt = 0;
		if(3 * C % 2 != (A + B + C) % 2) {
			++cnt;
			++B;
			++C;
		}
		while(B < C) {
			++cnt;
			++A;
			++B;
		}
		while(A < C) {
			++cnt;
			A += 2;
		}

		std::cout << cnt << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

template<class T>
struct WeightedUnionFind {
private:
    vector<int> par, rank;
    vector<T> diff_weight;
    
public:
    WeightedUnionFind() {}
    WeightedUnionFind(int n, T def = 0) {
        par.resize(n, -1);
        rank.resize(n, 0);
        diff_weight.resize(n, def);
    }
    
    int root(int x) {
        if (par[x] < 0) return x;
        int r = root(par[x]);
        diff_weight[x] += diff_weight[par[x]];
        return par[x] = r;
    }
    
    T weight(int x) {
        root(x);
        return diff_weight[x];
    }
    
    bool is_same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y, T w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }
    
    T diff(int x, int y) {
        return weight(y) - weight(x);
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, q;
    cin >> n >> q;
    WeightedUnionFind<ll> wuf(n);
    rep(i, q) {
        ll t;
        cin >> t;
        if (t == 0) {
            ll x, y, z;
            cin >> x >> y >> z;
            wuf.merge(x, y, z);
        }
        else {
            ll x, y;
            cin >> x >> y;
            if (wuf.root(x) == wuf.root(y)) {
                cout << wuf.diff(x, y) << endl;
            }
            else {
                cout << "?" << endl;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 4412