akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*
*/

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
const ll P =  1000000007;
ll factorial(ll n){
   ll ans = 1;
   for(int i = n;i>=1;i--){
     ans *= i;
     ans %= P;
   }
   return ans;
}
using Graph = vector<vector<int>>;

ll kzyou(ll a,ll k){//aのk乗を返す
    ll zyou = 1;
    for(ll i = 1;i<=k;i++){
        zyou *= a;
    }
    return zyou;
}

int main(){
  int a,b;
  cin >> a >> b;
  char A = char(48+a);//整数aのchar
  char B = char(48+b);//整数bのchar
  string Sa,Sb;
  for(int i = 0;i<b;i++){
    Sa.push_back(A);
  }
  for(int i = 0;i<a;i++){
    Sb.push_back(B);
  }
  if(Sa <= Sb) cout << Sa << endl;
  else cout << Sb << endl;

 }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll s[110000];
bool ok;
ll ans;
ll m, n;
int main() {
	cin >> m >> n;
	REP(i, n)cin >> s[i];
	if (m == 2) {
		ll a1 = 0, a2 = 0;
		REP(i, n) {
			if (i % 2 == 0 and s[i] == 1)a1++;
			if (i % 2 == 1 and s[i] == 2)a1++;
		}
		REP(i, n) {
			if (i % 2 == 0 and s[i] == 2)a2++;
			if (i % 2 == 1 and s[i] == 1)a2++;
		}
		cout << min(a1, a2) << endl;
		return 0;
	}
	REP(i, n - 1) {
		if (s[i] == s[i + 1]) {
			ans++;
			s[i + 1] = -1;
		}
	}
	cout << ans << endl;
}




Measured memory_bytes: 3888
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

int A[310][310];

signed main(){
	int N;
	cin >> N;
	for(int i = 0; i < N; ++i) {
		for(int j = 0; j < N; ++j) {
			cin >> A[i][j];
		}
	}
	int res = 0;
	for(int i = 0; i < N; ++i) {
		for(int j = 0; j < N; ++j) {
			res += A[i][j];
			bool f = false;
			for(int k = 0; k < N; ++k) {
				if(i == k || j == k) continue;
				int d = A[i][k] + A[k][j];
				if(d < A[i][j]) {
					cout << -1 << endl;
					return 0;
				}
				if(d == A[i][j]) {
					f = true;
				}
			}
			if(f) {
				res -= A[i][j];
			}
		}
	}
	cout << res / 2 << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,ans;
  ans=0;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  sort(a.begin(), a.end());
  for(int i=0;i<n;i++){
    for(int j=0;j<i;j++){
      for(int k=0;k<j;k++){
        if(a.at(k)+a.at(j)>a.at(i) && a.at(k)!=a.at(j) && a.at(j)!=a.at(i)){
          ans++;
        }
      }
    }
  }
  cout<<ans;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define f(i,n) for(int i=1;i<=n;i++)
#define mkp make_pair

int32_t main()
{
 int t=1;
 //cin>>t;
while(t--)
{
	int n;
    cin>>n;
 int  a[n+1][4],dp[n+1][4];
 f(i,n){  
 f(j,3){
cin>>a[i][j];
 }}
 dp[1][1]=a[1][1],dp[1][2]=a[1][2],dp[1][3]=a[1][3];
for(int i=2;i<=n;i++)
{
	for(int j=1;j<=3;j++)
	{
		if(j==1){ 
			dp[i][j]=max(dp[i-1][j+1],dp[i-1][j+2])+a[i][j];
		}else if(j==2){
	       dp[i][j]=max(dp[i-1][j+1],dp[i-1][1] )+a[i][j];
		}else{
	          dp[i][j]=max(dp[i-1][1],dp[i-1][2])+a[i][j];
		}
	}
}
int ans=INT_MIN;
 for(int i=1;i<4;i++)
 {ans=max(dp[n][i],ans);}
  cout<<ans<<endl;
}
   
}


Measured memory_bytes: 6528
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def main():
    n = inp()
    p = tuple(inpl())
    q = tuple(inpl())
    pre = []
    for i in permutations(range(1,n+1)):
        pre.append(i)
    pre.sort()
    x,y = 0,0
    for i in range(len(pre)):
        if pre[i] == p:
            x = i
        if pre[i] == q:
            y = i
    print(abs(x-y))

if __name__ == "__main__":
    main()

Measured memory_bytes: 47468
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;

//INSERT ABOVE HERE
signed main(){
  using D = double;
  D a,b,p,q,r;
  cin>>a>>b>>p>>q>>r;
  cout<<b+(b*p-(b-a)*q)/(q+r)<<endl;
  return 0;
}



Measured memory_bytes: 3308
#include<iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int main() {
  int n, res = 0;
  string str;
  cin >> n >> str;
  rep (iii, n) {
    string s;
    cin >> s;
    rep (i, s.size()) rep (j, s.size()) if (j != 0 && i + j * (str.size() - 1) < s.size()) {
      bool ok = true;
      rep (k, str.size()) if (s[i + j * k] != str[k]) ok = false;
      if (ok) {
	++res;
	goto next;
      }
    }
  next:;
  }
  cout << res << endl;
  return 0;
}

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

void solve(long long N, vector<long long> A){
	map<long long, long long> B;
	for(auto l: A) {
		B[l]++;
	}
	vector<long long> C;
	for(auto p: B) {
		while(p.second >= 2) {
			C.push_back(p.first);
			p.second -= 2;
		}
	}
	sort(C.begin(), C.end(), greater<int>());
	long long res = 0;
	if(C.size() >= 2) {
		res = max(res, C[0] * C[1]);
	}
	cout << res << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> A(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	solve(N, A);
	return 0;
}



Measured memory_bytes: 8064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define input_i(x) scanf("%d", &x)
#define input_lli(x) scanf("%lld", &x)
#define input_s(x) scanf("%s", x)

#define BUFSIZE 100000

int main(int argc, char const *argv[]) {
    long long int i, buf= 0, ans= 0;
    long long int N;
    input_lli(N);
    for(i= 1; i < N; i++) {
        ans+= i;
    }

    printf("%lld\n", ans);

    return 0;
}


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

using namespace std;

struct Edge{
    int from,to,w;
    bool friend operator < (const Edge& a,const Edge& b){
        return a.w<b.w;
    }
};
const int maxn=105;
vector<Edge> G;
int fa[maxn];
int V,E;
void init(){
    for(int i=1;i<=V;i++)
        fa[i]=i;
}

int find(int x){
    int y=fa[x];
    for(;fa[y]!=y;y=fa[y]);
    while(x!=y){
        int temp=fa[x];
        fa[x]=y;
        x=temp;
    }
    return y;
}

void merge(int x,int y){
    int nx=find(x);
    int ny=find(y);
    if(nx!=ny){
        fa[nx]=ny;
    }
}
int ans=0;
void krusal(int v){
    sort(G.begin(),G.end());
    E=G.size();
    V=v;
    init();
    for(int i=0;i<E;i++){
        Edge temp=G[i];
        int fa1=find(temp.from);
        int fa2=find(temp.to);
        if(fa1!=fa2){
            ans+=temp.w;
            fa[fa1]=fa2;
        }
    }
}

int main(){
    int V;
    cin>>V;
    E=0;
    for(int i=1;i<=V;i++){
        for(int j=1;j<=V;j++){
            int key;
            cin>>key;
            if(key!=-1){
                G.push_back(Edge{i,j,key});
            }
        }
    }
    krusal(V);
    cout<<ans<<endl;
}

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


int main(){
int N,M;
cin>> N>>M;
int LMA = 0;
int RMI = 2000000;

for(int i = 0; i<M;i++){
int li, ri;
cin >>li>>ri;
LMA = max(LMA, li);
RMI = min(RMI, ri);
}
int ans;
if(RMI<LMA)ans = 0;
else ans = RMI-LMA+1;
cout<<ans<<endl;

}


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

namespace Abc086
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            List<int> times = new List<int>();
            List<int> xs = new List<int>();
            List<int> ys = new List<int>();

            for (int i = 0; i < N; i++)
            {
                var rStr = Console.ReadLine();
                times.Add(int.Parse(rStr.Split(' ')[0]));
                xs.Add(int.Parse(rStr.Split(' ')[1]));
                ys.Add(int.Parse(rStr.Split(' ')[2]));
            }

            bool result = true;

            for (int i = 0; i < times.Count(); i++)
            {
                int dt = 0;
                int dd = 0;

                if (i == 0)
                {
                    dt = times[i];
                    dd = Math.Abs(xs[i]) + Math.Abs(ys[i]);
                }
                else
                {
                    dt = times[i] - times[i - 1];
                    dd = Math.Abs(xs[i] - xs[i - 1]) + Math.Abs(ys[i] - ys[i - 1]);
                }

                if (dt < dd)
                {
                    result = false;
                    break;
                }

                if (dt % 2 != dd % 2)
                {
                    result = false;
                    break;
                }

            }

            if (result)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 49020
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         // if (siz[rx] < siz[ry]) swap(rx,ry);
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1LL) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

int main(void) {
    string S, T;
    cin >> S >> T;
    if (T.substr(0,S.size()) == S) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

#define INF 1e9
template<class T> class treap{
public:
	struct node{
		T val,sum,mini,maxi;
		node *left , *right;
		int pri;
		unsigned sz;
		node(T val,int pri):val(val),sum(val),mini(val),maxi(val),pri(pri),sz(1){
			left = right = NULL;
		}
	};

	node *root;

	treap():root(NULL){
		srand(time(NULL));
	}

	unsigned size(){ return size(root); }
	unsigned size(node *v){ return !v?0:v->sz; }
	T sum(node *v){ return !v?0:v->sum; }
	T MIN(node *v){ return !v?INF:v->mini; }
	T MAX(node *v){ return !v?-INF:v->maxi; }

	node *update(node *v){
		v->sz = size(v->left)+size(v->right)+1;
		v->sum = sum(v->left)+sum(v->right)+v->val;
		v->mini = min( MIN(v->left) , MIN(v->right) );
		v->maxi = max( MAX(v->left) , MAX(v->right) );
		return v;
	}

	node *merge(node *s , node *t){
		if( !s || !t )return s?s:t;
		if( s->pri > t->pri){
			s->right = merge( s->right , t );
			return update(s);
		}
		else{
			t->left = merge( s, t->left);
			return update(t);
		}
	}

	pair<node*,node*> split(node *v,unsigned k){
		
		if(!v)return pair<node*,node*>(NULL,NULL);

		if( k <= size(v->left) ){
			pair<node*,node*> s = split( v->left, k );
			v->left = s.second;
			return make_pair( s.first , update(v) );
		}

		else{
			pair<node*,node*> s = split( v->right, k-size(v->left)-1 );
			v->right = s.first;
			return make_pair( update(v) , s.second );
		}
	}

	node *find(unsigned k){
		node *v=root;
		while(v){
			unsigned s = size(v->left);
			if( s > k ) v = v->left;
			else if( s == k )break;
			else{
				v = v->right;
				k -= s+1;
			}
		}
		return v;
	}

	int getval(int k){
		node *t=find(k);
		return t->val;
	}

	void insert(unsigned k,T val){ root = insert(root,k,val,rand()); }
	node *insert(node *t,unsigned k,T val,int pri){
		pair<node*,node*> s = split(t,k);
		t = merge( s.first , new node(val,pri));
		t = merge( t , s.second );
		return update(t);
	}

	void erase(int k){ root = erase( root, k );}
	node *erase(node *t, unsigned k){
		if(root->sz==1){
			root=NULL;
			return NULL;
		}
		pair<node*,node*>u,v;
		u = split(t,k+1);
		v = split(u.first,k);
		t = merge(v.first,u.second);
		return update(t);
	}

	void range_erase(int l,int r){ root = range_erase( root , l , r );}
	node range_erase(node *t,unsigned k){
		pair<node*,node*>u,v;
	}

	void push_back(T val){ insert(root?root->sz:0,val); }
	void pop_back(){ erase(root->sz-1); }

	void print_array(){
		int k = root->sz;
		cout<<"root value = "<<root->val<<endl;
		cout<<"size of array = "<<k<<endl;
		for(int i = 0; i < k ; i++ ){
			if( i ) cout<<" ";
			cout<<getval(i);
		}
		cout<<endl;
	}
};

int main(){
	treap<int> tri;
	int q;
	cin>>q;
	while(q--){
		int a,b;
		cin>>a;
		if(a!=2)cin>>b;
		if(a==0)tri.push_back(b);
		if(a==2)tri.pop_back();
		if(a==1)cout<<tri.getval(b)<<endl;

	}
	/*while(1){
		int a,b,c;
		cin>>a>>b;

		if(a!=-1)tri.insert(b,a);
		else tri.erase(b);
		tri.print_array();
	}*/
}


Measured memory_bytes: 12408
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
ans = 1 
if 0 in a:
    print(0)
    sys.exit(0)
for i in a:
    ans *= i
    if ans > 10**18:
        print(-1)
        sys.exit(0)
print(ans)

Measured memory_bytes: 21748
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int dp[500010];

int main(){
  int n,m; cin >> n >> m;
  vector<int> c(m);
  rep(i,m) cin >> c[i];
  rep(j,n+1) dp[j]=inf;
  dp[0]=0;
  rep(i,m)rep(j,n+1){
    if(j+c[i]<=n) chmin(dp[j+c[i]],dp[j]+1);
  }
  cout << dp[n] << endl;
}


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

const int MOD = 1000000007;


int gcd(int a, int b) {
    if (b==0) return a;
   	else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}


int main(){
	string S;
	cin>>S;
	int n=0,e=0,w=0,s=0;
	
	rep(i,S.size()){
		if(S[i]=='N') n=1;
		if(S[i]=='E') e=1;
		if(S[i]=='W') w=1;
		if(S[i]=='S') s=1;
	}
	
	if(n==1&&s==0){
		cout<<"No"<<endl;
		return 0;
	}
	if(s==1&&n==0){
		cout<<"No"<<endl;
		return 0;
	}
	if(e==1&&w==0){
		cout<<"No"<<endl;
		return 0;
	}
	if(w==1&&e==0){
		cout<<"No"<<endl;
		return 0;
	}
	else cout<<"Yes"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int N;
  N=100*a+10*b+c;
  if(N%4==0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main(void){
	int n,k,x,y;
	scanf("%d%d%d%d",&n,&k,&x,&y);
	if(n <= k){printf("%d\n",n*x);}
	else{printf("%d\n",k*x+(n-k)*y);}
	return 0;
}

Measured memory_bytes: 128
// E - Red and Green Apples

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int p[100000], q[100000], r[100000];

int main(){
	int X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;

	for (int i=0; i<A; i++) {
		cin >> p[i];
	}

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

	for (int i=0; i<C; i++) {
		cin >> r[i];
	}

	priority_queue<int> pq;

	sort(p, p+A, greater<int>());
	for (int i=0; i<X; i++) {
		pq.push(p[i]);
	}

	sort(q, q+B, greater<int>());
	for (int i=0; i<Y; i++) {
		pq.push(q[i]);
	}

	for (int i=0; i<C; i++) {
		pq.push(r[i]);
	}

	ll ans = 0;
	for (int i=0; i<X+Y; i++) {
		ans += pq.top();
		pq.pop();
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> inline void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7  
int main() {
    int n,m;
    cin>>n>>m;
    if(n==m)cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define llint long long

using namespace std;

llint n, m;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	if(n == m) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline

N,M,K=map(int,input().split())

p=list(range(N))
r=[0]*N

def find(x):
  if p[x]==x:
    return x
  else:
    p[x]=find(p[x])
    return p[x]

def unite(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return
  if r[x]<r[y]:
    p[x]=y
  else:
    p[y]=x
    if r[x]==r[y]:
      r[x]+=1

nc=[1]*N
f=[0]*N

for i in range(M):
  a,b=map(int,input().split())
  nc[a-1]+=1
  nc[b-1]+=1
  unite(a-1,b-1)

for i in range(K):
  c,d=map(int,input().split())
  if find(c-1)==find(d-1):
    nc[c-1]+=1
    nc[d-1]+=1

for i in range(N):
  f[find(i)]+=1

print(*[f[find(i)]-nc[i] for i in range(N)])


Measured memory_bytes: 14880
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;

int main() {
	int N;
	int a,maxi=0,ans=0;
	int c[100001] = {};
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> a;
		c[a]++;
		c[a - 1]++;
		c[a + 1]++;
		maxi = max(maxi, a);
	}
	for (int i = 0; i <= maxi+1; i++)
	{
		ans = max(c[i], ans);
	}
	cout << ans;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
    int n, m;
    string ans;
    cin >> n >> m;
    vector<pair<int, int>> condision(m);
    rep(i, m) {
        cin >> condision[i].first >> condision[i].second;
        condision[i].first--;
    }

    bool ok;
    rep(i, 1000) {
        ok = true;
        ans = to_string(i);
        if (ans.length() != n) continue;
        rep(j, m) if (ans[condision[j].first] != (char) (condision[j].second + '0')) ok = false;
        if (ok) {
            cout << i << endl;
            return 0;
        }

    }

    cout << "-1" << endl;

    return 0;
}

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

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

  string result = "";
  while (n > 0) {
    int a = (n - 1) % 26;
    result = (char)('a' + a) + result;
    n = (n - 1) / 26;
  }

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
int main(){
	int task,data[50],n;
	while(cin>>n>>task,n,task){
		for(int i=0;i<n;i++){
			data[i]=0;
		}
		while(1){
			for(int i=0;i<n;i++){
				if(task>0){
					data[i]++;
					task--;
				}else if(data[i]>0){
					task+=data[i];
					data[i]=0;
				}
			}
			int cnt=0,ans;
			for(int i=0;i<n;i++){
				if(data[i]>0){
					ans=i;
					cnt++;
				}
			}
			if(cnt==1&&task==0){
				cout<<ans<<endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1160
#define DBG 0 //submit 0
#if DBG
    #include <algorithm>
    #include<array>
    #include <ctime>
    #include <cstdlib>
    #include <string>
    #include <vector>
    #include <iostream>
    #include <cmath>
    #include <numeric>
#else
    #include <bits/stdc++.h>
#endif

using namespace std;


int main(){
    int i,j,k,tmp = 0,tmpi = 0,ans = 0;
    int N,M;
    //string S;
    cin >> N >> M;
    array<int, 2010> L = {0};
  	//char a = '';

  	//sort(L.begin(),L.end(),greater<int>());
    
    /*
    for(i=0;i<N;i++){
      for(j=i+1;j<N;j++){
      	for(k=j+1;k<N;k++){
          if((L[i] < L[j] + L[k])&&(L[i] > L[j] - L[k]))
            ans++;
          else
            break;
        }
      }
    }
    */
    if((N<=9)&&(M<=9))
      ans = M*N;
    else
      ans = -1;

    cout << ans << endl;

}


Measured memory_bytes: 256
s = gets.chomp
d1 = s[0,2].to_i
d2 = s[2,2].to_i
if (1..12).include?(d1) && (1..12).include?(d2)
  puts 'AMBIGUOUS'
elsif (1..12).include?(d1)
  puts 'MMYY'
elsif (1..12).include?(d2)
  puts 'YYMM'
else
  puts 'NA'
end


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

class Program
{
    //Constで定義すると警告が出るので、変数として定義
    static string InputPattern = "Input2";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("1819");
            WillReturn.Add("2003");
            WillReturn.Add("876");
            WillReturn.Add("2840");
            WillReturn.Add("1723");
            WillReturn.Add("1673");
            WillReturn.Add("3776");
            WillReturn.Add("2848");
            WillReturn.Add("1592");
            WillReturn.Add("922");
        }
        else {
            for (int I = 1; I <= 10; I++) {
                WillReturn.Add(Console.ReadLine());
            }
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        IEnumerable<int> tmp1 = InputList.Select(X => int.Parse(X));
        IEnumerable<int> tmp2 = tmp1.OrderByDescending(X => X).Take(3);

        foreach (int EachInt in tmp2) {
            Console.WriteLine(EachInt);
        }
    }
}

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

int main()
{
  char s[100];
  scanf("%s",s);
  char t[]="AKIHABARA";
  bool F=1;
  int i,j;
  for(i=0,j=0;s[i]||t[j];){
    if(s[i]==t[j]){
      i++;
      j++;
    }
    else if(t[j]=='A'){
      j++;
    }
    else{
      F=0;
      break;
    }
  }
  puts(F&&!s[i]&&!t[j]?"YES":"NO");
  return 0;
}


Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial
from heapq import heappop, heappush, heappushpop
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    for i in range(1, int(sqrt(N) + 2)):
        if i * i <= N:
            ans = i * i
        else:
            print(ans)
            exit()
if __name__ == '__main__':
    main()

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

typedef long long ll;

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

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define MOD 1000000007

ll comb[1252][1252];

int r,c,ai,aj,bi,bj;

int main(){
  cin>>r>>c>>ai>>aj>>bi>>bj;
  REP(i,1252)REP(j,1252){
    if(j==0 || j==i)comb[i][j]=1;
    else if(j>i)comb[i][j]=0;
    else comb[i][j] = (comb[i-1][j] + comb[i-1][j-1])%MOD;
  }
  int mincost = r+c+r+c;
  FOR(i,-1,2)FOR(j,-1,2){
    int cost = 0;
    int ci=ai, cj=aj;
    if(i==-1)ci=0,cost++;
    if(i==+1)ci=r-1,cost++;
    if(j==-1)cj=0,cost++;
    if(j==+1)cj=c-1,cost++;
    cost += abs(ci-bi)+abs(cj-bj);
    CHMIN(mincost, cost);
  }
  ll cnt = 0;
  FOR(i,-1,2)FOR(j,-1,2){
    int cost = 0;
    int ci=ai, cj=aj;
    if(i==-1)ci=0,cost++;
    if(i==+1)ci=r-1,cost++;
    if(j==-1)cj=0,cost++;
    if(j==+1)cj=c-1,cost++;
    cost += abs(ci-bi)+abs(cj-bj);
    if(mincost != cost)continue;
    int a = abs(i)+abs(ci-bi);
    int b = abs(j)+abs(cj-bj);
    cnt += comb[a+b][a];
    cnt %= MOD;
  }
  printf("%d %lld\n",mincost,cnt);
  return 0;
}


Measured memory_bytes: 15484
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}



int main() {
	int n; cin >> n;
	vector<int> p(n),sample(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		sample[i] =  i+1;
	}

	int cnt = 0;

	for (int i = 0; i < n; i++) {
		if (p[i] != sample[i]) cnt++;
	}
	//printVec(p);
	//printVec(sample);

	//cout << cnt << endl;
	if (cnt == 2||cnt==0) cout << "YES";
	else cout << "NO";

	cout << endl;
	return 0;
}

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

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

  int a, b, n;
  cin >> a >> b >> n;
  bool ok = true;
  for(int i = 0; i < n; ++i) {
    int s, f;
    cin >> s >> f;
    
    if((s < a && a < f) || (s < b && b < f) || (a <= s && f <= b)) ok = false;
  }
  if(ok) cout << 0 << endl;
  else cout << 1 << endl;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
    
#define all(a) a.begin(), a.end()
#define forn(l, r) for(int i = l; i < (r); ++i)
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
///#define int long long int
    
using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
using ii = pair<int, int>;
using li = pair<ll, int>;
using vi = vector<int>;
using graph = vector<vi>;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
    
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    
const ll mod =  1000000007;
const int INF = 0x3f3f3f3f;
const int MAXN = 312345;
// const double pi = 3.14159265359;
const double eps = 0.00000001;
    
int n, k;
int arr[55];
    
int job(int i, int j) {
    int x = k - (i + n - 1 - j);
    if (x < 0) return -INF;
    vi a;
    for (int k = 0; k < i; ++k) {
        a.push_back(arr[k]);
    }
    for (int k = n - 1; k > j; --k) {
        a.push_back(arr[k]);
    }
    sort(all(a));
    int u = 0, res = 0;
    while (u < (int)a.size() && a[u] < 0 && x) --x, ++u; 
    for (int k = u; k < (int)a.size(); ++k) {
        res += a[k];
    } 
    return res;
}

int32_t main() {
    $
    cin >> n >> k;
    forn (0, n) {
        cin >> arr[i];
    }
    int ans = -INF;
    for (int i = 0; i < n; ++i) {
        for (int j = n - 1; j >= i - 1; --j) {
            ans = max(ans, job(i, j));
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp make_pair
#define INF (1<<28)
typedef long long Int;

int N, B[64], C[64];
string A[64], D[64][64];
int g[64][64], vis[64];
int m, q[64];

void collect(int at) {
    if (vis[at]) return ;
    vis[at] = 1;
    q[m++] = at;
    rep (i, N) if (g[at][i]) collect(i);
}

int n, a, r[64], p[64];
Int f[64];

void prepare() {
    n = m;
    a = 0;
    rep (i, n) r[i] = q[i];
    rep (i, n) {
        p[i] = B[r[i]];
        f[i] = 0;
        rep (j, n) if (g[r[i]][r[j]]) f[i] |= 1LL<<j;
    }
}

void rec(int k, Int u) {
    int s = 0;
    rep (i, n) if (u&(1LL<<i)) s += p[i];
    if (s < a) return ;
    if (k == n) a = s;
    else {
        rep (i, k) if (!(u&(1LL<<i)) && !(f[i]&u)) return ;
        const int mask = (1LL<<n) - 1;
        if (u&(1LL<<k)) rec(k+1, u&(mask-f[k]));
        if (r[k]) rec(k+1, u&(mask-(1LL<<k)));
    }
}

int solve() {
    memset(vis, 0, sizeof(vis));
    int ans = 0;
    rep (i, N) if (!vis[i]) {
        m = 0;
        collect(i);
        prepare();
        rec(0, (1LL<<n)-1);
        ans += a;
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    for (;;) {
        cin >> N;
        if (N == 0) return 0;
        map<string, int> of;
        rep (i, N) {
            cin >> A[i] >> B[i] >> C[i];
            of[A[i]] = i;
            rep (j, C[i]) cin >> D[i][j];
        }
        memset(g, 0, sizeof(g));
        rep (i, N) rep (j, C[i]) g[i][of[D[i][j]]] = 1;
        printf("%d\n", solve());
    }
}

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

int main()
{
  int n;
  cin >> n;
  const ll LIMIT = 1e18;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    if (a[i] == 0)
    {
      cout << 0 << endl;
      return 0;
    }
  }

  ll sum = a[0];
  for (int i = 1; i < n; i++)
  {
    if (a[i] > LIMIT / sum)
    {
      cout << -1 << endl;
      return 0;
    }
    sum *= a[i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 4036
//Har Har Mahadev
using namespace std;
#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll long long int
#define pb push_back
#define mp make_pair
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " -> " << a << endl;
	err(++it, args...);
}

void testcase(){
	string s;
	cin >> s;
	int n = s.size();
	if(s[n-1] == 's')cout << s << "es";
	else cout << s << 's';
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		testcase();
	}
	return 0;
}


Measured memory_bytes: 3660
import sys
input = sys.stdin.readline

def solve():
    INF = 10**10

    N, M = map(int, input().split())
    keys = []
    costs = []
    for _ in range(M):
        a, b = map(int, input().split())
        costs.append(a)
        cs = list(map(int, input().split()))
        key = 0
        for c in cs:
            key |= 1<<(c-1)
        keys.append(key)

    dp = [INF] * (1<<N)
    dp[0] = 0
    for S in range(1<<N):
        for key, cost in zip(keys, costs):
            S2 = S | key
            c2 = dp[S] + cost
            if c2 < dp[S2]:
                dp[S2] = c2

    if dp[-1] == INF:
        print(-1)
    else:
        print(dp[-1])


solve()


Measured memory_bytes: 3188
X,N = map(int,input().split())
if N != 0:
    P = list(map(int,input().split()))
if N == 0:
    P = [3.2]
judge = P[0]
if X not in P:
    print(X)
plusminus = 0
if X in P:
    while True:
        plusminus +=1
        if X-plusminus not in P:
            
            print (X-plusminus)
            break
        elif X+plusminus not in P:
            print(X+plusminus)
            break

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

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

using namespace std;

int main(){
    int n;
    vector<ll> b;
    ll ans=0;
    vector<ll> a;

    cin >> n;
    int st,en;

    rep(i,n-1){
        ll bn;
        cin >> bn;
        b.emplace_back(bn);
        if(i==0){
            st=bn;
        }
        if(i==n-2){
            en=bn;
        }
    }

    a.emplace_back(st);
    for(int i=1;i<n-1;i++){
        ll mini=min(b[i],b[i-1]);
        a.emplace_back(mini);
    }
  	a.emplace_back(en);

    for(auto v : a){
        ans+=v;//printf("a=%d\n",v);
    }

    cout << ans << endl;

}

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

int main(){
  int n; cin >> n;
  string s; cin >> s;
  vector<int> v, e;
  v.push_back(0);
  e.push_back(0);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'W') {
      v.push_back(v[i]+1);
      e.push_back(e[i]);
    } else {
      e.push_back(e[i]+1);
      v.push_back(v[i]);
    }
  }
  int ans = 1e9;
  for (int i = 1; i <= n; i++) {
    int x = v[i-1] - v[0];
    int y = e[n] - e[i];
    ans = min(ans, x+y);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4088
//--- pD ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	PrintWriter out;
	public Solution() {
		reader = new Reader();
		out = new PrintWriter(System.out);
		while (reader.hasNext()) {
			run_case();
		}
		out.flush();
	}

	Map<Integer, Set<Integer>> adj;
	private void run_case() {
		int n = reader.ni();
		int m = reader.ni();
		adj = new HashMap<>();
		for (int i=0; i<m; i++) {
			int a = reader.ni();
			int b = reader.ni();
			adj.putIfAbsent(a, new HashSet<>());
			adj.putIfAbsent(b, new HashSet<>());
			adj.get(a).add(b);
			adj.get(b).add(a);
		}

		Integer[] vis = new Integer[n+5];

		Queue<State> q = new LinkedList<>();
		q.offer(new State(1, -1));
		while (!q.isEmpty()) {
			State cur = q.poll();
			if (vis[cur.idx] != null) continue;
			vis[cur.idx] = cur.pv;
			if (adj.containsKey(cur.idx)) {
				for (int nx : adj.get(cur.idx)) {
					if (vis[nx] != null) continue;
					q.offer(new State(nx, cur.idx));
				}
			}
		}

		boolean ok = true;
		for (int i=1; i<=n; i++) {
			if (vis[i] == null) ok = false;
		}

		if (ok) {
			out.println("Yes");
			for (int i=2; i<=n; i++) out.println(vis[i]);
		} else {
			out.println("No");
		}

		return;

	}
}

class State {
	public int idx, pv;
	public State(int idx, int pv) {
		this.idx = idx;
		this.pv = pv;
	}
}

class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public int ni() {return Integer.parseInt(this.next());}
	public long nl() {return Long.parseLong(this.next());}
	public String ns() {return this.next();}
}


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

public class Main{
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}



	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}


	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}


	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}


	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 String s=sc.next();
	 s=s.substring(s.indexOf('A'));
	 System.out.println(s.lastIndexOf('Z')+1);
	 
	 
	 
 }
	


}



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


int lowerBound(int *a,int n,int key){
    int s =0,e=n-1;
    int ans = 0;

    while(s<=e){
        int mid = (s+e)/2;

        if(a[mid]==key){
            ans = mid;
            e = mid - 1;
        }
        else if(a[mid]>key){
            e = mid - 1;
        }
        else{
            s = mid + 1;
        }
    }

    return ans;
}

int main(){
    int n,a,ar[10000],ar1[10000],sum=0;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>ar[i];
    }
    sort(ar,ar+n);
    for(int i=0; i<n; i++)
    {
        for(int j=i+1; j<n-1; j++)
        {
            int s = ar[i]+ar[j];
            //sum = lowerBound(ar,n,s);
            int x1 = j+1;
            while(s>ar[x1])
            {
                sum++;
                //cout<<ar[x1]<<" ";
                if(x1==n-1) break;
                x1++;
        }
        //cout<<sum<<endl;
    }
    //cout<<sum<<endl;
    //cout<<upperBound(ar,n,a)<<endl;
    }
    cout<<sum<<endl;

return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200123
#define ll long long
#define endl '\n'

using namespace std;

int n, m, ans, curr;
ll k, a[N], b[N];

void print_vetor(ll v[], int size) {
    for(int i=0; i < size; ++i) {
        cout << v[i] << ' ';
    }
    cout << endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> m >> k;

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

    for(int i=0; i < m; ++i) {
        cin >> b[i];
    }
    
    partial_sum(a, a + n, a);
    partial_sum(b, b + m, b);

    for(int i=0; i < n; ++i) {
        curr = 0;
        if(k >= a[i]) curr = i + 1;
        if(k > a[i]) {
            curr += upper_bound(b, b + m, k - a[i]) - b;
        }
        ans = max(ans, curr);
    }

    for(int i=0; i < m; ++i) {
        curr = 0;
        if(k >= b[i]) curr = i + 1;
        if(k > b[i]) {
            curr += upper_bound(a, a + n, k - b[i]) - a;
        }
        ans = max(ans, curr);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6720
def cp(x1,x2)
  x1[0]*x2[1]-x1[1]*x2[0]
end

def aux(p1,p2,p3,px)
  v1=[p1[0]-px[0],p1[1]-px[1]]
  v2=[p2[0]-px[0],p2[1]-px[1]]
  v3=[p3[0]-px[0],p3[1]-px[1]]
  w1=cp(v1,v2)
  w2=cp(v2,v3)
  w3=cp(v3,v1)
  if (w1 < 0 and w2 < 0 and w3 < 0) or (w1 > 0 and w2 > 0 and w3 > 0)
    return "YES"
  else
    return "NO"
  end
end

def main
  fh=STDIN
  #fh=File.new("vol0-0012.txt,"r")
  while fh.gets
    f = $_.chomp.split.map(&:to_f)
    puts aux([f[0],f[1]], [f[2],f[3]], [f[4],f[5]], [f[6],f[7]])
  end
end

if $0 == __FILE__ then
  main
end


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

int main()
{
	int n, m;
	cin >> n >> m;
	int a[m];
	for (int i = 0; i < m; ++i)
	{
		cin >> a[i];
	}
	
	int sum = 0;
	for (int i = 0; i < m; ++i)
	{
		sum += a[i];
	}
	
	if (n - sum < 0)
	{
		cout << -1 << endl;
	}
	else
	{
		cout << n - sum << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3636
import sys
input=sys.stdin.readline
n,q=map(int,input().split())
parent=list(range(n))
rank=[0]*n
def root(x):
	if x!=parent[x]:
		x=root(parent[x])
	return x
def same(x,y):
	return root(x)==root(y)
def unite(x,y):
	rx=root(x)
	ry=root(y)
	if rank[rx]<rank[ry]:
		parent[rx]=ry
	else:
		parent[ry]=rx
		if rank[rx]==rank[ry]:
			rank[rx]+=1
for i in range(q):
	c,a,b=map(int,input().split())
	if c==0:
		unite(a,b)
	else:
		if same(a,b):
			print(1)
		else:
			print(0)



Measured memory_bytes: 6756
// template version 1.13
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_pair(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

const int mod = 998244353;

int solve(){
  int n;cin>>n;
  vector<int> d(n);

  vi cnt(n+1);
  int M = -INF;
  rep(i, n) {
    cin>>d[i];
    cnt[d[i]]++;
    chmax(M, d[i]);
  }

  if (cnt[0]!=1 || d[0]!=0){
    cout << 0 << endl;
    return 0;
  }
  else{
    sort(all(d));
    dump(d);
    dump(cnt);

    int ans = 1;
    rep(j, 1, M+1){
      rep(_, cnt[j]){
        ans *= cnt[j-1];
        ans %= mod;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,a) for(ll i=ll(a-1);i>=0;--i)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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 (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
typedef complex<double> Point;
const ll MAX = 201;
constexpr ll nx[4] = {-1,0,1,0};
constexpr ll ny[4] = {0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    ll sl = s.length(),tl = t.length();
    ll ans = INF;
    rep(i,sl-tl+1){
        ll cnt = 0;
        rep(j,tl){
            if (s[i+j] != t[j]) cnt++;
        }
        chmin(ans,cnt);
    }
    PRINT(ans);
}



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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; i < (int)s.size() - 1; i++) {
    if (s[i] == s[i+1]) ++cnt;
  }
  cnt = min(n - 1, cnt + 2 * k);
  cout << cnt << '\n';
}


Measured memory_bytes: 512