akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define vii vector < pii >
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;}
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = 512;
vi P[N][N];
vi U[N][N];
vi comb(vi a,vi b) {
	vi c;
	for (auto it : a)
		c.pb(it);
	for (auto it : b)
		c.pb(it);
	return c;
}

db f(ll a,ll b) {
	return 1.0 * a / b;
}
vi O[N];
int main(void) {
	int n,m;
	cin>>n>>m;
	while (m --) {
		int u,v,w;
		cin>>u>>v>>w;
		for (int i = 0;i < w;++i) {
			P[u][v].pb(v);
			P[v][u].pb(u);
		}
	}
	auto Last = chrono::steady_clock::now().time_since_epoch().count();
	for (int k = 1;k <= n;++k)
		for (int i = 1;i <= n;++i)
			for (int j = 1;j <= n;++j)
				if (!P[i][k].empty() && !P[k][j].empty() && ((i != j && P[i][j].empty()) || P[i][j].size() > P[i][k].size() + P[k][j].size()))
					P[i][j] = comb(P[i][k],P[k][j]);
	for (int i = 1;i <= n;++i)
		for (int j = 1;j <= n;++j) {
			U[i][j] = P[i][j];
			sort(all(U[i][j]));
			U[i][j].resize(unique(all(U[i][j])) - U[i][j].begin());
		}
	cerr << "Pre-Process Time Taken: " << 1.0 * (chrono::steady_clock::now().time_since_epoch().count() - Last) / CLOCKS_PER_SEC << '\n';
	int Tmax;
	cin>>Tmax;
	for (int i = 0;i < Tmax;++i) {
		int Nnew;
		cin>>Nnew;
		while (Nnew --) {
			int ID,v;
			cin>>ID>>v;
			O[v].pb(i);
		}
	}
	int last = 0;
	int Vertex = 1;
	vi Answer;
	for (int i = 0;i < Tmax;) {
		if (Vertex == 1) {
			last = i;
		}
		pair < db , int > w = mp(0,1);
		for (int j = 1;j <= n;++j) {
			int cnt1 = lower_bound(all(O[j]),last + 1) - O[j].begin();
//			dbg(cnt1);
//			dbg(P[Vertex][j]);
			if (P[Vertex][j].empty())
				continue;
			smax(w,mp(f(cnt1,P[Vertex][j].size()),j));
			int cnt2 = lower_bound(all(O[j]),i + 1 + P[Vertex][1].size()) - O[j].begin();
//			dbg(cnt2);
			smax(w,mp(f(cnt2,P[Vertex][1].size() + P[1][j].size()),-j));
		}
		if (!w.fi) {
			Answer.pb(-1);
			++i;
			continue;
		}
		if (w.se < 0) {
			for (auto it : P[Vertex][1]) {
				Answer.pb(it);
				while (!O[it].empty() && O[it][0] <= last)
					O[it].erase(O[it].begin());
				++i;
			}
			Vertex = 1;
			last = i;
			w.se *= -1;
		}
		for (auto it : P[Vertex][w.se]) {
			Answer.pb(it);
			while (!O[it].empty() && O[it][0] <= last)
				O[it].erase(O[it].begin());
			++i;
		}
		Vertex = w.se;

	}
	if (Answer.size() > Tmax) {
		Answer.resize(Tmax);
	}
	for (auto it : Answer)
		cout << it << '\n';
    return 0;
}

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

using namespace std;
#define int long long
typedef long long ll;

std::vector<std::string> split(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;
}

signed main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(a - c) <= d) cout << "Yes" << endl;
    else if (abs(a - b) <= d && abs(b - c) <= d) cout << "Yes" << endl;
    else cout << "No" << endl;
}



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

int main(void) {
    int bus_stop[24] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8};
    int num, i, start, end;
    int idx1, idx2, diff, n;
    
    scanf("%d", &num);
    
    while(num--) {
        scanf("%d %d", &start, &end);
        (start < 6 && end < 6) ? (n = 6) : (n = 10);
        
        for(i = 0; i < n; i++) {
            if(bus_stop[i] == start)
                idx1 = i;
            }
        for(i = 0; i < n; i++) {
            if(bus_stop[i] == end)
                idx2 = i;
        }
        diff = fabs(idx1 - idx2);
        
        if(idx1 < idx2) {
            for(i = idx1; i <= idx2; i++) {
                printf("%d", bus_stop[i]);
                if(i != idx2) putchar(' ');
                else          putchar('\n');
            }
        } else if(idx1 > idx2) {
            if(start > 5) {
                if(end > 5) {
                    for(i = idx1; i <= idx2 + 15; i++) {
                        printf("%d", bus_stop[i]);
                        if(i != idx2 + 15) putchar(' ');
                        else          putchar('\n');
                    }
                } else if(end <= 4) {
                    for(i = idx1; i <= 9; i++) {
                        printf("%d", bus_stop[i]);
                        if(i != idx2) putchar(' ');
                        else          putchar('\n');
                    }
                    for(i = 5; i >= idx2; i--) {
                        printf("%d", bus_stop[i]);
                        if(i != idx2) putchar(' ');
                        else          putchar('\n');

                    }
                } else {
                    printf("%d %d\n", 9, 5);
                }
            } else {
                for(i = idx1; i >= idx2; i--) {
                    printf("%d", bus_stop[i]);
                    if(i != idx2) putchar(' ');
                    else          putchar('\n');
                }
            }
        }
    }
    
    return(0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  string a;
  cin>>a;
  if(a=="Sunny"){
    cout<<"Cloudy"<<endl;
  }
  else if(a=="Cloudy"){
    cout<<"Rainy"<<endl;
  }
  else{
    cout<<"Sunny"<<endl;
  }
  return 0;
}
    

  
  
  
      
                        
                        


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

int main(){
    char s[1000005];
    cin>>s+1;
    int len=strlen(s+1);
    bool v=false;
    for(int i = 1;i <= len;i++){
        if(i%2==0){
            if(s[i]!='i') {
                v=true;
                break;
            }
        }
        else {
            if(s[i]!='h'){
                v=true;
                break;
            }
        }
    }
    if(len%2) v=true;
    cout<<(v?"No":"Yes");
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.mutable

object Main {

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val a = Vector.fill(n)(sc.nextInt())

    val m = 1000005

    val cnt = mutable.ArrayBuffer.fill(m + 3)(0)

    a.foreach { x =>
      if (cnt(x) != 0) {
        cnt(x) = 2
      } else {
        (x until(m, x)).foreach { i => cnt(i) += 1 }
      }
    }
    println(a.count(cnt(_) == 1))
  }
}


Measured memory_bytes: 68564
def gcd(a,b):
    c = 0
    while b:
        (a,b),c = (b,a%b),c+1
    print(a,c)
        
while True:
    N,M = map(int,input().split())
    if N == 0:
        break
    gcd(N,M) if N>M else gcd(M,N)
    


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

string s;

int ans[101];
int n=0;

int main()
{
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
	    if(s[i]=='B') { n--; n=max(n,0); }
	    else
	      { n++; ans[n]=s[i]-'0'; }
	}
	
	for(int i=1;i<=n;i++) printf("%d",ans[i]);
	return 0;
}


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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, start, end) for(int i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int h, w, a, b;
    cin >> h >> w >> a >> b;

    cout << (h - a) * (w - b) << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(){

	int n, l[110];
	int sum=0;
	int flag=0;

	std::cin>> n;
	for(int i=0;i<n;i++){
		std::cin>> l[i];
		sum+=l[i];
	}

	for(int i=0;i<n;i++){
		if(sum<=2*l[i]){
			std::cout<< "No" << "\n";
			flag=1;
			break;
		}
	}
	if(flag==0) std::cout<< "Yes" << "\n";



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e9 + 7;

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

  string s;
  cin >> s;

  ll ans = 0, rec = 0;

  REP(i, s.size()){
    if(s[i] == 'W') ans += rec;
    else rec++;
  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 720
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	ld r;
	cin >> r;
	cout << setprecision(9) << fixed << 2.*pi*r << '\n';





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 3756
def main():
    import sys
    input = sys.stdin.readline

    n = int(input())

    L_MAX = 10**5
    D_TH = 10
    V_MAX = (1 << D_TH) - 1
    dp = [[0] * (L_MAX + 1)]
    # items = []
    items_v = []
    items_w = []

    for i in range(n):
        val, w = map(int, input().split())
        if i < V_MAX:
            i1 = i + 1
            i0 = (i + 1) >> 1
            dp_ = dp[i0][:]

            # for j in range(w):
            #     dp[i1][j] = dp[i0][j]
            for j in range(w, L_MAX + 1)[::-1]:
                if dp_[j] < dp_[j - w] + val:
                    dp_[j] = dp_[j - w] + val
            dp.append(dp_)
        else:
            # items.append((val, w))
            items_v.append(val)
            items_w.append(w)

    # items = tuple(items)

    q = int(input())
    for _ in range(q):
        v, l = map(int, input().split())
        v -= 1

        if v < V_MAX:
            ans = dp[v + 1][l]
        else:
            vv = []
            ww = []
            while v >= V_MAX:
                # vv.append(items[v - V_MAX][0])
                # ww.append(items[v - V_MAX][1])
                vv.append(items_v[v - V_MAX])
                ww.append(items_w[v - V_MAX])
                v = (v - 1) >> 1

            ans = dp[v + 1][l]
            # m = len(vv)
            m2 = 1 << len(vv)
            v_sub = [0] * m2
            w_sub = [0] * m2
            for bit in range(1, m2):
                bit_min = bit & (-bit)
                x = bit_min.bit_length() - 1

                s_w = w_sub[bit - bit_min] + ww[x]
                w_sub[bit] = s_w
                if s_w <= l:
                    s_val = v_sub[bit - bit_min] + vv[x]
                    v_sub[bit] = s_val
                    ans = max(ans, dp[v + 1][l - s_w] + s_val)

        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 907308
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
const ll MOD=1000000007,MOD2=998244353;

//nのp乗
ll power(ll n,ll p){
    if(p==0){return 1;}
    if(p%2==1){return n*power(n,(p-1)/2)*power(n,(p-1)/2);}
    else{return power(n,p/2)*power(n,p/2);}
}

int main() {
    int N,M;
    cin>>N>>M;
    vector<pair<int,int>> key(M);
    rep(i,M){
        cin>>key.at(i).first;
        int b;
        cin>>b;
        rep(j,b){
            int c;
            cin>>c;
            --c;
            key.at(i).second+=power(2,c);
        }
    }

    int P=power(2,N);
    vector<vector<int>> dp(M,vector<int>(P,-1));
    dp.at(0).at(key.at(0).second)=key.at(0).first;
    dp.at(0).at(0)=0;
    for(int i=1;i<M;i++){
        rep(j,P){
            dp.at(i).at(j)=dp.at(i-1).at(j);
        }
        rep(j,P){
            if(dp.at(i-1).at(j)!=-1){
                int k=(j|key.at(i).second);
                if(dp.at(i).at(k)==-1){dp.at(i).at(k)=dp.at(i-1).at(j)+key.at(i).first;}
                else{dp.at(i).at(k)=min(dp.at(i).at(k),dp.at(i-1).at(j)+key.at(i).first);}
            }
        }
    }
    cout<<dp.at(M-1).at(P-1)<<endl;
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  string s;
  cin >> s;
  string b = "";
  string t = "";
  i64 ans = 0;
  for(char x : s) {
    t.push_back(x);
    if(b == t) {
      continue;
    }
    else {
      ans++;
      b = t;
      t.clear();
    }
  }
  cout << ans << endl;
}


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

int main (void) {
  string s, t; cin >> s >> t;
  int w = t.length(), ans = INT_MAX;
  for (int i = 0;i + w <= (int)s.length();i++) {
    int cnt = 0;
    for (int j = i;j < i + w;j++) {
      if (s[j] != t[j - i]) cnt++;
    }
    ans = min(ans, cnt);
  }

  cout << ans << '\n';
}

Measured memory_bytes: 3628
import sys
# sys.stdin=open('input.txt','r')
# sys.stdout=open('output.txt','w')
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007
n=ii1()
arr=iia()
max=10**18
res,flag=1,0
if 0 in arr:
    print(0)
else:
    for i in range(n):
        res*=arr[i]
        if res>max:
            flag=1
            break
    if flag==1:
        print(-1)
    else:
        print(res)


Measured memory_bytes: 22528
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,m,i;
    cin>>n>>m;
    ll x[m];
    for (i=0;i<m;i++)
        cin>>x[i];
    sort(x,x+m);
    vector<ll> y;
    for (i=0;i<m-1;i++)
        y.pb(x[i+1]-x[i]);
    sort(y.rbegin(),y.rend());
    ll sum=0;
    for (i=0;i<n-1 && i<m-1;i++)
        sum+=y[i];
    cout<<x[m-1]-x[0]-sum<<endl;
}


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

int main() {
  int N;
  cin >> N;
  vector <tuple<string, int, int>> S;
  for (int i = 0; i < N; i++) {
    string A;
    int B;
    cin >> A >> B;
    S.push_back(make_tuple(A, B * -1, i + 1));
  }

  sort(S.begin(), S.end());

  for (int i = 0; i < N; i++) {
    cout << get<2>(S[i]) << endl;
  }
}


Measured memory_bytes: 256
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
using namespace std;
ll add(ll x,ll y)
{
return (x%hell+y%hell)%hell;
}
ll mul(ll x,ll y)
{
return ((x%hell)*(y%hell))%hell;
}
ll sub(ll x,ll y)
{
return (x-y+hell)%hell;
}
#define N  100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        string s;
        cin>>s;
        if(s.size()%2)
            cout<<"No";
        else
        {
            ll w=0;
            for(int i=0;i<s.size();i+=2)
            {
                if(s[i]=='h'&&s[i+1]=='i')
                    continue;
                else
                    w=1;
            }
            if(w)
                cout<<"No";
            else
                cout<<"Yes";
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for (int i = l; i<r;i++)
#define dec(i, l, r) for (int i = l; i>=r;i--)
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define pb(c) push_back(c)
#define vii vector<pair<int,int>>
#define ii pair<int,int>
#define   max(a, b) (((a)<(b))?b:a)
#define min(a, b) ((a>b)?b:a)
#define mp(i, j) make_pair(i,j)
#define ull unsigned long long int
#define ll  long long int
#define pie 3.141592653589793238
#define inf ((ll)1e18)
#define eps 1e-14
#define mod ((int)1e9+7)
#define maxlg 18
#define maxn 200002
#define left(i) ((i)<<1)
#define right(i) (((i)<<1)+1)

vii adj[maxn];
int dist[maxn];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
    
#endif
    int k;
    cin>>k;
    rep (i,0,k) {
        adj[i].push_back(mp((i+1)%k,1));
        adj[i].push_back(mp((i*10)%k,0));
    }
    fill(dist,dist+maxn,((int)100000));
    dist[1]=0;
    deque<ii> q;
    q.push_back(mp(1,0));
    while (!q.empty()) {
        int curr = q.front().first;
        int d = q.front().second;
        q.pop_front();
        for (ii nxt : adj[curr]) {
            int n = nxt.first;
            int type = nxt.second;
            if (dist[n] >  d +type) {
                dist[n]=d +type;
                if (type==0) q.push_front(mp(n,dist[n]));
                if (type==1) q.push_back(mp(n,dist[n]));
            }
        }
    }
    cout<<dist[0]+1;
    return 0;
}
























Measured memory_bytes: 9216
/* Author:bhagatsunny96
         JGEC
	   template__
	lets_code_it_ */
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long int 
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define test long long int t; cin>>t; while(t-->0)
#define fIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define loop(n) for(long long int i=0;i<n;i++)
#define loopr(n) for(long long int i=n-1;i>=0;i--)
#define lrp(a,b) for(long long int i=a;i<=b;i++)
#define lrn(a,b) for(long long int i=b;i>=a;i--)
#define endl '\n'
#define ivec vector<ll>
#define ivecp vector<pair<ll,ll>>
#define imap map<ll,ll>
#define uimap unordered_map<ll,ll>
#define iset set<ll>
#define cvec vector<char>
#define civecp vector<pair<char,ll>>
#define cimap map<char,ll>
#define ucimap unordered_map<char,ll>
#define cset set<char>
using namespace std;
ll gcd(ll a, ll b)
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);
}
ll lcm(ll a, ll b)  
 {  
    return (a*b)/__gcd(a, b);  
 }
 ll power(ll x, unsigned ll y) 
 { 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
 }
 bool isPrime(ll num)
 {
    bool flag=true;
    for(ll i =2;i<=num/2;i++) 
    {
       if(num%i==0) 
       {
          flag=false;
          break;
       }
    }
    return flag;
}
bool isPalin(ll num)
{
    bool flag=false;
    ll digit,rev=0,n=num;
    do
     {
         digit = num % 10;
         rev = (rev * 10) + digit;
         num = num / 10;
     } while (num != 0);
     if(rev==n)
     flag=true;
     return flag;
}
ll sumofdigits(ll n)
{
    ll c=0;
    while(n>0)
    {
        c++;
        n/=10;
    }
    return c;
}
bool sortinrev(const pair<int,int>&a,const pair<int,int>&b) 
{ 
    return (a.first > b.first); 
}
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
string sortString(string &str) 
{ 
   sort(str.begin(), str.end()); 
   return str;
} 
void countSort(ll arr[], ll n, ll exp) 
{ 
	ll output[n];
	ll i, count[10] = {0}; 
	for (i = 0; i < n; i++) 
		count[ (arr[i]/exp)%10 ]++; 
	for (i = 1; i < 10; i++) 
		count[i] += count[i - 1]; 
	for (i = n - 1; i >= 0; i--) 
	{ 
		output[count[ (arr[i]/exp)%10 ] - 1] = arr[i]; 
		count[ (arr[i]/exp)%10 ]--; 
	} 
	for (i = 0; i < n; i++) 
		arr[i] = output[i]; 
} 
void radixsort(ll arr[], ll n) 
{
    ll mx = arr[0]; 
	for (ll i = 1; i < n; i++) 
		if (arr[i] > mx) 
			mx = arr[i];
	ll m =mx;
	for (ll exp = 1; m/exp > 0; exp *= 10) 
		countSort(arr, n, exp); 
} 
void print(ll arr[], ll n) 
{ 
    for (ll i = 0; i < n; i++) 
        cout << arr[i] << " "; 
} 
int main() 
{
    fIO
    ll a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c<<endl;
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    if(s == "SSR")cout << 1 << endl;
    else if(s == "SRS")cout << 1 << endl;
    else if(s == "RSS")cout << 1 << endl;
    else if(s == "RSR")cout << 1 << endl;
    else if(s == "SRR")cout << 2 << endl;
    else if(s == "RRS")cout << 2 << endl;
    else if(s == "RRR")cout << 3 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 3600
// ABC92 B

#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;

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

    int sum = x;

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        sum += (d - 1) / a + 1;
    }

    cout << sum << endl;
}


Measured memory_bytes: 256
N, Y= map(int, input().split())
try:	
	for i in range(N+1):
		zandaka = Y - (10000*i)
		for j in range(N+1-i):
			k = (zandaka - 5000*j)//1000
			if(i + j + k == N):
				print(i, j, k)
				raise Exception
	print(-1,-1,-1)
except Exception:
	pass

Measured memory_bytes: 2940
h, n = gets.split.map(&:to_i)
a = Array.new(n){gets.split.map(&:to_i)}
dp = Array.new(h + 1){Float::INFINITY}
dp[0] = 0
h.next.times do |i|
  a.each do |x, y|
    if i + x <= h && dp[i + x] > dp[i] + y
      dp[i + x] = dp[i] + y
    elsif i + x > h && dp[h] > dp[i] + y
      dp[h] = dp[i] + y
    end
  end
end
puts dp[h]

Measured memory_bytes: 2172
#include<cstdio>
int n;
long long f[100];
int main()
{
    scanf("%d",&n);
    f[0] = 2, f[1] = 1;
    for(int i = 2;i <= n;i++) f[i] = f[i-1]+f[i-2];
    printf("%lld",f[n]);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = 1;
        int i = 1;
        while (a != 0) {
            a = sc.nextInt();
        	if (a == 0) {
                break;
        	  	}
        	System.out.println("Case "+ i + ": " + a);
            i ++;
        }
    }
}


Measured memory_bytes: 41368
function calc(prev, _i, n, s, depth) {
	if (n - 1 === depth) {
		if (_i <= s - prev && s - prev <= 9) {
			return (1);
		}
		return (0);
	}
	var ans = 0;
	for (var i = _i; i <= 9; i++) {
		if (prev + i > s) break;
		ans += calc(prev + i, i + 1, n, s, depth + 1);
	}
	return (ans);
}

Main(function(input) {
	input.trim().split('\n').forEach(function(line) {
		var tmp = line.split(' ');
		var n = tmp[0];
		var s = tmp[1];
		if (n === '0' && s === '0') {
			return;
		}
		console.log(calc(0, 0, +n, +s, 0));
	});
});

// Reading input
function Main(main) {
	var input = '';

	process.stdin.resume();
	process.stdin.setEncoding('utf8');
	process.stdin.on('data', function(chunk) {
		input += chunk;
	});
	process.stdin.on('end', function() {
		main(input);
	});
};

Measured memory_bytes: 15848
import sys

input = sys.stdin.readline
n, x = map(int, input().split())
a_list = list(map(int, input().split()))
a_list.sort()
cnt = 0
flag = 0
for a in a_list:
    if x >= a:
        cnt += 1
        x -= a
    else:
        flag = 1
        break
if flag == 0 and x > 0:
    cnt -= 1
print(max(cnt, 0))


Measured memory_bytes: 3060
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
# endregion

N, K = ri_()
print(sum(sorted(ri_(), reverse=True)[:K]))


Measured memory_bytes: 63084
//
//  CPlibrary
//
//  Created by Tanmay Singh on 3/03/2020.
// INDIAN INSTITUTE OF TECHNOLOGY (BHU) , VARANASI
//  Copyright © 2020 Tanmay Singh. All rights reserved.
//#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
 
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <climits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
 
#define FAST(); ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define mod 1000000007
typedef long long int  bigint ;
typedef std::vector< int > vi;
typedef std::vector< long long int > vll;
typedef std::vector< vi > vvi;
 
using namespace std;
void printAns( int i ){
    cout << (bigint) ( pow(2, i + 1 ) ) - 1 << endl ;
}
int main(){
    FAST() ;
    unsigned long long int  H ; cin >> H ;
    printAns(log2(H)) ;
    return 0 ;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

template<typename T>
struct BIT{
  int n;
  vector<T> bit[2];
  BIT(int n_=0):n(n_){
    bit[0].resize(n+1,0);
    bit[1].resize(n+1,0);
  }
  void add_sub(int p,int i,T x){
    for(i++;i<=n;i+=i&-i){
      bit[p][i]+=x;
    }
  }
  void add(int l,int r,T x){
    add_sub(0,l,-x*(l-1));
    add_sub(0,r,x*(r-1));
    add_sub(1,l,x);
    add_sub(1,r,-x);
  }
  T sum_sub(int p,int i){
    T s=0;
    for(i++;i;i-=i&-i){
      s+=bit[p][i];
    }
    return s;
  }
  T sum(int i){
    return sum_sub(0,i)+sum_sub(1,i)*i;
  }
  T sum(int l, int r){
    return sum(r-1) - sum(l-1);
  }
};

int main(){
  int N,Q;cin>>N>>Q;
  BIT<ll> b(N);
  rep(q,Q){
    int c; cin >> c;
    if(c==0){
      int s,t,x;cin>>s>>t>>x;s--;
      b.add(s,t,x);
    }
    else{
      int s,t;cin>>s>>t;s--;
      cout<<b.sum(s,t)<<'\n';
    }
  }
  return 0;
}



Measured memory_bytes: 4432
function F166(_input) {
    var lines = _input.split("\n");
    var first = lines.shift().split(' ').map(item => item*1);
    var n = first.shift();
    var num = {
        'A': first[0],
        'B': first[1],
        'C': first[2],
    };
    var route = [];
    lines.push('AC');

    for (let i = 0; i < n; i++) {
        const key1 = lines[i][0];
        const key2 = lines[i][1];

        if (!num[key1]&&!num[key2]) {
            console.log('No');
            return;
        }

        if (!num[key1]) {
            num[key1]++;
            num[key2]--;
            route.push(key1);
            continue;
        }

        if (!num[key2]) {
            num[key1]--;
            num[key2]++;
            route.push(key2);
            continue;
        }

        const nKey1 = lines[i+1][0];
        const nKey2 = lines[i+1][1];

        if (key1 === nKey1 || key1 === nKey2) {
            num[key1]++;
            num[key2]--;
            route.push(key1);
        } else {
            num[key1]--;
            num[key2]++;
            route.push(key2);
        }
    }

    console.log('Yes');
    route.map(item => console.log((item)));
}
F166(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 45616
// ALDS1_1_D 最大利益

#include <iostream>

using namespace std;

int main()
{
  int n;
  cin >> n;
  int *R = new int[n];
  for (int i = 0; i < n; i++)
    cin >> R[i];

  if (n == 2){
    cout << R[1] - R[0] << endl;
    return 0;
  }

  int inLeftMinimum = R[0];
  int dMax = R[1] - R[0];
  for (int i = 2; i < n; i++){
    if ((R[i - 1]) < inLeftMinimum)
      inLeftMinimum = R[i - 1];
    int d = R[i] - inLeftMinimum;
    if (d > dMax)
      dMax = d;
  }

  cout << dMax << endl;

  delete[] R;
  return 0;
}



Measured memory_bytes: 3616
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    vector<string> S;
    string tmp;
    for (size_t i = 0; i < N; i++)
    {
        cin >> tmp;
        S.emplace_back(tmp);
    }
    
    sort(S.begin(), S.end());
    int ans = 1;
    tmp = S[0];
    for (int i = 1; i < N; i++)
    {
        if (S[i]!= S[i - 1]){
            ans++;
        }

    }

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

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n;
  cin >> n;
  ll ans = 0;
  vector<ll> memo(n+1,0);
  int i,j;
  for(i=1;i<=n;i++)
  {
    for(j=i;j<=n;j+=i)
    {
      memo[j]++;
    }
  }
  for(i=1;i<=n;i++)
  {
    ans += i*memo[i];
  }
  cout << ans << "\n";
}


Measured memory_bytes: 81400
import math

n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]
args = sorted([(math.atan2(y,x),x,y) for x,y in xy])
ans = 0
for key,(sarg,sx,sy) in enumerate(args):
  tmpx,tmpy = sx,sy
  dist = tmpx**2 + tmpy**2
  for arg,x,y in args[key+1:]:
    tmpx += x
    tmpy += y
    tmp = tmpx**2 + tmpy**2
    if tmp < dist:
      break
    else:
      dist = tmp
  for arg,x,y in args[:key]:
    tmpx += x
    tmpy += y
    tmp = tmpx**2 + tmpy**2
    if tmp < dist:
      break
    else:
      dist = tmp
  ans = max(ans,dist)
print(math.sqrt(ans))

Measured memory_bytes: 3192
#include <iostream>
#include <string>
#include <locale>
#include <map>

using namespace std;

int main()
{
  locale loc;
  map<char, int> m;
  for (int i = 97; i <= 122; i++)
    m.insert(make_pair((char)i, 0));

  char c;
  while (cin >> c)
  {
    if (isupper(c, loc))
      c = tolower(c, loc);
    if (islower(c, loc))
      m.at(c)++;
  }

  for (int i = 97; i <= 122; i++)
    cout << (char)i << " : " << m.at((char)i) << endl;
  return 0;
}

Measured memory_bytes: 3112
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			int k = cin.Int();
			long[] a = cin.ArrayLong(n);

			long ans = long.MaxValue;
			for (int bit = 0; bit < 1 << n; bit++) {
				if (PopCount((ulong)bit) != k) {
					continue;
				}

				long temp = 0;
				long height = 0;
				for (int i = 0; i < n; i++) {
					if (height >= a[i]) {
						if (((1 << i) & bit) == 0) {
							continue;
						}

						temp += (height - a[i]) + 1;
						height++;
					} else {
						height = a[i];
					}
				}

				ans = Math.Min(ans, temp);
			}

			Console.WriteLine(ans);
		}

		public static int PopCount(ulong bits)
		{
			bits = ((bits & 0xaaaaaaaaaaaaaaaa) >> 1) + (bits & 0x5555555555555555);
			bits = ((bits & 0xcccccccccccccccc) >> 2) + (bits & 0x3333333333333333);
			bits = ((bits & 0xf0f0f0f0f0f0f0f0) >> 4) + (bits & 0x0f0f0f0f0f0f0f0f);
			bits = ((bits & 0xff00ff00ff00ff00) >> 8) + (bits & 0x00ff00ff00ff00ff);
			bits = ((bits & 0xffff0000ffff0000) >> 16) + (bits & 0x0000ffff0000ffff);
			bits = ((bits & 0xffffffff00000000) >> 32) + (bits & 0x00000000ffffffff);
			return (int)bits;
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private readonly Func<string> reader_;
		private string[] buf_;
		private int index_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 13268
s = input()
s = s[::-1]
t = ["dream", "dreamer", "erase", "eraser"]
for i in range(len(t)):
    t[i] = t[i][::-1]
can = True
i = 0
while i < len(s):
    can2 = False
    for j in range(len(t)):
        d = t[j]
        if s[i:i+len(d)] == d:
            can2 = True
            i += len(d)
    if not can2:
        can = False
        break

if can:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9264
#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>

#define arrayLength(array) (size_t)((sizeof array) / (sizeof array[0]))

int main() {
  int a = 0, b = 0;
  char s[255], *r;

  scanf(" %[^\n]s", &s);

  r = strtok(s, " ");

  while (r != NULL) {
    printf("%c", r[0]);
    r = strtok(NULL, " ");
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int cnt = 0;
  for (int x = 0; x * R <= N; ++x) {
    for (int y = 0; x * R + y * G <= N; ++y) {
      i64 d = N - x * R - y * G;
      if (d % B == 0) ++cnt;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3572
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
    
    
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		int[] score = new int[n];
		int[] tmp   = new int[n];
		for(int i = 0; i < n; i++) {
			score[i] = sc.nextInt();
			tmp[i] = score[i];
		}
		Arrays.sort(tmp);
		ArrayList<Integer> leaders = new ArrayList<Integer>();
		for(int i = 0; i < q; i++) {
			String in = sc.next();
			int a = sc.nextInt();
			if(in.equals("ADD")) {
				leaders.add(score[a-1]);
			}
			else if(in.equals("REMOVE")) {
				leaders.remove(leaders.indexOf(score[a-1]));
			}
			else {
				int L = 0;
				int U = 1000000001;
				Collections.sort(leaders);
				while(L != U) {
					int C = (L + U)/2;
					int prv = 0;
					int loss = 0;
					for(int j = 0; j < leaders.size(); j++) {
						int c = leaders.get(j) - C;
						int idL = Arrays.binarySearch(tmp, c); //p
						if(idL < 0) idL = idL * -1 - 1;
						else {
							while(idL-1 > 0 && tmp[idL-1] == c) idL--;
						}
						loss += Math.max(idL - prv, 0);
						prv = Arrays.binarySearch(tmp, leaders.get(j)) + 1;
						while(prv < tmp.length && tmp[prv] == leaders.get(j)) prv++;
					}
					loss += Math.max(n - prv, 0);
					if(loss <= a) {
						U = C;
					}
					else {
						L = C+1;
					}	
				}
				
				System.out.println((L == 1000000001)?"NA":L);
			}
		}
	}
}

Measured memory_bytes: 304484
#include <bits/stdc++.h>
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(var) var.begin(), var.end()
#define input freopen("input", "r", stdin)
#define output freopen("output", "w", stdout)
#define Fast ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
typedef long long ll;
using namespace std;

int dr[] = {0, 0, -1, +1, -1, -1, +1, +1};
int dc[] = {-1, +1, 0, 0, -1, +1, -1, +1};

int main(){
    ll d, t, s;
    cin >> d >> t >> s;
    if(t*s >= d) cout << "Yes" << endl;
    else cout << "No" << endl;
}



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

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

class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){}
        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for(int i = 0; i < size; i++) makeSet(i);
        }

        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

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

        void unite(int x, int y){
            link(findSet(x), findSet(y));
        }

        void link(int x, int y){
            if(rank[x] > rank[y]){
                p[y] = x;
            } else{
                p[x] = y;
                if( rank[x] == rank[y]){
                    rank[y]++;
                }
            }
        }

        int findSet(int x){
            if(x != p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

int main(){
    int n, a, b, q;
    int t;

    cin >> n >> q;
    DisjointSet ds = DisjointSet(n);

    for(int i = 0; i < q; i++){
        cin >> t >> a >> b;
        if(t == 0) ds.unite(a, b);
        else if( t == 1){
            if(ds.same(a, b)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }

    return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  int count = 0;
  for (int i = A; i <= B; ++i) {
    int m = i / 10000 % 10;
    int s = i / 1000 % 10;
    int j = i / 10 % 10;
    int h = i % 10;
    if (m == h && s == j) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static long solve(int N[] , int idx , int K){
		if(K == 0){
			return 1;
		}
		long len = N.length - idx - 1;
		if(len < 0){
			return 0;
		}
		// N[0] = 
		if(K == 1){
			long pat = len * 9;
			pat += N[idx];
			return pat;
		}else if(K == 2){
			long pat = len * (len - 1) / 2 * 81;
			pat += (N[idx] - 1) * len * 9;
			for(int i = idx + 1 ; i < N.length ; ++i){
				if(N[i] != 0){
					pat += solve(N , i , K - 1);
					break;
				}
			}
			return pat;
		}else{ // K == 3
			long pat = len * (len - 1) * (len - 2) / 6 * 729;
			pat += (N[idx] - 1) * len * (len - 1) / 2 * 81;
			for(int i = idx + 1 ; i < N.length ; ++i){
				if(N[i] != 0){
					pat += solve(N , i , K - 1);
					break;
				}
			}
			return pat;
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		int K = sc.nextInt();
		int Narr[] = new int[N.length()];
		for(int i = 0 ; i < Narr.length ; ++i){
			Narr[i] = N.charAt(i) - '0';
		}
		System.out.println(solve(Narr, 0 , K));
	}
}


Measured memory_bytes: 23380
#include <stdio.h>
#include <limits.h>

#define MAX(a,b) ((a)<(b)?(b):(a))
#define MIN(a,b) ((a)<(b)?(a):(b))

int dp[100001];

int fill(int n){
    for(int i=1; i<=n; i++)
        dp[i] = INT_MAX;
    while(dp[n] == INT_MAX){
        for(int i=0; i<=n; i++){
            for(int d=1; i+d<=n; d*=6){
                dp[i+d] = MIN(dp[i+d], dp[i]+1);
            }
            for(int d=1; i+d<=n; d*=9){
                dp[i+d] = MIN(dp[i+d], dp[i]+1);
            }
        }
    }
}

int main(){
    int n;
    scanf("%d", &n);
    fill(n);
    printf("%d\n", dp[n]);
}


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

int main(){ 
  int n, k;
  cin >> n >> k;
  int res = 0;
  while (n > 0) res++, n /= k;
  cout << res << endl; 
  return 0;
} 

Measured memory_bytes: 256
p = int(input())

num = [p]

count = 1

while num[-1] not in num[:-1]:
  count += 1
  
  if num[-1]%2 == 0:
  	num.append(num[-1]/2)
  else:
  	num.append(3*num[-1] + 1)
else:
  print(count)




Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll,null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<ll,ll>,null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<ll,ll> pi; 
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector 
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define PRECISE cout.precision(18);
#define F first
#define S second

ll w,h;
bool ok(ll a,ll b){
	if(a>=1&&a<=h&&b>=1&&b<=w)
		return true;
	return false;
}


int main(){
 

    FAST
	//PRECISE


cin>>h>>w;
ll a[h+1][w+1];
ll dp[h+1][w+1];
FOR(i,0,h+1)
FOR(j,0,w+1)
a[i][j]=1;
FOR(i,0,h+1)
FOR(j,0,w+1){
dp[i][j]=M;}

FOR(i,1,h+1){
	string s;
	cin>>s;
	FOR(j,1,w+1){
		if(s[j-1]=='#'){
			a[i][j]=0;
		}
	}

}
if(a[1][1]==0)
dp[1][1]=1;
else
dp[1][1]=0;

FOR(i,1,h+1){
	FOR(j,1,w+1){
		if(ok(i-1,j)){

			if(a[i][j]==1||(a[i][j]==0&&a[i-1][j]==0))
				dp[i][j]=min(dp[i][j],dp[i-1][j]);
			if(a[i-1][j]==1&&a[i][j]==0){
				dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
			}
		}
			if(ok(i,j-1)){
			if(a[i][j]==1||(a[i][j]==0&&a[i][j-1]==0))
				dp[i][j]=min(dp[i][j],dp[i][j-1]);
			if(a[i][j-1]==1&&a[i][j]==0){
				dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
			}
		}
	}
}

cout<<dp[h][w];



return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define N 2050
int n,L[N];

int _lb(int s , int x) {
    int l = s, r = n, mid, sol = n + 1;
    while (l <= r) {
        mid = (l + r) / 2;
        if (L[mid] < x) {
            l = mid + 1;
        } else {
            r = mid - 1;
            sol = mid;
        }
    }
    return sol;
}

int _ub(int s , int x) {
    int l = s, r = n, mid, sol = -1;
    while (l <= r) {
        mid = (l + r) / 2;
        if (L[mid] <= x) {
            l = mid + 1;
            sol = mid;
        } else {
            r = mid - 1;
        }
    }
    return sol;
}

void debug() {
    for (int i = 1 ; i <= n ; i++)
        printf(i == n ? "%d\n" : "%d " , L[i]);
}

int main() {
    scanf("%d" , &n);
    for (int i = 1 ; i <= n ; i++)
        scanf("%d" , &L[i]);
    sort(L + 1 , L + n + 1);
    int sol = 0;
    for (int a = 1 ; a <= n ; a++) {
        for (int b = a + 1 ; b <= n ; b++) {
            int cmin = L[b];
            int cmax = L[a] + L[b] - 1;
            int ub = _ub(max(a , b) + 1 , cmax), lb = _lb(max(a , b) + 1 , cmin);
            if (cmin > cmax || ub == -1 || lb == n + 1) continue;
            sol += (ub - lb + 1);
        }
    }
    printf("%d\n" , sol);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    int ans = 1;
    while(1){
        if(ans == n){
            cout << ans << endl;
            return 0;
        }
        else if(ans > n){
            cout << ans / 2 << endl;
            return 0;
        }
        ans *= 2;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

Measured memory_bytes: 3636