akhauriyash/Code-Regression huggingface dataset:
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
int main() {
	bool is2 = false;
	// a aa c ca c a b a ab a b c
	char s[200000];
	scanf("%s", s);
	int len = strlen(s);
	int k = len;
	for (int i = 0; i < len - 1; i++) {
		if (!is2 && s[i] == s[i + 1]) {
			is2 = true;
			i++;
			k--;
		} else {
			is2 = false;
		}
	}
	printf("%d\n", k);
	return 0;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    S=list(map(int,input().split()))
    Q=int(input())
    T=list(map(int,input().split()))
    ans=0
    for x in T:
        ans+=bool(bisect_right(S,x)-bisect_left(S,x))
    print(ans)

if __name__ == '__main__':
    main()



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

int main() {
   int a,b,c;
  string s;
  cin>>a>>b;
  c=1;
  int count=0;
 b=b-a;
  // a*2-1 times cout
  for(int i=1;i<a*2;i++){
    if(b+i>=-1000000&&b+i<=1000000){
  	cout<<b+i;
    cout<<" ";
    }
  }
  
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 1055050

main(){
    int n=in();
    int a[4];
    rep(i,3)a[i]=in();
    int l[10];
    rep(i,n)l[i]=in();
    int ans=INF;
    rep(i,1<<(n*2)){
        int tmp=0;
        int take[4]={};
        int mask=i;
        rep(j,n){
            if(mask%4!=0&&take[mask%4])tmp+=10;
            take[mask%4]+=l[j];
            mask/=4;
        }
        rep2(j,1,3){
            tmp+=abs(take[j]-a[j-1]);
        }
        if(take[1]==0||take[2]==0||take[3]==0)continue;
        ans=min(ans,tmp);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
const int N = 3;
const double EPS = 1e-12;

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}

bool on_line(P a, P b){
  int x = abs(a.real() - b.real()), y = abs(a.imag() - b.imag());
  if(!x || !y || x == y || -x == y || x == -y) return true;
  return false;
}

pair<bool, P> crosspointLL(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return pair<bool, P>(1, m[0]); // same line
  P ret = P(m[0] + B / A * (m[1] - m[0]));
  if (abs(A) < EPS) return pair<bool, P>(0, P(0, 0));
  pair<bool, P> res = pair<bool, P>(1, m[0] + B / A * (m[1] - m[0]));
  if(res.second.real() != (int)res.second.real() || res.second.imag() != (int)res.second.imag()) res.first = 0;
  return res;
}

bool check(P ps[N]){
  int my[8] = {1, -1, 0, 0, 1, 1, -1, -1};
  int mx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
  vector<P> aps, bps;
  REP(i, 8){
    REP(j, 8){
      L a = L(ps[0], ps[0] + P(my[i], mx[i]));
      L t = L(ps[2], ps[2] + P(my[j], mx[j]));
      pair<bool, P> r = crosspointLL(a, t);
      if(r.first) aps.push_back(r.second);
    }
  }
  REP(i, 8){
    REP(j, 8){
      L b = L(ps[1], ps[1] + P(my[i], mx[i]));
      L t = L(ps[2], ps[2] + P(my[j], mx[j]));
      pair<bool, P> r = crosspointLL(b, t);
      if(r.first) bps.push_back(r.second);
    }
  }
  bool f = false;
  REP(i, aps.size()) if(on_line(aps[i], ps[1])) f = true;
  if(!f) return false;
  f = false;
  REP(i, bps.size()) if(on_line(bps[i], ps[0])) f = true;
  return f;
}

int main() {
  int D; cin >>D;
  REP(d, D){
    P ps[N];
    REP(i, N){ int x, y; cin >>x >>y; ps[i] = P(x, y); }
    if(ps[0] == ps[2] || ps[1] == ps[2]) { cout <<0 <<endl; continue; }
    if(on_line(ps[0], ps[2]) && on_line(ps[1], ps[2])) { cout <<1 <<endl; continue; }
    if(on_line(ps[0], ps[2]) || on_line(ps[1], ps[2])) { cout <<2 <<endl; continue; }
    if(check(ps)) { cout <<3 <<endl; continue; }
    cout <<4 <<endl;
  }

  return 0;
}

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

int main(){
  int N;
  cin>>N;
  ll tmp=0;
  ll ans=0;
  for(int i=0;i<N;i++){
    cin>>tmp;
    ans+=tmp-1;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n, 0);
    rep(i,n) cin >> a[i];

    int m = inf;
    int cnt = 0;
    for (size_t i = 1; i <= 100; i++)
    {
        cnt = 0;
        for (size_t j = 0; j < n; j++)
        {
            cnt += (a[j]-i)*(a[j]-i);
        }
        m = min(m, cnt);
    }
    
    cout << m << endl;
    
}

Measured memory_bytes: 256
#include <stdio.h>

void merge_sort(int x[], int n)
{
	static int y[1000001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

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

int main()
{
	int i, N, A[1000001];
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%d", &(A[i]));
	merge_sort(A, N);
	
	int G = A[0];
	for (i = 1; i < N; i++) G = gcd(G, A[i]);
	
	int j, k = 0, prime[1001], flag[1000001] = {};
	for (i = 2; i * i <= A[N-1]; i++) {
		for (j = 0; j < k; j++) if (i % prime[j] == 0) break;
		if (j == k) prime[k++] = i;
	}
	for (i = 0; i < N; i++) {
		for (j = 0; j < k && A[i] != 1; j++) {
			if (A[i] % prime[j] != 0) continue;
			if (flag[j] != 0) break;
			else flag[j] = 1;
			while (A[i] % prime[j] == 0) A[i] /= prime[j];
		}
		if (j < k && A[i] != 1) break;
		else if (A[i] != 1) {
			if (flag[A[i]] != 0) break;
			else flag[A[i]] = 1;
		}
	}
	
	if (i < N) {
		if (G == 1) printf("setwise coprime\n");
		else printf("not coprime\n");
	} else printf("pairwise coprime\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 13320
# include <bits/stdc++.h>
/*
// ordered_set 
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
# define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/

using namespace std;
 
typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ll , ll >                                  pll;
 
# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define Sort(x)                                         sort(all(x))
# define InTheNameOfGod                                  ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
 
const ll md = 1e9 + 7;//998244353;
const int xn = 1e5 + 10;
const int xm = -20 + 10;
const int SQ = 320;
const int sq = 320 + 10;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
 
ll power(ll a, ll b) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2) % md : power(a * a % md, b / 2) % md));}
string abc = "abcdefghijklmnopqrstuvwxyz";


int n, qq, L, num[xn], par[2][22][xn];

void build(){
	for (int i = 1; i <= n; ++ i){
		int l = 0, r = i, mid;
		while (r - l > 1){
			mid = (l + r) / 2;
			if (num[i] - num[mid] > L) l = mid;
			else r = mid;
		}
		par[0][0][i] = r;
		l = i, r = n + 1;
		while (r - l > 1){
			mid = (l + r) / 2;
			if (num[mid] - num[i] <= L) l = mid;
			else r = mid;
		}
		par[1][0][i] = l;
	}
	for (int j = 1; j < 20; ++ j)
		for (int i = 1; i <= n; ++ i)
			for (int k = 0; k < 2; ++ k)
				par[k][j][i] = par[k][j - 1][par[k][j - 1][i]];
	
}
void Solve(int x, int y){
	bool flag = (x < y);
	int ans = 1;
	for (int j = 19; j >= 0; -- j){
		if (flag && par[flag][j][x] < y) x = par[flag][j][x], ans += (1 << j);
		else if (!flag && par[flag][j][x] > y) x = par[flag][j][x], ans += (1 << j);
	}
	cout << ans << endl;
}


int main(){
	InTheNameOfGod;
	
	cin >> n;
	for (int i = 1; i <= n; ++ i) 	cin >> num[i];
	cin >> L >> qq;
	build();
	while (qq --){
		int v, u;
		cin >> v >> u;
		Solve(v, u);
	}
	
	return 0;
}


Measured memory_bytes: 17664
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main(void) {
    
    ll n;
    cin>>n;
    vll c(n),s(n),f(n);
    rep(i,n-1){
        cin>>c[i]>>s[i]>>f[i];
    }
    for(int i=0;i<n;i++){
        ll now=0;
        for(int j=i;j<n-1;j++){
            ll t = ceil(max(0LL,now-s[j])/(double)f[j]);
            now = t*f[j]+s[j];
            now += c[j];
        }
        fin(now);
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>
#include<string>
#include<queue>

using namespace std;

int N;
long long K;
const int MAX_keta=41;
long long Accum[2][MAX_keta];
long long pow2[MAX_keta];



long long solve(long long K,int keta,bool EASY){
    long long ret=0;
    if(EASY){
        for(int i=keta;i>=0;i--){
            ret += pow2[i]*max(Accum[0][i],Accum[1][i]);
        }
        return ret;
    }
    if(keta==0){
        if(K>0){
            ret=max(Accum[0][0],Accum[1][0]);
        }else{
            ret=Accum[1][0];
        }
        return ret;
    }
    if(pow2[keta]&K){
        long long ret0,ret1;
        //0 or 1を試す
        //if 0
        ret0=pow2[keta]*Accum[1][keta]+solve(K,keta-1,true);
        //if 1
        ret1=pow2[keta]*Accum[0][keta]+solve(K-pow2[keta],keta-1,false);
        ret=max(ret0,ret1);
    }else{
        //0しか選択肢なし
        ret=pow2[keta]*Accum[1][keta]+solve(K,keta-1,false);
    }
    return ret;
}

int main(){
    cin>>N>>K;
    pow2[0]=1;
    for(int i=1;i<MAX_keta;i++){
        pow2[i]=2*pow2[i-1];
    }
    for(int i=0;i<MAX_keta;i++){
        Accum[0][i]=0;
        Accum[1][i]=0;
    }
    for(int i=0;i<N;i++){
        long long A;
        cin>>A;
        for(int i=0;i<MAX_keta;i++){
            if(A & pow2[i]){
                Accum[1][i]++;
            }else{
                Accum[0][i]++;
            }
        }
    }
    int keta;
    for(int i=0;i<MAX_keta;i++){
        if(K & pow2[i]) keta=i;
    }/*
    for(int i=0;i<=keta;i++){
        cout<<Accum[0][i]<<' '<<Accum[1][i]<<endl;
    }
    cout<<keta<<endl;*/
    long long ans=solve(K,keta,false);
    for(int i=keta+1;i<MAX_keta;i++){
        ans += pow2[i]*Accum[1][i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int xmax = x, ymin = y;
    imfor(i, n) {
        int xi;
        cin >> xi;
        xmax = max(xmax, xi);
    }
    imfor(i, m) {
        int yi;
        cin >> yi;
        ymin = min(ymin, yi);
    }
    if (xmax < ymin) {
        cout << "No War" << endl;
    }
    else {
        cout << "War" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
  int n,i;long long sum = 0;cin >> n;
  int a[n+2];a[0]=a[n+1]=0;
  for(i=1;i<=n;i++){
    cin >> a[i];sum += abs(a[i]-a[i-1]);
  }
  sum += abs(a[n]);
  for(i=1;i<=n;i++){
    cout << sum-(abs(a[i+1]-a[i])+abs(a[i]-a[i-1]))+abs(a[i+1]-a[i-1]) << endl;
  }
}
  

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> broken(n + 1);
  rep(i, m) {
    int a;
    cin >> a;
    broken.at(a) = true;
  }
  vector<int> dp(n + 2);
  const int mod = 1000000007;
  dp.at(n) = 1;
  for (int i = n - 1; i >= 0; i--) {
    if (broken.at(i)) {
      dp.at(i) = 0;
      continue;
    }
    dp.at(i) = (dp.at(i + 1) + dp.at(i + 2)) % mod;
  }
  cout << dp.at(0) << endl;
  return 0;
}

Measured memory_bytes: 3776
#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 ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main()
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    string s,t;
    cin>>s>>t;
    ll n = s.length();
    ll m = t.length();

    ll ans=INT_MAX;
    for(int i=0; i<n-m+1; i++){
        ll tot=0;
        for (int j = 0; j < m; ++j)
        {
            if(s[i+j]!=t[j]){
                tot++;
            }
        }
        ans=min(ans, tot);
    }

    cout<<ans;

    return 0;
}

Measured memory_bytes: 3660
import sys
from collections import deque

n=int(input())
s=['']*n
for i in range(n):
    s[i]=sys.stdin.readline().strip()

ss=sorted(s)

cnt=0
i=0
while i<n:
    curcnt=1
    j=i+1
    while j<n:
        if ss[i]!=ss[j]:
            break
        j+=1
        curcnt+=1
    i=i+curcnt
    cnt=max(cnt,curcnt)

i=0
while i<n:
    curcnt=1
    j=i+1
    while j<n:
        if ss[i]!=ss[j]:
            break
        j+=1
        curcnt+=1
    if curcnt==cnt:
        print(ss[i])
    i=i+curcnt

Measured memory_bytes: 20508
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define A first
#define B second
#define db double
#define lowbit(p) (p&(-p))
using namespace std;
inline void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void read(ll &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void Min(int &x,int y){
	if (x>y)x=y;
}
void Max(int &x,int y){
	if (x<y)x=y;
}
void Min(ll &x,ll y){
	if (x>y)x=y;
}
void Max(ll &x,ll y){
	if (x<y)x=y;
}

map< pii,int >id;
#define M 100005
struct ed{
	int x,l,nx;
}e[M*12];
int nx[6*M],dis[6*M],n,m,ecnt=1;
bool mark[6*M];
int tot;
queue<int>Q[2];
inline void add(int x,int y,int l){
	e[ecnt]=(ed){y,l,nx[x]};
	nx[x]=ecnt++;
}
void bfs(int s,int t){
	int x,now=0;
	memset(dis,63,sizeof(dis));
	dis[s]=0;
	Q[now].push(s);
	
	for (;!Q[now].empty();now=!now){
		for (;!Q[now].empty();){
			x=Q[now].front(); Q[now].pop();
			if (mark[x])continue;
			mark[x]=1;
			if (x==t){
				printf("%d\n",dis[t]);
				return ;
			}
			for (int i=nx[x];i;i=e[i].nx){
				if (dis[x]+e[i].l<dis[e[i].x]){
					dis[e[i].x]=dis[x]+e[i].l;
					Q[now^e[i].l].push(e[i].x);
				}
			}
		}		
	}
	printf("-1\n");
}
inline int cal(int x,int col){
	int &res=id[mp(x,col)];
	if (res)return res;
	res=++tot;
	add(x,res,1);
	add(res,x,0);
	return res; 
}
int main(){
	int Caseid;
// 	freopen("4.in","r",stdin);
//	read(Caseid);
	read(n); read(m);	
	int i,x,y,c;
	tot=n;
	for (i=1;i<=m;i++){
		read(x); read(y); read(c);
		x=cal(x,c);
		y=cal(y,c);
		add(x,y,0);
		add(y,x,0);
	}
	bfs(1,n);
	return 0;
}

Measured memory_bytes: 44928
n = gets.to_i
array = []
ans = 10**18
(1..Math.sqrt(n)).each do |i|
	if n % i == 0
		array << [i, n/i]
	end
end

array.each do |x,y|
	dist = x + y - 2
	ans = dist if ans > dist
end

puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)


int main(){
    char a;
    cin >> a;

    if(a < 'a'){
        cout << 'A' << endl;
    }else{
        cout << 'a' << endl;
    }

    return 0;
}


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

int main(){

  ll a,b=0;
  cin>>a>>b;
  
 
  if(a>b){  
    int i=0;
    while(1){
      i++;
      if( (b*i)%a==0){cout<<b*i<<endl;return 0;}
    }
  }
  else{
    int i=0;
    while(1){
      i++;
      if( (a*i)%b==0){cout<<a*i<<endl;return 0;}
    }
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <math.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define str string
#define deb_arr(arr,n) for(ll i=0;i<(n);i++){ cout << (arr)[i] << " ";}
#define in_arr0(arr,n) for(ll i=0;i<(n);i++){ cin >> (arr)[i]; }
#define in_arr1(arr,n) for(ll i=1;i<=(n);i++){ cin >> (arr)[i];}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> pbds;
#define vll vector<ll> 
#define fr(n) for(i=0;i<(n);i++)
#define fr1(n) for(i=1;i<=(n);i++)
#define pll pair<ll,ll>
#define f first
#define s second
#define vpll vector<pll>
#define ump unordered_map
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define IN(a,b) ((a).find(b)!=(a).end())
#define pb push_back
#define mkp make_pair
#define PI M_PI
#define INF 1e18
#define deb(x) if(ON) cout << #x <<" : " << x << endl
#define fast ios_base::sync_with_stdio(false)
#define io cin.tie(NULL),cout.tie(NULL)
#define ON !false
ll dx[]={0,-1,0,1};
ll dy[]={1,0,-1,0};
const ll mod=1e9+7;
inline ll add(ll a,ll b){
    return  ((a%mod)+(b%mod)+mod)%mod;
}
inline ll mul(ll a,ll b){
    return ((a%mod)*(b%mod)+mod)%mod;
}
void pause(ll id){
    cout << "Waiting " << id << endl;
    cin >> id;
}

const int mxn=1e5+10;


void init(){

    return ;
}


signed main(){
    fast;
    io;
    if(!true){
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    }
    init();
    ll i,j;
    ll n,m,x;
    cin >> n >> m >> x;
    ll arr[n][m];
    ll c[n];
    for(i=0;i<n;i++){
        cin >> c[i];
        for(j=0;j<m;j++){
            cin >> arr[i][j];
        }
    }
    ll ans=INF;
    for(ll msk=0;msk<(1ll<<n);msk++){

        ll val=0;
        vll ok(m,0);

        for(i=0;i<n;i++){
            if(((msk>>i)&1) == 0){
                //deb("F");
                continue;
            }
            val+=c[i];
            for(j=0;j<m;j++){
                ok[j]+=arr[i][j];
            }
        }

        for(i=0;i<m;i++){
            if(ok[i] < x){
                break;
            }
        }
       // deb(val);
        if(i==m){
            ans=min(ans,val);
        }
    }
    if(ans < INF){
        cout << ans << endl;
    }
    else{
        cout << -1 << endl;
    }
   
    return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }
 
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
 
    double ave = 0;
    for(int i = 0; i < n; i++){
        ave += a[i];
    }
    ave /= n;
 
    ll ans_min = 0;
    for(int i = 1; i < n; i++){
        if(abs(a[i] - ave) < abs(a[ans_min] - ave)){
            ans_min = i;
        }
    }
    cout << ans_min << endl;
    return 0;
}

Measured memory_bytes: 256
#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;

int n, m, q;
int a[51], b[51], c[51], d[51];
int v[11];
int ans = 0;

void dfs(int cid) {
	if (cid <= n) {
		rep(i, v[cid - 1], m + 1) {
			v[cid] = i;
			dfs(cid + 1);
		}
	} else {
		int sc = 0;
		rep(i, 0, q) {
			if (v[b[i]] - v[a[i]] == c[i]) sc += d[i];
		}
		ans = max(ans, sc);
	}
}

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

	cin >> n >> m >> q;
	
	rep(i, 0, q) cin >> a[i] >> b[i] >> c[i] >> d[i];

	v[0] = 1;
	dfs(1);

	cout << ans << endl;
}


Measured memory_bytes: 3652
#define Kafuu signed
#define Chino main

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>

#define maxn 305
#define inf 0x3f3f3f3f
#define px putchar
#define pn px('\n')
#define ps px(' ')
#define pd puts("======================")
#define pj puts("++++++++++++++++++++++")

using namespace std;

inline int read(){
	int x=0,y=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')y=1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return y?-x:x;
}
template<typename T>
inline T read(){
	T x=0;
	int y=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')y=1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return y?-x:x;
}
int f[2][maxn][maxn];
char s[maxn];
Kafuu Chino(){
	scanf("%s",s+1);
	int n=strlen(s+1),k=read(),ans=0;
	for(register int i=1;i<=n;++i)f[0][i][i]=1;
	for(register int i=0;i<=k;++i){
		for(register int len=2;len<=n;++len)
			for(register int st=1,en=st+len-1;en<=n;++st,++en){
				f[i&1][st][en]=max(f[i&1][st+1][en],f[i&1][st][en-1]);
				if(s[st]==s[en])f[i&1][st][en]=max(f[i&1][st][en],f[i&1][st+1][en-1]+2);
				if(i)f[i&1][st][en]=max(f[i&1][st][en],f[i&1^1][st+1][en-1]+2);
			}
		ans=max(ans,f[i&1][1][n]);
	}
	printf("%d\n",ans);
}


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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;

vector<int> divisor(int n){
  vector<int> res;
  for (int i(1);i*i<=n;i++){
    if (n%i==0){
      res.push_back(i);
      if (i != n/i) res.push_back(n/i);
    }
  }
  return res;
}

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  int B[1000001] = {0};
  int cnt1(0);
  for(int i(0);i<N;i++){
    cin>>A[i];
    if(A[i] == 1) cnt1++;
    B[A[i]]++;
  }
  if(cnt1 == 1){
    cout << 1 << endl;
    return 0;
  }else if(cnt1 != 0){
    cout << 0 << endl;
    return 0;
  }
  int cnt(0);
  for(int i(0);i<N;i++){
    vector<int> m = divisor(A[i]);
    bool flag(true);
    for(int j(0);j<int(m.size());j++){
      if(m[j] == 1) continue;
      if(m[j] == A[i]){
        if(B[A[i]] >= 2) flag = false;
      }else{
      //  cout << m[j] << " "<<  B[m[j]] << endl;
        if(B[m[j]] != 0){
          flag = false;
        }
      }
    }
    //cout << endl;
    if(flag){
      cnt++;
      //cout << A[i] << endl;
    }
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 7952
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

vll a,b,c,d ;

void ins(int i,int j,int k,int l){
	a.emplace_back(i) ;
	b.emplace_back(j) ;
	c.emplace_back(k) ;
	d.emplace_back(l) ;
}

int main(){
	ll h,w ;
	cin >> h >> w ;
	vvll g(h+2,vll(w+2,0)) ;
	for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) cin >> g.at(i).at(j) ;
	for(int i=1;i<=h;i++){
		if(i&1){
			for(int j=1;j<w;j++){
				if(g.at(i).at(j)&1){
					ins(i,j,i,j+1) ;
					g.at(i).at(j+1)++ ;
				}
			}
			if(i!=h&&g.at(i).at(w)&1){
				ins(i,w,i+1,w) ;
				g.at(i+1).at(w)++ ;
			}
		}else{
			for(int j=w;j>1;j--){
				if(g.at(i).at(j)&1){
					ins(i,j,i,j-1) ;
					g.at(i).at(j-1)++ ;
				}
			}
			if(i!=h&&g.at(i).at(1)&1){
				ins(i,1,i+1,1) ;
				g.at(i+1).at(1)++ ;
			}
		}
	}
	cout << a.size() << endl ;
	for(int i=0;i<a.size();i++) cout << a.at(i) << " " << b.at(i) << " " << c.at(i) << " " << d.at(i) << endl ;
}


Measured memory_bytes: 8152
/*
      author : nishi5451
      created: 11.08.2020 20:53:45
*/

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


int main(){
    int k;
    cin >> k;
    int ans;
    if(k%2==0) cout << (k/2)*(k/2) << endl;
    else cout << (k-1)/2*((k-1)/2+1) << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll powmod(ll a, ll b) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

const int N = 200000 + 20;
const int INF = 0x3f3f3f3f;

int n;
ll a[N], sum[N];
map<ll, ll> cnt;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", a + i);
    sum[i] = sum[i - 1] + a[i];
  }
  for (int i = 0; i <= n; ++i) {
    cnt[sum[i]]++;
  }
  ll ans = 0;
  for (const auto & kv : cnt) {
    if (kv.second > 1) {
      ll x = kv.second;
      ans += x * (x - 1) / 2LL;
    }
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 15872
from statistics import mean, median,variance,stdev
import sys
import math

#x = input().split()
#y = input().split()
a = []
x = int(input())
y = int(input())
z = int(input())
#for i in range(len(x)):
#   a.append(int(x[i]))
print((x+y)*int(z/2))

Measured memory_bytes: 5148
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	vector<int>t(999,0);
	for(int i=1; i<=999; ++i)
		for(int j=1; j<=i; ++j)
			t[i-1]+=j;

	int a, b;
	cin>>a>>b;
	
	cout<<t[b-a-1]-b<<endl;

	return 0;
}


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

template <typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n = 0) : n(n), d(n + 1) {}
  void add(int i, T x = 1) {
    for (i++; i <= n; i += i & -i) d[i] += x;
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i & -i) x += d[i];  // 最下位bitの加算
    return x;
  }
  T sum(int l, int r) { return sum(r - 1) - sum(l - 1); }
};

int main() {
  ll n, d, a, ans = 0;
  cin >> n >> d >> a;
  vector<pair<ll, ll>> p(n);

  rep(i, n) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());

  BIT<ll> bit(n + 1);

  rep(i, n) {
    ll x = p[i].first;
    ll h = p[i].second;
    h -= bit.sum(i);
    if (h <= 0) continue;
    ll num = (h + a - 1) / a;
    ans += num;
    ll damage = num * a;
    bit.add(i, damage);
    int rx = min(x + d * 2, 1001001001ll);
    bit.add(
        upper_bound(p.begin(), p.end(), pair<ll, ll>(rx + 1, -1)) - p.begin(),
        -damage);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7920
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

int main() {
	string s, ans;
	vector<int> Stac;
	getline(cin, s);
	for (char ch: s) {
		if (ch == '0') Stac.push_back(0);
		else if (ch == '1') Stac.push_back(1);
		else if (ch == 'B') {
			if(Stac.size()>0) Stac.pop_back();
		}
	}

	for(int v:Stac) {
		cout << v;
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#define ll long long
using namespace std;

ll arr[100005];

map <ll,int> freq;
int main()
{
    int n;
    cin >> n;
    
    int checker = 0;
    ll a,b,c;
    for (int i = 1; i <= n; i++){
      cin >> arr[i];
      ll f = arr[i];
      if (checker == 0){
        a = f;
        freq[a] = 1;
        checker++;
      }
      else if (checker == 1){
        if (a == f)
          freq[a]++;
        else{
          b = f;
          freq[b]=1;
          checker++;
        }
      }
      else if (checker == 2){
        if (a==f){
          freq[a]++;
        }
        else if (b == f){
          freq[b]++;
        }
        else{
          c = f;
          freq[c] = 1;
          checker++;
        }
      }
      else if (checker == 3){
        if (a==f){
          freq[a]++;
        }
        else if (b == f){
          freq[b]++;
        }
        else if (c==f){
          freq[c]++;
        }
        else{
          checker++;
        }
      }
      else if (checker > 3){
        cout << "No" << endl;
        return 0;
      }
    }

    if (checker == 1){
      if(a == 0 && freq[a] == n){
        cout << "Yes" << endl;
      }
      else{
        cout << "No" << endl;
      }
      return 0;
    }

    if (checker == 2 && n%3 == 0){
      if ((a==0 && freq[a] == n/3 && freq[b] == (2*n)/3)||(b==0 && freq[b] == n/3 && freq[a] == (2*n)/3)){
        cout << "Yes" << endl;
      }
      else 
        cout << "No" << endl;
      return 0;
    }

    if (checker == 3 && n%3 == 0){
      if (freq[a] == freq[b] && freq[c] == freq[b]){
        if ((a^b^c) == 0){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }

    cout << "No" << endl;

    return 0;
}

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,m,k; cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  REP(i,n) cin >> a[i];
  REP(i,m) cin >> b[i];
  
  vector<ll> as(n+1, 0), bs(m+1, 0);
  REP(i,n) as[i+1] = as[i] + a[i];
  REP(i,m) bs[i+1] = bs[i] + b[i];

  int ans = 0;
  REP(i,n+1){
    if(as[i]>k) break;
    ll rest = k - as[i];
    auto itr = upper_bound(ALL(bs), rest);
    itr--;
    int tmp = i + (itr - bs.begin());
    ans = max(ans, tmp);
  }
  /*
  REP(i,m+1){
    if(bs[i]>k) break;
    ll rest = k - bs[i];
    auto itr = upper_bound(ALL(as), rest);
    itr--;
    int tmp = i + (itr - as.begin());
    ans = max(ans, tmp);
  }
  */
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9540
#include<iostream>
#include<string>
using namespace std;
typedef long long ll;

int main()
{
	int x;
	cin >> x;
	int res = 0, f = 0;
	for (int i = 1;i <= x;i++)
	{
		res += i;
		if (res >= x)
		{
			f = i;
			break;
		}
	}
	cout << f;
}

Measured memory_bytes: 3164
#include<cstdio>
#define min(a,b) (a<b?a:b)
int main()
{
	long long n,m;
	scanf("%lld %lld",&n,&m);
	long long minn=min(n,m/2);
	long long ans=minn;
	n-=minn;
	m-=2*minn;
	if(n==0&&m>=4){
		ans+=m/4;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(int argc, char const *argv[]){
	int a[5],n[]={0,0,0},i,tmp;
	char s[5];
	scanf("%s",s);
	a[3]=s[3]-'0';
	a[2]=s[2]-'0';
	a[1]=s[1]-'0';
	a[0]=s[0]-'0';
	while(1){
		tmp=a[0];
		for(i=0;i<3;i++)
			tmp=(n[i]==0)? tmp+a[i+1]:tmp-a[i+1];
		if(tmp==7)
			break;
		if(n[0]==0)
			n[0]=1;
		else{
			n[0]=0;
			if(n[1]==0)
				n[1]=1;
			else{
				n[1]=0;
				if(n[2]==0)
					n[2]=1;
				else
					break;
			}
		}
	}
	for(i=0;i<4;i++){
		if(i!=0){
			if(n[i-1]==0)
				printf("+");
			else
				printf("-");
		}
		printf("%d",a[i]);
	}
	printf("=7");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    string s;
    cin >> s;

    deque<char> dq;
    for(int i = 0; i < s.size(); i++) {
        dq.push_back(s[i]);
    }

    int q;
    cin >> q;

    int cnt = 0;
    for(int i = 0; i < q; i++) {
        int t; cin >> t;
        if (t == 1) {
            cnt ++;
        } else {
            int f; char c; cin >> f >> c;
            if (f == 1) {
                if (cnt % 2) dq.push_back(c);
                else dq.push_front(c);
            } else {
                if (cnt % 2) dq.push_front(c);
                else dq.push_back(c);
            }
        }
    }

    if (cnt % 2) {
        for(int i = dq.size()-1; i >= 0; i--) {
            cout << dq[i];
        }
    }
    else {
        for(int i = 0; i < dq.size(); i++) {
            cout << dq[i];
        }
    }
    
    //cout << ans << endl;
    return 0;
}

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

using namespace std;

const int N = 2e3 + 5;
int a[N];

int main(){
    int a,b;
    cin>>a>>b;
    int ans;
    ans=max(a+b,a-b);
    ans=max(ans,a*b);
    cout << ans << '\n';
  }


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

struct node
{
    int left = -1;
    int right = -1;
    int sibling = -1;
    int degree;
    int depth;
    int height;
    int parent = -1;
    string type;   // {root, internal node, leaf}
};

int getHeight(vector<node> &, int, int);

int main(int argc, char const *argv[])
{

    int n = 0;
    cin >> n;

    vector<node> bt(n);

    if (n == 1) {
        int id = 0, l = -1, r = -1;
        cin >> id >> l >> r;
        bt[id].left = -1;
        bt[id].right = -1;
        bt[id].degree = 0;
    } else {
        for (int i = 0; i < n; ++i)
    {
        int id = 0, l = -1, r = -1;
        cin >> id >> l >> r;
        bt[id].left = l;
        bt[id].right = r;

        bt[l].parent = id;
        bt[r].parent = id;

        bt[l].sibling = r;
        bt[r].sibling = l;

        if (l == -1 && r == -1) {
            bt[id].degree = 0;
        } else if (l == -1 || r == -1) {
            bt[id].degree = 1;
        } else {
            bt[id].degree = 2;
        }
    }
    }

    int i_root = 0;
    for (int i = 0; i < n; ++i)
    {
        if (bt[i].parent == -1)
        {
            bt[i].type = "root";
            i_root = i;

        }
        else if (bt[i].degree > 0)
        {
            bt[i].type = "internal node";
        }
        else if (bt[i].degree == 0)
        {
            bt[i].type = "leaf";
        }
    }
    
    int height_bt = getHeight(bt, i_root, 0);

    for (int i = 0; i < n; ++i)
    {
        cout << "node " << i << ": parent = " << bt[i].parent << ", ";
        cout << "sibling = " << bt[i].sibling << ", ";
        cout << "degree = " << bt[i].degree << ", ";
        cout << "depth = " << bt[i].depth << ", ";
        cout << "height = " << bt[i].height << ", ";
        cout << bt[i].type << endl;
    }

    return 0;
}

int getHeight(vector<node> &bt, int id, int dep) {
    int res = 0;

    if (id == -1) {
        return res;
    } else {
        bt[id].depth = dep;

        if (bt.size() == 1 || bt[id].type == "leaf") {
            ;
        } else {
                res = max(getHeight(bt, bt[id].left, dep + 1), getHeight(bt, bt[id].right, dep + 1)) + 1;
        }
    }    

    bt[id].height = res;

    return res;
}



Measured memory_bytes: 3156
#include <stdio.h>
 
int main(void)
{
 
 long int a, b,x;
 
  scanf("%ld %ld", &a,&b);
 
 x=a%b;
 
 if(x<b-x)
 printf("%ld",x);
 else
 printf("%ld",b-x);
  b=x;
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
void swap (long long int *x,long long int *y) {
  long long temp = *x;
  *x = *y;
  *y = temp;
}
int partition (long long int array[],long long int ary[],long long int left,long long int right) {
  long long int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;
  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    if (i < j) {
      swap(&array[i], &array[j]);
      swap(&ary[i], &ary[j]);
    }
  } while (i < j);
  swap(&array[pivot], &array[j]);
  swap(&ary[pivot], &ary[j]);
  return j;
}
void quick_sort (long long int array[],long long int ary[],long long int left,long long int right) {
  long long int pivot;
  if (left < right) {
    pivot = partition(array,ary,left,right);
    quick_sort(array,ary,left,pivot-1);
    quick_sort(array,ary,pivot+1,right);
  }
}
int main(){
  long long int n,m,cnt = 0,ans = 0;
  scanf("%lld %lld",&n,&m);
  long long int a[n],b[n];
  for(int i = 0;i < n;i++){
    scanf("%lld %lld",&a[i],&b[i]);
  }
  quick_sort(a,b,0,n - 1);
  for(long long int i = 0;i < n;i++){
    if(b[i] < m){
      m -= b[i];
      ans += a[i] * b[i];
    }else{
      printf("%lld\n",ans + a[i] * m);
      return 0;
    }
  }
}

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

int main(){
  
  int n,x,i,j,k,count=0;
  while(1){
    
    cin >> n >> x;
    
    if(n == 0 && x == 0)break;
    
    for(i=1;i<=n-2;i++){
      for(j=i+1;j<=n-1;j++){
	for(k=j+1;k<=n;k++){
	  if  ((i+j+k)==x){
	    count++;
	  }
	  }
      }
    }
    cout << count<< endl;
    count=0;
    }
  
}


Measured memory_bytes: 3096
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-10;
const vi emp;

inline int Time_to_Int(int h,int m,int s){
	return h*3600+m*60+s;
}

int h,m,s,sta,fin;

inline void Int_to_Time(int num){
	h=num/3600;
	m=num%3600/60;
	s=num%60;
}

int main(){
	for(int i=0;i<3;i++){
		cin>>h>>m>>s;
		sta=Time_to_Int(h,m,s);
		cin>>h>>m>>s;
		fin=Time_to_Int(h,m,s);
		Int_to_Time(fin-sta);
		cout<<h<<' '<<m<<' '<<s<<endl;
	}
}

Measured memory_bytes: 3072
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint extgcd(lint a, lint b, lint &x, lint &y) {
  lint g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
lint invMod(lint a, lint m) {
  lint x, y;
  if (extgcd(a, m, x, y) == 1) return (x + m) % m;return 0;
}
lint mo=1000003,zy=1;
lint zyo(lint x,lint y){
    lint ret=1,a=x;
    while(y>0){
    	if(y%2==1) ret=(ret*a)%mo;
    	a=(a*a)%mo;y/=2;
    }
    return ret;
}
vector<lint> ka;
//[x,y]
lint p(int x,int y){
	assert(y<mo && x>0);
	return ka[y]*invMod(ka[x-1],mo)%mo;
}
lint cal(lint x,lint d,lint n){
	if(x==0) return 0;
	if(d==0) return zyo(x,n+1);
	lint ix=x*invMod(d,mo)%mo;
	assert(x==(ix*d)%mo);
	//cout<<(ix*d)%mo<<' '<<(ix+n)*d%mo<<endl;
	if(ix+n>=mo) return 0;
	//return ((ka[mo-1]*ka[ix-1]%mo)*p(ix+n+1,mo-1)%mo)*invMod(zyo(d,mo-2-n),mo)%mo;
	return p(ix,ix+n)*zyo(d,n+1)%mo;
}
int main()
{
	ka.pb(1);rep(i,1141919) ka.pb((ka[i]*(i+1))%mo);
	int t,x,d,n;cin>>t;
	rep(i,t){
		cin>>x>>d>>n;cout<<cal(x,d,n-1)<<endl;
	}
}


Measured memory_bytes: 18408
r_cnt,d_cnt,w_cnt = map(int, input().split())
rei = list(map(int, input().split()))
den = list(map(int, input().split()))
wari = []
min_amount = 0
for i in range(w_cnt):
    a,b,c = map(int, input().split())
    amount = rei[a - 1] + den[b - 1] - c
    if i == 0 or amount < min_amount:
        min_amount = amount

amount = min(rei) + min(den)
if amount < min_amount:
    min_amount = amount
print(min_amount)

Measured memory_bytes: 18736
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int an, bn, cn, i, buf, ans, x, y;
	priority_queue<int, vector<int>, greater<int>> c;
	cin >> an >> bn >> cn;
	vector<int> a(an), b(bn);
	rep(i, an) {
		cin >> a[i];
	}
	rep(i, bn) {
		cin >> b[i];
	}
	rep(i, cn) {
		cin >> x >> y >> buf;
		c.push(a[x - 1] + b[y - 1] - buf);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	ans = min(a[0] + b[0], c.top());
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1660
import java.io.BufferedReader;
import java.io.InputStreamReader;
  
public class Main
{
    public static void main (String[] args) throws Exception
    {
        BufferedReader stdReader =
        new BufferedReader(new InputStreamReader(System.in));
        String natural[] = stdReader.readLine().split(" ",0);
        int x = Integer.parseInt(natural[0]);
        int y = Integer.parseInt(natural[1]);
        if (x < y) {
        	// swap two integers with XOR
            x = x ^ y ^ (y = x);
        }
        System.out.println(gcd(x, y));
    }
    private static int gcd(int x, int y) {
        return y == 0? x: gcd(y, x % y);
    }
}

Measured memory_bytes: 24280
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

template <class T>
vector<T> sumup(const vector<T>& a) {
  int N = a.size();
  vector<T> res(N + 1);
  for (int i = 0; i < N; i++) res[i + 1] = res[i] + a[i];
  return res;
}

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int N, Q;
  string S;
  while (cin >> N >> Q >> S) {
    vector<int> hit(N, 0);
    for (int i = 1; i < N; i++) {
      if (S[i - 1] == 'A' && S[i] == 'C') hit[i] = 1;
    }
    vector<int> sum = sumup(hit);
    for (int q = 0; q < Q; q++) {
      int l, r;
      cin >> l >> r;
      int res = sum[r] - sum[l];
      cout << res << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1792