akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define INFTY 1000000001
int N,n[500000],i,j,k,C=0;
int n1,n2,Lf[500000],Rf[500000];

void merge (int L,int M,int R){
	n1= M-L;
	n2= R-M;
	for (i=0;i<n1;i++){
		Lf[i]=n[L+i];
//		printf("%d",Lf[i]);
	}
	for (i=0;i<n2;i++){
		Rf[i]=n[M+i];
//		printf("%d",Rf[i]);
	}
	Lf[n1]=INFTY;
	Rf[n2]=INFTY;
	i=0;
	j=0;
	for (k=L;k<R;k++){
		if (Lf[i]<Rf[j]){
			n[k]=Lf[i];
//			printf("\n%d",n[k]);
			i=i+1;
		}else{
			n[k]=Rf[j];
//			printf("\n%d",n[k]);
			j=j+1;
		}
		C++;
	}
}


void mergeSort(int L,int R){
	if (L+1<R){
		int M;
		M=(L+R)/2;
		mergeSort(L,M);
		mergeSort(M,R);
		merge(L,M,R);
	}
}

int main(void){


	scanf("%d\n",&N);
	for (i=0;i<N;i++){
		scanf("%d",&n[i]);
	}
	mergeSort(0,N);

	for (i=0;i<N;i++){
		printf("%d",n[i]);
		if (i!=N-1){
			printf(" ");
		}
	}
	printf("\n");
	printf("%d\n",C);
	return 0;
}

Measured memory_bytes: 5488
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


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

    ll n,m;
    cin >> n >> m;
    ll a[n][m];
    ll temp;
    F0R(i,n){
      ll t;
      cin >> t;
      ll temp[t];
      F0R(j,m){
          a[i][j] = 0;
      }
      F0R(j,t){
        cin >> temp[j];
        temp[j]--;
        a[i][temp[j]] = 1;
      }
    }
    ll ans = 0;
    F0R(i,m){
      ll cool = true;
      F0R(j,n){
        if(a[j][i] == 0) cool = false;
      }
      if(cool) ans++;
    }

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

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); // ボールの数
		int[] A = new int[N]; // ボールの値
		TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
		int max = 0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			max = Math.max(max, A[i]);
			// 各数値の重複を数えてmapに入れる
			if (map.containsKey(A[i])) {
				int cnt = map.get(A[i]);
				map.put(A[i], cnt + 1);
			} else {
				map.put(A[i], 1);
			}
		}
		sc.close();

		long ans = 0;
		for (int i = 0; i <= max; i++) {
			// カウントがない場合は見ない
			if (!map.containsKey(i)) {
				continue;
			}
			// 重複を取り出す組み合わせを計算
			long c = map.get(i);
			ans += c * (c - 1l) / 2l;
		}

		for (int i = 0; i < N; i++) {
			// i番目を引く
			long cnt = map.get(A[i]);
			// diffを計算
			long d = cnt - 1l;
			System.out.println(ans - d);
		}
	}
}


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

using namespace std;

typedef long long ll;

ll MOD = 1000000007;

int main(int, char**) {
        int n;
        cin >> n;
        map<string, int> mp;
        int x = 0;
        for (int i=0; i<n; i++) {
                string s;
                cin >> s;
                mp[s] += 1;
                if (mp[s] > x) x = mp[s];
        }
        vector<string> ans;
        for (auto i=mp.begin(); i!=mp.end(); ++i){
                if (i->second == x) ans.push_back(i->first);
        }
        sort(ans.begin(), ans.end());
        for (auto i:ans) cout << i << endl;
        return 0;
}


Measured memory_bytes: 27636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  cin>>A>>B>>C;
  if(A==B&&A!=C){
    cout<<"Yes"<<endl;
  }
  else if(A==C&&A!=B){
    cout<<"Yes"<<endl;
  }
  else if(B==C&&B!=A){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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

int64_t power(int x, int n){
  int64_t x_mod[32]; x_mod[0] = x%1000000007;
  rep(i, 31) x_mod[i+1] = (x_mod[i]*x_mod[i])%1000000007;
  bitset<32> bit(n);
  int64_t ans = 1;
  rep(i, 32) if(bit.test(i)) ans = (ans*x_mod[i])%1000000007;
  return (int64_t)ans;
}

int64_t combination(int a, int b){
  int64_t m=1, n=1;
  rep(i, b) {
    m *= a-i; m %= 1000000007;
    n *= i+1; n %= 1000000007;
  }
  n = power(n, 1000000005);
  return (m*n) % 1000000007;
}

int main(){
  int n, a, b; cin >> n >> a >> b;
  int64_t all, nCa, nCb;
  all = power(2, n) - 1; 
  nCa = combination(n, a);
  nCb = combination(n, b);
  int ans = (all - nCa - nCb + 1000000007*2)%1000000007;
  cout << ans << endl;
}

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

int myf(int x,int y){
  	if(x%y==0)return x/y;
  	else return x/y+1;
}

signed main(){
    int N,H;cin>>N>>H;
    vector<pair<int,int>>vec(2*N);
    REP(i,2*N){
        int a;cin>>a;
        if(i%2==0){
            vec[i]=mp(-a,0);
        }
        else vec[i]=mp(-a,1);
    }
    sort(vec.begin(),vec.end());
    int ans=0;
    for(int i=0;i<2*N&&H>0;){
        if(vec[i].second==1){
          	H+=vec[i].first;
          	i++;
        }
      	else{	
			ans+=myf(H,-vec[i].first);
          	break;
        }
        ans++;
    }
    cout<<ans<<endl;
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}

	inline int ts(char *s)
	{
		int a=0,c=fetch();
		while(c<=32 && c!=EOF)c=fetch();
		while(c>32 && c!=EOF)s[a++]=c,c=fetch();
		s[a]=0;
		return a;
	}
}
using ae86::ty;
using ae86::ts;

const int _ = 100007 * 3 , mo = 998244353;

inline int c2i(char x){if(x=='R')return 0;if(x=='G')return 1;if(x=='B')return 2;return -1;}

int n,nn;char s[_];
vector<int> cnts(3);

int main()
{
	n=ty(),nn=ts(s+1);
	lint ans=1;
	for(int i=1;i<=nn;i++)
	{
		vector<int> now=cnts,nex;
		cnts[c2i(s[i])]++;
		nex=cnts,sort(now.begin(),now.end()),sort(nex.begin(),nex.end());
		if(now[0]!=nex[0])ans=ans*(now[1]-now[0])%mo;
		if(now[1]!=nex[1])ans=ans*(now[2]-now[1])%mo;
	}
	for(int i=1;i<=n;i++)ans=ans*i%mo;
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std; 
#define all(c) c.begin(),c.end()
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ; 
typedef vector<int> vi;
#define mod 1000000007

bool first_row_or_column(pair<int,int> p) {
    return p.first == 0 || p.second == 0;
}
int main()
{
 //freopen("input.txt","r",stdin);
 //freopen("output.txt","w",stdout);
  ios::sync_with_stdio(0);
// cin.tie(0);
/* 
int n;
cin>>n;
vi v(n);
REP(i,0,n-1)
cin>>v[i];
vi v2=v;
sort(all(v2));
 */
 string s,t;
 cin>>s>>t;
 vector<vector<pair<int,pair<int,int>>>>dp(s.size()+1,vector<pair<int,pair<int,int>>>(t.size()+1,{0,{0,0}}));
 for(int i=1;i<=s.size();++i){
     for(int j=1;j<=t.size();++j){
         if(s[i-1]==t[j-1])
        {
        dp[i][j]=make_pair(dp[i-1][j-1].first+1,make_pair(i-1,j-1));

        }
        if(dp[i][j].first<dp[i-1][j].first){
            dp[i][j]=make_pair(dp[i-1][j].first,make_pair(i-1,j));
        }
        if(dp[i][j].first<dp[i][j-1].first){
            dp[i][j]=make_pair(dp[i][j-1].first,make_pair(i,j-1));
        }
         
        
     }
 }
  string ans;
 if(s[s.size()-1]==t[t.size()-1])
 ans+=s[s.size()-1];
int i=dp[s.size()][t.size()].second.first;
int j=dp[s.size()][t.size()].second.second;
while(i&&j){
    if(s[i-1]==t[j-1]){
        ans+=s[i-1];
    }
    int i1=i,j1=j;
    i=dp[i1][j1].second.first;
    j=dp[i1][j1].second.second;
}
reverse(all(ans));
cout<<ans;

 
 

    return 0;
}

Measured memory_bytes: 109036
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    keyence = "keyence"
    S = readline().rstrip()
    for i in range(len(S)):
        for j in range(i, len(S)):
            s = "".join([S[:i], S[j:]])
            if s == keyence:
                print("YES")
                return
    print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9208
import java.util.Scanner;

class Main {

		public static void main(String[] args){
			Scanner scan = new Scanner(System.in);
			int a = scan.nextInt();
			int b = scan.nextInt();
			int c = scan.nextInt();
			if(a <= b && b <= c){
				System.out.println(a + " " + b + " " + c);
			}else
			if(c <= b && b <= a){
				System.out.println(c + " " + b + " " + a);
			}else
			if(b <= a && a <= c){
				System.out.println(b + " " + a + " " + c);
			}else
			if(b <= c && c <= a){
				System.out.println(b + " " + c + " " + a);
			}else
			if(c <= a && a <= b){
				System.out.println(c + " " + a + " " + b);
			}else
			if(a <= c && c <= b){
				System.out.println(a + " " + c + " " + b);
			}
	}
}

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

int main() {
	int A, B, K;
	cin >> A >> B >> K;
	if (A + K - 1 < B - K + 1) {
		for (int i = 0; i < K; i++) cout << A + i << endl;
		for (int i = K - 1; i >= 0; i--) cout << B - i << endl;
	}
	else for (int i = A; i <= B; i++) cout << i << endl;
}

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

using namespace std;

int main ()
{
    int n, ans = 0;
    cin >> n;
    string str = to_string(n);
    for (unsigned int i = 0; i < str.length(); i++)
        ans += str[i] - 48;
    if (ans == 1)   
        cout << 10;
    else
        cout << ans;
    cout << endl;
}

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

template<int mod> class modint
{   
private:
    int val;
public:
    int value(){ return val; }
    modint(int x=0){ val=x%mod; }
    modint pow(int n){
        modint res(1),x(val);
        while(n>0){ if(n&1) res*=x; x*=x; n>>=1; }
        return res;
    }
    modint inv(){ return pow(mod-2); }
    modint& operator+=(modint rhs){ val+=rhs.val; if(val>=mod) val-=mod; return *this; }
    modint& operator-=(modint rhs){ val+=mod-rhs.val; if(val>=mod) val-=mod; return *this; }
    modint& operator*=(modint rhs){ val=val*rhs.val%mod; return *this; }
    modint& operator/=(modint rhs){ *this*=rhs.inv(); return *this; }
    modint operator+(modint rhs){ return modint(val)+=rhs; }
    modint operator-(modint rhs){ return modint(val)-=rhs; }
    modint operator*(modint rhs){ return modint(val)*=rhs; }
    modint operator/(modint rhs){ return modint(val)/=rhs; }
};

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

    using mint=modint<1000000007>;
    int N; cin>>N;
    vector<vector<int>> a(N,vector<int>(N));
    for(int i=0;i<N;i++) for(int j=0;j<N;j++) cin>>a[i][j];

    vector<mint> dp(1<<N);
    dp[0]=1;
    for(int S=0;S<(1<<N);S++){
        int i=__builtin_popcount(S);
        for(int j=0;j<N;j++) if(~S>>j&1){
            if(a[i][j]) dp[S|(1<<j)]+=dp[S];
        }
    }
    cout<<dp[(1<<N)-1].value()<<endl;
    return 0;
}

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

int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;
	int u,v;
	long long s;
	set<pair<int,long long>> edge[n];
	for (int i = 0; i < m; ++i)
	{
		cin>>u>>v>>s;--u;--v;
		edge[u].insert({v,s});
		edge[v].insert({u,s});
	}
	queue<int> que;
	int memo[n]={},f=0,f2=0;
	long long ans[n],tmp;
	memo[0]=1;
	ans[0]=1LL;
	que.push(0);
	while(!que.empty())
	{
		int now=que.front();que.pop();
		for (auto i=edge[now].begin(); i != edge[now].end(); ++i)
		{
			auto v=*i;
			if (memo[v.first]==0)
			{
				if (memo[now]==1)
				{
					memo[v.first]=2;
				}
				else
				{
					memo[v.first]=1;
				}
				ans[v.first]=v.second-ans[now];
				que.push(v.first);
			}
			else
			{
				if (memo[now]==memo[v.first])
				{
					if ((ans[v.first]-v.second+ans[now])%2LL==1LL)
					{
						cout<<"0\n";
						return 0;
					}
					else if (f)
					{
						long long ntmp=(ans[v.first]-v.second+ans[now])/2LL;
						if (memo[now]==1)
						{
							ntmp*=-1LL;
						}
						if (tmp!=ntmp)
						{
							cout<<"0\n";
							return 0;
						}
					}
					else
					{
						tmp=(ans[v.first]-v.second+ans[now])/2LL;
						if (memo[now]==1)
						{
							tmp*=-1LL;
						}
						if (tmp<0LL)
						{
							cout<<"0\n";
							return 0;
						}
					}
					f=1;
				}
				else
				{
					if (ans[v.first]!=v.second-ans[now])
					{
						cout<<"0\n";
						return 0;
					}
				}
			}
		}
	}
	long long l=100000000000000000LL,r=100000000000000000LL;
	if (f)
	{
		for (int i = 0; i < n; ++i)
		{
			if (memo[i]==1)
			{
				ans[i]+=tmp;
			}
			else
			{
				ans[i]-=tmp;
			}
		}
	}
	for (int i = 0; i < n; ++i)
	{
		if (memo[i]==1)
		{
			l=min(l,ans[i]);
		}
		else
		{
			r=min(r,ans[i]);
		}
	}
	if (f)
	{
		if (l>0&&r>0)
		{
			cout<<"1\n";
		}
		else
		{
			cout<<"0\n";
		}
		return 0;
	}
	if (l<=0LL)
	{
		long long cab=1LL-l;
		l+=cab;
		r-=cab;
	}
	if (r<=0LL)
	{
		long long cab=1LL-l;
		r+=cab;
		l-=cab;
	}
	if (l<=0LL||r<=0LL)
	{
		cout<<"0\n";
	}
	else
	{
		cout<<abs(l-r)+1LL<<endl;
	}
	return 0;
}


Measured memory_bytes: 19072
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::terminate;
using std::string;
using std::vector;

template<class T> inline T max(T X, T Y) {
    return X > Y ? X : Y;
}

void solve() {
    int N, K; cin >> N >> K;
    string S; cin >> S;
    vector<int> I;

    for (int i = 0; i < N; ++i) {
        if (i == 0) {
            I.push_back(0);
        } else {
            if (S[i - 1] != S[i]) {
                I.push_back(i);
            }
        }
    }
    I.push_back(N);

    int ans = 0;
    for (int k = 0; k < I.size() - 1; ++k) {
        int tmp = 0;

        if (S[I[k]] == '0') {
            if (k + 2 * K > I.size() - 1) {
                tmp = I[I.size() - 1] - I[k];
            } else {
                tmp = I[k + 2 * K] - I[k];
            }
        } else {
            if (k + 2 * K  + 1 > I.size() - 1) {
                tmp = I[I.size() - 1] - I[k];
            } else {
                tmp = I[k + 2 * K + 1] - I[k];
            }
        }

        ans = max(tmp, ans);
    }

    cout << ans << endl;
}

int main() {

#ifdef DEV
    std::ifstream in("input");
    cin.rdbuf(in.rdbuf());

    int t; cin >> t;
    for (int x = 1; x <= t; ++x) {
        solve();
    }
#else
    solve();
#endif

    return 0;
}


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

int main(){
    std::string s;
    std::getline(std::cin, s);
    for(int i=0; i<s.length(); i++){
        if(s[i] >= 65 && s[i] <=90){
            printf("%c",s[i]+32);
        }else if(s[i] >= 97 && s[i] <=122){
            printf("%c",s[i]-32);
        }else{
            std::cout << s[i];
        }
    }
    std::cout << std::endl;
  return 0;
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////
bool pp(string s)
{
    string t=s;
    reverse(s.begin(),s.end());
    return s==t;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
      string s;
      cin>>s;
      int n=s.length();
    if(pp(s) && pp(s.substr(0,(n-1)/2)) && pp(s.substr((n+1)/2)))
cout<<"Yes";
else cout<<"No";
  }
  return 0;
}

Measured memory_bytes: 256
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

bb = 10**18

def main():
    n = ii()
    a = li()
    ans = 1

    if 0 in a:
        print(0)
        return

    for i in range(len(a)):
        ans *= a[i]
        if ans > bb:
            print(-1)
            break
    else:
        print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 84900
N,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
if a[0]>x:
    ans+=a[0]-x
    a[0]=x
for i in range(1,N):
    if a[i]+a[i-1]>x:
        ans+=a[i]-(x-a[i-1])
        a[i]=x-a[i-1]
print(ans)

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

using ll = long long;
const ll INF = 1e18, MAX_COST = 2500;
typedef pair<ll, ll> P;
using edge = pair<ll, P>;


signed main() {
    ll N, M, S;
    cin >> N >> M >> S;
    S = min(S, MAX_COST);
    vector<vector<edge>> G(N);
    for (int i = 0; i < M; ++i) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        --u, --v;
        G[u].push_back(edge(v, P(a, b)));
        G[v].push_back(edge(u, P(a, b)));
    }
    vector<ll> c(N), d(N);
    for (ll i = 0; i < N; ++i) {
        cin >> c[i] >> d[i];
    }
    vector<vector<ll>> dist(N, vector<ll>(MAX_COST + 1, INF));
    priority_queue<edge, vector<edge>, greater<edge>> que;

    dist[0][S] = 0;
    que.push(edge(0, P(0, S)));

    while (que.size()) {
        edge e = que.top();
        que.pop();
        ll time = e.first, now = e.second.first, money = e.second.second;
        if (dist[now][money] < time) continue;
        if (money + c[now] <= MAX_COST) {
            ll ntime = time + d[now], nmoney = money + c[now];
            if (dist[now][nmoney] > ntime) {
                dist[now][nmoney] = ntime;
                que.push(edge(ntime, P(now, nmoney)));
            }
        }

        for (auto e : G[now]) {
            if (money < e.second.first) continue;
            ll nxt = e.first, ntime = time + e.second.second, nmoney = money - e.second.first;
            if (dist[nxt][nmoney] > ntime) {
                dist[nxt][nmoney] = ntime;
                que.push(edge(ntime, P(nxt, nmoney)));
            }
        }
    }

    for (ll i = 1; i < N; ++i) {
        ll ans = INF;
        for (ll j = 0; j <= MAX_COST; ++j) {
            ans = min(ans, dist[i][j]);
        }
        cout << ans << endl;
    }
    return 0;
} 

Measured memory_bytes: 7332
#include <bits/stdc++.h>
using namespace std;
int hashh[200005],ans[200005],memo[1<<26],arr[26];

int main(){
	for(int i=0;i<(1<<26);i++) memo[i]=INT_MAX;
	string s;
	cin >> s;
	int len=s.length();
	s="*"+s;
	hashh[0]=0;
	for(int i=1;i<=len;i++){
		arr[s[i]-'a']++;
		int hv=0;
		for(int j=0;j<26;j++){
			if(arr[j]%2) hv=(hv|(1<<j));
		}
		hashh[i]=hv;
	}
	memo[0]=0;
	for(int i=1;i<=len;i++){
		ans[i]=i;
		if(memo[hashh[i]]!=INT_MAX) ans[i]=min(ans[i],memo[hashh[i]]+1);
		for(int j=0;j<26;j++){
			if(memo[hashh[i]^(1<<j)]!=INT_MAX) ans[i]=min(ans[i],memo[hashh[i]^(1<<j)]+1);
		}
		memo[hashh[i]]=min(memo[hashh[i]],ans[i]);
	}

	cout << ans[len] << endl;

	return 0;
}

Measured memory_bytes: 264264
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int H,W,K;cin>>H>>W>>K;
    vector<string> cake(H);
    vector<vector<int>> v(H,vector<int>(W,0));
    REP(i,H)cin>>cake[i];
    int num=0;
    REP(i,H)REP(j,W){
        if(cake[i][j]=='#')num++;
        v[i][j]=num;
    }
    REP(i,H){
        int st1=-1,st2=-1;// 列iにいちごがあるか
        REP(j,W){
            if(cake[i][j]=='#'){st1=j;break;}
        }
        for(int j=W-1;j>=0;j--){
            if(cake[i][j]=='#'){st2=j;break;}
        }
        if(st1==-1){
            REP(j,W-1)v[i][j]=0;
        }else{
            REP(j,st1)v[i][j]=v[i][st1];
            FOR(j,st2,W)v[i][j]=v[i][st2];
        }
    }
    int ind=-1;
    REP(i,H){
        if(v[i][0]!=0){ind=i;break;}
    }
    for(int i=ind-1;i>=0;i--){
        REP(j,W){
            if(v[i][j]==0)v[i][j]=v[i+1][j];
        }
    }
    FOR(i,ind+1,H){
        REP(j,W){
            if(v[i][j]==0)v[i][j]=v[i-1][j];
        }
    }
    REP(i,H){
        REP(j,W){if(j)cout<<" ";cout<<v[i][j];}
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp make_pair
#define pb push_back
#define fp first
#define sp second
typedef long long int ll;
typedef pair<ll,ll> pp;
#define check(x, i) ((x>>i)&1LL)
#define set(x,i) (x|(1LL<<i))
#define unset(x,i) (x&~(1LL<<i))
#define INF LONG_MAX
#define MAX_N 20
#define MAX 200005
#define mod 1000000007
#define REP(i,n) for(i=0;i<n;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define len(i,s) for(i=0;s[i];i++)
#define T() ll t;cin>>t;while(t--)
ll gcd (ll a, ll b){return (a?gcd(b%a,a):b);}
ll pow1(ll a,ll b,ll MOD){ll ans=1;while(b!=0){if(b&1)ans=(ans*a)%MOD;a=(a*a)%MOD;b=b/2;}return ans;}
ll modInverse(ll a,ll p){return pow1(a,p-2,p);}


int main()
{
  boost
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);    
    freopen("output.txt", "w", stdout);
#endif 
  ll n,d;
  cin>>n>>d;
  ll ans=0;
  ll i;
  REP(i,n)
  {
    ll x,y;
    cin>>x>>y;
    double dist=sqrt(x*x+y*y);
    if(dist<=d)
      ans++;
  }
  cout<<ans;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
bool prime[10000001];
int main() {
    for(long long int i=2;i<3162;i++)if(!prime[i])for(long long int j=i*2;j<=10000000;j+=i)prime[j]=1;
    int n;
    while(cin>>n,n){
        for(;;n--){
            if(!prime[n]&&!prime[n-2]&&!prime[n-6]&&!prime[n-8]){
                cout<<n<<endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 10924
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))

using namespace std;

int t, n, s[1000], f[1000];

int solve()
{
	int sum = 0;
	
	FOR(i, 0, n)
	{
		sum += f[i] - s[i];
	}

	return t - sum;
}

int main()
{
	while( cin >> t, t)
	{
		cin >> n;
		
		FOR(i, 0, n)
		{
			cin >> s[i];
			cin >> f[i];
		}
		
		int a = solve();
		
		if( a <= 0)
			cout << "OK" << endl;
		else
			cout << a << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
line1 = gets.strip
num=line1.to_i
num_sum=num*(num+1)/2
num5=(num/5).to_i
num3=(num/3).to_i
num15=(num/15).to_i
num_sum3=num3*(num3+1)/2
num_sum5=num5*(num5+1)/2
num_sum15=num15*(num15+1)/2
puts num_sum-num_sum3*3-num_sum5*5+num_sum15*15

Measured memory_bytes: 14264
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define all(x) (x).begin(), (x).end()
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL


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

  ll n;
  cin >> n;
  ll now = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (a >= now) {
      now = a;
    }
    else {
      ans += (now - a);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;
int INF = 1000000000;
vector<int> L;
int N, A, B, C;

int dfs(int n, int a, int b, int c) {
    if(n == N) {
        if(a == 0 || b == 0 || c == 0) return INF;
        return abs(A - a) + abs(B - b) + abs(C - c) - 30;
    }

    int rec0 = dfs(n + 1, a, b, c);
    int rec1 = min(rec0, dfs(n + 1, a + L[n], b, c) + 10);
    int rec2 = min(rec1, dfs(n + 1, a , b + L[n], c) + 10);
    int rec3 = min(rec2, dfs(n + 1, a , b, c + L[n]) + 10);
    return rec3;
}
int main() {
    cin >> N >> A >> B >> C;
    for(int i = 0; i < N; i++) {
        int l;
        cin >> l;
        L.push_back(l);
    }
    cout << dfs(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
S = input()
flag = False
if S[0]=='A':
        flag = True
        count = 0
        for i in range(2,len(S)-1):
                if S[i]=='C': 
                        if count==0: count+=1
                        else:
                                flag = False
                                break
        if count==0: flag = False
        if flag:
                for i in range(len(S)):
                        if S[i]!='C' and S[i]!='A' and S[i].upper()==S[i]:
                                        flag = False
                                        break
                        '''
                        if S[i]=='c' or S[i] == 'a':
                                flag = False
                                break
                        else:
                                if S[i]!='C' and S[i]!='A' and S[i].upper()==S[i]:
                                        flag = False
                                        break'''
if flag: print("AC")
else: print("WA")

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

int main(){
  int n; cin>>n;
  vector<int> num(n*3);
  for(int i=0;i<n*3;i+=3){
    cin>>num[i];
    num[i+1]=num[i]-1;
    num[i+2]=num[i]+1;
  }int ans=0,count=1;
  sort(num.begin(),num.end());
  int re=num[0];
  for(int i=1;i<n*3;i++){
    if(re==num[i]) count++;
    else{
      ans=max(ans,count);
      count=1;
      re=num[i];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int t[5];
int main(){
  while(cin>>t[0]&&t[0]){
    for(int i=1;i<5;i++)cin>>t[i];
    for(int i=0;i<5;i++){
      int a=0,b=0;
      for(int j=0;j<5;j++){
	if(i==j)continue;
	if(t[i]%3+1==t[j])a++;
	if(t[i]==t[j]%3+1)b++;
      }
      if((a>0)==(b>0))cout<<3<<endl;
      else if(a>0)cout<<1<<endl;
      else cout<<2<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int n,ans=1;
int main()
{
	cin>>n;
	while(ans<=n)
	{
		ans*=2;
	}
	cout<<ans/2;
}


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

int main(void) {
    string n;
    long k;
    cin >> n;
    long s = n.size();
    cin >> k;

    auto comb = [&](long a, long b) {
        long r = 1;
        if(a < b) return 0l;
        for(long i=0; i<b; i++)
            r *= a-i, r /= i+1;
        return r;
    };
    auto pow9 = [&](long a) -> long{
        if(a<0) return 0;
        switch(a) {
            case 0: return 1;
            case 1: return 9;
            case 2: return 81;
            case 3: return 729;
        }
        return 0;
    };

    long r = 0, t = 0;
    for(long i=0; i<s; i++) {
        if(n[i] == '0') continue;
        // 0
        r += comb(s-1-i, k-t) * pow9(k-t);
        // 1<= <n[i]
        r += comb(s-1-i, k-t-1) * (n[i]-'0' - 1) * pow9(k-1-t);
        t++;
    }
    {
        long a = 0;
        for(long i=0; i<s; i++)
            a += n[i] != '0';
        if(a == k)
            r ++ ;
    }
    cout << r << endl;
}


Measured memory_bytes: 256
N = int(input())
S = input()

max = 0
for i in range(N-1):
    s1 = S[:i+1]
    s2 = S[i+1:]
    s1 = list(set(s1))
    s2 = list(set(s2))
    count = 0
    for e in s1:
        if e in s2:
            count += 1
    if count > max:
        max = count

print(max)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  string s;
  ll a, b, c, d;
  cin >> a>>b>>c>>d;
  
  //vector<ll> a(n);  rep(i, 0, n) cin >> a[i];
  
  //cout << n << "\n";
  
  cout << (d==1) << "\n";

}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <limits>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <map>
#include <utility>
using namespace std;
#define rep(i, n) for (int i =0; i < (int)(n); i++)
typedef pair<int, string> P;




int main() {
    int n;
    cin >> n;
    long long ans=0;
    rep(i, n) {
        ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 1003;

string s[MAX_N];
string e[2];
int a[MAX_N][MAX_N];
int b[MAX_N][MAX_N][3];
int m,n;

int main()
{
	scanf("%d%d",&n,&m);
	rep(i,n){
		cin >> s[i];
	}
	rep(i,2){
		cin >> e[i];
	}
	rep(i,n){
		rep(j,m){
			a[i][j] = 0;
			rep(k,3){
				b[i][j][k] = 0;
			}
		}
	}
	int ans = 0;
	rep(i,n-1){
		rep(j,m-1){
			if(s[i][j] == e[0][0] && s[i+1][j] == e[1][0] && s[i][j+1] == e[0][1] && s[i+1][j+1] == e[1][1]){
				ans++;
				rep(k,2){
					rep(l,2){
						a[i+k][j+l] += 1;
					}
				}
			}else if(s[i][j] == e[0][0] && s[i+1][j] == e[1][0] && s[i][j+1] == e[0][1]){
				if(e[1][1] == 'J'){
					b[i+1][j+1][0] += 1;
				}else if(e[1][1] == 'O'){
					b[i+1][j+1][1] += 1;
				}else{
					b[i+1][j+1][2] += 1;
				}
			}else if(s[i+1][j] == e[1][0] && s[i][j+1] == e[0][1] && s[i+1][j+1] == e[1][1]){
				if(e[0][0] == 'J'){
					b[i][j][0] += 1;
				}else if(e[0][0] == 'O'){
					b[i][j][1] += 1;
				}else{
					b[i][j][2] += 1;
				}
			}else if(s[i][j] == e[0][0] && s[i+1][j] == e[1][0] && s[i+1][j+1] == e[1][1]){
				if(e[0][1] == 'J'){
					b[i][j+1][0] += 1;
				}else if(e[0][1] == 'O'){
					b[i][j+1][1] += 1;
				}else{
					b[i][j+1][2] += 1;
				}
			}else if(s[i][j] == e[0][0] && s[i][j+1] == e[0][1] && s[i+1][j+1] == e[1][1]){
				if(e[1][0] == 'J'){
					b[i+1][j][0] += 1;
				}else if(e[1][0] == 'O'){
					b[i+1][j][1] += 1;
				}else{
					b[i+1][j][2] += 1;
				}
			}
		}
	}
	int mx = 0;
	rep(i,n){
		rep(j,m){
			rep(k,3){
				mx = max(mx,b[i][j][k]-a[i][j]);
			}
		}
	}
	cout << ans+mx << "\n";
	return 0;
}

Measured memory_bytes: 19856
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var N = parseInt(tmp[0], 10);
	var M = parseInt(tmp[1], 10);
	var A = [];
	var box = [];
	var ans = 0 ;
	for (var i = 0; i < M; i++) {
		base = input[i+1].split(" ");
		base1 = parseInt(base[0], 10);
		base2 = parseInt(base[1], 10);
		A.push(base1);
		A.push(base2);
	}

	for (var k = 0; k < N; k++) {
		for(var i = 0, s = A, c = 0; i < s.length; i++) c += (s[i] === k+1); // 4
		console.log('%d',c);
	}
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N =  sc.nextInt();
		long A[] = new long[N];
		for(int i=0;i<N;i++) {
			A[i] = sc.nextLong();
		}
		long min = A[0];
		int count =0;
		for(int i=0;i<N;i++) {
			if (A[i]<=min) {
				count ++;
				min = A[i];
			}
		}
		System.out.println(count);
		return ;
	}
}

Measured memory_bytes: 61820
#include<stdio.h>
int main(void){
  int N,flag=0;
  char S;
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%c",&S);
    if(S=='Y'){
      flag=1;
    }
  }
  if(flag==0){
    printf("Three\n");
  }else{
    printf("Four\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<int> cnt_e(n);
	char ew;
	int cnt=0;

	for(int i=0; i<n; i++){
		cin >> ew;
		if(ew=='E'){
			cnt++;
		}
		cnt_e.at(i)=cnt;
	//	cout << cnt_e.at(i) << endl;
	}	

	int ans=n;
	int tmp;
	for(int i=0; i<n; i++){
		if(i==0){
			tmp = cnt_e.at(n-1)-cnt_e.at(0);
		}else{
			tmp = cnt_e.at(n-1)-cnt_e.at(i) + (i-cnt_e.at(i-1));
		}
		
		if(tmp<ans){
			ans = tmp;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;

/////////////////////////////////////////////

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

////////////////////////////////

#define int long long


void solve(){

	int n;
	cin>>n;
	vector<int> a(n);

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

	set<int> s;
	int ans = 0;

	for(int i = 0 ; i < n;  ++i){

		s.insert(a[i]);

		if(*s.begin()==a[i])
			ans++;

	}
	cout<<ans<<endl;
}


signed main(){
    
    int t;
    t = 1;
    //cin>>t;
    while(t--)
        solve();
}



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

using Graph=vector<vector<int>>;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

bool isBipartite(const Graph &g){
    int n=g.size();
    vector<int> color(n,-1);
    function<bool(int,int)> dfs=[&](int v,int c){
        if(color[v]!=-1){
            if(color[v]!=c) return false;
            return true;
        }
        color[v]=c;
        bool isok=true;
        for(auto &e:g[v]){
            isok&=dfs(e,!c);
        }
        return isok;
    };
    for(int i=0;i<n;i++){
        if(color[i]==-1){
            if(!dfs(i,0)){
                return false;
            }
        }
    }
    return true;
}

bool solve(int n){
    map<pair<int,int>,int> mp;
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        char dir;
        cin>>dir;
        mp[{x,y}]=i;
        if(dir=='x') mp[{x+1,y}]=i+n;
        else mp[{x,y+1}]=i+n;
    }

    Graph g(2*n);
    for(int i=0;i<n;i++) g[i].push_back(i+n),g[i+n].push_back(i);
    for(auto &e:mp){
        int x=e.first.first,y=e.first.second;
        int idx=e.second;
        for(int i=0;i<4;i++){
            int tox=x+dx[i],toy=y+dy[i];
            if(mp.count({tox,toy})){
                if(mp[{tox,toy}]%n!=idx%n){
                    g[(idx+n)%(2*n)].push_back(mp[{tox,toy}]);
                }
            }
        }
    }
    return isBipartite(g);
}

int main(){
    int n;
    while(cin>>n,n){
        cout<<(solve(n) ? "Yes" : "No")<<endl;
    }
    return 0;
}


Measured memory_bytes: 9012
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;


// ============union_find_tree===============
ll MAX_N = 100000;
vector<ll> par(MAX_N);//MAX_N == num of node
vector<ll> tree_rank(MAX_N);

void init(ll n)
{
  for (ll i = 0; i < n; ++i)
  {
    par.at(i) = i;
    tree_rank.at(i) = 0;
  }
}

ll find(ll x)
{
  if (par.at(x) == x)
  {
    return x;
  }
  else
  {
    return par.at(x) = find(par.at(x));
  }
}

void unite(ll x, ll y)
{
  x = find(x);
  y = find(y);
  if (x == y)
  {
    return;
  }
  if (tree_rank.at(x) < tree_rank.at(y))
  {
    par.at(x) = y;
  }
  else
  {
    par.at(y) = x;
    if (tree_rank.at(x) == tree_rank.at(y))
    {
      tree_rank.at(x)++;
    }
  }
}

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


int main()
{
  ll N, M, K;
  cin >> N >> M >> K;
  init(N);
  vector<ll> ans(N, -1);
  for (ll i = 0; i < M; ++i) {
    ll a, b;
    cin >> a >> b;
    --a;
    --b;
    ans.at(a) -= 1;
    ans.at(b) -= 1;
    unite(a, b);
  }
  vector<ll> num(N, 0);
  for (ll i = 0; i < N; ++i) {
    num.at(find(i)) += 1;
  }
  for (ll i = 0; i < N; ++i) {
    ans.at(i) += num.at(find(i));
  }
  for (ll i = 0; i < K; ++i) {
    ll c, d;
    cin >> c >> d;
    --c;
    --d;
    if (same(c, d)) {
      ans.at(c) -= 1;
      ans.at(d) -= 1;
    }
  }
  for (ll i = 0; i < N; ++i) {
    cout << ans.at(i) << ' ';
  }
  cout << endl;
}


Measured memory_bytes: 3968
import os
import sys

import numpy as np

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

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, K = list(map(int, sys.stdin.buffer.readline().split()))
A = list(map(int, sys.stdin.buffer.readline().split()))

A = np.array(A, dtype=int)
if K == 0:
    print(A.sum())
    exit()

# 各桁は独立に決まるので
# ビットが多く立ってる方を採用する
# d = 1
# ans = 0
# while d < 10 ** 13:
#     cnt1 = np.count_nonzero(A & d)
#     cnt0 = N - cnt1
#     ans += d * max(cnt1, cnt0)
#     d <<= 1
# print(ans)

DIGIT = (10**12).bit_length() + 1
# dp[d][s]:
# 上から DIGIT - d 桁目まで決めたときの最大値
# s = 0 のとき K より小さいことが確定した
dp = np.zeros((DIGIT, 2), dtype=int)
dp[0][1] = 0
dp[0][0] = -IINF

for d in range(1, DIGIT):
    mask = 1 << (DIGIT - d - 1)
    cnt0 = np.count_nonzero(A & mask)
    cnt1 = N - cnt0
    s0 = mask * cnt0
    s1 = mask * cnt1

    dp[d][0] = dp[d - 1][0] + max(s0, s1)
    if K & mask:
        # どっちも使える
        dp[d][1] = max(dp[d][1], dp[d - 1][1] + s1)
        dp[d][0] = max(dp[d][0], dp[d - 1][1] + s0)
    else:
        dp[d][1] = max(dp[d][1], dp[d - 1][1] + s0)
print(dp.max())


# def test():
#     ret = 0
#     for k in range(K + 1):
#         ret = max(ret, (A ^ k).sum())
#     print(ret)
#
#
# test()


Measured memory_bytes: 21560
import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    long C = scanner.nextLong();
    long[] h = new long[N];
    for (int i = 0; i < N; i++) h[i] = scanner.nextInt();

    long[] dp = new long[N + 1];
    Deque<Line> deque = new LinkedList<>();

    for (int i = 1; i <= N; i++) {
      long hi = h[i - 1];
      while (deque.size() > 1) {
        Line last = deque.removeLast();
        if (deque.peekLast().y(hi) > last.y(hi)) {
          deque.addLast(last);
          break;
        }
      }
      if (!deque.isEmpty()) dp[i] = deque.peekLast().y(hi) + hi * hi + C;
      Line line = new Line(-2 * hi, hi * hi + dp[i]);
      while (deque.size() > 1) {
        Line first = deque.removeFirst();
        Line next = deque.peekFirst();
        if ((first.a - next.a) * (line.b - first.b) < (line.a - first.a) * (first.b - next.b)) {
          deque.addFirst(first);
          break;
        }
      }
      deque.addFirst(line);
    }

    System.out.println(dp[N]);
  }

  private static class Line {
    public final long a;
    public final long b;

    private Line(long a, long b) {
      this.a = a;
      this.b = b;
    }

    public long y(long x) {
      return x * a + b;
    }
  }
}


Measured memory_bytes: 95640
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<functional>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265358979

using namespace std;
typedef pair<int, int> P;

int x[100001], y[100001];
int check[100001] = {};
int sum[100001] = {};

int main(void) {
	int n, m;
	
	long long int count = 0;

	check[1] = 1;
	cin >> n >> m;
	FOR(i, 1, n) {
		sum[i] = 1;
	}

	FOR(i, 1, m) {
		cin >> x[i] >> y[i];
		if (sum[x[i]] == 1) {
			if (check[x[i]] == 1) {
				check[x[i]] = 0;
				check[y[i]] = 1;
			}
		}
		else {
			if (check[x[i]] == 1) {
				check[y[i]] = 1;
			}
		}
		sum[x[i]]--;
		sum[y[i]]++;
	}

	FOR(i, 1, n) {
		if (check[i] == 1) {
			count++;
		}
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll maxn = 610;
int a[maxn*maxn], b[maxn*maxn];
double f[maxn], ans;
vector <int> vec[maxn];
ll n, m;
double DP(double p) {
	for(int i = 1; i <= n; ++i) {
		f[i] = 0;
	}
	f[n] = 0;
	for(int i = n - 1; i >= 1; --i){
		ll len = vec[i].size();
		if(p == i && len == 1) {
			f[i] = inf;
			continue;
		}
		double t = 1.0 / (len - (p == i));
		double mx = 0;
		for(int j = 0; j < len; ++j) {
			int v = vec[i][j];
			mx = max(mx, (f[v]+1)*t);
			f[i] += (f[v] + 1) * t;
		}
		if(p == i)	f[i] -= mx;
	}
	return f[1];
}
int main () {
	cin >> n >> m;
	for(int i = 1; i <= m; ++i) {
		cin >> a[i] >> b[i];
		vec[a[i]].push_back(b[i]);
	}
	ans = DP(0);
	for(int i = 1; i <= n; ++i) {
		ans = min(ans, DP(i));
	}
	printf("%.9f\n", ans);
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;


//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  return ((x * y) / gcd(x, y));
}

int n, a[15];
int ans(int x, int nasu, int sum){
  if(n < x){
    if(nasu % 2 == 0){
      return sum + 1;
    } else {
      return sum;
    }
  }
  sum = ans(x + 1,nasu *= (a[x] - 1), sum);
  sum = ans(x + 1, nasu *= a[x], sum);
  sum = ans(x + 1, nasu *= (a[x] + 1), sum);
  return sum;
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int nasu = 1, ans = 1;
  cin >> n;
  reps(i, n){
    cin >>a[i];
    ans *= 3;
    if(a[i] % 2 == 0){
      nasu *= 2;
    }
  }
  cout << ans - nasu << '\n';
  return 0;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007


signed main(){
    string s;
    cin>>s;
    if(s[3]==s[2]&&s[5]==s[4]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3580
def strip_zero matrix
    matrix2 = matrix.dup
    matrix2.each{|row|
        if row.all?{|elem| elem == 0}
            matrix2.delete(row)
        end
    }
    matrix2 = matrix2.transpose
    matrix2.each{|row|
        if row.all?{|elem| elem == 0}
            matrix2.delete(row)
        end
    }
    matrix2 = matrix2.transpose
    matrix2
end

lines = []
count = 0
while line = gets
    if line.chomp! != ""
        lines << line.split("").map(&:to_i)
        count += 1
        if count == 8
            lines = strip_zero lines
            type = ""
            case lines[0]
                when [1, 1] then type = "A"
                when [1] then type = "B"
                when [1, 1, 1, 1] then type = "C"
                when [0, 1] then type = "D"
                when [1, 1, 0] then type = "E"
                when [1, 0] then type = "F"
                when [0, 1, 1] then type = "G"
            end
            puts type
        end
    else
        lines = []
        count = 0
    end
end

Measured memory_bytes: 8900