akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define ll long long
using namespace std;
int n,k,tot,pre[400005],nxt[400005],a[400005],l[400005],r[400005],sl[400005],sr[400005];
ll ans;
bool flag[400005];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
int main()
{
	scanf("%d%d",&n,&k);
	tot=n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		pre[i]=i-1,nxt[i]=i+1;
		q.push(make_pair(a[i],i));
		l[i]=r[i]=1;
	}
	nxt[n]=0;
	while(!q.empty())
	{
		int node=q.top().second;
		q.pop();
		if(flag[node])continue;
		int L=node,R=node,len=1;
		while(a[pre[L]]==a[node])L=pre[L],len++;
		while(a[nxt[R]]==a[node])R=nxt[R],len++;
		int last=0;
		for(int i=L,j=1;i!=nxt[R];i=nxt[i],j++)
		{
			sl[j]=sl[j-1]+l[i];
			sr[j]=sr[j-1]+r[i];
			if(i<=n)last=j;
			if(last&&j>=k)ans+=1ll*sl[min(j-k+1,last)]*r[i];
			flag[i]=1;
		}
		if(len<k)
		{
			nxt[pre[L]]=pre[nxt[R]]=0;
			continue;
		}
		for(int i=1;i<=len/k;i++)
		{
			r[tot+i]=sr[min(len,(i+1)*k-1)]-sr[i*k-1];
			l[tot+i]=sl[len-(len/k-i+1)*k+1]-sl[max(0,len-(len/k-i+2)*k+1)];
		}
		nxt[pre[L]]=tot+1,pre[tot+1]=pre[L];
		pre[nxt[R]]=tot+len/k,nxt[tot+len/k]=nxt[R];
		for(int i=1;i<len/k;i++)
		{
			nxt[tot+i]=tot+i+1;
			pre[tot+i+1]=tot+i;
		}
		for(int i=1;i<=len/k;i++)a[tot+i]=a[L]+1;
		q.push(make_pair(a[tot+1],tot+1));
		tot+=len/k;
	}
	printf("%lld\n",ans+n);
	return 0;
}

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

#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, n, m) for(int (i) = (n); (i) < (m); ++(i))

// constexpr int INF = 1e9;
constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

int N, M;
vector<vector<pair<int, int>>> g;
vector<ll> dist;
bool ans = true;
void dfs(int v){
  for(auto edge : g[v]){
    auto [nv, d] = edge;
    if(dist[nv] == INF){
      dist[nv] = dist[v] + d;
      dfs(nv);
    }
    else if(dist[nv] != dist[v] + d){
      ans = false;
      return;
    }
  }
}
int main(){
  cin >> N >> M;
  g.resize(N);
  dist.resize(N, INF);
  REP(i, M){
    int L, R, D;
    cin >> L >> R >> D;
    L--, R--;
    g[L].push_back({R, D});
    g[R].push_back({L, -D});
  }
  REP(i, N){
    if(dist[i] == INF){
      dist[i] = 0;
      dfs(i);
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 15316
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int main()
{
	int a, b;
	cin >> a >> b;
	if (a + b >= 10)printf("error\n");
	else cout << a + b << endl;
	//cout << min(min(a + b, b + c), c + a) << endl;
	//printf(((b*10+c)%4==0) ? "YES\n" : "NO\n");
}

Measured memory_bytes: 256
from bisect import bisect, bisect_left

n,q=map(int,input().split())
s=input()
l=[]
r=[]
for i in range(q):
	L,R=map(int,input().split())
	l.append(L-1)
	r.append(R-1)

a=[]
c=[]
for i in range(n-1):
	if s[i:i+2]=='AC':
		a.append(i)
		c.append(i+1)

for i in range(q):
	print(bisect(c,r[i])-bisect_left(a,l[i]))

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

#define ll long long
#define ld long double
#define db double
#define str string
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define selp(a) for(auto i:a)cout<<i<<" ";cout<<nl;
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const db pi=2*acos(0.0);

int main(){
    nimble
    ll r;
    cin>>r;
    double x=2*pi*r;
    cout<<preci(7)<<x<<nl;
    return 0;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> bool chmax(Type_a &a,const Type_b &b){if(a<b){a=b;return true;}return false;}
template<class Type_a,class Type_b> bool chmin(Type_a &a,const Type_b &b){if(a>b){a=b;return true;}return false;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	string key="MARCH";
	
	int n;
	cin>>n;
	
	map<char,int> mp;
	REP(i,n){
		string s;
		cin>>s;
		mp[s[0]]++;
	}
	
	llong ans=0;
	REP(i,3)for(int j=i+1;j<4;++j)for(int k=j+1;k<5;++k){
		ans+=(llong)mp[key[i]]*mp[key[j]]*mp[key[k]];
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

const int MAX = 100'000;
const int NIL = -1;

struct Node {
    int parent = NIL;
    int left = NIL;
    int right = NIL;
};

Node T[MAX];
int D[MAX];

void setDepth(int u, int d) {
    D[u] = d;
    if (T[u].left != NIL) setDepth(T[u].left, d + 1);
    if (T[u].right != NIL) setDepth(T[u].right, d);
}

void print(int u) {
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].parent << ", ";
    cout << "depth = " << D[u] << ", ";
    if (T[u].parent == NIL) {
        cout << "root, ";
    } else if (T[u].left == NIL) {
        cout << "leaf, ";
    } else {
        cout << "internal node, ";
    }
    cout << "[";
    int c = T[u].left, i = 0;
    while (c != NIL) {
        if (i) {
            cout << ", ";
        }
        cout << c;
        c = T[c].right;
        i++;
    }
    cout << "]" << endl;
}

int main() {

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        int id, k;
        cin >> id >> k;
        if (k) {
            int c;
            cin >> c;
            T[id].left = c;
            T[c].parent = id;
            for (int j = 0; j < k - 1; j++) {
                cin >> T[c].right;
                T[T[c].right].parent = id;
                c = T[c].right;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        if (T[i].parent == NIL) {
            setDepth(i, 0);
            break;
        }
    }

    for (int i = 0; i < n; i++) {
        print(i);
    }
}


Measured memory_bytes: 4572
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool bo[100];
vector<int>v1,v2,v3;
void f(int n)
{
	v1.clear();
	while(n!=0)
	{
		int t=n%10;
		n/=10;
		v1.pb(t);
	}
}
int main()
{
	int n,k;
	cin>>n>>k;
	int a[100];
	for(int i=0;i<k;i++)
	{
		cin>>a[i];
	}
	bool bo=0;
	for(int i=n;i<=100000;i++)
	{
		int t=i;
		f(t);
		bo=0;
		for(int j=0;j<v1.size();j++)
		{
			for(int kk=0;kk<k;kk++)
			{
				if(v1[j]==a[kk])
				{
					bo=1;
				}
			}
		}
		if(bo==0)
		{
			cout<<i<<endl;
			return 0;
		}
		/*for(int j=0;j<k;j++)
		{
			cout<<a[j]<<endl;
		}*/
		//cout<<i<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
ld eps = (ld)1 / 1e15;
ll inf = 1e18, mod2 = 998244353, mod1 = 1e9 + 7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main()
{
    //freopen("race.in", "r", stdin), freopen("race.out", "w", stdout);
    fast_io;
    string a;
    ll n, i;
    bool bl = 0;
    cin >> a;
    n = a.size();
    for (i = 0; i < n; i += 2)
        if (a[i] != 'h') bl = 1;
    for (i = 1; i < n; i += 2)
        if (a[i] != 'i') bl = 1;
    if (n % 2) bl = 1;
    cout << (bl ? "No" : "Yes");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

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

	int a, b, c;
	cin >> a >> b >> c;

	vector<int> v(n);
	rep(i, n) cin >> v[i];

	sort(v.begin(), v.end(), greater<int>());

	double ans = c / a, res = c;
	rep(i, n) {
		res += v[i];
		ans = max(ans, res / (a + (i+1)*b ));
	}
	
	cout << (int)ans << endl;

	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}



struct KMP{

    string s;
    string t;
    int s_size,t_size;
    vector<bool> match;
    vector<int> table;

    KMP(string a, string b){
        s = a;
        t = b;
        s_size = s.size();
        t_size = t.size();
        match.resize(s.size());
        REP(i,s_size) match[i] = false;

        table.resize(t_size + 1);

        make_table();
    }


    void make_table();

    int compute_match();

};


void KMP::make_table(){
    table[0] = -1;
    table[1] = 0;

    int j = 0;
    int i = 2;
    while(i < t.size() + 1){

        if(t[i-1] == t[j]){
            table[i] = j + 1;
            i = i + 1;
            j += 1;
        }
        else if(j > 0){
            j = table[j];
        }
        else{
            table[i] = 0;
            i = i + 1;
        }

    }
}


int KMP::compute_match(){
    int m = 0,i = 0;
    int cnt = 0;

    

    while(m  + i < s_size ){
        if(s[m + i] == t[i]){
            i = i + 1;
            if(i == t_size) return m;
        }
        else{
            m = m + i - table[i];
            if(i > 0) i = table[i];
        }
    }
    return -1;


}

signed main(){
    int n;
    string s;
    cin >> n >> s;
    int l = 0 , r = n/2 + 1;

    while(l + 1 < r){
        int leng = (l + r) / 2;
        bool flag = false;
        REP(i,n){
            if( i + leng - 1 >= n or n - i - leng < leng) break;
            KMP hoge(s.substr(i + leng, n - i - leng),s.substr(i,leng));
            if(hoge.compute_match() != -1){
                flag = true;
                break;
            }
        }


        if(flag) l = leng;
        else r = leng;
    }
    


    cout << l << endl;



}

Measured memory_bytes: 384
def main():
    N, A, B = (int(i) for i in input().split())
    if (N == 1 and A != B) or (B - A < 0):
        print(0)
    elif N == 1:
        print(1)
    elif N == 2:
        print(1)
    else:
        print((N-2)*B - (N-2)*A + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
#include<stdio.h>
int main(void){
	int i,k,a,b;
    scanf("%d%d%d",&k,&a,&b);
	for(i=b;i>=a;i--){
		if(i%k){
        }else{
            printf("OK");
			return 0;
        }
	}
	printf("NG");
	return 0;
}

Measured memory_bytes: 1728
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N;
    std::cin >> N;

    std::vector<int64_t> A;
    std::vector<int64_t> B;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t a, b;
        std::cin >> a >> b;
        A.push_back(a);
        B.push_back(b);
    }

    std::reverse(A.begin(), A.end());
    std::reverse(B.begin(), B.end());

    int64_t count = 0;
    for (int64_t i = 0; i < N; ++i) {
        auto nowA = A[i] + count;
        auto rem = nowA % B[i];
        if (rem != 0) {
            count += B[i] - rem;
        }
    }

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<ll> a(N);
	vector<ll> b(N);
	ll sum_a = 0, sum_b = 0;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		sum_a += a[i];
	}
	for (int i = 0; i < N; ++i) {
		cin >> b[i];
		sum_b += b[i];
	}

	if (sum_a < sum_b) {
		cout << -1 << endl;
		return 0;
	}

	vector<ll> x;
	vector<ll> y;
	for (int i = 0; i < N; ++i) {
		if (a[i] > b[i]) {
			x.push_back(a[i] - b[i]);
		} else if (a[i] < b[i]) {
			y.push_back(b[i] - a[i]);
		}
	}
	sort(x.begin(), x.end(), greater<ll>());

	vector<bool> ch_a(N, false);
	int xi = 0, yi = 0;
	while (yi < y.size()) {
		if (x[xi] >= y[yi]) {
			x[xi] -= y[yi];
			ch_a[xi] = true;
			y[yi++] = 0;
		} else {
			y[yi] -= x[xi];
			x[xi] = 0;
			ch_a[xi++] = true;
		}
	}

	int res = y.size();
	for (int i = 0; i < N; ++i) {
		if (ch_a[i]) { ++res; }
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 2812
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define intmin -2147483647
#define llmax 9223372036854775807
typedef long long ll;
using namespace std;

string s, smem, s2;
bool alp[26];
int cnt, mn, cnt2;

int main(){
	cin >> s;
	smem = s;
	lp(26) {
		alp[i] = false;
	}
	lp(s.size()) {
		alp[s[i] - 'a'] = true;
	}

	mn = intmax;
	lp(26) {
		if (alp[i]) {
			cnt = -1;
			s2 = smem;
			do{
				s = s2;
				LP(s.size()-1, j) {
					if (s[j] == i + 'a' || s[j + 1] == i + 'a')
						s2[j] = i + 'a';
				}
				cnt++;
//				cout << cnt << sp << s << sp << s2 << endl;
			} while (s != s2);
			cnt2 = 0;
			LP(s.size(), j) {
				if (s[s.size() - 1 - j] == i + 'a') {
					cnt2 = j;
					break;
				}
			}
			cnt = max(cnt, cnt2);
			mn = min(mn, cnt);
		}
	}
	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 256
data = input()
data = data.split(" ")
n = int(data[0])
k = int(data[1])
sum = 0
for b in range(1, n+1):
    sum += (n//b*max(0,b-k)+max(0,n%b-k+1))
if k == 0: sum-=n
print(sum)

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

int N;
vector<int> A;
vector<int> memo, memo2;

int GCD(int a, int b){
	if(b == 0) return a;
	else return GCD(b, a % b);
}

int main(){
	cin >> N;
	A.resize(N);
	for(int i = 0; i < N; i++) cin >> A[i];
	memo.resize(N);
	for(int i = 0; i < N; i++){
		if(i == 0) memo[i] = A[i];
		else memo[i] = GCD(memo[i - 1], A[i]);
	}
	memo2.resize(N);
	for(int i = N - 1; i >= 0; i--){
		if(i == N - 1) memo2[i] = A[i];
		else memo2[i] = GCD(memo2[i + 1], A[i]);
	}
	int res = 0;
	for(int i = 0; i < N; i++){
		if(i == 0) res = max(res, memo2[i + 1]);
		else if(i == N - 1) res = max(res, memo[i - 1]);
		else res = max(res, GCD(memo[i - 1], memo2[i + 1]));
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main(){
  int ei,ma,sc,en;
  int max=0,nm;
  for(int i=0;i<2;i++){
    cin>>ei>>ma>>sc>>en;
    nm=ei+ma+sc+en;
    if(max<nm){
      max=nm;
    }
  }
  cout<<max<<endl;
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root;

void insert(int);
void inorder(Node);
void preorder(Node);
Node treesearch(Node,int);

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treesearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }
  
  return 0;
  

}

void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if (z->key < x->key)
      x=x->left;
    else
      x=x->right;
  }
  z->parent=y;
  if(y==NIL)
    root=z;
  else {
    if(z->key < y->key)
    y->left=z;
  else
    y->right=z;
  }
}

void inorder(Node u){
  if(u==NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  
}

void preorder(Node u){
  if (u==NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

Node treesearch(Node u,int k){
  while(u!=NIL){
    if(u->key==k) return u;
    else if(u->key > k) u=u->left;
    else u=u->right;
  }
  return NIL;
}



Measured memory_bytes: 20448
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7;
const int MAX_N=10000;
ll n,q,h,s,d;

int main(){
	cin >> q >> h >> s >> d >> n;
	
	int a=min(q*4, min(h*2, s));
	if(n%2) cout << min((n/2)*d+a, n*a) << endl;
	else cout << min((n/2)*d, n*a) << endl;

	return 0;
}
	


Measured memory_bytes: 256
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

#define double      	long double
#define int         	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x) 			memset(x, 0, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N=1e5 + 5;
const int MOD=1e9 + 7;

int32_t main()
{
	IOS;
	int T=1;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		int x;
		cin >> x;
		int n;
		cin >> n;
		mi mp;
		rep(i,1,n)
		{
			int f;
			cin >> f;
			mp[f]++;
		}
		if(mp[x]==0)
		{
			cout << x;
			return 0;
		}
		int l,r;
		l = x;
		r = x;
		while(mp[l]>0)
			l--;
		while(mp[r]>0)
			r++;
		//deb2(l,r);
		if((x-l)>(r-x))
			cout << r;
		else
			cout << l;
	}
}



Measured memory_bytes: 3648
//
//  main.cpp
//  B - Palindrome-philia
//
//  Created by Hashizo on 2019/12/08.
//  Copyright © 2019 Hashizo. All rights reserved.
//

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

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

int main(int argc, const char * argv[]) {
	ll ans = 0;

	string s;
	cin >> s;

	REP(i, (s.size()/2)) {
		if(s.substr(i, 1) != s.substr((s.size()-(i+1)), 1)) {
			ans++;
		}
	}

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


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

int main(){
  list<int> height;
  list<int> width;
  string str;
  int a, b;
  cin >> str;
  cin >> a >> b;
  int t = -1;
  int co = 0;
  for (int i = 0; i < str.size(); i++){
    if (str[i] - 'F' == 0) co++;
    if (str[i] - 'T' == 0){
      if (t == 1) {
          height.push_back(co);
      }
      if (t == -1) width.push_back(co);
      t *= -1;
      co = 0;
    }
  }
  if (co > 0) {
    if (t == 1) {
      height.push_back(co);
    }
    if (t == -1) width.push_back(co);
  }

  int wdp[16001];
  int hdp[16001];
  for (int i = 0; i < 16001; i++){
    wdp[i] = 0;
    hdp[i] = 0;
  }
  wdp[8000] = 1;

  int ma = 0;
  while (!height.empty()){
    int u = height.front();
    height.pop_front();
    for (int i = 8000 - ma; i <= 8000 + ma; i++){
      if (wdp[i] > 0){
        wdp[i] = 0;
        hdp[i-u]++;
        hdp[i+u]++;
      }
    }
    ma += u;
    swap(wdp, hdp);
  }
  if (wdp[8000 + b] == 0) {
    printf("No\n");
    return 0;
  }

  for (int i = 0; i < 16001; i++){
    wdp[i] = 0;
    hdp[i] = 0;
  }
  int flag = 0;
  wdp[8000] = 1;
  while (!width.empty()){
    int u = width.front();
    width.pop_front();
    for (int i = 8000 - ma; i <= 8000 + ma; i++){
      if (wdp[i] > 0){
        wdp[i] = 0;
        if (flag != 0) hdp[i-u]++;
        hdp[i+u]++;
      }
    }
    flag = 1;
    ma += u;
    swap(wdp, hdp);
  }
  if (wdp[8000 + a] == 0) {
    printf("No\n");
    return 0;
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, M; cin >> N >> M;
    vector<tuple<int, int, int>> d(M);
    for (int i = 0; i < M; i++)
    {
        int p, y; cin >> p >> y;
        d[i] = make_tuple(p, y, i);
    }
    vector<vector<int>> out(M, vector<int>(12));
    sort(d.begin(), d.end());
    int np = 0;
    int num = 1, c1, c2;
    for (int i = 0; i < M; i++)
    {
        int p, y, x;
        tie(p, y, x) = d[i];
        if(np != p) {
            np = p;
            num = 1;
        }
        c1 = p; c2 = num;
        for (int j = 0; j < 6; j++)
        {
            out[x][j] = c2 % 10;
            c2 /= 10;
        }
        for (int j = 0; j < 6; j++)
        {
            out[x][j+6] = c1 % 10;
            c1 /= 10;
        }
        num++;
    }

    for (int i = 0; i < M; i++)
    {
        for (int j = 11; j >= 0; j--)
        {
            cout << out[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 11264
//157 B - Bingo
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int sheet[3][3];
    bool state[3][3]={false};
    rep(i ,3){
        rep(j ,3){
            cin >> sheet[i][j]; 
        }
    }
    int n; cin >> n;
    vector<int> b(n);
    rep(i ,n) cin >> b[i];
    rep(i ,3){
        rep(j ,3){
            rep(k ,n){
                if(sheet[i][j]==b[k]) state[i][j]=true;
            }
        }
    }
    bool flag=false;
            if( (state[0][0] && state[0][1] && state[0][2] )|| 
                (state[0][0] && state[1][0] && state[2][0]) ||
                (state[0][0] && state[1][1] && state[2][2]) ) flag=true;
            else if(state[0][1] && state[1][1] && state [2][1]) flag=true;
            else if((state[0][2] && state[1][1] && state [2][0]) ||
                (state[0][2] && state[1][2] && state[2][2])) flag=true;
            else if(state[1][0] && state[1][1] && state [1][2]) flag=true;
            else if(state[2][0] && state[2][1] && state [2][2]) flag=true;
    cout << ( flag ? "Yes" : "No" ) << endl;
}

Measured memory_bytes: 256
def devide2two(n):
    arr=[]
    arr.append((n-1))
    for i in range(2, int(-(-n**0.5//1))+1):
        if n%i==0:
            a = n/i
            arr.append(i-1+ a-1)
    
    return min(arr)
n = int(input())
print(int(devide2two(n)))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int a,b,c;cin>>a>>b>>c;
    cout<<min({a+b,b+c,c+a})<<endl;
}


Measured memory_bytes: 3580
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

typedef long long ll;
#define pb push_back
#define mp make_pair

vector<ll> a, b;

void solve()
{
    int N, K;
    cin >> N >> K;
    
    for(int i = 0; i < N; i++)
    {
        ll x;
        cin >> x;
        if(x <= 0)
        {
            a.pb(-x);
        }
        else
        {
            b.pb(x);
        }
    }
    
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    
    ll ans = linf;

    
    if(K - 1 < a.size())
    {
        ans = min(ans, a[K - 1]);
    }
    
    if(K - 1 < b.size())
    {
        ans = min(ans, b[K - 1]);
    }
    
    for(int i = 1; i < K; i++)
    {
        if(i - 1 < a.size() && K - i - 1 < b.size())
        {
            ans = min(ans, 2 * a[i - 1] + b[K - i - 1]);
        }
        
        if(i - 1 < b.size() && K - i - 1 < a.size())
        {
            ans = min(ans, 2 * b[i - 1] + a[K - i - 1]);
        }
    }
    
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
    //freopen("file.in", "r", stdin);freopen("file.out", "w", stdout);
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 1656
s = input()
t = input()
n = len(s)
nxt = [list() for x in range(n + 1)]
nxt[n] = [n for x in range(26)]
for i in range (n - 1, -1, -1):
    for v in nxt[i + 1]:
        nxt[i].append(v)
    nxt[i][ord(s[i]) - ord('a')] = i;
ans = 0
cur = 0
for i in range (len(t)):
    c = ord(t[i]) - ord('a')
    if (nxt[0][c] == n) :
        ans = 0
        cur = -1
        break
    if (nxt[cur][c] == n) :
        ans += 1
        cur = 0
    cur = nxt[cur][c] + 1
print(ans * n + cur)

Measured memory_bytes: 41540
import java.io.BufferedReader;
import java.io.InputStreamReader;


class Main {

	public static void main(String[] args) throws Exception {
		Integer numWeekday = 0;	//曜日の番号(0:日、1：月、....6:土)
		Integer result = 0;	// ログイン回数
		Integer total = 0;	// 総ポイント数


		try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
			String[] data = reader.readLine().split(" ");
			Integer a = Integer.parseInt(data[0]);
			Integer b = Integer.parseInt(data[1]);
			Integer c = Integer.parseInt(data[2]);

			while (total < c) {
				// ログイン回数+1,曜日+1,総ポイント+a
				result += 1;
				numWeekday = (numWeekday + 1) % 7;
				total += a;

				if(numWeekday == 0){
					total += b;
				}

			}

			System.out.println(result);

		}
	}

}


Measured memory_bytes: 57716
s = list(input())
n = len(s)
i = 0
cnt = 0
while i < n - 1:
    if n == 1:
        break
    if (s[i] == '0' and s[i + 1] == '1') or (s[i] == '1' and s[i + 1] == '0'):
        s[i:i + 2] = []
        i = max(i - 1, 0)
        cnt += 2
        n = len(s)
    else:
        i += 1

print(cnt)

Measured memory_bytes: 3956
#include<iostream>

#include<math.h>

 using namespace std ;

 int main()

{

short int a,b,c,d;

cin>>a;

cin>>b;

cin>>c;

cin>>d;

if((abs(c-a))<=d) cout<< "Yes";

else

 if((abs(c-b)<=d)&& ( abs(b-a)<=d) ) cout<< "Yes";

else

cout<< "No";

}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;

double PI = 3.141592;

int main(void) {

    double x = 0;
    double y = 0;
    double r = 0;
    double a = 90;
    double d = 0;
    while(true){

        scanf("%lf,%lf", &r, &d);
        if( r == 0 && d == 0 ) break;

        x += r * cos( a * PI / 180 );
        y += r * sin( a * PI / 180 );
        // cerr << x << " " << y << endl;
        a -= d;
    }
    cout << (int)x << endl << (int)y << endl;


    return 0;
}

Measured memory_bytes: 3500
#include <stdio.h>

int main()
{
  int a[3];
  int total = 0;
      
  scanf("%d %d %d", &a[0], &a[1], &a[2]);
  
  for (int x = 0; x < 3; x++) {
    if (a[x] != 5 && a[x] != 7) {
      break;
    }
    total += a[x];
  }
  if (total != 17) {
    printf("NO");
  } else {
    printf("YES");
  }
}

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

int main()
{
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if ((r<=x && x<=W-r)&&(r<=y && y<=H-r)) cout<<"Yes";
    else cout<<"No";
    cout<<endl;
}



Measured memory_bytes: 3116
#include <iostream>

using namespace std;

#define maxN 3000

int n;
double p[maxN];
double cache[maxN][maxN];

double prob(int i, int remaining) {
    if (remaining == 0) {
        double x = 1;
        for (; i<n; i++) x*=(1-p[i]);
        return x;
    }
    if (i >= n || remaining < 0) return 0;
    if (cache[i][remaining] != -1) return cache[i][remaining];
    return cache[i][remaining] = p[i]*prob(i+1, remaining-1) + (1-p[i])*prob(i+1, remaining);
}

int main() {
    cin >> n;
    for (int i = 0; i<=n; i++) {
        for (int j = 0; j<=n; j++) {
            cache[i][j] = -1;
        }
    }
    for (int i = 0; i<n; i++) {
        cin >> p[i];
    }
    double sum = 0;
    for (int i = n/2+1; i<=n; i++) {
        sum += prob(0, i);
    }
    printf("%.10lf\n", sum);
    return 0;
}

Measured memory_bytes: 70784
#include <cstdio>

int main(void)
{
    int A,B,N;
    scanf("%d%d%d",&N,&A,&B);
    if(N==1)
    {
        if(A==B)
            printf("1\n");
        else
            printf("0\n");
    }
    else 
    {
        if(A>B)
            printf("0\n");
        else
            printf("%lld\n",(long long )(B-A)*(N-2)+1);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ar array<int,2>
#define inf 1000000000000000000 
int mod=1e9+7;
int min(int a,int b){return (a<b)?a:b;}
int max(int a,int b){return (a>b)?a:b;}
int fp(int a,int b){if(b==0) return 1;int x=fp(a,b/2);x=(x*x)%mod;if(b&1) x=(x*a)%mod;return x;}


const int N=2e5+5;



void solve()
{
    int n;
    cin>>n;
    int mx=0,ans=0,x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(x<mx)
            ans+=mx-x;
        mx=max(mx,x);
    }
    cout<<ans;
}

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
 srand(time(0));
 int t;
 t=1;
 for(int i=1;i<=t;i++)
 {
   solve();
 }


}

Measured memory_bytes: 3648
#include <iostream>
#include <assert.h>
#include <vector>

int64_t calc_gcd(int64_t a, int64_t b){
  if (b == 0) return a;
  return calc_gcd(b, a % b);
}

int64_t calc_lcm(int64_t a, int64_t b) {
  int64_t gcd = calc_gcd(std::max(a, b), std::min(a,b));
  int64_t lcm = a / gcd * b;
  assert(std::max(a,b) <= lcm);
  return lcm;
}

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

  int32_t N;
  std::cin >> N;
  int64_t lcm, tmp;
  std::cin >> lcm;
  for(int32_t i = 0; i < N - 1; i++){
    std::cin >> tmp;
    lcm = calc_lcm(lcm, tmp);
  }
  std::cout << lcm << std::endl;
  return 0;
}


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

int main() {
    int N; cin >> N;
    string s; cin >> s;

    int ans = 0;
    int x = 0;
    for (int i = 0; i < N; i++)
    {
        if(s[i]=='I') x++;
        else if(s[i]=='D') x--;

        ans = max(ans, x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
P = [2, 10, 3, 12, 5, 15]
Q = [380, 1520, 550, 1870, 850, 2244]
L = 50
R = [0] + [1e9]*L
for p, q in zip(P, Q):
    for i in range(L-p+1):
        R[i+p] = min(R[i+p], R[i] + q)
while 1:
    v = int(input())
    if v == 0:
        break
    print(R[v//100])



Measured memory_bytes: 5612
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int A, B, C;
	int a, b, con, ans;
	
	cin>>A>>B>>C;
	
	
	if(A%2 || B%2 || C%2) cout<<0<<endl;
	else if(A == B && B == C && C == A) cout<<-1<<endl;
	else {
		a = abs(A-B), b = abs(C-B), con = 0;
		
		while(a%2 == 0){
			con++;
			a /= 2;
		}
		ans = con; con = 0;
		
		while(b%2 == 0){
			con++;
			b /= 2;
		}
		
		cout<<min(ans,con)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define maxn 100000
bool vis[maxn];
struct segment{
	int L, R, id;
};
bool cmpl(const segment &lhs, const segment &rhs){
	return lhs.L > rhs.L;
}
bool cmpr(const segment &lhs, const segment &rhs){
	return lhs.R < rhs.R;
}
segment L[maxn], R[maxn];
int dis(int pos, int L, int R){
	if(pos < L) return L - pos;
	if(pos > R) return pos - R;
	return 0;
}
int main(){
	int N;
	scanf("%d",&N);
	for(int i = 0; i < N; i += 1){
		int Li, Ri;
		scanf("%d %d", &Li, &Ri);
		L[i].L = R[i].L = Li;
		L[i].R = R[i].R = Ri;
		L[i].id = R[i].id = i;
	}
	std::sort(L, L + N, cmpl);
	std::sort(R, R + N, cmpr);
	long long ansl = 0;
	int posl = 0;
	for(int i = 0, j = 0; i < N || j < N;){
		if(i == 0 && j == 0){
			vis[L[i].id] = true;
			if(posl < L[i].L) ansl += L[i].L - posl, posl = L[i].L;
			if(posl > L[i].R) ansl += posl - L[i].R, posl = L[i].R;
			i += 1;
			continue;
		}
		if(j < N && vis[R[j].id] == true){
			j += 1;
			continue;
		}
		if(i < N && vis[L[i].id] == true){
			i += 1;
			continue;
		}
		if(i == N){
			vis[R[j].id] = true;
			if(posl < R[j].L) ansl += R[j].L - posl, posl = R[j].L;
			if(posl > R[j].R) ansl += posl - R[j].R, posl = R[j].R;
			j += 1;
		}
		else if(j == N){
			vis[L[i].id] = true;
			if(posl < L[i].L) ansl += L[i].L - posl, posl = L[i].L;
			if(posl > L[i].R) ansl += posl - L[i].R, posl = L[i].R;
			i += 1;
		}
		else{
			if(dis(posl, L[i].L, L[i].R) < dis(posl, R[j].L, R[j].R)){
				vis[R[j].id] = true;
				if(posl < R[j].L) ansl += R[j].L - posl, posl = R[j].L;
				if(posl > R[j].R) ansl += posl - R[j].R, posl = R[j].R;
				j += 1;
			}
			else{				
				vis[L[i].id] = true;
				if(posl < L[i].L) ansl += L[i].L - posl, posl = L[i].L;
				if(posl > L[i].R) ansl += posl - L[i].R, posl = L[i].R;
				i += 1;
			}
		}
	}
	ansl += dis(posl ,0 ,0);
	for(int i = 0; i < N; i += 1) vis[i] = false;
	long long ansr = 0;
	int posr = 0;
	for(int i = 0, j = 0; i < N || j < N;){
		if(i == 0 && j == 0){
			vis[R[j].id] = true;
			if(posr < R[j].L) ansr += R[j].L - posr, posr = R[j].L;
			if(posr > R[j].R) ansr += posr - R[j].R, posr = R[j].R;
			j += 1;
			continue;
		}
		if(j < N && vis[R[j].id] == true){
			j += 1;
			continue;
		}
		if(i < N && vis[L[i].id] == true){
			i += 1;
			continue;
		}
		if(i == N){
			vis[R[j].id] = true;
			if(posr < R[j].L) ansr += R[j].L - posr, posr = R[j].L;
			if(posr > R[j].R) ansr += posr - R[j].R, posr = R[j].R;
			j += 1;
		}
		else if(j == N){
			vis[L[i].id] = true;
			if(posr < L[i].L) ansr += L[i].L - posr, posr = L[i].L;
			if(posr > L[i].R) ansr += posr - L[i].R, posr = L[i].R;
			i += 1;
		}
		else{
			if(dis(posr, L[i].L, L[i].R) < dis(posr, R[j].L, R[j].R)){
				vis[R[j].id] = true;
				if(posr < R[j].L) ansr += R[j].L - posr, posr = R[j].L;
				if(posr > R[j].R) ansr += posr - R[j].R, posr = R[j].R;
				j += 1;
			}
			else{				
				vis[L[i].id] = true;
				if(posr < L[i].L) ansr += L[i].L - posr, posr = L[i].L;
				if(posr > L[i].R) ansr += posr - L[i].R, posr = L[i].R;
				i += 1;
			}
		}
	}
	ansr += dis(posr ,0 ,0);
	printf("%lld", std::max(ansl, ansr));
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using Int = long long unsigned;

Int divisor(Int n) {

  Int a=sqrt(n);
  for(Int i = a; i>=0; i--) {
    if(n % i == 0) {
      return i;break;
    }
  }
  return 0;
}

Int issq(Int n){
    Int a=floor(sqrt(n));
    return(a*a==n);
}

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

    Int n; cin>>n;
    if(issq(n)){
        Int k=sqrt(n);
        cout<<"0 0 "<<k<<" 0 0 "<<k<<'\n';
    }
    else{
        Int k=sqrt(n)+1;
        k*=k;
        Int p=divisor(k-n);
        Int l=sqrt(k);
        cout<<"0 0 "<<p<<' '<<l<<' '<<l<<' '<<(k-n)/p<<'\n';
    }
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#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 <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>
#include <numeric>

#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(); }

//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 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,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007

int main() {
	int n;
	cin >> n;
	int tmp = -1;
	int cnt = 0;
	int ret = 0;
	REP(i, n) {
		int a;
		cin >> a;
		if (a == tmp)cnt++;
		else {
			tmp = a;
			ret += cnt / 2;
			cnt = 1;
		}
	}
	ret += cnt / 2;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
S = input()

import math

even_s=[]
odd_s=[]

for i in range(len(S)):
        if i%2 == 0:
                even_s.append(int(S[i]))
        else:
                odd_s.append(int(S[i]))

e_1num = even_s.count(1)
e_0num = even_s.count(0)

o_1num = odd_s.count(1)
o_0num = odd_s.count(0)

res = min(e_1num+o_0num, e_0num+o_1num)

print(res)

Measured memory_bytes: 4084
# n = int( input() )
# a = list( map( int, input().split() ) )
# a.sort()

# a_list = []
# a_dic = {}
# for a_i in reversed( a[ : -2 ] ):
#     try:
#         a_dic[ a_i ] += 1
#     except KeyError:
#         a_dic[ a_i ] = 1
#         a_list.append( a_i )

# ans = a_list[ 0 ]
# for a_i in a_list[1:]:
#     print( ans )
#     ans += ( a_dic[ a_i ] + 1 ) * a_i

# print( ans )

# 以下カンニング
n = int( input() )
a = list( map( int, input().split() ) )
a.sort()

ans = 0
for k in range( 1, n ):
    ans += a[ n - k // 2 - 1]

print( ans )

Measured memory_bytes: 31612
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<queue>
#include<cmath>
#include<tuple>
#include<utility>
#include<functional>
#include<algorithm>



using namespace std;

long long N,sum=0ll;

int main() {
	cin>>N;
	for(int i=1;i<=N;i++)if(i%3!=0&&i%5!=0)sum+=i;
	cout<<sum<<endl;

	return 0;
}



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

int main() {
  int N, P;
  vector<int> A(50);

  cin >> N >> P;

  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }

  ll dp[51][2];
  dp[0][0] = 1;
  dp[0][1] = 0;

  for(int i = 0; i < N; i++) {
    if(A[i] % 2 == 0) {
      dp[i + 1][0] = dp[i][0] * 2;
      dp[i + 1][1] = dp[i][1] * 2;
    }else {
      dp[i + 1][1] = dp[i + 1][0] = dp[i][1] + dp[i][0];
    }
  }

  cout << dp[N][P] << endl;

}


Measured memory_bytes: 256
import java.util.Scanner

import scala.annotation.tailrec

object Main {

  /**
    * 駅の情報
    *
    * @param timeToNext 次の駅までの所要時間
    * @param firstTime  開通式開始から発車するまでの時間
    * @param frequency  発車間隔
    */
  case class Station(timeToNext: Int, firstTime: Int, frequency: Int)

  implicit class EnrichInt(i: Int) {
    def isDivisibleBy(a: Int): Boolean = i % a == 0
  }

  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val sts = for (_ <- 0 until n - 1) yield Station(sc.nextInt(), sc.nextInt(), sc.nextInt())
    sts.toList
  }

  def nextDepartureTime(time: Int, st: Station): Int = {
    if (time < st.firstTime) {
      // まだ開通式開始から発車されていない。
      return st.firstTime
    }
    // 最初の電車が発車してからの時間
    val timeLengthSinceFirst = time - st.firstTime

    if (timeLengthSinceFirst isDivisibleBy st.frequency) {
      // すぐ発車
      return time
    }

    val timeLengthSincePrevDeparture = timeLengthSinceFirst % st.frequency
    val waitTimeLength = st.frequency - timeLengthSincePrevDeparture

    time + waitTimeLength
  }

  /**
    * @param time     現在の時刻
    * @param stations 駅の列
    * @return 最後の駅に着く時刻
    */
  @tailrec
  def timeToTerminal(time: Int, stations: List[Station]): Int = {
    stations match {
      case Nil => time
      case (currentStation :: nextStations) =>
        val departureTime = nextDepartureTime(time, currentStation)
        timeToTerminal(departureTime + currentStation.timeToNext, nextStations)
    }
  }

  /**
    * @param sts 駅の列
    * @return 最後の駅に着くまでの時間
    */
  def timeLengthToTerminal(sts: List[Station]): Int = {
    // 時刻を0とする。
    timeToTerminal(0, sts)
  }

  def main(args: Array[String]): Unit = {
    val stations = read()
    stations.tails.map(timeLengthToTerminal).foreach(println)
  }
}


Measured memory_bytes: 32604
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

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

int main() {

    ll N,M;
    cin >> N >> M;
    ll A[N];
    rep(i,N) A[i] = 1;
    ll R[N];
    rep(i,N) R[i] = 0;
    R[0] = 1;
    rep(i,M){
        ll x,y;
        cin >> x >> y;
        if(A[x-1]>0) A[x-1]--;
        A[y-1]++;
        if(R[x-1]==1){
            R[y-1] = 1;
            if(A[x-1]==0) R[x-1] = 0;
        }
    }
    ll out = 0;
    rep(i,N) out += R[i];
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int A, B, C;
  int ans = 0;

  cin >> A >> B >> C;

  if(A == B){
    ans++;
  }
  if(A == C){
    ans++;
  }
  if(B == C){
    ans++;
  }

  if(ans == 1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <ctime> 
#include <queue>
#include <stack>
#include <bitset> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <iostream>
#include <algorithm>

#define fi first
#define se second
#define pb push_back
#define MP std::make_pair
#define PII std::pair<int, int>
#define all(x) (x).begin(), (x).end()
#define CL(a, b) memset(a, b, sizeof a)
#define rep(i, l, r) for (int i = (l); i <= (r); ++ i)
#define per(i, r, l) for (int i = (r); i >= (l); -- i)
#define PE(x, a) for (int x = head[a]; x;x = edge[x].next)

typedef long long ll;

template <class T>
inline void rd(T &x) {
    char c = getchar(), f = 0; x = 0;
    while (!isdigit(c)) f = (c == '-'), c = getchar();
    while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
    x = f ? -x : x;
}

char s[300];

int main() {
    scanf("%s", s);
    rep(i, 0, 2) printf("%c", s[i]); puts("");
    return 0;
}

Measured memory_bytes: 3760
def prediction():
    weather = input()
    weathers = ['Sunny', 'Cloudy', 'Rainy']
    counter = 0
    for i in weathers:
        if i == 'Rainy':
            return 'Sunny'
        elif i == weather:
            return weathers[counter + 1]
        counter += 1

if __name__ == "__main__":
    print(prediction())


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using ll=int64_t;
using vi=vector<int>;
using vll=vector<ll>;
int gcd(int x,int y){
  int u,v,r;
  u=min(x,y);
  v=max(x,y);
  r=v%u;
  while(r>0){
    v=u;
    u=r;
    r=v%u;
  }
  return u;
}
ll pw(ll x,ll y){
  ll z;
  if(y==0) return 1;
  else{
    z=pw(x,y/2)*pw(x,y/2);
    if(y%2==1) z*=x;
    return z;
  }
}
int main() {
  ll n,i,k;
  cin>>n;
  k=1;
  while ((pw(26L,k)-1)*26/25<n) k++;
  n-=(pw(26L,k-1)-1)*26/25+1;
  vi a(k);
  for(i=k-1;i>=0;i--){
    a.at(i)=n%26;
    n/=26;
  }
  for(i=0;i<k;i++) cout<<(char)('a'+a.at(i));
  cout<<endl;
}

Measured memory_bytes: 3624