akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <random>

#define int long long
#define pb push_back
#define ff first
#define ss second
#define ld long double
#define rsz resize
#define ass assign

using namespace std;

mt19937 gen(time(nullptr));

const int INF = 1e18;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int ans = 0;
    for (int elem : a) {
        if (elem <= x) {
            x -= elem;
            ans++;
        } else {
            cout << ans;
            return 0;
        }
    }
    if (x > 0) ans--;
    cout << ans;
    return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        var S = Console.ReadLine();
        var subStrs = new HashSet<char>() { 'A', 'C', 'G', 'T' };

        int maxLen = 0;
        for(int startIndex = 0; startIndex < S.Length; startIndex++)
        {
            int count = 0;
            for(int i = startIndex; i < S.Length; i++)
            {
                if (!subStrs.Contains(S[i]))
                {
                    break;
                }

                count++;
            }
            maxLen = Math.Max(maxLen, count);
        }

        Console.WriteLine(maxLen);
    }
}



Measured memory_bytes: 13396
#include<stdio.h>

int main(){

	int n, i=0,a=0;

	scanf("%d", &n);

	while (n>i){
		i++;
		if (i % 3 == 0){

			printf(" %d", i);

		}

		else if (i % 10 == 3 || (i / 100) % 10 == 3|| i / 1000 == 3){

			printf(" %d", i);

		}

		else{

			a = i / 10;
			if (a % 10 == 3){

				printf(" %d", i);

			}
			

		}



	}
	printf("\n");
		return 0;
	}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <stack>
using namespace std;

typedef long long ll;

// dp[a][b]ÉÍfrom a to bÌ¶ððÍµ½Æ«A½¶Ì¶ªoÄ­é©ðL^µÄ¨­
ll dp[101][101];

ll cp=-1;
ll idx;
char result=0;
bool fin=false;

bool watch=false;

// ðÍµÈªçJEgµÄ¢­
int dfs(const string str,const int from,const int to){
	string res;
	ll pos=0;
	ll resCnt=0;
	while(1){
		ll initPos=pos;
		if(pos>=str.size())
			break;
		if(str[pos]>='0'&&str[pos]<='9'){
			for(ll i=pos+1; ; i++){
				if(!(str[i]>='0'&&str[i]<='9')){
					pos=i;
					break;
				}
			}
			ll cnt=atoi(str.substr(initPos,pos-initPos).c_str());
			if(str[pos]=='('){
				stack<ll> s;
				s.push(0);
				ll start=pos;
				while(1){
					pos++;
					if(str[pos]=='(')
						s.push(0);
					else if(str[pos]==')')
						s.pop();
					if(s.size()==0)
						break;
				}
				string subs=str.substr(start+1,pos-start-1);
				for(ll i = 0; i < cnt; i++){
					//if(dp[start+1][pos-1]!=-1){
					//	ll sum=cp+dp[start+1][pos-1];
					//	if(sum<idx){
					//		cp=sum;
					//		resCnt+=dp[start+1][pos-1];
					//		continue;
					//	}
					//}
					resCnt+=dfs(subs,start+1,pos-1);
					if(result!=0||fin)
						return 0;
				}
				pos++;
			}
			// ¶Ìê
			else{
				for(ll i = 0;i < cnt; i++){
					cp++;
					if(cp>idx){
						fin=true;
						return 0;
					}
					if(cp==idx){
						result=str[pos];
						return 0;
					}
				}
				resCnt+=cnt;
				pos++;
			}
		}
		else{
			for(ll i = initPos; ; i++){
				if(i>=str.size()){
					pos=i+1;
					break;
				}
				else if(!(str[i]>='A'&&str[i]<='Z')){
					pos=i;
					break;
				}
				else{
					resCnt++;
					cp++;
					if(cp>idx){
						fin=true;
						return 0;
					}
					if(cp==idx){
						result=str[i];
						return 0;
					}
				}
			}
		}
	}
	dp[from][to]=resCnt;
	return resCnt;
}

int main(){
	string str;
	while(cin>>str>>idx&&!(str=="0"&&idx==0)){
		for(int i = 0; i < 101; i++)
			for(int j = 0; j < 101; j++)
				dp[i][j]=-1;
		watch=true;
		fin=false;
		cp=-1;
		result=0;
		dfs(str,0,str.size()-1);
		if(result==0)
			cout<<0<<endl;
		else
			cout<<result<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
    int n,m;
    cin>>n>>m;
    int A[n][m],b[m];
    for(int i=0;i<=n-1;i++){
        for(int j=0;j<=m-1;j++){
            cin>>A[i][j];
        }
    }
    for(int i=0;i<=m-1;i++){
        cin>>b[i];
    }
    int c;
    for(int i=0;i<=n-1;i++){
        c=0;
        for(int j=0;j<=m-1;j++){
            c+=A[i][j]*b[j];
        }
        cout<<c<<endl;
    }
    return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 400040;
const int S = 200002;

const ll INF = LLONG_MAX/3;

struct edge{
    int to;
    ll cost;
};

vector<edge> G[N];
ll d[N];

bool IN(int x){
    return 0<=x && x<N;
}

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

    rep(i,n){
        int dd,c;
        cin >>dd >>c;

        rep(j,N)for(int k:{-1,1}){
            int nx = j + k*dd;
            if(IN(nx)) G[j].pb({nx,c});
        }
    }

    fill(d,d+N,INF);
    d[S] = 0;

    using P = pair<ll,int>;
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push({0,S});
    while(!pq.empty()){
        P c = pq.top();
        pq.pop();

        int v = c.se;
        if(c.fi > d[v]) continue;

        for(const auto &e:G[v]){
            if(d[e.to] > d[v]+e.cost){
                d[e.to] = d[v]+e.cost;
                pq.push({d[e.to], e.to});
            }
        }
    }

    ll ans = d[S+x];
    if(ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 231592
/// https://atcoder.jp/contests/dwacon6th-prelims/tasks/dwacon6th_prelims_d
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rng(1);
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0);
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define gg exit(0);

const int N=100010;

int n;
int cnt[N],a[N];
set<int> st;
vector<int> ans;

void inc(int x){
    ans.pb(x);
    st.erase(x);
}
void dec(){
    st.insert(ans.back());
    ans.pop_back();
}

void dfs(int ban){
    if(ans.size()==n){
        forv(i,ans) cout<<i<<" ";
        gg
    }
    if(st.count(ban) && cnt[ban]==n-ans.size())
        return;
    cnt[ban]--;
    for(auto it=st.begin();it!=st.end();it++){
		if(*it==ban) continue;
		inc(*it);
		dfs(a[*it]);
		dec();
	}
	cnt[ban]++;
}

main(){
    #define task "arrangement"
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);

    if((n=in)==2) return cout<<-1,0;
    forinc(i,1,n) cnt[a[i]=in]++,st.insert(i);
    dfs(0);
}



Measured memory_bytes: 11008
import sys
from collections import deque
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,M=map(int,input().split())
    edge=[[] for _ in range(3*N)]
    for i in range(M):
        u,v=map(lambda x: int(x)-1,input().split())
        for k in range(3):
            edge[u*3+k].append(v*3+(k+1)%3)
    S,T=map(lambda x:int(x)-1,input().split())
    que=deque()
    que.append(S*3)
    c=[-1]*(3*N)
    c[S*3]=0
    while que:
        v=que.popleft()
        for nv in edge[v]:
            if c[nv]==-1:
                c[nv]=c[v]+1
                que.append(nv)
    print(c[T*3]//3 if c[T*3]!=-1 else -1)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 79012
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  vector<int> H;
  rep(i,N){
    int h;
    cin >> h;
    H.push_back(h);
  }

  int ret = 0;
  rep(i,N){
    bool flg = true;
    rep(j,i){
      if(H[j] > H[i]) flg = false;
    }
    if(flg) ret++;
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 256
for _ in range(int(input())):
    x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())
    print(["NO","YES"][abs((x1 - x2) * (y3 - y4) - (x3 - x4) * (y1 - y2)) < 1e-10])


Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll = long long;
const int M = 1000000007;
int n, m, k, ans = 0;
int A[1002];
int main()
{
    cin >> n >> m;
    if (m >= n) cout << "unsafe";
    else cout << "safe";
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i += 2) {
		cout << s[i];
	}
	cout << endl;
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
 
int main(){
  string s, t ;
  cin >> s ;
  cin >> t ;
  if(s.length() + 1 == t.length()){
    if(t.compare(0, s.length(), s) == 0){
      cout << "Yes" ;
      return 0 ;
    }
  }
  cout << "No" ;
  return 0 ;
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
	int N, L;
	int aji[210];
	int i;
	int sum=0;

	int min = 10000;
	scanf("%d%d", &N, &L);
	for (i = 1;i <= N;i++)
	{
		aji[i] = L + i - 1;
		if (abs(aji[i]) < abs(min))min = aji[i];
	
		sum += aji[i];
		
	}
		printf("%d\n", sum-min);
	
	return 0;
}

Measured memory_bytes: 128
#include <unordered_set>
#include <iostream>
#include <string>


using namespace std;

class A {
	string S;

public:
	void solve()
	{
		cin >> S;

		cout << "2018" << S.substr(4) << endl;
	}
};


class B {
	int N, d;
	unordered_set <int> s;

public:
	void solve()
	{
		cin >> N;
		for (int i{ 0 }; i < N; i++)
		{
			cin >> d;
			s.insert(d);
		}

		cout << s.size() << endl;
	}
};


int main()
{
	A solution;
	solution.solve();
	return 0;
}

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

using namespace std;

#define LL long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define rep(i,a,b) for(int i = (a) ; i <= (b) ; i++)
#define per(i,a,b) for(int i = (a) ; i >= (b) ; i--)
#define mem(a) memset(a,0,sizeof(a))
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const int INF = 1e9;
const LL mod = 1e9 + 7;
const int maxn = 2e5 + 7;

int main() {
    int n;
    while(cin >> n) {
        int x1 = n % 10;
        int x2 = (n / 10) % 10;
        int x3 = n / 100;
//        cout << x1 << " " << x2 << " " << x3 << endl;
        if(x1 == 7 || x2 == 7 || x3 == 7) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
dic = {}
n = int(input())
a = [int(x) for x in input().strip().split()]

for i in range(1,n+1):
    dic[i] =[]

for i in range(n-1):
    dic[a[i]].append(i+2)

res = [len(dic[i]) for i in range(1,n+1)]
for r in res:
    print(r)

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

long mn = 1e18;

int main() {
  long n; cin >> n;
  for(long i = 1; i * i <= n; ++i) {
    if(n % i == 0) {
      mn = min(mn, i + (n/i) - 2);
    }
  }
  cout << mn << endl;
}


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

int main(){
  int k,n;
  cin >> k >> n;
  vector<int> vec(n);
  for(int i = 0;i < n;i ++){
    cin >> vec.at(i);
  }
  
  int kekka;
  vector<int> v(n);
  
  for(int i = 0;i < n;i ++){
    if(i == n - 1)v.at(n - 1) = k - vec.at(n - 1) + vec.at(0);
    else v.at(i) = vec.at(i + 1) - vec.at(i);    
  }
  
  sort(v.begin(),v.end());
  for(int i = 0;i < v.size() - 1;i ++){
    kekka += v.at(i);
  }
  cout << kekka << endl;
}

Measured memory_bytes: 1792
N, A, B, C  = map(int, input().split())
L = [int(input()) for _ in range(N)]
INF = 10 ** 9


def dfs(cur, a, b, c):
  if cur == N:
    # -30で各Lの一回目の使用のコストを調整する。abs(a-A)で何度+-1の処理が必要かを計算する。
    return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
  # 各Lを使うか使わないか決める
  ret0 = dfs(cur + 1, a, b, c) # 材料として使わない場合
  ret1 = dfs(cur + 1, a + L[cur], b, c) + 10 # aの材料として使う場合
  ret2 = dfs(cur + 1, a, b + L[cur], c) + 10 # bの材料として使う場合
  ret3 = dfs(cur + 1, a, b, c + L[cur]) + 10 # cの材料として使う場合
  return min(ret0, ret1, ret2, ret3)

print(dfs(0,0,0,0))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
#define db long double
#define ull unsigned long long int
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define Nmax 1000005
#define INF 1000000000
#define MOD 1000000007
#define MAXN 1000005
 
using namespace std;

string s;
ll d;
ll dp[10005][101][2];

ll recur(ll pos,ll rem,ll flag)
{
	if(pos==s.length())
	{
		if(rem==0) return 1;
		else return 0;
	}
	if(dp[pos][rem][flag]!=-1) return dp[pos][rem][flag];
	ll res=0,limit;
	if(flag==1) limit=9;
	else limit=s[pos]-'0';
	// cout<<"-->"<<limit<<"\n";
	for(ll i=0;i<=limit;i++)
	{
		ll newflag=flag,remain=rem;
		if(flag==0 && i<limit) newflag=1;
		// remain*=10;
		// remain+=i;
		// remain%=d;
		res+=recur(pos+1,(rem+i)%d,newflag);
		res%=MOD;
	}
	return dp[pos][rem][flag]=res;

}

int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    int tests=1;
    // compute();
    // cin>>tests;
    while(tests--)
    {
    	ll i,j;
    	cin>>s;
    	cin>>d;
    	// cout<<s;
    	memset(dp,-1,sizeof(dp));
    	cout<<(recur(0,0,0)-1+MOD)%MOD;

    }
    	return 0;
    
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

const ll MOD = 1e9+7;
ll N, M;

ll kai(ll x) {
   ll ret = 1;
   while (x > 0) {
      // ret *= x;
      ret = ((ret%MOD) * (x%MOD))%MOD;
      x--;
   }
   return ret;
}

int main() {
   cin >> N >> M;

   if (abs(N-M) >= 2) {
      cout << 0 << endl;
      return 0;
   }

   ll Min = min(N, M), Max = max(N, M);
   if (Min == Max) {
      // cout << (kai(Min) * 2 * Min)%MOD << endl;
      cout << (2*kai(Min) * kai(Min))%MOD << endl;
   } else {
      cout << ((kai(Min)%MOD) * (kai(Max)%MOD))%MOD << endl;
   }


   return 0;
}

Measured memory_bytes: 256
from sys import stdin

h,w,k = [int(x) for x in stdin.readline().rstrip().split()]
li = [["" for i in range(w)]for j in range(h)]
for i in range(h):
    s = stdin.readline().rstrip()
    for j in range(w):
        li[i][j] = s[j]
lin = [[0 for i in range(w)]for j in range(h)]
count = 0
for i in li:
    if "#" not in i:
        count += 1
    else:
        break
point = 0
for i in range(count,h):
    kosuu = li[i].count("#")
    if kosuu == 0:
        for j in range(w):
            lin[i][j] = lin[i-1][j]
    else:
        point += 1
        kai = 0
        for k in range(w):
            lin[i][k] = point
            if li[i][k] == "#":
                kai += 1
                if kai < kosuu:
                    point += 1
for i in range(count):
    for j in range(w):
        lin[i][j] = lin[count][j]
for i in lin:
    print(*i)

Measured memory_bytes: 8144
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    int x = nextInt();
    int y = nextInt();

    if(y%2==1){
      System.out.println("No");
    }
    else{
      int c = 2*x - y/2;
      int t = y/2 - x;
      if(c>=0 && t>=0){
        System.out.println("Yes");
      }
      else{
        System.out.println("No");
      }
    }


    //System.out.println();

  }

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

  static int gcd(int a,int b){
    if(a%b!=0){
      return gcd(b,a%b);
    }
    else{
      return b;
    }
  }

  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int a[n];
	int b[n];
	for (int i = 0; i < n; i++) a[i] = ri(), b[i] = ri();
	std::pair<int, int> ps[n];
	for (int i = 0; i < n; i++) ps[i] = {b[i], a[i]};
	std::sort(ps, ps + n);
	int64_t cur = 0;
	bool res = true;
	for (int i = 0; i < n; i++) {
		if (cur + ps[i].second > ps[i].first) {
			res = false;
			break;
		}
		cur += ps[i].second;
	}
	std::cout << (res ? "Yes" : "No") << std::endl;
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <queue>


using namespace std;


void dfs(int cur, int pre, vector<vector<int>> &graph, vector<int> &cnt, vector<int> &ans) {
    ans[cur] += cnt[cur];
    for (int next: graph[cur]) {
        if (next != pre) {
            ans[next] += ans[cur];
            dfs(next, cur, graph, cnt, ans);
        }
    }
}

int main() {
    int N, Q;
    cin >> N >> Q;

    vector<vector<int>> graph(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vector<int> cnt(N);
    while (Q--) {
        int p, x;
        cin >> p >> x;
        p--;
        cnt[p] += x;
    }

    vector<int> ans(N);

    queue<int> que;
    vector<bool> visited(N, false);
    que.push(0);

    while (!que.empty()) {
        int cur = que.front();
        que.pop();
        visited[cur] = true;

        ans[cur] += cnt[cur];

        for (int next: graph[cur]) {
            if (visited[next]) continue;
            que.push(next);
            ans[next] += ans[cur];
        }


    }


    //dfs(0, -1, graph, cnt, ans);

    for (int i = 0; i < N; i++) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 16372
#include<bits/stdc++.h>
using namespace std;
char s[1000006];
int q, l = 400000, r = 400000, f = 1;
string st;
int main(int argc, char const *argv[])
{
	cin >> st;
	s[l] = st[0];
	for (int i = 1; i < st.length(); ++i)
	{
		{
			r ++;
			s[r] = st[i];
		}
	}
	cin >> q;
	while (q --)
	{
		int ti;
		cin >> ti;
		if (ti == 1)
			f = 1 - f;
		else
		{
			int fc;
			char c;
			cin >> fc >> c;
			if (fc == 1)
			{
				if (f)
				{
					l --;
					s[l] = c;
				}
				else
				{
					r ++;
					s[r] = c;
				}
			}
			else
			{
				if (f == 0)
				{
					l --;
					s[l] = c;
				}
				else
				{
					r ++;
					s[r] = c;
				}
			}
		}


	}
	if (f == 1)
	{
		for (int i = l; i <= r; ++i)
		{
			cout << s[i];
		}
	}
	else
	{
		for (int i = r; i >= l; --i)
		{
			cout << s[i];
		}
	}
	return 0;
}

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

int main()
{
    int A,B,a,b;
    cin>>A>>B;
    
    for(int i=0;i<1010;i++){
        if((i*8)/100==A&&i/10==B){
            cout<<i<<endl;
            exit(0);
        }
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
#define fi first
#define se second
#define pb push_back
#define soo(v) sort(v.rbegin(),v.rend())
#define so(v) sort(v.begin(),v.end())
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
//#define endl '\n'
#define dbv(v) cout<<endl;cout<<#v<<"-->> ";for(auto it:v){cout<<it<<" ";}cout<<endl;
#define dbm(m)cout<<endl;cout<<#m<<"-->> ";for(auto it:m){cout<<it.fi<<" "<<it.se.fi<<" "<<it.se.se<<endl;}
#define dbs(s)cout<<endl;cout<<#s<<"-->> ";for(auto it:s){cout<<it<<" ";}cout<<endl;
#define mod 1000000007
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl;
#define mx 1e18
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v)  *min_element(v.begin(),v.end())
#define double long double
#define re(s) reverse(s.begin(),s.end())
#define io std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
int powe(int x,int n)
{
  if(n==0)return 1;
  if(n%2==0)
    return powe((x%mod*x%mod)%mod,n/2)%mod;
  return (x%mod*powe((x%mod*x%mod)%mod,(n-1)/2))%mod;
}
int gcd(int A,int B)
{
  if(B==0)return A;
  return gcd(B,A%B);
}

int32_t main()
{
  io
int n,k;
cin>>n>>k;
int ans=0;
vector<int>gcd(k+1);
for(int i=k;i>=1;i--)
{
  gcd[i]=powe(k/i,n);
}
for(int i=k;i>=1;i--)
{
  for(int j=2*i;j<=k;j+=i)
  {
    
   gcd[i]=(gcd[i]-gcd[j]+mod)%mod;
  }
}
for(int i=1;i<=k;i++)
{ans=(ans+(gcd[i]*i)%mod)%mod;}
cout<<ans<<endl;

}

Measured memory_bytes: 4004
#include<bits/stdc++.h>
#define int long long

using namespace std;

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

    int n, k;
    string s;
    cin >> n >> k >> s;

    int cnt = 1, ans = 0, sec = 0;
    for (int i = 1; i < n; i++)
    {
        if (s[i] == s[i - 1])
            cnt++;
        else
            ans += cnt - 1, cnt = 1, sec++;
    }
    ans += cnt - 1, sec++;

    while (k--)
    {
        if (sec > 2)
            sec -= 2, ans += 2;
        else if (sec == 2)
            sec--, ans++;
        else
            break;
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        String str = sc.next();
        int abc[] = new int[3];
        for (int i = 0; i < str.length(); i++) {
            for (int j = 0; j < 3; j++) {
                if (str.charAt(i) == "abc".charAt(j)) {
                    abc[j]++;
                }
            }
        }

        Arrays.sort(abc);

        System.out.println(((abc[1] - abc[0] < 2) && (abc[2] - abc[0] < 2)) ? "YES" : "NO");
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


Measured memory_bytes: 24644
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ASheepAndWolves solver = new ASheepAndWolves();
        solver.solve(1, in, out);
        out.close();
    }

    static class ASheepAndWolves {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            w.println(s.nextInt() <= s.nextInt() ? "unsafe" : "safe");
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
    return x * f;
}

int main() {
    int q = read();
    priority_queue<int> l;
    priority_queue<int, vector<int>, greater<int> > r;
    long long ans = 0;
    while (q--) {
        int t = read();
        if (t == 1) {
            int a = read(), b = read();
            ans += b;
            l.push(a);
            r.push(a);
            if (l.top() > r.top()) {
                int x = l.top(); l.pop();
                int y = r.top(); r.pop();
                ans += abs(x - y);
                l.push(y); r.push(x);
            }
        } else {
            printf("%d %lld\n", l.top(), ans);
        }
    }
    return 0;
}

Measured memory_bytes: 3828
N = gets.to_i
p = gets.split.map &:to_i

p((p.first + 1).times.map{|i|
  q = p.dup
  sum = i
  q[0] -= i
  until q.size == 1
    sum += [0, q[0]].max * 2
    q[1] -= [0, q[0]].max
    q.shift
  end
  sum + [0, q[0]].max
}.min)

Measured memory_bytes: 8928
#include<bits/stdc++.h>
#define ll long long
#define pb push_back 
#define pll pair<ll,ll>
#define mp make_pair
#define F first
#define S second
using namespace std;
const int N=1e5+5;
ll n,Q,k;
vector<pll>v[N];
queue<pll>q;
ll dist[N];
int main()
{
	for(int i=0;i<N;i++)dist[i]=1e18;
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		a--,b--;
		v[a].pb(mp(b,c));
		v[b].pb(mp(a,c));
	}
	cin>>Q>>k;
	q.push(mp(k-1,0));
	while(!q.empty())
	{
		pll p=q.front();q.pop();
		if(dist[p.F]>p.S)
			dist[p.F]=p.S;
		else
			continue;
		for(int i=0;i<v[p.F].size();i++)
		{
			int to=v[p.F][i].F;
			ll cost=v[p.F][i].S+p.S;
			q.push(mp(to,cost));
		}
	}
	while(Q--)
	{
		int x,y;
		cin>>x>>y;
		x--,y--;
		cout<<dist[x]+dist[y]<<endl; 
	}
	return 0;
}

Measured memory_bytes: 10864
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <vector>

#define rep(i,min,max) for(int i=min;i<max;i++)
#define rrep(i,min,max) for(int i=max;i>=min;i--)

using namespace std;

int main(){
  int o[5];
  rep(i,0,5)cin >> o[i];
  int time = 0;
  int sub = 10;
  rep(i,0,5){
    sub = o[i] % 10 != 0 ? min(sub, o[i] % 10):sub;
    if(o[i] % 10 == 0){
      time+=o[i];
    }else{
      time+=((o[i]/10)+1)*10;
    }
  }
  cout << time - 10 + sub << endl;
  return 0;
}


Measured memory_bytes: 256
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g PROGRAM -o OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
    if (!y)
        return x;
    return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;


inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d,string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while(getline(ss,t,d))
    {
        words.pb(t);
    }

    return words;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
    auto start = chrono::high_resolution_clock::now();
#endif
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    cin >> s;
    int i = 0;
    int ans = 0,mx=0;
    while (i < 3)
    {
        if(s[i]=='R')
            ans++;
        else
            ans = 0;
        mx = max(ans, mx);
        i++;
    }

    cout << mx;

#ifdef LOCAL
    auto end = chrono::high_resolution_clock::now();
    double time_taken =
        chrono::duration_cast<chrono::nanoseconds>(end - start).count();

    time_taken *= 1e-9;

    cerr << "\nTime taken by program is : " << fixed
         << time_taken << setprecision(9);
    cerr << " sec" << endl;
#endif
    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string s; cin >> s;
    int pos = 0;
    while(true)
    {
        pos = s.find("BC", pos);
        if(pos == -1) break;
        s.replace(pos, 2, "D");
    }

    ll ans = 0;
    ll a = 0;
    REP(i, s.length())
    {
        if(s[i] == 'A') a++;
        else if(s[i] == 'D') ans += a;
        else a = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 720
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
    long long int n,ans=0;
    string s;
    cin>>s;
    vector<int>a(4);
    a[0]=0;
    a[1]=0;
    a[2]=0;
    a[3]=0;
    for(int i=0;i<s.size();i++){
    	if(i%2==0){
    		if(s[i]=='0'){
    			a[0]++;
    		}
    		else{
    			a[1]++;
    		}
    	}
    	else{
    		if(s[i]=='0'){
    			a[2]++;
    		}
    		else{
    			a[3]++;
    		}
    	}
    }
    ans=(min(a[0],a[3])+min(a[1],a[2]))*2;
    cout<<ans<<endl;
    
    
}

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

#define ll long long int
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MOD = 1e9 + 7;
typedef unsigned long long u64;

int main()
{
    IOS;
    int t = 1;
    //cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        int diff[n + 1];
        unordered_map<long, long> mp;
        for (int i = 1; i <= n; i++)
        {
            int x;
            cin >> x;
            diff[i] = i - x;
            mp[i + x] += 1;
        }
        ll ct = 0;
        for (int i = 1; i <= n; i++)
        {
            if (diff[i] > 0)
            {
                ct += mp[diff[i]];
            }
        }
        cout << ct << endl;
    }
    return 0;
}


Measured memory_bytes: 12912
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, char) => {
        read_value!($next, String).chars().collect::<Vec<char>>()[0]
     };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
    ($next:expr, isize1) => {
        read_value!($next, isize) - 1
    };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}
#[allow(dead_code)]
const MOD: u64 = 1000000007;
#[allow(dead_code)]
fn to_num(c: char) -> i64 {
    c as i64 - 48
}


fn main() {
    input!{
        H: usize, W: usize,
        C: [String; H],
    }
    for s in C {
        println!("{}", s);
        println!("{}", s);
    }
}

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

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    vector<int> a(n);
    rep(i, n) {
        scanf("%d", &a[i]);
    }
    // k学期の評点→a[0]*a[1]*...*a[k-1]
    // k+1学期の評点→a[1]*a[2]*...*a[k]
    // a[k]>a[0]ならば、k+1学期の評点はk学期より高いと言える
    // n学期の評点がn-1学期の評点より高いのはa[n-1]>a[n-1-k]のとき
    rep(i, n-k) {
        if (a[i] < a[i+k]) printf("Yes\n");
        else printf("No\n");
    }
}

Measured memory_bytes: 4060
#include <stdio.h>

int main(void){
  int i, n, x, y, z;
  x = y = z = 1;
	
  scanf("%d", &n);
	
  for(i = 0; i < n - 1; i++){
    z = x + y;
    y = x;
    x = z;
  }
	
  printf("%d\n", z);

  return 0;

}



Measured memory_bytes: 2116
import java.util.*;

public class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        int INF = 1100000000;

        int n = sc.nextInt();
        int[][] ab = new int[n][2];
        for(int i=0; i<n; i++){
            ab[i][0] = sc.nextInt();
            ab[i][1] = sc.nextInt();
        }

        Arrays.sort(ab, new Comparator<int[]>(){
                public int compare(int[] a, int[] b){
                    return a[1] - b[1];
                }
            });

        int[][] dp = new int[n+1][n+1];
        for(int i=0; i<=n; i++) Arrays.fill(dp[i],INF);
        dp[0][0] = 0;

        for(int i=0; i<n; i++){
            for(int j=0; j<=i; j++){
                if(dp[i][j]==INF) continue;
                dp[i+1][j] = Math.min(dp[i][j],dp[i+1][j]);
                if(dp[i][j]+ab[i][0]<=ab[i][1]){
                    dp[i+1][j+1] = Math.min(dp[i][j]+ab[i][0], dp[i][j+1]);
                }
            }
        }

        int ans = 0;
        for(int i=0; i<=n; i++){
            if(dp[n][i]!=INF) ans = i;
        }

        System.out.println(ans);
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

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

#define COUT(x) cout << #x << " = " << (x) << ", "
typedef long long ll;
const int MOD = 1000000007;

class UnionFind{
public:
  vector<ll> par; //Ë¶™„ÇíË°®„ÅôÈÖçÂàó
  vector<ll> siz; //ÂêÑÈõÜÂêà„ÅÆ„Çµ„Ç§„Ç∫
  vector<ll> amt; //ÂêÑÈõÜÂêà„ÅÆË¶ÅÁ¥†Êï∞
  UnionFind(ll n): par(n), siz(n, 1LL), amt(n, 1LL){
    for(ll i = 0; i < n; i++) par[i] = i;
  }
  ll root(ll x){
    return par[x] == x ? x : par[x] = root(par[x]);
  }
  bool unite(ll x, ll y){
    x = root(x);
    y = root(y);
    ll x_amt = amt[x];
    ll y_amt = amt[y];
    if(x == y) return false;
    if(siz[x] < siz[y]){
      par[x] = y;
      amt[y] = x_amt + y_amt;
    }else{
      par[y] = x;
      if(siz[x] == siz[y]) siz[x]++;
      amt[x] = x_amt + y_amt;
    }
    return true;
  }
  bool same(ll x, ll y){
    return root(x) == root(y);
  }
  ll amount(ll x){
    return amt[root(x)];
  }
};
  
int main(){
  ll N,M;
  cin >> N >> M;
  vector<pair<ll,ll>> B(M);
  UnionFind u(N);
  for(int i = 0; i < M; i++){
    cin >> B[i].first >> B[i].second;
    B[i].first--; B[i].second--;
  }
  vector<ll> res(M);
  for(int i = M-1; i >= 0; i--){
    ll x = B[i].first, y = B[i].second;
    if(u.same(x,y)){
      res[i] = 0;
    }else{
      ll tmp1 = u.amount(x);
      ll tmp2 = u.amount(y);
      res[i] = tmp1 * tmp2;
      u.unite(x,y);
    }
  }
  for(int i = 0; i < M; i++){
    if(i){
      res[i] += res[i-1];
    }
    cout << res[i]  << endl;
  }
}


Measured memory_bytes: 6016
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	string N;
	cin >> N;
	cat ans =0, prefsum =0;
	for(int i =0; i < (int)N.length(); i++) ans +=N[i]-'0';
	for(int i =0; i < (int)N.length(); i++) {
		if(N[i] > '0') ans =max(ans, ((int)N.length()-1-i)*9+prefsum+N[i]-'1');
		prefsum +=N[i]-'0';
	}
	cout << ans << "\n";
	return 0;}

// look at my code
// my code is amazing


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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll a, b;
	cin >> a >> b;
	ll ans = 0;
	ll nr = 1;
	while (nr < b)
	{
		ans++;
		nr += (a - 1);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;
int main()
{
  int X;
  cin >> X;
  int ans = X;
  int flg = 0;
  while(true){
    for(int i=2; i<X; i++){
      if(ans%i==0) flg=1;
    }
    if(flg==0){
      cout << ans << endl;
      break;
    } else {
      flg = 0;
      ans++;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim = 1e5+5;
const int mod = 1e9+7;

map<int,int> str;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin>>n;
	for(int i=0;i<n;i++) {
		int t;
		cin>>t;
		str[t]++;
	}
	if(str.size()>3)
		cout<<"No";
	else if(str.size()==3) {
		int cnt[3],val[3],z = 0;
		for(auto& pr:str)
			val[z] = pr.first, cnt[z] = pr.second, z++;

		if(cnt[0]==cnt[1] && cnt[1]==cnt[2] && (val[0]^val[1]^val[2])==0)
			cout<<"Yes";
		else
			cout<<"No";
	}
	else if(str.size()==2) {
		int cnt[2],val[2],z = 0;
		for(auto& pr:str)
			val[z] = pr.first, cnt[z] = pr.second, z++;

		if(val[0]==0 && 2*cnt[0]==cnt[1])
			cout<<"Yes";
		else
			cout<<"No";
	}
	else
	{
		int cnt[1],val[1],z = 0;
		for(auto& pr:str)
			val[z] = pr.first, cnt[z] = pr.second, z++;

		if(val[0]==0)
			cout<<"Yes";
		else
			cout<<"No";
	}
	return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	double a, b, h, m; read(a, b, h, m);

	double hpar = (h + m / 60) / 12;
	double mpar = m / 60;

	double diff = min(abs(hpar - mpar), 1 - abs(hpar - mpar));
	double ang = diff * 2 * 3.14159265358979;

	double len2 = a * a + b * b - 2 * a * b * cos(ang);
	double len = sqrt(len2);

	cout << fixed << setprecision(13);
	die(len);	
}


Measured memory_bytes: 4232
#include <bits/stdc++.h>
#ifdef DEBUG
#include "../debug.h"
#else
#define debug(...) 42
#endif

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  int r, s, p;
  cin >> r >> s >> p;
  vector<int> ar = {r, p, s};
  string t; cin >> t;
  vector<bool> vis(n);
  auto win = [&](char a, char b) {
    if(a == 'r') {
      if(b == 's') return true;
      return false;
    }
    if(a == 'p') {
      if(b == 'r') return true;
      return false;
    }
    if(a == 's') {
      if(b == 'p') return true;
      return false;
    }
    assert(false);
    return false;
  };
  int res = 0;
  string rps = "rps";
  for(int i = 0; i < n; ++i) {
    vector<int> dp(3);
    if(vis[i]) continue;
    for(int x = 0; x < 3; ++x) {
      if(win(rps[x], t[i])) {
        dp[x] = ar[x];
      }
    }
    for(int j = i + k; j < n; j += k) {
      assert(!vis[j]);
      vis[j] = true;
      debug(dp);
      vector<int> ndp(3);
      for(int x = 0; x < 3; ++x) {
        int add = 0;
        if(win(rps[x], t[j])) {
          add = ar[x];
        }
        for(int y = 0; y < 3; ++y) {
          if(y == x) continue;
          ndp[x] = max(ndp[x], dp[y] + add);
          debug(j, x, y, ndp[x]);
        }
      }
      dp = std::move(ndp);
    }
    debug(dp);
    res += max({dp[0], dp[1], dp[2]});
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int n[2],c[2];
	while(cin>>n[0],n[0]){
		int h[2][110],r[2][110],mx[2][110];
		rep(q,2){
			rep(i,n[q])mx[q][i]=0,cin>>h[q][i]>>r[q][i];
			if(!q)cin>>n[1];
		}
		mx[0][0]=(h[0][0]>h[1][0]&&r[0][0]>r[1][0])+1;
		mx[1][0]=(h[0][0]<h[1][0]&&r[0][0]<r[1][0])+1;
		int p;
		c[0]=c[1]=p=0;
		while(c[0]<n[0]||c[1]<n[1]){
			int tmax=0,f;
			rep(k,2){
				rep(i,n[k]){
					f=h[k][i]<h[p][c[p]]&&r[k][i]<r[p][c[p]];
					if(f&&tmax<mx[k][i])tmax=mx[k][i];
					if((f&&!mx[k][i])||c[p]==n[p]){
						p^=1;
						goto NEXT;
					}
				}
			}
			mx[p][c[p]++]=tmax+1;
			NEXT:;
		}
		cout<<max(mx[0][n[0]-1],mx[1][n[1]-1])<<endl;
	}
	return 0;
}

Measured memory_bytes: 0