akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define str string
#define ld long double
#define vec vector
#define vll vec<ll>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()
#define kai "\n"
#define yuque priority_queue
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mie min_element
#define mae max_element
#define tos to_string
#define sep setprecision
#define lob lower_bound
#define upb upper_bound
#define nep next_permutation
#define MOD 1000000007ll
#define MIN (1e-10)
#define equal(a,b) (abs((a)-(b))<MIN)
#define v2 ten
#define chokusen senbun
#define tenten senbun
#define takaku vec<ten>
using namespace std;
void solve();
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed;
	solve();
}
struct pea{
	ll f,s;
	bool operator<(const pea &p)const{
		return f!=p.f?f<p.f:s<p.s;
	};
};
struct tri{
	ll f,s,t;
	bool operator<(const tri &p)const{
		if(f!=p.f)return f<p.f;
		if(s!=p.s)return s<p.s;
		return t<p.t;
	};
};
class ten{
public:
	ld x,y;
	ten operator+(ten p){return{x+p.x,y+p.y};}
	ten operator-(ten p){return{x-p.x,y-p.y};}
	ten operator*(ld k){return{k*x,k*y};}
	ten operator/(ld k){return{x/k,y/k};}
	ld abs(){return sqrt(abs2());}
	ld abs2(){return x*x+y*y;};
	bool operator<(const ten &p)const{return x!=p.x?x<p.x:y<p.y;};
	bool operator==(const ten &p)const{return (-MIN<x-p.x)&&(x-p.x<MIN)&&(-MIN<y-p.y)&&(y-p.y<MIN);};
	ld naiseki(v2 b){return x*b.x+y*b.y;}
	ld gaiseki(v2 b){return x*b.y-y*b.x;}
};
struct senbun{ten p1,p2;};
struct en{ten o;ld r;};
ll lis(const vll &a){
	ll n=a.size();
	vll l;l.pub(a[0]);
	rep(i,1,n){
		if(l.back()<a[i])l.pub(a[i]);
		else *lob(ALL(l),a[i])=a[i];
	}
	return l.size();
}
//最大正方形
/*ll daisei(const vec<vll> &g){
	ll h=g.size(),w=g[p].size();
	vec<vll> dp(h,vll(w,1));
	rep(i,0,h)
	rep(i,1,h){
		rep(i,1)
	}
}*/
void solve(){
	ll n;cin>>n;
	vll a(n);
	rep(i,0,n)cin>>a[i];
	cout<<lis(a)<<kai;
}


Measured memory_bytes: 4620
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

ll ans;
ll A, B, C;
bool flag;
void solve(ll a, ll b, ll c, ll count);

int main()
{
    cin >> A >> B >> C;
    ans = 0;
    flag = true;
    solve(A, B, C, 0);
    if (flag)
    {
        cout << ans << endl;
    }
    else
    {
        cout << -1 << endl;
    }
}

void solve(ll a, ll b, ll c, ll count)
{
    if (a == A && b == B && c == C && count != 0)
    {
        flag = false;
        return;
    }
    else if ((a % 2) + (b % 2) + (c % 2))
    {
        return;
    }
    ans++;
    solve((b + c) / 2, (c + a) / 2, (a + b) / 2, count + 1);
    return;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();

        System.out.println(( 10 * g + b) % 4 == 0 ? "YES" : "NO");

        
    }
}

Measured memory_bytes: 35132
import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N = int(input())
Prime=[]
for i in range(2,N+1):
  Prime +=prime_factorize(i)
  
c=collections.Counter(Prime)
P_count=c.values()

count_2=len([1 for x in P_count if x>=2])
count_4=len([1 for x in P_count if x>=4])
count_14=len([1 for x in P_count if x>=14])
count_24=len([1 for x in P_count if x>=24])
count_74=len([1 for x in P_count if x>=74])
answer=(count_2-2)*(count_4-1)*count_4//2+(count_4-1)*count_14+(count_2-1)*count_24+count_74
print(answer)

Measured memory_bytes: 3316
#include <cstdio>
#include <cstdlib>

int N, Z, W;
int a[2010];
//int memo[2][2010][2010];
int memo[2][2010];

/*int srch(int wh, int p2, int p1)
{
	int i;
	if(p2==N+2-1)
		return abs(a[p1]-a[p2]);
	if(memo[wh][p2][p1] != -1)
		return memo[wh][p2][p1];
	if(wh==0){
		int mx = -1, mxi;
		int v3;
		for(i=p2+1; i<N+2; i++){
			v3 = srch(1-wh, i, p2);
			if(mx==-1 || v3 > mx){
				mx = v3;
				mxi = i;
			}
		}
		memo[wh][p2][p1] = mx;
		return mx;
	}
	else{
		int mn=-1, mni;
		int v3;
		for(i=p2+1; i<N+2; i++){
			v3 = srch(1-wh, i, p2);
			if(mn=-1 || v3 < mn){
				mn = v3;
				mni = i;
			}
		}
		memo[wh][p2][p1] = mn;
		return mn;
	}*/
	/*if(wh==0){
		int mx = -1, mxi;
		int tmp;
		int p3;
		for(i=p2+1; i<N+2; i++){
			p3 = srch(1-wh, i, p2);
			if(mx==-1 || abs(a[i]-a[p3]) > mx){
				mx = abs(a[i]-a[p3]);
				mxi = i;
			}
		}
		memo[wh][p2][p1] = mxi;
		return mxi;
	}
	else{
		int mn=-1, mni;
		int tmp;
		int p3;
		for(i=p2+1; i<N+2; i++){
			p3 = srch(1-wh, i, p2);
			if(mn=-1 || abs(a[i]-a[p3]) < mn){
				mn = abs(a[i]-a[p3]);
				mni = i;
			}
		}
		memo[wh][p2][p1] = mni;
		return mni;
	}*/
//}

int srch(int wh, int p2)
{
	int i;
	if(memo[wh][p2] != -1)
		return memo[wh][p2];
	if(wh==0){
		int mx = abs(a[p2]-a[N+2-1]), mxi;
		int v3;
		for(i=p2+1; i<N+2-1; i++){
			v3 = srch(1-wh, i);
			if(mx==-1 || v3 > mx){
				mx = v3;
				mxi = i;
			}
		}
		memo[wh][p2] = mx;
		return mx;
	}
	else{
		int mn=abs(a[p2]-a[N+2-1]), mni;
		int v3;
		for(i=p2+1; i<N+2-1; i++){
			v3 = srch(1-wh, i);
			if(mn=-1 || v3 < mn){
				mn = v3;
				mni = i;
			}
		}
		memo[wh][p2] = mn;
		return mn;
	}
}

void solve()
{
	int i, j, k;
	for(i=0; i<2; i++){
		for(j=0; j<2010; j++)
			memo[i][j] = -1;
	}
	int res = srch(0, 1);
	printf("%d\n", res);
	/*int p1=0, p2=1, p3;
	int wh=0;
	while(1){
		if(wh==0){
			p3 = memo[wh][p2][p1];
			if(p3==-1)
				break;
			p1 = p3;
			wh = 1;
		}
		else{
			p3 = memo[wh][p1][p2];
			if(p3==-1)
				break;
			p2 = p3;
			wh = 0;
		}
	}
	printf("%d\n", abs(a[p1]-a[p2]));*/
}

int main()
{
	//freopen("in.txt", "r", stdin);
	int i;
	scanf("%d", &N);
	scanf("%d%d", &a[0], &a[1]);
	for(i=0; i<N; i++)
		scanf("%d", &a[i+2]);
	solve();
	return 0;
}

Measured memory_bytes: 256
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
vector<vector<ll> > prod(vector<vector<ll> > &a, vector<vector<ll> > &b){
  int n = a.size();
  vector<vector<ll> > res = vector<vector<ll> >(n, vector<ll>(n, 0));
  rep(i, n){
    rep(j, n){
      rep(k, n){
        res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % mod;
      }
    }
  }
  return res;
}

vector<vector<ll> > power(vector<vector<ll> > a, ll k){
  vector<vector<ll> > res = vector<vector<ll> >(a.size(), vector<ll>(a.size(), 0));
  rep(i, a.size())res[i][i] = 1;
  ll tmp = k;
  vector<vector<ll> > curr = a;
  while(tmp){
    if(tmp % 2 == 1)res = prod(res, curr);
    curr = prod(curr, curr);
    tmp /= 2;
  }
  return res;
}

int main(int argc, char const* argv[])
{
  int n;
  ll k;
  cin >> n >> k;
  vector<vector<ll> > a = vector<vector<ll> >(n, vector<ll>(n, 0));
  rep(i, n){
    rep(j, n)cin >> a[i][j];
  }
  vector<vector<ll> > ap = power(a, k);
  ll res = 0;
  rep(i, n){
    rep(j, n){
      res = (res + ap[i][j]) % mod;
    }
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 384
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



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

  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) {
    cin >> p[i];
    p[i]--;
  }

  vector<int> a(n), b(n);
  rep(i, n) a[i] = (i + 1) * 30000;
  rep(i, n) b[i] = (i + 1) * 30000;
  reverse(b.begin(), b.end());
  vector<bool> used(n, false);
  rep(i, n) {
    used[p[i]] = true;
    FOR(j, p[i] + 1, n) {
      if (!used[j]) a[j]++;
    }
    repr(j, p[i] - 1) {
      if (!used[j]) b[j]++;
    }
  }
  rep(i, n) cout << a[i] << ' ';
  cout << '\n';
  rep(i, n) cout << b[i] << ' ';
  cout << '\n';





  
  return 0;
}


Measured memory_bytes: 896
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

int main()
{


    int a,b;
    string op;

    while(1){
        cin >> a >> op >> b;
        if(op == "?"){
            break;
        }
        else if(op == "+"){
            cout << (a+b) << endl;
        }
        else if(op == "-"){
            cout << (a-b) << endl;
        }
        else if(op == "*"){
            cout << (a*b) << endl;
        }
        else if(op == "/"){
            cout << (a/b) << endl;
        }
        else{
        }
    }
    return 0;
}


Measured memory_bytes: 3176
n = int(input())
s = [0 if i=="o" else 1 for i in input()]
for i in range(4):
  dp = [0]*n
  dp[0], dp[1] = divmod(i, 2)
  for i in range(2, n):
    dp[i] = dp[i-2]^dp[i-1]^s[i-1]
  if dp[-2]^dp[-1]^s[-1] == dp[0] and dp[-1]^dp[0]^s[0] == dp[1]:
    A = ["S" if i==0 else "W" for i in dp]
    print(*A, sep="")
    break
else:
  print(-1)

Measured memory_bytes: 9080
string_list = input().split()
num_list = list(map(int, string_list))
W = num_list[0]
H = num_list[1]
x = num_list[2]
y = num_list[3]
r = num_list[4]
if (r <= x) & (x + r <= W) & (r <= y) & (y + r <= H):
    print('Yes')
else:
    print('No')


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

int main()
{
  string s,t;
  cin >> s >> t;
  
  int n = s.size();
  int ans = 0;
  for(int i = 0; i < n; i++){
    int k = 0;
    for(int j = i; ; j++){
      if(ans == n){
        cout << "Yes" << endl;
        return 0;
      }
      if(t[k] == s[j]){
        ans++;
        k++;
      }else if(t[k] != s[j]){
        break;
      }
       if(j == n-1){
        j = -1;
      }
    }//for
    ans = 0;
  }
  
  cout << "No" << endl;
}

Measured memory_bytes: 3640
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e5+10,size=1<<20,mod=998244353;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

struct edge{int y,next;}a[N];int len,last[N];
void ins(int x,int y) {a[++len]=(edge){y,last[x]};last[x]=len;}

void upd(int &x) {x+=x>>31&mod;}

ll power(ll a,ll b=mod-2) {
	ll c=1;
	for(   ;b;b>>=1,a=a*a%mod)
		if(b&1) c=c*a%mod;
	return c;
}

int n,m,f[N],sum[3][N],sz[3],g[N],num,ans,fir,inv=power(fir=power(10,18));

int main() {
	qr(n);
	for(int graph=0;graph<3;graph++) {
		if(len) memset(last+1,0,n<<2),len=0;
		qr(m); for(int j=1,x,y;j<=m;j++) {
			qr(x),qr(y);
			if(x>y) swap(x,y);
			ins(x,y);
		}
		int now=power(fir,n);
		for(int i=n; i;i--) {
			//求sg函数(f)
			++num;
			for(int k=last[i];k;k=a[k].next)
				g[f[a[k].y]]=num;
			f[i]=0;
			while(g[f[i]]==num) f[i]++;
			sz[graph]=max(sz[graph],f[i]);
			upd(sum[graph][f[i]]+=now-mod);
			now=(ll)now*inv%mod;
		}
	}
	for(int i=0;i<=sz[0];i++)
		for(int j=0,k;j<=sz[1];j++) {
			k=i^j;
			upd(ans+=(ll)sum[0][i]*sum[1][j]%mod*sum[2][k]%mod-mod);
		}
	pr2(ans);
	return 0;
}


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

using namespace std;


void solve(){
    int x, n;
    cin>>x>>n;
    unordered_set<int> s;
    for(int i=0; i<n; ++i) {
        int a;
        cin>>a;
        s.insert(a);
    }
    for(int i=x, j=x-1; ; ++i, --j){
        if(!s.count(i)){
            cout<<i;
            return;
        }
        if(!s.count(j)){
            cout<<j;
            return;
        }
    }
}


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

    // int T; cin>>T; while(T--)
        solve();
}

Measured memory_bytes: 3632
import numpy as np
N=int(input())
c=np.array([[0]*10]*10)
for n in range(1,N+1):
  sn=str(n)
  i=int(sn[0])
  j=int(sn[-1])
  c[i][j]+=1

cnt=0
for i in range(10):
  for j in range(10):
    cnt+=c[i][j]*c[j][i]
    
print(cnt)

Measured memory_bytes: 12504
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    n=int(input())
    A=list(map(int,input().split()))

    print(max([abs(A[i]-A[j]) for i in range(n) for j in range(n)]))

resolve()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000007
#define inf 1e18
#define inp(arr,n) for(int i=0;i<n;i++) cin>>arr[i]
#define fr(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int T=1;
    while (T--) {
        char ch;
        cin>>ch;
        int n=ch;
        if(n>=65 && n<=90) cout<<"A\n";
        else cout<<"a\n";
    }
    return 0;
}

Measured memory_bytes: 3636
/*input
0 0 1 1
*/
macro_rules! input_vec {
    () => {
        input!()
            .split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };
    ($delimiter:expr) => {
        input!()
            .split($delimiter)
            .map(|x| x.parse().unwrap())
            .collect()
    };
}

macro_rules! input {
    () => {{
        let mut return_ = String::new();
        std::io::stdin().read_line(&mut return_).ok();
        return_.pop();
        return_
    }};
}

fn main() {
    let v: Vec<f64> = input_vec!();
    println!(
        "{:.8}",
        ((v[2] - v[0]).powf(2.0) + (v[3] - v[1]).powf(2.0)).sqrt()
    );
}



Measured memory_bytes: 5052
/* 
* ID: juryc
* PROG: MIN-MAX-SUMS
* LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
map<int,int> mp; 
int a[N]; 
ll fact[N];
ll invfact[N];
ll mod=1e9+7;
ll modpow(ll a,ll b){
ll res=1; a%=mod;
while(b){
if(b&1) { res=(res*a)%mod; }
a=(a*a)%mod;
b>>=1;
}
return res;
}

ll inv(ll a){
return modpow(a,mod-2);
}

void compute(){
fact[0]=invfact[0]=1;
for(int i=1;i<N;i++){
fact[i]=(fact[i-1]*i)%mod;
invfact[i]=inv(fact[i]);
}
}

ll choose(ll n,ll r){
if(n<0||r<0||n<r) return 0;
if(n==r) return 1;
if(r==0)return 1;
return ((fact[n]*invfact[r])%mod*invfact[n-r])%mod;
}

int main(){
int n,k; cin>>n>>k;
for(int i=1;i<=n;i++){ cin>>a[i];  if(mp.find(a[i])==mp.end()) mp[a[i]]=1; else mp[a[i]]++;}
sort(a+1,a+1+n);
compute();
ll ans=0;
for(int i=1;i<=n;i++){
ans=(ans+(a[i]*choose(i-1,k-1))%mod)%mod;
ans=(ans-(a[i]*choose(n-i,k-1))%mod+mod)%mod;
}
cout<<ans<<"\n";
return 0;
}




Measured memory_bytes: 9832
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll read(){
	ll sum=0,f=1;
	char s=getchar();
	while (s<'0' or s>'9'){
		if (s=='-')f=-1;
		s=getchar();
	}
	while (s>='0' and s<='9'){
		sum=sum*10+s-'0';
		s=getchar();
	}
	return sum*f;
}
int main(){
	ll x=read(),k=read(),d=read();
	if (x<0)x*=-1;
	ll p=x/d;
	if (k<=p){
		ll ans=x-k*d;
		cout<<ans<<endl;
		return 0;
	}
	ll ans1=x-p*d;
	ll ans2=ans1-d;
	ans2*=-1;
	k-=p;
	if (k%2)cout<<ans2<<endl;
	else cout<<ans1<<endl;
	return 0;
}



Measured memory_bytes: 3624
n,k=map(int,input().split())
ans=[0 for _ in range(n*3)]
ans[1]=1

idou=[]

for _ in range(k):
  a=list(map(int,input().split()))
  idou.append(a)
  
    
mod=998244353

rui=[0 for _ in range(n+1)]
rui[1]=1
  
for i in range(2,n+1):
  for g in idou:
    x,y=g
    left=max(0,i-y-1)
    right=max(0,i-x)
    ans[i]+=(rui[right]-rui[left])%mod

    
  rui[i]+=((rui[i-1]+ans[i]))%mod

    
    

print(ans[n]%mod)
  


Measured memory_bytes: 121908
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  string s;
  int K;
  cin >> s >> K;
  int n = s.length();

  REP(i, n) {
    char c = s[i];
    int cnt = 'z' - c + 1;
    if(K >= cnt && c != 'a') {
      s[i] = 'a';
      K -= cnt;
    }
  }
  if(K > 0) {
    s[n - 1] += K % 26;
  }

  cout << s << endl;
}


Measured memory_bytes: 512
#pragma warning(disable:4996)
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>

using namespace std;

int main() {
	int n;
	char s[100001];
	cin >> n >> s;
	char count = '/';
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (count != s[i]) {
			++ans;
			count = s[i];
		}
	}
	cout << ans << endl;
	return 0;
}

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

signed main() {
  int N;
  cin >> N;
  
  vector<int> kazu(20000);
  kazu.at(0) = 9;
  kazu.at(1) = 12;
  for( int i = 2; i < 20000; i++ ){
    kazu.at(i) = kazu.at(i-1) + (kazu.at(i-1)-kazu.at(i-2)+2);
  }
  
  int ans = 0;
  int waru = N/10;
  if( waru > 0 ){
    ans = kazu.at(waru-1);
  }
  
  int plus = 0;
  for( int i = waru*10; i <= N; i++ ){
    for( int j = 1; j <= N; j++ ){
      string C = to_string(i);
      string D = to_string(j);
      if( C.at(0) == D.back() && D.at(0) == C.back() ) plus++;
    }
  }
  for( int i = waru*10; i <= N; i++ ){
    for( int j = 1; j <= N; j++ ){
      string C = to_string(i);
      string D = to_string(j);
      if( C.at(0) == D.back() && D.at(0) == C.back() && C != D ) plus++;
    }
  }
  cout << ans + plus << endl;
  
  
    
  
}

Measured memory_bytes: 384
import java.io.*;
import java.util.*;

public class Main {
  private static List<Integer> solve(int n, int m, int[][] abs) {
    int[] counts = new int[n + 1];
    for (int[] ab : abs) {
      int a = ab[0];
      int b = ab[1];
      counts[a]++;
      counts[b]++;
    }
    
    List<Integer> answers = new ArrayList<>();
    for (int i = 1; i <= n; i++) {
      answers.add(counts[i]);
    }
    return answers;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    int m = reader.nextInt();
    int[][] abs = reader.nextInt(m, 2);
    for (int answer : solve(n, m, abs)) {
      out.println(answer);
    }
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 22612
fun main() {
  val (L, R, d) = readInts()
  var cnt = 0
  for (i in L..R) {
    if (i % d == 0) cnt++
  }
  println(cnt)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 36372
from heapq import heappush, heappop
import sys
from operator import itemgetter
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
class UnionFind():
    def __init__(self, n):
        self.par = [-1 for i in range(n)]

    def root(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.root(self.par[x]) # contraction
            return self.par[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            if self.par[x] > self.par[y]: # merge technique
                x, y = y, x
            self.par[x] += self.par[y]
            self.par[y] = x

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def size(self, x):
        return -self.par[self.root(x)]

n = int(input())
points = []
for i in range(n):
    x, y = map(int, input().split())
    points.append([x, y, i])

edge = []
points.sort(key=itemgetter(0))
for i in range(1, n):
    dist = points[i][0] - points[i-1][0]
    edge.append((points[i][2], points[i-1][2], dist))
    edge.append((points[i-1][2], points[i][2], dist))

points.sort(key=itemgetter(1))
for i in range(1, n):
    dist = points[i][1] - points[i-1][1]
    edge.append((points[i][2], points[i-1][2], dist))
    edge.append((points[i-1][2], points[i][2], dist))

# print(edge)
edge.sort(key=itemgetter(2))
uf = UnionFind(n)
ans = 0
for u, v, cost in edge:
    if not uf.same(u, v):
        ans += cost
        uf.unite(u, v)
print(ans)


Measured memory_bytes: 67840
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <cassert>
#define SIZE 205
#define MX 100005
#define MOD 1000000007

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

int A[SIZE];
ll dp[2][MX];

int main()
{
	int n,X;
	scanf("%d %d",&n,&X);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	sort(A,A+n);
	int pos=0;
	for(int i=0;i<MX;i++) dp[pos][i]=i;
	for(int i=0;i<n;i++)
	{
		pos^=1;
		for(int j=0;j<MX;j++)
		{
			dp[pos][j]=dp[pos^1][j]*(ll) i%MOD;
			dp[pos][j]+=dp[pos^1][j%A[i]];
			if(dp[pos][j]>=MOD) dp[pos][j]-=MOD;
		}
	}
	printf("%lld\n",dp[pos][X]);
	return 0;
}


Measured memory_bytes: 1664
/*
定义叶子节点为必胜点
一个点的胜败情况为：所有子节点异或起来然后取反
如果一个点有两个子节点都是必胜那么就是First 
*/ 
#include<bits/stdc++.h>
#define N 500005
using namespace std;
int head[N],son[N],father[N];
bool dp[N];
int n,x,y;
struct Tree{
    int nxt,to;
}e[500005];
int k=0;
void add(int x,int y){e[++k].nxt=head[x];e[k].to=y;head[x]=k;}
void dfs2(int u,int fa)
{
    son[u]=1;
    for (int i=head[u];i;i=e[i].nxt){
        int v=e[i].to;
        if (v==fa) continue;
        dfs2(v,u);
        son[u]=son[u]+son[v]; father[v]=u;
    }
}
bool flag=false;
void dfs(int u,int fa)
{
    if (son[u]==1){
    	dp[u]=true;
    	return;
	}
	int tot=0;
    if (flag) return;
    for (int i=head[u];i;i=e[i].nxt){
        int v=e[i].to;
        if (v==father[u]) continue;
        dfs(v,u);
        if (dp[v]==true) tot++;
        if (tot>=2){
            flag=true;
            return;
        }
        dp[u]=dp[u]^dp[v];
    }
    dp[u]=!dp[u];
}
int main()
{
    scanf("%d",&n);
    for (int i=1;i<n;i++){
        scanf("%d%d",&x,&y);
        add(x,y); add(y,x);
    }
    dfs2(1,-1); dfs(1,-1);
    if (flag||dp[1]) puts("First");
    else puts("Second");
    return 0;
}

Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define nl cout<<endl
 
#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()
 
#define pb push_back
#define ff first
#define ss second
#define hell 1000000007
 
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define N 300009
 
ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
int main()
{	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll n;cin>>n;
	vi v,a,b;	
	rep(i,1,n+1)
	{
		ll x;cin>>x;
		a.pb(x);
		v.pb(i);
	}
	rep(i,1,n+1)
	{
		ll x;cin>>x;	
		b.pb(x);
	}
	sort(all(v));
	ll ca=0,cb=0;

	ll curr=1;
	do
	{
		if(v==a)
		ca=curr;
		if(v==b)
		cb=curr;

		curr++;
	}
	while(next_permutation(all(v)));

	cout<<abs(ca-cb)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<functional>
 #include<utility>
 
 using namespace std;
 
 int arr[1000000+5];
 
 bool is_prime(int x)
 {
   if(x==2) return true;
   else
   {
     for(int i=2;i<=sqrt(x);i++)
     {
       if(x%i==0) return false;        
     }    
     return true;
   }     
 }

 int main()
 {
   int n;
   int count=0;
   cin>>n;
   int k=n;
   while(n%2==0)
   {
     arr[count++]=2;
     n/=2;             
   }
   int kk=n;
 if(n>1)
 {
   if(is_prime(kk)) arr[count++]=kk;
   else
   {
     for(int i=3;i<=kk;i=i+2)
     {
       if(is_prime(i))
       {
         while(n%i==0)
         {
           arr[count++]=i;
           n/=i;             
         }               
       }        
       if(n==1) break;
     }
   }
 }
   cout<<k<<":";
   for(int i=0;i<count;i++) cout<<" "<<arr[i];
   cout<<endl;
   //while(1);
   return 0;
 }

 

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1'000'000'007

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

    double ans = 0.0;
    for(int i=1; i<=n; i++){
        int sc = i;
        double tmp = 1.0;
        while(sc < k){
            tmp *= 0.5;
            sc *= 2;
        }
        ans += tmp / n;
    }
    cout << setprecision(12) << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
int main(int argc, char const *argv[]) {
  int k;
  std::cin >> k;
  if (k%2==1) {
    std::cout <<((k+1)/2)*((k-1)/2)<< '\n';
  }
  else{
  std::cout << (k/2)*(k/2) << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
var i,j,k,l,m,n,q,w,a,b,c:int64;
begin
    readln(a,b,c,k);
    k:=k mod 2;
    if k=1 then begin
        if abs(b-a)>1000000000000000000 then writeln('Unfair')
        else writeln(b-a);
    end
    else begin
        if abs(a-b)>1000000000000000000 then writeln('Unfair')
        else writeln(a-b);
    end;
end.

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

int main(){
    int N, D, see, out;

    cin >> N >> D;

    see = 2 * D + 1;
    if(N % see == 0){
        out = N / see;
    }else{
        out = N / see + 1;
    }
    cout << out << endl;
}

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

int M, N;

void dfs(int i, int limit, vector<int> &keep, vector<vector<int>> &array, int &count) {
  if(i == N) {
    for(int j = limit; j <= M; j++) {
      keep.at(i - 1) = j;
      for(int l = 0; l < N; l++) {
        array.at(count).at(l) = keep.at(l);
      }
      count++;
    }
  }
  else {
    for(int j = limit; j <= M; j++) {
      keep.at(i - 1) = j;
      dfs(i + 1, j, keep, array, count);
    }
  }
}

int main() {
  int Q;
  cin >> N >> M >> Q;
  map<tuple<int, int, int>,int> data;
  for(int i = 0; i < Q; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    data[make_tuple(a, b, c)] = d;
  }
  int64_t total = 1;
  for(int i = N + M - 1; i >= M; i--) {
    total *= i;
  }
  for(int i = 2; i <= N; i++) {
    total /= i;
  }
  vector<vector<int>> array(total, vector<int> (N));
  vector<int> keep(N);
  int count = 0;
  dfs(1, 1, keep, array, count);
  int ans = 0;
  for(int i = 0; i < total; i++) {
    int sum = 0;
    for(int k = 0; k < N; k++) {
      for(int l = k + 1; l < N; l++) {
        if(data.count(make_tuple(k + 1, l + 1, array.at(i).at(l) - array.at(i).at(k)))) {
          sum += data[make_tuple(k + 1, l + 1, array.at(i).at(l) - array.at(i).at(k))];
        }
      }
    }
    if(sum > ans) {
      ans = sum;
    }
  }
  cout << ans << endl;     
}

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

int main() {
  vector<string> vec(1);
  //for (int i = 0;i < 3;i++) {
  //  cin >> vec.at(i);
  //}
  cin >> vec.at(0);

  if (vec.at(0) == "AAA") {
    cout << "No" << endl;
  } else if (vec.at(0) == "BBB") {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  
#if 0
  if (vec.at(0) == "A" && vec.at(1) == "A" && vec.at(2) == "A") {
    cout << "No" << endl;
  } else if (vec.at(0) == "B" && vec.at(1) == "B" && vec.at(2) == "B") {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
#endif
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int dp[n+1][3];
	int a,b,c;
	n--;
	cin>>a>>b>>c;
	dp[1][0]=a;
	dp[1][1]=b;
	dp[1][2]=c;
	int i=2;
	while(n--)
	{
		int a1,b1,c1;
		cin>>a1>>b1>>c1;
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a1;
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b1;
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c1;
		i++;
	}
	cout<<max(max(dp[i-1][0],dp[i-1][1]),dp[i-1][2]);
}

Measured memory_bytes: 1408
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

int main() {
	int n;
	cin >> n;
	vector<pair<string, pair<int, int> > > v(n);

	for (int i = 0; i < n; ++i) {
		cin >> v[i].first >> v[i].second.first;
		v[i].second.second = i + 1;
	}

	sort(v.begin(), v.end());
	int i = 0;

	while (i < n) {
		string s = v[i].first;
		vector<pair<int, int> > temp;

		while (i < n && v[i].first == s) {
			temp.push_back(v[i].second);
			i++;
		}

		sort(temp.rbegin(), temp.rend());

		for (int j = 0; j < (int) temp.size(); ++j) {
			cout << temp[j].second << endl;
		}
	}

	return 0;
}

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

namespace _175_b
{
    internal class MakingTriangle
    {
        private static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException());
            var l = Console.ReadLine()?.Split(" ").Select(int.Parse).ToArray();

            if (n < 3)
            {
                Console.WriteLine(0);
                return;
            }
            if (l == null) return;

            var count = 0;
            for (var i = 0; i < n; i++)
            {
                for (var j = i + 1; j < n; j++)
                {
                    for (var k = j + 1; k < n; k++)
                    {
                        if (IsDifferentLength(l[i], l[j], l[k]))
                        {
                            if(IsTriangle(l[i], l[j], l[k]))
                            {
                                count++;
                            }
                        }
                    }
                }
            }

            Console.WriteLine(count);
        }

        private static bool IsTriangle(int a, int b, int c)
        {
            return a + b > c && b + c > a && c + a > b;
        }

        private static bool IsDifferentLength(int a, int b, int c)
        {
            return a != b && b != c && c != a;
        }
    }
}


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

int main(){
    int x, y, a, b = 1;
    cin >> x >> y;
    if (x > y) {
        a = x%y;
        for (int i = 1; i <= a; i++){
            if(a%i == 0){
                if (y%i == 0) b = i;
            }
        }
    }
    else if (x < y){
        a = y%x;
        for (int i = 1; i <= a; i++){
            if(a%i == 0){
                if (x%i == 0) b = i;
            }
        }
    }
    else b = x;
    cout << b << endl;
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include<queue>

typedef long long ll;
using namespace std;

int main()
{
    int H, W;
    int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
    cin >> H >> W;
    char A[1000][1000];
    queue < pair<int,int> > q;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A[i][j];
            if (A[i][j] == '#') q.push(make_pair(i, j));
        }
    }
    int ans = 0;
    while (!q.empty()) {
        int tmp =  q.size();
        queue < pair<int, int> > nq;
        for (int i = 0; i < tmp; i++) {
            int x = q.front().first;
            int y = q.front().second;
            q.pop();
            for (int j = 0; j < 4; j++) {
                int px = x + dx[j];
                int py = y + dy[j];
                if (px < 0 || px >= H || py < 0 || py >= W) continue;
                if (A[px][py] == '.'){
                    nq.push(make_pair(px, py));
                    A[px][py] = '#';
                }
            }
        }
        if (nq.empty()) break;
        q = nq;
        ans++;
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int power(int x,int y){
   if(y==0){
   return 1;
   }
  if(y%2==0){
     return power(x,y/2)*power(x,y/2);
  }
  else{
      return x*power(x,y/2)*power(x,y/2);
  }
}
int main(){
  int r;
  cin>>r;
  cout<<power(r,2)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
struct node{
  struct node *parent;
  struct node *l;
  struct node *r;
  int key;
};
typedef struct node * Node;
 
#define NIL NULL
Node root;

void Insert(int k){
Node p = NIL;
Node q = root;
Node z;

z = malloc(sizeof(struct node));
z->key = k;
z->l = NIL;
z->r = NIL;

while(q != NIL){
p = q;
if(z->key < q->key){
q = q->l;
}
 else {
q = q->r;
}
}
z->parent = p;

if(p == NIL){
root = z;
}
 else if(z->key < p->key){
p->l = z;
}
 else {
p->r = z;
}
}

void Inorder(Node u){
if(u->l != NIL){
Inorder(u->l);
}
printf(" %d",u->key);

if(u->r != NIL){
Inorder(u->r);
}
}

void Preorder(Node u){
printf(" %d",u->key);
if(u->l != NIL){
Preorder(u->l);
}
if(u->r != NIL){
Preorder(u->r);
}
}

int main(void){
int n,i,x;
char com[20];

scanf("%d",&n);

root = malloc(sizeof(struct node));
root = NIL;

for(i = 0 ; i < n ; i++){
scanf("%s",com);

if(com[0] == 'i'){
scanf("%d",&x);

Insert(x);
}
 else {            
Inorder(root);
printf("\n");
Preorder(root);
printf("\n");
}
}
return 0;
}

Measured memory_bytes: 24036
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

int main() {
    vector<int> n(3);
    cin >> n[0] >> n[1] >> n[2];
    
    sort(n.begin(), n.end());
    
    cout << n[0] + n[1] << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var hwn = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var point = new long[10];
        point[0] = (long)(hwn[0] - 2) * (hwn[1] - 2);
        var dic = new Dictionary<int, Dictionary<int,int>>();
        for(var i = 0; i < hwn[2]; i++)
        {
            var input = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
            for(var j = 0; j < 3; j++)
                for(var h = 0; h < 3; h++)
                {
                    var hh = input[0] - j;
                    var ww = input[1] - h;
                    if (1 > hh || hh > hwn[0]-2 || 1 > ww || ww > hwn[1]-2)
                        continue;
                    if (!dic.ContainsKey(hh))
                        dic[hh] = new Dictionary<int, int>();
                    if (dic[hh].ContainsKey(ww))
                        dic[hh][ww]++;
                    else dic[hh][ww] = 1;
                    point[dic[hh][ww]]++;
                }
        }
        for (var i = 0; i < 9; i++)
            WriteLine(point[i] - point[i + 1]);
        WriteLine(point[9]);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 90992
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

vector<string> ans;
int n;

void dfs(string &s, char c, int i){
    if(i == n){
        ans.push_back(s);
        return;
    }
    for(char a = 'a'; a <= c+1; a++){
        s += a;
        dfs(s, max(a,c), i+1);
        s.pop_back();
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    string tmp = "a";
    dfs(tmp, 'a', 1);
    sort(ans.begin(), ans.end());
    for(string &s : ans)    cout << s << endl;
    return 0;
}

Measured memory_bytes: 9716
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#define FOR(i, a, b)  for(int i=a;i<=b;++i)
#define rep(i, n) for(int i=0;i<=n;++i)
using namespace std;


int main(){
  int x;  cin >> x;
  int max=0;
  rep(i, x){
    int n=0;
    FOR(j, 2, 10){
      int m=pow(i,j);
      if(m>x)  break;
      n = m;
    }
    if(max <= n)  max=n;
  }
  cout << max << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
    ll N, A, B, ans = 0;
    cin >> N >> A >> B;
    ans = (N / (A + B)) * A + min(N % (A + B), A);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
/////calc (mod MOD)
const ll MOD = 1000000007;
/////nCk (mod MOD) BEGIN/////
//faccal -> n!, k!^(MOD-2)()
//comb -> nCk (mod MOD)
ll mlpow(ll x, ll p) { //(x^p) % MOD
    ll tmp = 1;
    if(p == 0) return 1;
    while(p != 0) {
        if(p & 1) tmp = tmp*x % MOD;
        x = x*x % MOD;
        p = p >> 1;
    }
    return tmp;
}

#define facMAX 2000000
ll fac[facMAX];     //n! (mod MOD)
ll facM2[facMAX];   //(k!)^(MOD-2) (mod MOD)
void faccal(ll up) {
    fac[0] = 1;
    facM2[0] = 1;
    for(int i = 0; i < up + 1; i++){
        fac[i+1] = fac[i] * (i+1) % MOD;
        facM2[i+1] = facM2[i] * mlpow(i+1, MOD-2) % MOD;
    }
}

//nCk = n!*(k!)^(M-2)*((n-k)!)^(M-2)
ll comb(ll n, ll k) {
    if(n == 0 && k == 0) return 1;
    if(n < k || n < 0) return 0;
    ll tmp = (facM2[n-k] * facM2[k]) % MOD;
    return tmp * fac[n] % MOD;
}

int main(){
    ll n; scanf("%lld", &n);
    ll ans = 0;
    if(n > 1){
        ans = mlpow(10, n) + mlpow(8, n);
        ans %= MOD;
        ans += (2*MOD-mlpow(9, n)*2)%MOD;
        ans %= MOD;
    }

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


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

long long s;

void init() {
    std::cin >> s;
}

int get_c(long long x) {
    long long c = std::max(0LL, (long long)std::sqrt(x) - 10);
    
    // std::cout << "c = " << c << std::endl;

    while (c * c < x) {
        c++;
    }
    return c;
}

void solve() {
    long long c = get_c(s);

    // std::cout << 0 << 0 << c << 1  << c * c - s << c << std::endl;
    if (c * c == s) {
        printf("%lld %lld %lld %lld %lld %lld\n", 0LL, 0LL, c, 0LL, 0LL, c);
    } else {
        printf("%lld %lld %lld %lld %lld %lld\n", 0LL, 0LL, c, 1LL, c * c - s, c);
    }
}

int main() {
    // freopen("input.txt", "r", stdin);

    init();
    solve();

    return 0;
}

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

if station_num == 1:
    print(0)
else:
    station_list = [[0, 0, 0] for i in range(station_num)]
    
    for i in range(station_num - 1):
        station_list[i] = input().split()
    # print(station_list)
    
    for i in range(station_num):
        count = int(station_list[i][0]) + int(station_list[i][1])
        now_position = i + 1
        while True:
            if now_position == station_num - 1 or now_position == station_num:
                print(count)
                break
            else:
                while True:
                    if count < int(station_list[now_position][1]):
                        count = int(station_list[now_position][1])
                    elif count % int(station_list[now_position][2]) == 0:
                        count += int(station_list[now_position][0])
                        now_position += 1
                        break
                    else:
                        count = count + int(station_list[now_position][2]) - (count % int(station_list[now_position][2]))

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
int n,p[100],q[100],r[100],b[100];
int dp[100];
int func(int v){
    if(v==-1)
        return 1;
    if(dp[v]!=0)
        return dp[v];
    int r_=func(r[v]-1),b_=func(b[v]-1);
    return dp[v]=(p[v]+q[v])*r_*b_/__gcd(p[v]*r_,q[v]*b_);
}
signed main(){
    while(cin>>n,n){
    for(int i=0;i<n;i++){
        cin>>p[i]>>q[i]>>r[i]>>b[i];
        dp[i]=0;
    }
    int ans=0;
    for(int i=0;i<n;i++)
        ans=max(ans,func(i));
    cout<<ans<<endl;
    }
}



Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
#define MAX 100000

int parent(int i) {
  return i / 2;
}

int left(int i) {
  return 2 * i;
}

int right(int i) {
  return 2 * i + 1;
}

int main() {
  int H, i, A[MAX+1];

  cin >> H;

  for (i = 1; i <= H; i++) cin >> A[i];

  for (i = 1; i <= H; i++) {
    cout << "node " << i << ": key = " << A[i] << ", ";
    if (parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
    if (left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
    if (right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3124