akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;

struct node {
  int key;
  node *R,*L,*P;
};

node *rt,*nil;

node * find(node *u, int k){
  while(u != nil && k != u->key){
    if(k < u->key) u = u->L;
    else u = u->R;
  }
  return u;
}

void inst(int k){
  node *y = nil;
  node *x = rt;
  node *z;

  z = (node *)malloc(sizeof(node));
  z->key = k;
  z->L = nil;
  z->R = nil;

  while(x != nil){
    y = x;
    if(z->key < x->key){
      x = x->L;
    }else{
      x = x->R;
    }
  }

  z->P = y;
  if(y == nil){
    rt = z;
  }else{
    if(z->key < y->key){
      y->L = z;
    }else {
      y->R = z;
    }
  }
}

void indr(node *u){
  if(u == nil) return;
  indr(u->L);
  printf(" %d",u->key);
  indr(u->R);
}

void prodr(node *u){
  if(u == nil) return;
  printf(" %d",u->key);
  prodr(u->L);
  prodr(u->R);
}

int main(){
  int n,i,x;
  string cm;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    cin >> cm;
    if(cm[0] == 'f'){
      scanf("%d",&x);
      node *t = find(rt,x);
      if(t != nil) printf("yes\n");
      else printf("no\n");
    }else if(cm == "insert"){
      scanf("%d",&x);
      inst(x);
    }else if(cm == "print"){
      indr(rt);
      printf("\n");
      prodr(rt);
      printf("\n");
    }
  }
  
  return 0;
}



Measured memory_bytes: 22076
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    if(a>b){swap(a,b);}
    vector<ll> A(n+1,-E);
    for(int i=0;i<n;i++){cin>>A[i+1];}
    for(int i=2;i<=n;i++){if(A[i]-A[i-2]<a){cout<<0<<endl; return 0;}}
    vector<ll> dp(n+1,0);
    dp[0]=1;
    ll l=0;
    ll mx=0;
    for(int i=1;i<=n;i++){
        while(l<i && A[i]-A[l]>=b){l++;}
        if(l<mx){dp[i]=dp[i-1];}
        else{dp[i]=dp[l-1]-(mx-2>=0?dp[mx-2]:0); dp[i]+=dp[i-1];}
        if(A[i]-A[i-1]<a){mx=i;}
        dp[i]%=MOD;
    }
    
    ll ans=dp.back();
    for(ll i=n-1;i>=1;i--){
        if(A[i+1]-A[i]<a){ans-=dp[i-1]; break;}
    }
    ans%=MOD;
    if(ans<0){ans+=MOD;}
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 1792
#define judge
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int inf = 0x3f3f3f3f;
const int ninf = 0xcfcfcfcf;
const double pi = acos(-1.0);
static int faster_iostream = []() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  return 0;
}();

int main() {
#ifndef judge
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  // b = a + b;
  // d = c + d;
  cout << max(0, min(b, d) - max(a, c)) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int n,R;
	scanf("%d", &n);
	scanf("%d", &R);
	int u = -2000000000;
	int l = R;
	while (--n) {
		scanf("%d", &R);
		if (u < (R - l)) u = R - l;
		if (l > R) l = R;
	}
	printf("%d\n", u);
}


Measured memory_bytes: 2752
N = int(input())
c = input()
W = 0
R = c.count('R')
if R == 0 or R == N:
  print(0)
  exit()
ans = N
t = 0
for i in range(N):
  if c[i] == 'W':
    W += 1
  else:
    R -= 1
  t = max(R,W)
  ans = min(ans, t)
print(ans)

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

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

	int col[9] = {};

	for(int i = 0; i < n; ++i){
	 	int m = floor( a[i] / 400 );
		if( m < 8 ){
			col[m]++;
		} else {
			col[8]++;
		}
	}

	int min = 0;
	for(int i = 0; i < 8; ++i){
		if( col[i] > 0){
			min++;
		}
	}

	int max = min;
	if( (min + col[8]) >= 8){
		max += col[8];
	} else if( min == 0){
		min = 1;
		if( col[8] > 8 ){
			max = col[8];
		} else {
			max = col[8];
		}
	} else if( (min + col[8]) < 8){
		max += col[8];
	}
	
	cout << min << " " << max << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        var xkd = ReadLine().Split().Select(long.Parse).ToArray();
        var X = Abs(xkd[0]);
        var K = xkd[1];
        var D = xkd[2];

        long d = X / D;
        
        long ans = X;
        if (K<d)
        {
            ans = X - D * K;
        }
        else
        {
            K -= d;
            X -= D * d;
            //WriteLine(X);
            if (K % 2 == 0)
                ans = X;
            else
                ans = Abs(X - D);
        }
        WriteLine(ans);
    }
}


Measured memory_bytes: 28244
#include<iostream>
using namespace std;
int main()
{
  
  int count5 = 0;
  int count7 = 0;
  
  for(int i = 0; i < 3; i++)
  {
	int n;
    cin >> n;
    
    if(n == 5)
    {
      count5++;
    }
    else if(n == 7)
    {
      count7++;
    }
  }
  
  if(count5==2 && count7==1)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
      

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define mp make_pair
#define v vector
#define inp_push(no, v) \
    ll no;              \
    cin >> no;          \
    v.push_back(no);
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define UN(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define N 200005
#define mod 1000000009
#define INF INT64_MAX

//////////////////////////IMPORTANT FUNCTIONS/////////////////////////////////////////////

/* Guidlines berfore submitting solution
1. Check N value before submitting
2. Check all constant kind of values you are using. Might give WA. Think
3. Check mod value
*/

v<ll> fact(N);
v<ll> prime_check(1e7 + 1);
v<ll> primes;

long long powmod(long long x, long long y, long long m)
{
    long long res = 1LL;
    while (y)
    {
        if (y & 1)
            res = (res * x) % m;
        x = (x * x) % m;
        y /= 2;
    }
    return res;
}

void init_fact()
{
    fact[0] = 1;
    for (ll i = 1; i < N; i++)
    {
        fact[i] = (fact[i - 1] * i) % mod;
    }
}

ll C(ll n, ll r)
{
    if (n < r)
        return 0;
    ll temp = fact[n] * powmod(fact[r], mod - 2, mod) % mod;
    temp *= powmod(fact[n - r], mod - 2, mod);
    temp %= mod;
    return temp;
}

void Sieve()
{
    for (ll i = 2; i <= 1e7; i++)
    {
        if (prime_check[i])
            continue;
        primes.pb(i);
        for (ll j = 2 * i; j <= 1e7; j += i)
            prime_check[j] = i;
    }
}
ll phi(ll n)
{
    ll i, res = n;
    for (i = 2; i * i <= n; i++)
        if (n % i == 0)
        {
            while (n % i == 0)
                n /= i;
            res -= res / i;
        }
    if (n > 1)
        res -= res / n;
    return res;
}

/////////////////////////////////////START CODE HERE/////////////////////////////////////////////

ll n;
v<ll> dp(1e7 + 1);
v<ll> dp1(1e7 + 1);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // init_fact();
    Sieve();
    cin >> n;
    ll ans = 0;
    for (ll i = 1; i <= n; i++)
    {
        ll m = prime_check[i];
        if (i == 1)
            dp[i] = 1, dp1[i] = 0;
        else if (m == 0)
            dp[i] = 2, dp1[i] = 1;
        else if ((i / m) % m != 0)
        {
            dp[i] = dp[i / m] * 2, dp1[i] = 1;
        }
        else
        {
            dp[i] = (dp[i / m] / (dp1[i / m] + 1)) * (dp1[i / m] + 2);
            dp1[i] = dp1[i / m] + 1;
        }
        // cout << dp[i] << " ";
        ans += i * dp[i];
    }
    cout << ans << "\n";
}

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

int main() {
    string s;
    cin >> s;
    bool good = true;
    for (int i = 0; i < 3; i++) {
        if (s[i] == s[i + 1]) {
            good = false;
            break;
        }
    }

    if (good) {
        cout << "Good" << endl;
    } else {
        cout << "Bad" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
//#define i_7 (long long)(1e9+7)
#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

template <typename T>
class SegmentTree {
    using F = function<T(T, T)>;
    int n;
    F f;
    T t;
    vector <T> dat;
public:
    SegmentTree(F f, T t) : f(f), t(t) {}
    void init(int n_) {
        n = 1;
        while (n < n_) n <<= 1;
        dat.assign(n << 1, t);
    }
    void build(const vector <T> &v) {
        auto n_ = (int)v.size();
        init(n_);
        for (int i = 0; i < n_; i++) dat[n + i] = v[i];
        for (int i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
    }
    //k番目の値をxに変更する。
    void set_val(int k, T x) {
        dat[k += n] = x;
        while (k >>= 1) dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
    }
    //[a,b)に対してfを適用する。
    T query(int a, int b) {
        T vl = t, vr = t;
        for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) vl = f(vl, dat[l++]);
            if (r & 1) vr = f(dat[--r], vr);
        }
        return f(vl, vr);
    }
};

int n, k;
int l[10], r[10];
long long dp[200'010];

int main(){
  using namespace std;
  cin>>n>>k;
  REP(i, k) cin>>l[i]>>r[i];
  typedef pair<int, int> P;
  vector<P> vec;
  REP(i, k) vec.push_back(P(l[i], r[i]));
  sort(ALL(vec));
  REP(i, k){
    l[i] = vec[i].first;
    r[i] = vec[i].second;
  }
  REP(i, n) dp[i] = -1;
  
  auto f = [](long long a, long long b) { return mod(a + b); };
  SegmentTree<long long> seg(f, 0LL);
  seg.build(vector<long long>(n, 0LL));
  
  seg.set_val(0, 1);
  for(int pos = 1; pos < n; pos++){
    long long res = 0;
    for(int i = 0; i < k; i++){
      if(l[i] > pos) break;
      int st = pos - min(pos, r[i]);
      int ed = pos - l[i];
      res += seg.query(st, ed + 1);
      res = mod(res);
    }
    seg.set_val(pos, res);
  }
  long long ans = seg.query(n - 1, n);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10440
#include<bits/stdc++.h>
using namespace std;
int bu;
struct q{
	int l , r , in;
};
bool comp(q a , q b)
{
	if((a.l)/bu!=(b.l)/bu)
		return (a.l)/bu < (b.l)/bu;
	else
		return a.r < b.r;
}
int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	int n , m1;
	cin>>n>>m1;
	int arr[n] , answer[m1];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	q query[m1+1];
	bu=sqrt(n);
	for(int i=0;i<m1;i++)
	{
		int x , y;
		cin>>x>>y;
		x-- , y--;
		query[i]={x , y , i};
	}
	sort(query , query+m1 , comp);
	int m[n+1] , total=0;
	memset(m , 0 , sizeof(m));
	int curl=0 , curr=-1;
	for(int i=0;i<m1;i++)
	{
		while(curr<query[i].r)
		{
			if(m[arr[curr+1]]==0)
				total++;
			m[arr[++curr]]++;
		}
		while(curl<query[i].l)
		{
				m[arr[curl]]--;
				if(m[arr[curl]]==0)
					total--;
				curl++;
		}
		while(curl>query[i].l)
		{
			if(m[arr[curl-1]]==0)
				total++;
			m[arr[--curl]]++;
		}
		while(curr>query[i].r)
		{
			m[arr[curr]]--;
			if(m[arr[curr]]==0)
				total--;
			curr--;
		}
		answer[query[i].in]=total;
	}
	for(int i=0;i<m1;i++)
		cout<<answer[i]<<" ";
}

Measured memory_bytes: 15516
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define fi first
#define se second
#define dbg(...) cerr<<"["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"<<endl;
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=2e5+100;
ll sum[maxn];
int c[maxn];
int cnt=0;
void add(int x)
{
    while(x<=cnt)
    {
        c[x]++;
        x+=x&(-x);
    }
}
int get_sum(int x)
{
    int ans=0;
    while(x)
    {
        ans+=c[x];
        x-=x&(-x);
    }
    return ans;
}
ll h[maxn];
int v[maxn];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    rep(i,1,n+1) scanf("%lld",&sum[i]),sum[i]-=1ll*k;
    rep(i,1,n+1) sum[i]=sum[i-1]+sum[i],h[i]=sum[i];
    sort(h+1,h+n+1);
    cnt=unique(h+1,h+n+1)-h-1;
    //printf("%d\n",cnt);
    ll ans=0;
    rep(i,1,n+1)
    {
        int pos=lower_bound(h+1,h+cnt+1,sum[i])-h;
        if(sum[i]>=0) ans++;
        ans+=get_sum(pos);
        add(pos);
    }
    printf("%lld\n",ans);
    return 0;
}













Measured memory_bytes: 4096
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int main(){
	//~ #ifndef ONLINE_JUDGE
    //~ freopen("file.in", "r", stdin);
	//~ #endif	
	int n,type=1;
	scanf("%d",&n);
	deque<int>d;
	while(n--){
		int x;
		scanf("%d",&x);
		if(type)
			d.pb(x);
		else
			d.push_front(x);
		type^=1;	
	}
	if(!type)
		reverse(all(d));
	tr(it,d)
		printf("%d ",*it);
	puts("");	
	return 0;
}


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

int main() {

    int a, b, c, k;

    scanf("%d %d %d", &a, &b, &c);
    scanf("%d", &k);

    if(a >= b && a >= c) {
        printf("%.0lf\n", a * pow(2, k) + b + c);
    } else if(b > a && b > c) {
        printf("%.0lf\n", a + b * pow(2, k) + c);
    } else {
        printf("%.0lf\n", a + b + c * pow(2, k));
    }

}


Measured memory_bytes: 128
r = p = 0
l = [0, 0]
for c in input():
    f = c == '<'
    if c != p:
        p = c
        if f:
            r -= min(l)
            l = [0, 0]
    l[f] += 1
    r += l[f]
if not f:
    r -= min(l)
print(r)


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

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	int c;
	c=0;
	for (int i=0;i<N;i++){
	  cin >> a.at(i);
	}
	for (int i=0;i<N;i++){
		c^=a.at(i);
	}
	if(c==0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 640
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

N = int(input())
a = list(map(int, input().split()))
s = set()
cnt = 0
for v in a:
    if 1 <= v <= 399:
        s.add(1)
    elif 400 <= v <= 799:
        s.add(2)
    elif 800 <= v <= 1199:
        s.add(3)
    elif 1200 <= v <= 1599:
        s.add(4)
    elif 1600 <= v <= 1999:
        s.add(5)
    elif 2000 <= v <= 2399:
        s.add(6)
    elif 2400 <= v <= 2799:
        s.add(7)
    elif 2800 <= v <= 3199:
        s.add(8)
    elif 3200 <= v:
        cnt += 1
print(max(1,len(s)), len(s) + cnt)


Measured memory_bytes: 5460
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

LL ksum[401][401]; // sum_(0~j) j^i
LL dp[401][401];// i人目を見た時までにn個のキャンディを消費したときの数値
int a[401];
int b[401];
void init() {
	REP(j, 401)ksum[0][j] = 1;
	REP(i, 400) REP(j, 401) ksum[i + 1][j] = (ksum[i][j] * j) % MOD;
	REP(i, 401)REP(j, 400)ksum[i][j + 1] = (ksum[i][j + 1] + ksum[i][j]) % MOD;
}

LL getsum(int l, int r, int p) {
	return (ksum[p][r] - ksum[p][l - 1] + MOD) % MOD;
}

int main() {
	int n, c;
	init();
	scanf("%d%d", &n, &c);
	REP(i, n)scanf("%d", &a[i]);
	REP(i, n)scanf("%d", &b[i]);
	dp[0][0] = 1;

	REP(i, n) {
		REP(j, c + 1) {
			REP(k, c-j+1) {
				dp[i + 1][j + k] = (dp[i + 1][j + k] + dp[i][j] * getsum(a[i], b[i], k))%MOD;
			}
		}
	}
	cout << dp[n][c] << endl;
	return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <string>
#include <stdlib.h>
#include <cstdlib>
using namespace std;
int main(){
    int h,w;
    int n,x[1000],y[1000];
    cin>>h>>w;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>x[i]>>y[i];
    int count=0;
    for(int i=1;i<n;i++){
        if((x[i-1]>x[i]&&y[i-1]>y[i])||(x[i-1]<x[i]&&y[i-1]<y[i])){
            int xd=abs(x[i-1]-x[i]);
            int yd=abs(y[i-1]-y[i]);
            if(xd>=yd)
                count+=xd;
            if(xd<yd)
                count+=yd;
        }
        if((x[i-1]<=x[i]&&y[i-1]>=y[i])||(x[i-1]>=x[i]&&y[i-1]<=y[i])){
            int xd=abs(x[i-1]-x[i]);
            int yd=abs(y[i-1]-y[i]);
            count+=xd+yd;
        }
    }
    cout<<count<<endl;
    return 0;
}
 

Measured memory_bytes: 1168
<?php
define('MOD', 10 ** 9 + 7);

fscanf(STDIN, '%d %d', $n, $k);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));

$cnt1 = $cnt2 = 0;
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $n; $j++) {
        if ($i === $j) continue;

        if ($i < $j && $a[$i] > $a[$j]) $cnt1++;
        elseif ($i > $j && $a[$i] > $a[$j]) $cnt2++;
    }
}

$x1 = (1 + $k) * $k / 2 % MOD;
$x2 = (1 + $k - 1) * ($k - 1) / 2 % MOD;
$ans = (($cnt1 * $x1) % MOD + ($cnt2 * $x2) % MOD) % MOD;
echo $ans . PHP_EOL;

Measured memory_bytes: 4728
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int  n,m,u,v,du[100005],h[100005];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	cin>>h[i];
	for(int i=1;i<=m;i++){
		cin>>u>>v;
		if(h[u]<=h[v]) du[u]++;
		if(h[v]<=h[u]) du[v]++;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	if(!du[i])
	ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4432
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	int n;
	cin >> n;
	set<int> s;

	rep(i,0,n){
		int d;
		cin >> d;
		s.insert(d);
	}
	
	P(s.size());
	ret 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class C { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		var S = GetString().ToCharArray();
		long N = S.Length;

		long cnt = 0;
		var stack = new Stack<long>();
		for(long i = 0; i < N; i++)
		{
			if(stack.Count > 0 && stack.Peek() != S[i])
			{
				stack.Pop();
				cnt += 2;
			}
			else
			{
				stack.Push(S[i]);
			}
		}
		WriteLine(cnt);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 28468
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <algorithm>
#include <queue>
#include <deque>
#include <cstring>
#include <string>
#include <iostream>
#include <set>
#include<sstream>
#define ll long long
#define maxn 101000
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;

long long n,a[100100],ni[100100],sum[100100],ans,vk;
int main()
{
    #ifdef local
    freopen("in.txt", "r", stdin);
    #endif // local
	scanf("%lld",&n);
	vk=1;
	for(ll i=1;i<=n;i++)
        vk=vk*i%mod;
    for(ll i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
    }
    ni[0]=ni[1]=1;
    sum[1]=1;
    for(ll i=2;i<=n;i++)
    {
        ni[i]=(mod-mod/i)*ni[mod%i]%mod;
        sum[i]=(sum[i-1]+ni[i])%mod;
    }
    //for(int i=1;i<=n;i++)printf("%lld    %lld\n",ni[i],sum[i]);
    for(int i=1;i<=n;i++)
    {
        ans=(ans+sum[n-i+1]*a[i]%mod+(sum[i]-1)*a[i]%mod)%mod;
    }
    ans=(ans*vk)%mod;
    printf("%lld",ans);
	return 0;
}









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

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

Measured memory_bytes: 256
//author: zekigurbuz (Zeki Gurbuz) 2020
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define all(x) begin(x),end(x)

const int N = 1e5 + 10;
const int M = 1e9 + 7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

template<class T>void ckmin(T&a,T b){a=min(a,b);}
template<class T>void ckmax(T&a,T b){a=max(a,b);}

void precomp() {

}


void solve() {
	string s; cin >> s;
	if (s == "ABC") cout << "ARC" << endl;
	else cout << "ABC" << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	precomp();
	int t = 1; // cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve();
	}
	return 0;
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll long long int 
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vppll vector<pair<pll,pll>>
#define mp make_pair
#define pb push_back
#define mapll map<ll,ll>
#define fir first
#define sec second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0);
#define fo(i,b) for(i=0;i<b;i++)
#define repa(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define all(x) (x).begin(), (x).end()
#define s(v) v.size()
const long long int MAX = (ll)(1e18+1);
const long long int MIN = (ll)(-1e18-1);
const long long int mod = (ll)(1e9+7);
using namespace std;

ll max(ll a,ll b,ll c) {return max(max(a, b), c);}
ll min(ll a,ll b,ll c) { return min(min(a, b), c);}
ll max(ll a,ll b) {return (a>b) ? a : b;}
ll min(ll a,ll b) {return (a<b) ? a : b;}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power_mod(ll a, ll n, ll mod_){ ll p=1; while(n){ if(n%2){ p=(p*a)%mod_;} n/=2; a=(a*a)%mod_;} return p%mod_;}
                                                 /*Code Begins*/
vll top, col;
vvll graph;
ll pos;

void dfs(ll u){
    col[u]=1;
    for(auto v : graph[u]){
        if(col[v]==0) dfs(v);
    }
    top[pos]=u;
    pos--;
}

int main(){
    _cin;
    // cout << setprecision(15);
    ll mn = MAX, mx = MIN;
    ll n, t, m, k, i, j,  sum=0,  prev, flag=0, cnt=0;
    ll x=0, y=0, fx, diff, tot=0, l , r;
    int TC=1;
    // cin >> TC;
while(TC--){
    cin >> n >> m;
    graph.assign(n,{});
    top.assign(n,0);
    col.assign(n,0);
    vll dp(n);
    pos=n-1;
    fo(i,m){
        cin >> x >> y;
        x-- ; y--;
        graph[x].pb(y);
    }
    fo(i,n){
        if(col[i]==0) dfs(i);
    }
    fo(i,n){
        for(auto y : graph[top[i]]){
            dp[y] = max(dp[y],dp[top[i]]+1);
        }
    }
    mx=0;
    // fo(i,n) cout << top[i] << ' ';
    // cout << endl;
    // fo(i,n) cout << dp[i] << ' ';
    // cout << endl;
    fo(i,n) mx = max(mx,dp[i]);
    cout << mx;
}
 return 0;      
}

Measured memory_bytes: 9472
#include <stdio.h>
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))

int main(void) {
	int a, b, c;
	
	scanf("%d %d %d", &a, &b, &c);
	printf("%d\n",  max(a,max(b,c)) - min(a,min(b,c)));
	
	return 0;
}

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

#define iFOR(idx, from, upto) for (int  idx = from; idx < upto; ++idx)
#define lFOR(idx, from, upto) for (long idx = from; idx < upto; ++idx)

#define ll long long

using namespace std;

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

    long sum = 0;

    iFOR(i, 1, n + 1) {
        if (i % 3 != 0 && i % 5 != 0) sum += i;
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
using namespace std;
typedef long long int ll;
static const ll MOD = 1000000007;

int main(){
	int n, k;
	cin >> n >> k;
	if(n > k){
		cout << 0 << endl;
		return 0;
	}
	ll res = 1;
	for(int i = k; i >= k - n + 1; i--){
		res *= i;
		res %= MOD;
	}
	cout << res << endl;
	return 0;
}



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

int main(){
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;

    if(s == u) a--;
    else if(t == u) b--;

    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
//Coded by tzc_wk
/*
Êý¾Ý²»Çå¿Õ£¬±¬ÁãÁ½ÐÐÀá¡£
¶à²â²»¶ÁÍê£¬±¬ÁãÁ½ÐÐÀá¡£
±ß½ç²»ÌØÅÐ£¬±¬ÁãÁ½ÐÐÀá¡£
Ì°ÐÄ²»Ö¤Ã÷£¬±¬ÁãÁ½ÐÐÀá¡£
D P Ë³Ðò´í£¬±¬ÁãÁ½ÐÐÀá¡£
´óÐ¡ÉÙµÈºÅ£¬±¬ÁãÁ½ÐÐÀá¡£
±äÁ¿²»Í³Ò»£¬±¬ÁãÁ½ÐÐÀá¡£
Ô½½ç²»ÅÐ¶Ï£¬±¬ÁãÁ½ÐÐÀá¡£
µ÷ÊÔ²»×¢ÊÍ£¬±¬ÁãÁ½ÐÐÀá¡£
Òç³ö²» l l£¬±¬ÁãÁ½ÐÐÀá¡£
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
int n=read();
vector<string> v;
int a[15],pre[15];
inline void dfs2(int x,int t){
	if(x==n+1){
		fill0(pre);
		fd(i,n,1)	pre[a[i]]=i;
		bool flag=1;
		fz(i,1,t)	if(pre[i]<pre[i-1])	flag=0;
		if(flag){
			string t;
			for(int i=1;i<=n;i++)	t.push_back(a[i]+'a'-1);
			v.push_back(t);
		}
		return;
	}
	if(a[x]){
		dfs2(x+1,t);
		return;
	}
	for(int i=1;i<=t;i++){
		a[x]=i;
		dfs2(x+1,t);
		a[x]=0;
	}
}
inline void dfs(int x,int lst,int t){
	if(x==t+1){
		dfs2(1,t);
		return;
	}
	for(int i=lst+1;i<=n;i++){
		a[i]=x;
		dfs(x+1,i,t);
		a[i]=0;
	}
}
signed main(){
	fz(i,1,n){
		dfs(1,0,i);
	}
	sort(all(v));
	for(int i=0;i<v.size();i++){
		if(i==0||v[i]!=v[i-1])	cout<<v[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 37228
#include<stdio.h>

int main(){
  int H,W;
  scanf("%d%d",&H,&W);
  getchar();
  char a[H][W];
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      scanf("%c",&a[i][j]);
    }
    getchar();
  }

  for (int i = 0; i < H; i++){
    int j=0;
    while (a[i][j]=='.')
    {
      if (j==W-1)
      {
        for (int k = 0; k < W; k++)
        {
          a[i][k]='0';
        }
      }
      j++;
    }
  }
  for (int j = 0; j < W; j++){
    int i=0;
    while (a[i][j]=='.'||a[i][j]=='0')
    {
      if (i==H-1)
      {
        for (int k = 0; k < H; k++)
        {
          a[k][j]='0';
        }
      }
      i++;
    }
  }

  for (int i = 0; i < H; i++){
    int count_0=0;
    for (int j = 0; j < W; j++){
      if(a[i][j]!='0'){
        printf("%c",a[i][j]);
      }else if(a[i][j]=='0'){
        count_0++;
      }
    }
    if (count_0==W){ 
      continue;
    }else{
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 1652
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include<vector>

using namespace std;
typedef long long ll;

ll ans,mx,sum,mn=1e8,cnt=1;

int main(){
	ll h;
	cin>>h;
	while(h!=1){
		if(h%2!=0) h--;
		h/=2;
		cnt*=2;
		ans+=cnt;
	}
	cout<<ans+1<<endl;
}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val h = sc.nextInt()
    val w = sc.nextInt()
    val d = sc.nextInt()

    data class Pos(val x: Int, val y: Int, var dsum: Int = 0)

    val A: Array<Array<Pos>> = Array(d) { Array(h * w / d + 1) { Pos(9999, 9999) } }

    for (y in 0 until h) {
        for (x in 0 until w) {
            val v = sc.nextInt() - 1 // to 0 origin
            A[v % d][v / d] = Pos(x, y)
        }
    }
    for (di in 0 until d) {
        var dsum = 0
        if (A[di].isNotEmpty()) {
            var t = A[di][0]
            for (i in 1 until A[di].count()) {
                val tnext = A[di][i]
                dsum += Math.abs(t.x - tnext.x) + Math.abs(t.y - tnext.y)
                tnext.dsum = dsum
                t = tnext
            }
        }
    }

    val q = sc.nextInt()
    for (i in 0 until q) {
        var m = 0
        val L = sc.nextInt() - 1
        val R = sc.nextInt() - 1

        val Ld = A[L % d][L / d].dsum
        val Rd = A[R % d][R / d].dsum

        println(Rd - Ld)
    }
}


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

int d[100];
int f[100];
int G[100][100];
int now_time = 1;

void input_graph(int n) {
    int u, k, v;
    rep(i, n) {
        scanf("%d %d", &u, &k);
        u--;
        rep(j, k) {
            scanf("%d", &v);
            v--;
            G[u][v] = 1;
        }
    }
}

void dfs(int s, int n) {
    rep(i, n) {
        if(d[i] == -1 && G[s][i] == 1) {
            d[i] = now_time++;
            dfs(i, n);
        }
    }
    f[s] = now_time++;
}

void init(int n) {
    rep(i, n) { d[i] = -1; }
}

void print_graph(int n) {
    rep(i, n) { printf("%d %d %d\n", i + 1, d[i], f[i]); }
}

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int n;
    cin >> n;
    init(n);
    input_graph(n);
    rep(i, n) {
        if(d[i] == -1) {
            d[i] = now_time++;
            dfs(i, n);
        }
    }
    print_graph(n);
}


Measured memory_bytes: 3212
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
	while(1){
		int n, p[10000], d[10000], a, b, max=0, index=-1;
		
		cin >> n;
		if(n==0) break;
		
		for(int i=0; i<n; ++i){
			scanf(" %d %d %d", &p[i], &a, &b);
			d[i] = a+b;
			if(max<d[i]){
				max=d[i];
				index=i;
			}	
		}
		
		printf("%d %d\n",p[index], max);
	}
	return 0;
}

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

#define x first
#define y second

#ifdef ONLINE_JUDGE
#define DEBUG(x)
#else
#define DEBUG(x) cerr << #x << ": " << x << endl;
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int mod=1000000000+7;

int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}

template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}

int n,m,a[100000],red;
typedef pair<int,ii> iii;
vector<iii> chng;

int md(int i) {return i<0?i+m:i;}

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

	cin >> n >> m;
	cin >> a[0];a[0]--;
	ll cur=0;
	for (int i=1;i<n;i++) {
		cin >> a[i];a[i]--;
		chng.emplace_back(a[i-1]+1,ii{-1,-1});
		chng.emplace_back(a[i],ii{0,md(a[i]-a[i-1])-1});
		red+=a[i]<a[i-1];
		cur+=min(a[i]+1,md(a[i]-a[i-1]));
	}

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

	ll M=cur;
	for (int i=0,j=0;i<m;i++) {
		smin(M,cur);
		while (j<chng.size() && chng[j].x<=i) {
			if (chng[j].y.x==-1) red++;
			else {
				red--;
				cur+=chng[j].y.y;
			}
			j++;
		}
		cur-=red;
	}

	cout << M << endl;
}

Measured memory_bytes: 5108
class Solver
  attr_reader :nodes

  def initialize(n)
    @nodes = (0..n-1).map { |i| Node.new(i) }
  end

  def exec
    calc_height(nodes.find(&:root?))
    nodes.each { |node| node.depth = calc_depth(node); }
    puts_result
  end

  def add_node(input)
    id = input[0]

    nodes[id].left_child = input[1]
    nodes[id].right_child = input[2]

    if nodes[id].has_left_child?
      nodes[input[1]].parent = id
      nodes[input[1]].sibling = input[2]
    end

    if nodes[id].has_right_child?
      nodes[input[2]].parent = id
      nodes[input[2]].sibling = input[1]
    end
  end

  def calc_depth(node)
    return 0 unless node.has_parent?

    node2 = nodes[node.parent]
    cnt = 1
    while node2.has_parent?
      node2 = nodes[node2.parent]
      cnt += 1
    end

    return cnt
  end

  def calc_height(node)
    return node.height = 0 unless node.has_children?

    if node.has_left_child?
      left_child = nodes[node.left_child]
      calc_height(left_child)
    end

    if node.has_right_child?
      right_child = nodes[node.right_child]
      calc_height(right_child)
    end

    node.height = [left_child&.height || 0, right_child&.height || 0].max + 1
  end

  def puts_result
    nodes.each do |node|
      puts "node #{node.id}: parent = #{node.parent}, sibling = #{node.sibling}, degree = #{node.degree}, depth = #{node.depth}, height = #{node.height}, #{node.type}"
    end
  end
end

class Node
  attr_accessor :id, :parent, :left_child, :right_child, :sibling, :depth, :height

  def initialize(id)
    @id = id
    @left_child = -1
    @right_child = -1
    @parent = -1
    @sibling = -1
    @height = 0
  end

  def root?
    !has_parent?
  end

  def children
    [@left_child, @right_child]
  end

  def has_left_child?
    left_child != -1
  end

  def has_right_child?
    right_child != -1
  end

  def has_children?
    has_left_child? || has_right_child?
  end

  def has_parent?
    parent != -1
  end

  def type
    return 'root' if root?
    return 'leaf' unless has_children?
    'internal node'
  end

  def degree
    children.count { |c| c != -1 }
  end
end

n = gets.to_i
solver = Solver.new(n)
n.times do |i|
  input = gets.split(' ').map(&:to_i)
  solver.add_node(input)
end

solver.exec


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

using namespace std;

typedef long long ll;

struct TradePair {
    ll a, b;
    bool operator<(const TradePair &rhs) const { return a - b < rhs.a - rhs.b; }
};

ll N, ans;
TradePair tp[3];

int main() {
    scanf("%lld", &N);
    for (int i = 0; i < 3; i++) scanf("%lld", &tp[i].a);
    for (int i = 0; i < 3; i++) scanf("%lld", &tp[i].b);
    sort(tp, tp + 3);
    if (tp[0].a > tp[0].b) {
        ans = N;
        for (int i = 0; i * tp[0].b <= N; i++) 
            for (int j = 0; i * tp[0].b + j * tp[1].b <= N; j++) {
                int k = (N - i * tp[0].b - j * tp[1].b) / tp[2].b;
                ans = max(ans, i * tp[0].a + j * tp[1].a + k * tp[2].a + N - i * tp[0].b - j * tp[1].b - k * tp[2].b);
            }
    } else if (tp[1].a > tp[1].b) {
        N = N % tp[0].a + N / tp[0].a * tp[0].b; ans = N;
        for (int i = 0; i * tp[1].b <= N; i++) {
            int j = (N - i * tp[1].b) / tp[2].b;
            ans = max(ans, i * tp[1].a + j * tp[2].a + N - i * tp[1].b - j * tp[2].b);
        }
    } else if (tp[2].a > tp[2].b) {
        ans = N;
        for (int i = 0; i * tp[0].a <= N; i++) {
            int j = (N - i * tp[0].a) / tp[1].a;
            ans = max(ans, i * tp[0].b + j * tp[1].b + N - i * tp[0].a - j * tp[1].a);
        } 
        ans = ans / tp[2].b * tp[2].a + ans % tp[2].b;
    } else {
        ans = N;
        for (int i = 0; i * tp[0].a <= N; i++)
            for (int j = 0; i * tp[0].a + j * tp[1].a <= N; j++) {
                int k = (N - i * tp[0].a - j * tp[1].a) / tp[2].a;
                ans = max(ans, i * tp[0].b + j * tp[1].b + k * tp[2].b + N - i * tp[0].a - j * tp[1].a - k * tp[2].a);
            }
    }
    printf("%lld\n", ans);
}

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

int main(void)
{
	string s;
	cin >> s;
	int place_c = -1;
	int place_f = -1;
	for (int i=0; i < s.size(); i++)
	{
		if (s[i] == 'C' && place_c == -1)
		{
			place_c = i;
		}
		else if (s[i] == 'F')
		{
			place_f = i;
		}
	}
	if (place_c < place_f  && place_c!=-1)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
}

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


int main()
{
  string s;
  string a;
  bool oh=0;
  cin>>s>>a;
  if(s[1]==a[1]&&s[0]==a[2]&&s[2]==a[0])
        cout<<"YES";
   
    else cout<<"NO";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
template <class X> void print(X x) { cout << x << endl; }
void print(vl x) {
    for(ll i : x) {
        cout << i << " ";
    }
    cout << endl;
}
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v, m;
ll codeforces = 1;
string S, T;
vl A, B;
void input() {
    cin >> n;
    cin >> S;
}
void solve() {
    rep(i, n) { a += S[i] - '0'; }
    A.pb(1);
    B.pb(1);
    rep(i, n) {
        A.pb((A.back() * 2) % (a + 1));
        if(a != 1)
            B.pb((B.back() * 2) % (a - 1));
        else
            B.pb(1);
    }
    // print(A);
    // print(B);
    x = 0;
    y = 0;
    rep(i, n) {
        if(S[i] - '0') {
            x = (x + A[n - 1 - i]) % (a + 1);
            if(a != 1)
                y = (y + B[n - 1 - i]) % (a - 1);
        }
        // cout << i << " " << x << " " << y << 3 << endl;
    }

    // cout << a << " " << x << " " << y << endl;

    rep(i, n) {
        if(S[i] == '0') {
            t = 1;
            p = (x + A[n - 1 - i]) % (a + 1);
            while(p) {
                // cout << i << " " << p << endl;
                k = p;
                q = 0;
                while(k) {
                    q += k % 2;
                    k /= 2;
                }
                p = p % q;
                t++;
            }
            print(t);
        } else {
            if(a == 1)
                print(0);
            else {
                t = 1;
                p = (y - B[n - 1 - i] + (a - 1)) % (a - 1);
                while(p) {
                    k = p;
                    q = 0;
                    while(k) {
                        q += k % 2;
                        k /= 2;
                    }
                    p = p % q;
                    t++;
                }
                print(t);
            }
        }
    }
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    while(codeforces--) {
        solve();
    }
}

Measured memory_bytes: 6880
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


class Node(object):
    def __init__(self, key=None):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None


def tree_insert(top, z):
    y = None
    x = top
    while isinstance(x, Node):
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y is None:
        top = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z
    return top


def tree_find(node, key):
    if not node:
        return False
    if node.key == key:
        return True
    if key < node.key:
        return tree_find(node.left, key)
    return tree_find(node.right, key)


def inorder_walk(node):
    if node.left:
        inorder_walk(node.left)
    print('', node.key, end='')
    if node.right:
        inorder_walk(node.right)


def preorder_walk(node):
    print('', node.key, end='')
    if node.left:
        preorder_walk(node.left)
    if node.right:
        preorder_walk(node.right)


n = int(stdin.readline())
#assert n <= 500000

top = None
for _ in range(n):
    cmd = stdin.readline()
    if cmd.startswith('i'):
        key = int(cmd[7:])
        #assert -2000000000 <= key <= 2000000000
        top = tree_insert(top, Node(key))
    elif cmd.startswith('f'):
        key = int(cmd[5:])
        r = tree_find(top, key)
        print('yes' if r else 'no')
    else:
        inorder_walk(top)
        print()
        preorder_walk(top)
        print()

Measured memory_bytes: 167924
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

std::vector<lli>
divisors(lli M) {
  std::vector<lli> ans;
  int n;
  for (n = 1; n * n < M; ++n) {
    if (M % n == 0) {
      ans.push_back(n);
      ans.push_back(M / n);
    }
  }
  if (n * n == M) {
    ans.push_back(n);
  }
  return ans;
}

using namespace std;

void solve(lli budget) {
  auto divs = divisors(2*budget);
  sort(begin(divs), end(divs));

  lli ans_a = budget, ans_n = 1;
  for (auto &&n : divs) {
    lli const a2 = 2*budget/n - n + 1;
    if (a2 > 0 && a2 % 2 == 0) {
      ans_n = n, ans_a = a2 / 2;
    }
  }
  cout << ans_a << " " << ans_n << "\n";
}

int main() {
  // cout << fixed << setprecision(10);

  lli B;
  while (cin >> B && B) {
    solve(B);
  }

  return 0;
}



Measured memory_bytes: 3156
n, x = map(int, input().split(' '))
l = list(int(s) for s in input().split(' '))

bounce = [0]
d = 0

for i in range(n):
    d += 0 + l[i]
    bounce.append(d)

count = 0
for i in bounce:
    if i <= x:
        count += 1

print(count)

Measured memory_bytes: 3064