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

vector<int> par;
vector<int> rnk;
vector<int> sze;

void makeSets(int n) {
    par.resize(n);
    rnk.resize(n);
    sze.resize(n);
    for(int i=0; i<n; i++) {
        par[i] = i;
        rnk[i] = 0;
        sze[i] = 1;
    }
}

int find(int x) {
    if(x != par[x]) par[x] = find(par[x]);
    return par[x];
}

void unite(int xp, int yp) {
    int x = find(xp);
    int y = find(yp);
    if(x == y) return;
    if(rnk[x] > rnk[y]) {
        sze[x] += sze[y];
        par[y] = x;
    } else {
        sze[y] += sze[x];
        par[x] = y;
    }
    if(rnk[x] == rnk[y]) rnk[y]++;
}

bool same(int x, int y) {
    return find(x) == find(y);
}

long long size(int x) {
    return (long long)sze[find(x)];
}


int main() {
    long long N,M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    for(int i=0; i<M; ++i) {
        cin >> A[i] >> B[i];
        --A[i];
        --B[i];
    }
 
    makeSets(N);
    vector<long long> res(M + 1);
    res[M] = N * (N - 1) / 2;
 
    for(int i=M-1; i>=1; --i) {
        if(same(A[i], B[i])) res[i] = res[i + 1];
        else res[i] = res[i + 1] - size(A[i]) * size(B[i]);
        unite(A[i], B[i]);
    }
 
    for(int i=1; i<=M; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 4096
/* Priyansh Agarwal*/
#include<bits/stdc++.h>
#include<algorithm>
#include<unordered_map>
#include<vector>
#include<unordered_set>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define nline "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define debug(x) cout << #x << " " << x <<endl;
#define set_bits __builtin_popcount
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod)
{ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
vector<int> sieve(int n) {int*arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
bool revsort(ll a, ll b) {return a > b;}
void swap(int &x, int &y) {int temp = x; x = y; y = temp;}
ll combination(ll n, ll r, ll m, ll* fact) {ll val1 = fact[n]; ll val2 = mminvprime(fact[r], m); ll val3 = mminvprime(fact[n - r], m); return ((val1 * val2) % m * val3) % m;}
/*--------------------------------------------------------------------------------------------------------------------------*/
int main()
{
	fastio();
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
	freopen("Error.txt", "w", stderr);
#endif
	ll *ans = new ll[100001]();
	for (int i = 1; i <= 100; i++)
	{
		for (int j = 1; j <= 100; j++)
		{
			for (int k = 1; k <= 100; k++)
			{
				ans[i * i + j * j + k * k + i * j + j * k + i * k]++;
			}
		}
	}
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 4392
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef pair<LL, LL> PII;
typedef vector<string> VS;
inline LL toInt(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(x,c) for(auto x: (c))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(c) (c).begin(), (c).end()
#define REVERSE(c) reverse(ALL(c))
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define STABLE_SORT(c) stable_sort(ALL(c))
#define STABLE_RSORT(c) stable_sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)), (c).end());
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x)  cerr << #x << " = " << (x) << endl;


int main() {
	LL N, M;
	cin >> N >> M;
	vector<PII> D;
	REP(i, N) {
		LL a, b;
		cin >> a >> b;
		D.PB(MP(a, b));
	}
	SORT(D);
	LL sum = 0;
	REP(i, N) {
		LL a = D[i].first;
		LL b = D[i].second;
		if (b <= M) {
			sum += a * b;
			M -= b;
		} else {
			sum += a * M;
			break;
		}
	}
	cout << sum << endl;
	
    return 0;
}


Measured memory_bytes: 2420
using System;

namespace ABC044A{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var N = sr.Next<int>();
            var K = sr.Next<int>();
            var X = sr.Next<int>();
            var Y = sr.Next<int>();

            if(N < K){
                Console.WriteLine(N * X);
            } else{
                Console.WriteLine(K * X + (N - K) * Y);
            }
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];
        private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = _sr.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

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

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

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, max = 0;
	cin >> n;
	vector< vector<int> > arr (2, vector<int>(n));
	for(int i = 0; i < n; i++) cin >> arr[0][i];
	for(int i = 0; i < n; i++) cin >> arr[1][i];

	for(int i = 0; i < n; i++) {
		int count = 0;
		for(int j = 0; j < n; j++) {
			if(i == j) {
				count += arr[0][j] + arr[1][j];
			} else if(j < i) {
				count += arr[0][j];
			} else if(i < j) {
				count += arr[1][j];
			}
		}
		if(max < count) max = count;
	}
	cout << max << 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++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long 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;
    }
 
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

ll N,A,B,C;
vector<ll> L(10);

ll dfs(ll ind, ll a, ll b, ll c){
    ll m = 1e18;
    if(a>0 && b>0 && c>0){
        m = abs(A-a) + abs(B-b) + abs(C-c);
    }
    if(ind == N) return m;
    cmin(m, dfs(ind+1, a + L[ind], b, c)+(a==0?0:10LL));
    cmin(m, dfs(ind+1, a, b + L[ind], c)+(b==0?0:10LL));
    cmin(m, dfs(ind+1, a, b, c + L[ind])+(c==0?0:10LL));
    cmin(m, dfs(ind+1, a, b, c));
    return m;
}

int main(){
    cin >> N >> A >> B >> C;
    rep(i,N){
        cin >> L[i];
    }
    cout << dfs(0,0,0,0) << endl;
}

Measured memory_bytes: 3640
// 

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if ((a + b) % 2 == 0) {
        cout << (a + b) / 2 << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	private static int N_MAX = 1000000;

	public static void main(String[] args){
		boolean[] sieve = new boolean[N_MAX];
		for (int i = 2; i < N_MAX; i++) {
			if (sieve[i] == false) {
				for (int j = i + i; j < N_MAX; j += i) {
					sieve[j] = true;
				}
			}
		}

		for (Scanner input = new Scanner(System.in); input.hasNextInt(); ) {
			int n = input.nextInt(), result = 0;
			for (int i = 2; i <= n; i++) {
				if (sieve[i] == false) {
					result++;
				}
			}
			System.out.println(result);
		}
	}
}

Measured memory_bytes: 13000
import math
k = int(input())
ans = 0
for a in range(1, k + 1):
    for b in range(a, k + 1):
        x = math.gcd(a, b)
        for c in range(b, k + 1):
            y = math.gcd(x, c)
            if a == b and b == c:
                ans += y
            elif a == b or b == c:
                ans += y * 3
            else:
                ans += y * 6
print(ans)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
const int N=105;
int n,a[N];
int main(void){
    scanf("%d",&n);
    int sum=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    int tmp=0;
    int ans=0x3f3f3f3f;
    for(int i=1;i<=n;i++){
        tmp+=a[i];
        ans=min(ans,abs(tmp-(sum-tmp)));
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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



int main(){
    string s;
    cin >> s;
    if(s=="SUN"){
        cout << 7 << endl;
    }
    if(s=="MON"){
        cout << 6 << endl;
    }
    if(s=="TUE"){
        cout << 5 << endl;
    }
    if(s=="WED"){
        cout << 4 << endl;
    }
    if(s=="THU"){
        cout << 3 << endl;
    }
    if(s=="FRI"){
        cout << 2 << endl;
    }
    if(s=="SAT"){
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dbg puts("It's Just Begining.Wait For The End!!!!!\n")
#define CHECK(x) cout << (#x) << " is " << (x) <<"\n";
#define endl printf("\n")
typedef pair<ll,ll> pii;
#define pb push_back
#define ms(a,b) memset(a, b, sizeof(a))
#define in(x) scanf("%lld",&x)
#define out(x) printf("%lld",x)
#define X first
#define Y second
#define sps printf(" ")
#define dou(x) cout<<fixed<<setprecision(6)<<x
#define all(v) v.begin(),v.end()
#define dis(it,it1) distance(it,it1)+1
#define MAX 200005
#define INF 1000000000
#define MOD 1000000007
#define print(cs) printf("Case %lld: ",cs)
#define Yesno(ok) if(ok)puts("YES");else puts("NO")
#define yesno(ok) if(ok)puts("Yes");else puts("No")
ll lcm(ll a,ll b)
{
    return ((a*b)/__gcd(a,b));
}
int main()
{
    ll test=1;
    while(test--)
    {
        ll i,j,k,l,n,m,r;
        in(n);in(l);in(r);
        l=ceil(n/(double)l);
        r*=l;
        cout<<r;endl;
    }
}


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

namespace _0038
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string s = Console.ReadLine();
                if (s == null)
                {
                    break;
                }
                int[] x = s.Split(',').Select(int.Parse).ToArray();
                Array.Sort(x);
                bool a = true;
                if (x[0] == x[3] || x[1] == x[4])
                {
                    Console.WriteLine("four card");
                }
                else if ((x[0] == x[2] && x[3] == x[4]) || (x[0] == x[1] && x[2] == x[4]))
                {
                    Console.WriteLine("full house");
                }
                else if (x[0] == 1 && x[1] == 10 && x[2] == 11 && x[3] == 12 && x[4] == 13)
                {
                    Console.WriteLine("straight");
                }
                else if (x[0] == x[2] || x[1] == x[3] || x[2] == x[4])
                {
                    Console.WriteLine("three card");
                }
                else if ((x[0] == x[1] && x[2] == x[3]) || (x[0] == x[1] && x[3] == x[4]) || (x[1] == x[2] && x[3] == x[4]))
                {
                    Console.WriteLine("two pair");
                }
                else if (x[0] == x[1] || x[1] == x[2] || x[2] == x[3] || x[3] == x[4])
                {
                    Console.WriteLine("one pair");
                }
                else if (a)
                {
                    a = false;
                    for (int i = 0; i < 10; i++)
                    {
                        bool flag = true;
                        for (int j = 0; j < 5; j++)
                        {
                            if (x[j] != i + j)
                            {
                                flag = false;
                            }
                        }
                        if (flag)
                        {
                            Console.WriteLine("straight");
                            a = true;
                        }
                    }
                    if (!a)
                    {
                        Console.WriteLine("null");
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 9416
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

int N;

void func(){

	char buf[20];
	int low = - 1500000000,high = 1500000000,tmp,pre = BIG_NUM;
	bool FLG = true;

	for(int i = 1; i <= N; i++){
		scanf("%s",buf);

		if(buf[0] == 'x'){

			if(pre == BIG_NUM){
				if(i != 1){
					FLG = false;
				}else{
					//Do nothing
				}
			}else{

				if(i%2 == 0){
					low = max(low,pre+1);
					if(low > high){
						FLG = false;
					}
				}else{
					high = min(high,pre-1);
					if(low > high){
						FLG = false;
					}
				}
			}
			pre = BIG_NUM;
		}else{
			tmp = 0;
			if(buf[0] == '-'){
				for(int k = 1; buf[k] != '\0'; k++){
					tmp = 10*tmp + buf[k] - '0';
				}
				tmp *= -1;
			}else{
				for(int k = 0; buf[k] != '\0'; k++){
					tmp = 10*tmp + buf[k] - '0';
				}
			}
			if(i > 1 && pre == BIG_NUM){

				if(i%2 == 0){
					high = min(high,tmp-1);
					if(low > high){
						FLG = false;
					}
				}else{
					low = max(low,tmp+1);
					if(low > high){
						FLG = false;
					}
				}
			}else{ //i == 1 || pre != BIG_NUM

				if(i != 1){
					if(i % 2 == 0){
						if(tmp <= pre)FLG = false;
					}else{
						if(tmp >= pre)FLG = false;
					}
				}
			}
			pre = tmp;
		}
	}

	if(!FLG)printf("none\n");
	else{
		if(low == high){
			printf("%d\n",low);
		}else{
			printf("ambiguous\n");
		}
	}

}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

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

int main() {
  string s;
  cin >> s;
  string res;
  for (char c : s) {
    if (c == 'B') {
      if (not res.empty()) {
        res.pop_back();
      }
    } else {
      res += c;
    }
  }
  cout << res << '\n';
}


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

struct P
{
    int x,y,z;

    bool operator<(const P &a)const{
              return x>a.x;
    }

};

vector<P> v[101103];
//bitset<4001000> b;
int a,c,i,b,k,n,d,m;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
long long o[100130];
long long l[101103];
int j[101130];
int e[110];
int dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long x,y,mod=998244353;
long long z;
double pi=3.14159265;
P u[10600];
stack<int> s;

//set<int> s;
queue<int> q;

//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p,p1;
//list<int> l;

string r;
//char r[133];
//deque<int> de;
bool as(P a,P b)
{
    if(o[a.x]!=o[b.x])
    return o[a.x]<o[b.x];
    return a.y<b.y;
}


int main()
{
    scanf("%d %d %d %d",&a,&b,&c,&d);
    for(int t=1;t<=b;t++)
    {
        scanf("%d %d %d %d",&n,&m,&i,&k);
        v[n].push_back({m,i,k});
        v[m].push_back({n,i,k});
    }
    memset(o,-1,sizeof(o));
    memset(l,-1,sizeof(l));
    q.push(c);
    j[c]=1;
    o[c]=0;
    for(;q.size();j[q.front()]=0,q.pop())
    for(int h=0;h<v[q.front()].size();h++)
    if(o[v[q.front()][h].x]<0||o[v[q.front()][h].x]>o[q.front()]+v[q.front()][h].y)
    {
        o[v[q.front()][h].x]=o[q.front()]+v[q.front()][h].y;
        if(!j[v[q.front()][h].x])
        {
            j[v[q.front()][h].x]=1;
            q.push(v[q.front()][h].x);
        }
    }


    q.push(d);
    j[d]=1;
    l[d]=0;
    for(;q.size();j[q.front()]=0,q.pop())
    for(int h=0;h<v[q.front()].size();h++)
    if(l[v[q.front()][h].x]<0||l[v[q.front()][h].x]>l[q.front()]+v[q.front()][h].z)
    {
        l[v[q.front()][h].x]=l[q.front()]+v[q.front()][h].z;
        if(!j[v[q.front()][h].x])
        {
            j[v[q.front()][h].x]=1;
            q.push(v[q.front()][h].x);
        }
    }
    for(int t=1;t<=a;t++)
        o[t]+=l[t];
    for(int t=a-1;t>0;t--)
        o[t]=min(o[t],o[t+1]);
    for(int t=1;t<=a;t++)
        printf("%lld\n",1000000000000000-o[t]);
}


Measured memory_bytes: 10368
import math
from functools import reduce
K = int(input())
ans = 0
for i in range(1, K-1):
    for j in range(i+1, K):
        for k in range(j+1, K+1):
            n = math.gcd(i, math.gcd(j,k))
            ans += 6*n
for i in range(1, K+1):
    for j in range(i+1, K+1):
        n = math.gcd(i,j)
        ans += 6*n
print(ans+sum(list(i for i in range(K+1))))

Measured memory_bytes: 9536
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    SC = [il() for _ in range(M)]
    mx = pow(10, N)

    for n in range(0, mx):
        if len(str(n)) != N: continue
        isSC = True
        for s, c in SC:
            if str(n)[s - 1] != str(c):
                isSC = False

        if isSC:
            print(n)
            exit()

    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder.AISing
{
    class D
    {
        private static int Popcount(int x)
        {
            x = (x & 0x55555555) + (x >> 1 & 0x55555555);
            x = (x & 0x33333333) + (x >> 2 & 0x33333333);
            x = (x & 0x0f0f0f0f) + (x >> 4 & 0x0f0f0f0f);
            x = (x & 0x00ff00ff) + (x >> 8 & 0x00ff00ff);
            return (x & 0x0000ffff) + (x >> 16 & 0x0000ffff);
        }


        public static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var x = Console.ReadLine();

            var bitN = x.Count(c => c == '1');
            if (bitN == 0)
            {
                for (int i = 0; i < n; i++)
                    Console.WriteLine(1);
                return;
            }
            if (bitN == 1)
            {
                if (x[n - 1] == '1')
                {
                    for (int i = 0; i < n - 1; i++)
                        Console.WriteLine(2);
                    Console.WriteLine(0);
                }
                else
                {
                    for (int i = 0; i < n - 1; i++)
                        if (x[i] == '1')
                            Console.WriteLine(0);
                        else
                            Console.WriteLine(1);
                    Console.WriteLine(2);
                }
                return;
            }

            int xmodp = 0;
            int xmodm = 0;
            for (int i = 0; i < n; i++)
            {
                xmodp = ((xmodp << 1) + x[i] - '0') % (bitN + 1);
                xmodm = ((xmodm << 1) + x[i] - '0') % (bitN - 1);
            }

            var diffp = new int[n];
            var diffm = new int[n];
            diffp[n - 1] = 1 % (bitN + 1);
            diffm[n - 1] = 1 % (bitN - 1);
            for (int i = n - 1; i > 0; i--)
            {
                diffp[i - 1] = (diffp[i] << 1) % (bitN + 1);
                diffm[i - 1] = (diffm[i] << 1) % (bitN - 1);
            }

            for (int i = 0; i < n; i++)
            {
                int y;
                if (x[i] == '1')
                    y = (xmodm - diffm[i] + (bitN - 1)) % (bitN - 1);
                else
                    y = (xmodp + diffp[i] + (bitN + 1)) % (bitN + 1);
                Console.WriteLine(CalcF(y) + 1);
            }
        }
        
        static int CalcF(int x)
        {
            int n = 0;
            while (x > 0)
            {
                x %= Popcount(x);
                n++;
            }
            return n;
        }
    }
}


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

#define int long long

struct Combination {
  int mod; // e.g. 1000000007
  vector<int> fact; // factorial
  vector<int> invf; // inverse factorial
  vector<vector<int> > part; // partition number

  /*
    constructor : O(sz+log(mod))   
    make factorial table (fact) and inverse factorial table (invf)
  */
  Combination(int sz, int mod) : fact(sz+1), invf(sz+1), mod(mod) {
    fact[0] = 1;
    for ( int i = 1; i < (int)fact.size(); i++ ) {
      fact[i] = fact[i-1]*i%mod;
    }
    invf[sz] = inv(fact[sz]);
    for ( int i = sz-1; i >= 0; i-- ) {
      invf[i] = invf[i+1]*(i+1)%mod;
    }
  }

  int pow(int x, int n) const {
    int ret = 1;
    while ( n > 0 ) {
      if ( n & 1 ) (ret *= x) %= mod;
      (x *= x) %= mod;
      n >>= 1;
    }
    return ret;
  }

  int inv(int x) const {
    return pow(x, mod - 2);
  }

  /*
    permutation
  */
  int P(int n, int r) const {
    if ( r < 0 || n < r ) return (0);
    return fact[n]*invf[n-r]%mod;    
  }

  /*
    combination
  */
  int C(int n, int r) const {
    if ( r < 0 || n < r ) return (0);    
    return fact[n]*invf[r]%mod*invf[n-r]%mod;    
  }  

  /*
    combination with repetition
  */
  int H(int n, int r) const {
    if ( n < 0 || r < 0 ) return 0;
    if ( n == 0 && r == 0 ) return 1;
    return C(n+r-1, n);    
  }

  /*
    stirling number
  */
  int S(int n, int r) const {
    int ret = 0;
    for ( int i = 1; i <= r; i++ ) {
      int add = C(r, i)*pow(i, n)%mod;      
      if ( (r-i)&1 ) ret += mod-add;
      else ret += add;
      ret %= mod;      
    }
    (ret *= invf[r]) %= mod;
    return ret;
  }

  /*
    bell number
  */
  int B(int n, int r) const {
    int ret = 0;
    for ( int i = 1; i <= r; i++ ) {
      (ret += S(n, i)) %= mod;      
    }
    return ret;
  }

  /*
    calc partition number
    return and make partition number table (part)
  */
  vector<vector<int> > built_part(int n, int r) {
    part = vector<vector<int> >(n+1, vector<int>(r+1, 0));
    part[0][0] = 1;
    for ( int i = 0; i <= n; i++ ) {
      for ( int j = 1; j <= r; j++ ) {
	if ( i-j >= 0 ) {
	  (part[i][j] = part[i][j-1]+part[i-j][j]) %= mod;	  
	} else {
	  part[i][j] = part[i][j-1];
	}
      }
    }
    return part;    
  }
};

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

  int N, M, K;
  cin >> N >> M >> K;

  int MOD = 1e9+7;  
  Combination comb(200001, MOD);
  int ans = 0;
  
  for ( int i = 1; i < N; i++ ) {
    ans += (N-i)*M%MOD*M%MOD*i;    
    ans %= MOD;    
  }

  for ( int i = 1; i < M; i++ ) {
    ans += (M-i)*N%MOD*N%MOD*i;
    ans %= MOD;
  }

  ans *= comb.C(N*M-2, K-2);

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


Measured memory_bytes: 3328
dp = [1] * (10**5 + 1)
dp[2] = 2
for i in range(3, 10**5+1):
    dp[i] = (dp[i-1] + dp[i-2]) % 1000000007

n, m = map(int, input().split())
start = 0
res = 1
for i in range(m):
    nex = int(input())
    if nex == start:
        res = 0
        break
    res = (res * dp[(nex-1)-start]) % 1000000007
    #print('res :', res)
    start = nex + 1
else:
    res = (res * dp[n - start]) % 1000000007
    #print('res :', res)
print(res)

Measured memory_bytes: 6900
using System;
using System.Collections.Generic;
using System.Linq;

public static partial class Program
{
    public static void Main()
    {
        var xyzk = CRL().ArrayLongs();
        var x = xyzk[0];
        var y = xyzk[1];
        var z = xyzk[2];
        var k = xyzk[3];
        var axis = CRL().ArrayLongs().Sort();
        var bxis = CRL().ArrayLongs().Sort();
        var cxis = CRL().ArrayLongs().Sort();

        var list = new List<long>();
        for (int i = 0; i < x; i++)
        {
            for (int j = 0; j < y; j++)
            {
                list.Add(axis[i] + bxis[j]);
            }
        }

        list.Sort();
        list.Reverse();

        var result = new List<long>();
        for (int i = 0; i < Math.Min(k, list.Count); i++)
        {
            for (int j = 0; j < z; j++)
            {
                result.Add(list[i] + cxis[j]);
            }
        }

        result.Sort();
        result.Reverse();
        for (int i = 0; i < k; i++)
        {
            CWL(result[i]);
        }
    }
}

public static partial class Program
{
    //テンプレここから
    private static long ToInt(this string str) => long.Parse(str);
    private static long[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray();
    public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToInt();
    public static string CRL() => Console.ReadLine();
    public static void CWL(object obj) => Console.WriteLine(obj);
    public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static long Sign(this long i) => Math.Sign(i);
    public static bool IsEven(this long i) => i % 2 == 0;
    public static bool IsEven(this int i) => i % 2 == 0;
    public static long[] dx = new long[] { 0, -1, 0, 1 };
    public static long[] dy = new long[] { -1, 0, 1, 0 };
    public static long mod = 1000000007;
    public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
    public static long ToLong(this char c) => c.ToString().ToInt();
    public static long[] Sort(this long[] array)
    {
        var list = array.ToList();
        list.Sort();
        return list.ToArray();
    }
    public static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b);
    public static long LCM(long a, long b) => a * b / GCD(a, b);
    //テンプレここまで
}


Measured memory_bytes: 63388
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String a = sc.next(), b = sc.next(), c = sc.next();
        int ans  = 0;

        for(int i = 0; i < n; i++){
            char x = a.charAt(i);
            char y = b.charAt(i);
            char z = c.charAt(i);

            if(x == y && y == z) continue;
            else if(x == y || y == z || z == x) ans++;
            else ans += 2;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
n, m = map(int, input().split())
li_swich = [[0]*n for _ in range(m)]
li_k = []
for i in range(m):
    k, *swich = map(int, input().split())
    for j in swich:
        li_swich[i][j-1] = 1
li_p = [int(x) for x in input().split()]
#すべてのすいっちについて考える
how_many = 0
for i in range(1<< n):
    b = True
    for k in range(len(li_swich)):
        count = 0
        li = li_swich[k]
        for j in range(len(li)):
            if (i>>j)&1:
                count += li[j]
        if count%2  != li_p[k]:
            b = False
    if b:
        how_many += 1

print(how_many)

Measured memory_bytes: 41672
#include <stdio.h>
// dirtyW

int main(void){
	int h,m,s;
	int H,M,S;
	int i;
	for(i=0;i<3;i++){
		scanf("%d%d%d%d%d%d", &h, &m, &s, &H, &M, &S);
		S -= s;
		if(S<0){
			S+=60, M--;
		}
		M -= m;
		if(M<0){
			M+=60, H--;
		}
		H -= h;
		printf("%d %d %d\n", H, M, S);
	}
	return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

vector<int> ball;
vector<int> A;
vector<int> B;
bool flag;

void solve(int i){
	if(flag == true) return;
	if(i == 10){
		for(int i = 1; i < A.size(); ++i){
			if(A[i - 1] > A[i]){
				return;
			}
		}
		for(int i = 1; i < B.size(); ++i){
			if(B[i - 1] > B[i]){
				return;
			}
		}
		flag = true;
	} else {
		A.push_back(ball[i]);
		solve(i + 1);
		A.pop_back();
		
		B.push_back(ball[i]);
		solve(i + 1);
		B.pop_back();
	}
}

int main(){
	int T; scanf("%d", &T);
	while(T--){
		ball.clear();
		for(int i = 0; i < 10; ++i){
			int digit; scanf("%d", &digit);
			ball.push_back(digit);
		}
	
		flag = false;
		solve(0);
		printf(flag ? "YES\n" : "NO\n");
	}
}


Measured memory_bytes: 2672
#ifndef _WIN32
#include<iostream>
#endif 
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<tuple>
#include<complex>
#include<queue>
#include<functional>
using namespace std;
typedef long long LL;
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
template<typename T> bool chmin(T &l, T r) {
	bool res = l > r;
	if (res) {
		l = r;
	}
	return res;
}
#define IL inline
#define X real()
#define Y imag()
#define fi first
#define se second
typedef complex<double> P;
typedef pair<P, P> LS;
typedef bool B;
typedef double D;
const D EPS = 1e-8;
IL D dot(P a, P b) {
	return a.X*b.X + a.Y*b.Y;
}
IL D cross(P a, P b) {
	return a.X*b.Y - a.Y*b.X;
}
IL int sgn(P a, P b, P c) {
	if (cross(b - a, c - a) > EPS)return 1;
	if (cross(b - a, c - a) < -EPS)return -1;
	if (dot(b - a, c - a) < -EPS)return 2; // b-a-c
	if (dot(a - b, c - b) < -EPS)return -2; // a-b-c
	return 0;
}



struct cww {
	cww() {
		cout << fixed;
		cout << setprecision(10);
	}
}star;

IL D distance_P_LS(P p, LS ls) {
	P a, b, c = p;
	tie(a, b) = ls;
	if (dot(b - a, c - a) < EPS)return abs(c - a);
	if (dot(a - b, c - b) < EPS)return abs(c - b);
	return abs(cross(b - a, c - a)) / abs(b - a);
}
IL B is_LS_LS(LS p, LS q) {
	P a, b, c, d;
	tie(a, b) = p;
	tie(c, d) = q;
	return sgn(a, b, c)*sgn(a, b, d) <= 0
		&& sgn(c, d, a)*sgn(c, d, b) <= 0;
}

IL D distance_LS_LS(LS p, LS q) {
	if (is_LS_LS(p,q))return 0;
	return min({
		distance_P_LS(p.fi,q),
		distance_P_LS(p.se,q),
		distance_P_LS(q.fi,p),
		distance_P_LS(q.se,p)
	});
}

P rot(P p, double r) {
	return P(p.X*cos(r) - p.Y*sin(r), p.X*sin(r) + p.Y*cos(r));
}

const D PI = acos(-1);
const D FI = 72.0 / 180.0*PI;
typedef pair<double, int> pp;
const int ss[][2] = { { 0,2 },{ 0,3 },{ 1,3 },{ 1,4 },{ 2,4 } };
typedef priority_queue<pp, vector<pp>, greater<pp>> QUE;
int main() {
	int N, M, L;
	while (cin >> N >> M >> L, N) {
		vector<LS> ls(5 * N);
		REP(i, N) {
			double x, y, a, r;
			cin >> x >> y >> a >> r;
			P p(x, y);
			vector<P> pt(5);
			pt[0] = rot(P(0, r), a / 180.0*PI);
			REP(i, 4)pt[i + 1] = rot(pt[i], FI);
			REP(j, 5) {
				ls[i * 5 + j] = LS(p + pt[ss[j][0]], p + pt[ss[j][1]]);
			}
		}
		vector<vector<double>> dist(N * 5, vector<double>(N * 5));
		REP(i, 5 * N)REP(j, 5 * N) {
			if (i == j)dist[i][j] = 0;
			else dist[i][j] = distance_LS_LS(ls[i], ls[j]);
		}
		int S = 5 * (M - 1);
		int G = 5 * (L - 1);





		vector<double> res(N * 5, 1e18);
		res[S] = 0;
		QUE que;
		que.push(pp(0, S));
		while (que.size()) {
			int v; double cost;
			tie(cost, v) = que.top();
			que.pop();
			if (cost > res[v])continue;
			REP(u, 5 * N) if (u != v) {
				double ncost = cost + dist[u][v];
				if (chmin(res[u], ncost))que.push(pp(ncost, u));
			}
		}
		cout << res[G] << endl;
	}
	return 0;
}

Measured memory_bytes: 5424
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{

    int N,K;
    cin >> N >> K;
    int ans = 1;
    for(int i=0; i<N; i++)
    {
    	ans = min(ans*2, ans+K);
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	if(N == 3){
		cout << 2 << endl;
		cout << 1 << ' ' << 3 << endl;
		cout << 2 << ' ' << 3 << endl;
	}
	else if(N == 4){
		cout << 4 << endl;
		cout << 1 << ' ' << 2 << endl;
		cout << 1 << ' ' << 3 << endl;
		cout << 2 << ' ' << 4 << endl;
		cout << 3 << ' ' << 4 << endl;
	}
	else if(N % 2 == 0){
		int M = 4 * N / 2;
		cout << M << endl;
		int T = N/2;
		for(int i=1;i<=T;i++){
			if(i==1){
				cout << i << ' ' << T << endl;
				cout << i << ' ' << T+1 << endl;
				cout << N+1-i << ' ' << T << endl;
				cout << N+1-i << ' ' << T+1 << endl;
			}
			else{
				cout << i << ' ' << i-1 << endl;
				cout << i << ' ' << (N+1)-(i-1) << endl;
				cout << N+1-i << ' ' << i-1 << endl;
				cout << N+1-i << ' ' << (N+1)-(i-1) << endl;
			}
		}
	}
	else{
		int M = N / 2 * 4;
		cout << M << endl;
		int T = N/2;
		for(int i=1;i<=T;i++){
			if(i==1){
				cout << i << ' ' << N << endl;
				cout << N-i << ' ' << N << endl;
			}
			else{
				cout << i << ' ' << i-1 << endl;
				cout << i << ' ' << N-(i-1) << endl;
				cout << N-i << ' ' << i-1 << endl;
				cout << N-i << ' ' << N-(i-1) << endl;
			}
		}
		cout << N << ' ' << T << endl;
		cout << N << ' ' << T+1 << endl;
	}

}

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

namespace org
{
    template <class T>
    T make_value()
    {
        T tmp;
        return tmp;
    }

    template <class T>
    T VALUE()
    {
        T tmp;
        std::cin >> tmp;
        return tmp;
    }

    template <class T>
    std::vector<T> make_vector(long long size)
    {
        std::vector<T> tmp(size);
        return tmp;
    }

    template <class T>
    std::vector<T> VECTOR(long long size)
    {
        auto tmp = make_vector<T>(size);
        for (long long i = 0; i < tmp.size(); i++)
        {
            std::cin >> tmp.at(i);
        }
        return tmp;
    }

    template <class T>
    std::vector<std::vector<T>> make_matrix(long long line, long long row)
    {
        std::vector<std::vector<T>> tmp;
        tmp.resize(line);
        for (long long i = 0; i < tmp.size(); i++)
        {
            tmp.at(i).resize(row);
        }
        return tmp;
    }

    template <class T>
    std::vector<std::vector<T>> MATRIX(long long line, long long row)
    {
        auto tmp = make_matrix<T>(line, row);
        for (long long i = 0; i < tmp.size(); i++)
        {
            for (long long j = 0; j < tmp.at(0).size(); j++)
            {
                std::cin >> tmp.at(i).at(j);
            }
        }
        return tmp;
    }

    template <class T>
    bool find(std::vector<T> vec, T value)
    {
        for (long long i = 0; i < vec.size(); i++)
        {
            if (vec.at(i) == value)
            {
                return 1;
            }
        }
        return 0;
    }

} // namespace org

std::ostream &operator<<(std::ostream &os, const std::vector<long long> vec)
{
    for (long long i = 0; i < vec.size(); i++)
    {
        os << vec.at(i) << " ";
    }
    return os;
}

std::ostream &operator<<(std::ostream &os, const std::vector<std::vector<long long>> vec)
{
    for (long long i = 0; i < vec.size(); i++)
    {
        for (long long j = 0; j < vec.at(0).size(); j++)
        {
            os << vec.at(i).at(j) << " ";
        }
        os << std::endl;
    }
    return os;
}

using ll = long long;
using namespace std;

using org::MATRIX;
using org::VECTOR;
#define VEC(name, size, type) auto name = org::VECTOR<type>(size)
#define MAT(name, line, row, type) auto name = org::MATRIX<type>(line, row)
#define llV(name, size) VEC(name, size, long long)
#define stV(name, size) VEC(name, size, std::string)
#define llM(name, line, row) MAT(name, line, row, long long)
#define stM(name, line, row) MAT(name, line, row, std::string)
#define ll(name) auto name = org::VALUE<long long>()

#define rep1(max1) for (long long i = 0; i < max1; i++)
#define rep2(max1, max2)                 \
    for (long long i = 0; i < max1; i++) \
        for (long long j = 0; j < max1; j++)

int main()
{
    ll(X);
    ll(N);
    llV(p, N);
    ll i = 0;
    ll j = 0;
    while (org::find(p, X + i))
        i++;
    while (org::find(p, X - j))
        j++;

    if (i >= j)
    {
        cout << X - j << endl;
    }
    else
    {
        cout << X + i << endl;
    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 2147483647;
int prime = 998244353;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);
double PI = 3.14159265358979;
int n;
bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0){
            return false;
        }
    }
    return true;
}

signed main(){
    cin >> n;
    int tmp = 11;
    REP(i,n){
        while(!IsPrime(tmp)) tmp += 5;
        cout << tmp << " ";
        tmp += 10;
    }
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    int A,B,X,Y,Z,max;

    cin >> A >> B;

    X=A+B;
    Y=A-B;
    Z=A*B;

    max=X;
    if(Y>max)max=Y;
    if(Z>max)max=Z;

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i,x,n;
	
	scanf("%d",&n);
	
	for(i=1;i<=n;i++)
	{
		x = i;
		if(x % 3 == 0)
			printf(" %d",i);
		else if(x % 10 == 3)
			printf(" %d",i);
		else
		{
			while( (x /= 10) > 0)
			{
				if(x % 10 == 3)
				{
					printf(" %d",i);
					break;
				}
			}
		}
		
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 600
from collections import deque
import sys
input = sys.stdin.readline

INF = float('inf')

def BellmanFord(adjList, vSt, INF):
    numV = len(adjList)
    negINF = -INF
    costs = [INF] * numV
    costs[vSt] = 0
    vNows = set([vSt])

    for _ in range(numV):
        vChangeds = set()
        for vFr in vNows:
            costFr = costs[vFr]
            for vTo, wt in adjList[vFr]:
                c2 = costFr + wt
                if c2 < costs[vTo]:
                    costs[vTo] = c2
                    vChangeds.add(vTo)
        if not vChangeds:
            return costs
        vNows = vChangeds

    for v in vNows:
        costs[v] = negINF

    Q = deque(vNows)
    while Q:
        vFr = Q.popleft()
        for vTo, wt in adjList[vFr]:
            if costs[vTo] == negINF: continue
            costs[vTo] = negINF
            Q.append(vTo)

    return costs


N, M, P = map(int, input().split())
adjL = [[] for _ in range(N)]
for _ in range(M):
    A, B, C = map(int, input().split())
    A, B = A-1, B-1
    adjL[A].append((B, -C+P))

costs = BellmanFord(adjL, 0, INF)

ans = costs[N-1]
if ans == -INF:
    print(-1)
else:
    print(max(0, -ans))


Measured memory_bytes: 73180
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static final int X = 0;
	public static final int Y = 1;
	public static final int A = 0;
	public static final int B = 1;
	public static final int C = 2;
	public static final int D = 3;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		doIt();

	}
	public static void doIt(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String s = sc.next();
			String[] ss = s.split(",");
			double[][] pos = new double[4][2];
			for(int i = 0; i < 4; i++){
				pos[i][X] = Double.parseDouble(ss[2*i]);
				pos[i][Y] = Double.parseDouble(ss[2*i + 1]);
			}
			boolean bOK = calc(pos[A], pos[B], pos[C], pos[D]);
			bOK &= calc(pos[B], pos[C], pos[D], pos[A]);
			//bOK &= calc(pos[C], pos[D], pos[A], pos[B]);
			//bOK &= calc(pos[D], pos[A], pos[B], pos[C]);
			if(bOK){
				System.out.println("YES");
			}
			else{
				System.out.println("NO");
			}
		}
	}
	
	//tAC = AB + sBDよりtを出して、t < 1ならfalse
	public static boolean calc(double[] a, double[] b, double[] c, double[] d){
		//Aを原点にする
		double[] b0 = new double[2];
		double[] c0 = new double[2];
		double[] d0 = new double[2];
		double[] bd = new double[2];
		for(int i = 0; i < 2; i++){
			b0[i] = b[i] - a[i];
			c0[i] = c[i] - a[i];
			d0[i] = d[i] - a[i];
			bd[i] = d0[i] - b0[i];
		}
		//これは嘘！
//		if(c0[X] == 0 || c0[Y] == 0){
//			return true;
//		}
		double t = 0;
		if(bd[X] == 0){
			t = b0[X] / c0[X];
		}
		else if(bd[Y] == 0){
			t = b0[Y] / c0[Y];
		}
		else{
			t = (b0[X] * bd[Y] - b0[Y] * bd[X]) / (c0[X] * bd[Y] - c0[Y] * bd[X]);
		}
		//System.out.println(t);
		if(t > 1 || t < 0){
			return false;
		}
		else{
			return true;
		}
	}
}

Measured memory_bytes: 12000
#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 Graph = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

    int h,w;
    cin>>h>>w;
    char maze[h][w];
    vector<vector<int>>black(h,vector<int>(w,-1));
    queue<p>que;
    rep(i,h){
        rep(j,w){
            cin>>maze[i][j];
            if(maze[i][j]=='#'){
                que.emplace(i,j);
                black[i][j]=0;
            }
        }
    }
    int ans=0;
    while(!que.empty()){
        int x,y;
        tie(y,x)=que.front();
        que.pop();
        ans=black[y][x];
        rep(i,4){
            int a=x+dx[i];
            int b=y+dy[i];
            if(a<0||a>=w||b<0||b>=h)continue;
            if(black[b][a]!=-1)continue;
            black[b][a]=black[y][x]+1;
            que.emplace(b,a);
        }
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 16192
#include <iostream>

using namespace std;

long N, ans;

void fn(int d, long x) {
  if (x > N) return; 
  bool t = false, f = false, s = false;
  long xx = x;
  while (xx > 0) {
    if (xx % 10 == 3) t = true;
    else if (xx % 10 == 5) f = true;
    else if (xx % 10 == 7) s = true;
    xx /= 10;
  }
  if (t && f && s) {
    ++ans;
  }
  if (d > 0) {
    fn(d - 1, 10 * x + 3); 
    fn(d - 1, 10 * x + 5); 
    fn(d - 1, 10 * x + 7); 
  }
} 

int main() {
  cin >> N;
  ans = 0;
  fn(10, 0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void run(){
		int n = sc.nextInt();
		for(int i =0; i < n;i++){
			BigInteger bi1 = new BigInteger(sc.next());
			BigInteger bi2 = new BigInteger(sc.next());
			BigInteger ans = bi1.add(bi2);
			if(ans.toString().length() > 80){
				System.out.println("overflow");
			}else{
				System.out.println(ans);
			}
		}
		
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
		
	}
}

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

//create arrays outside of main()
int a[300000] = {};

int main()
{
    int n;

    cin >> n;

    for (int i = 0; i < (3 * n); i++)
    {
        cin >> a[i];
    }

    sort(a, a + (3 * n));

    long long sum = 0;

    for (int i = n; i < (3 * n); i += 2)
    {
        sum += a[i];
    }

    cout << sum;

    return 0;
}

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--)
#define TR(X)                                                  \
    ({                                                         \
        if (1) cerr << "TR: " << (#X) << " = " << (X) << endl; \
    })
#define LL(name) \
    ll name;           \
    cin >> name;
#define VL(name, num) \
    vl name(num);           \
    FOR(INPUT_VL_I, 0, num) { cin >> name[INPUT_VL_I]; }

int main() { cin.sync_with_stdio(0);
    LL(N);
    LL(M);
    VL(H, N);
    vl good(N, 1);

    FOR(i, 0, M) {
        LL(A);
        LL(B);

        A--, B--;
        if (H[A] >= H[B]) good[B] = false;
        if (H[A] <= H[B]) good[A] = false;
    }

    cout << accumulate(all(good), 0ll) << endl;
}  // cin.tie(0) bei schnellem Wechseln


Measured memory_bytes: 4816