akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    ll now = 1000;
    rep(i,n-1) if(a[i] < a[i+1]) {
        ll r = now/a[i];
        now += r*(a[i+1]-a[i]);
    }
    cout << now << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h> // imports every library in c++
using namespace std; // ; is essential | says that you are USING the libraries

//  COMMAND TO USE WHEN RUNNING CODE: g++ day3.cpp -o day3 -std=c++11 -O2  | to run: ./(name of file)  //

// PRACTICE //

int N, x;

int main() {
    cin >> N;
    for ( int i = 1; i < 11; i++ ) {
        x = 111;
        x *= i;
        if ( N <= x ) {
            cout << x;
            return 0;
        }
    }
    return 0;
}

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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).Take(2).Sum());
        }

    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<random>
#include<math.h>
#include<limits.h>
#include<iterator>
#include<queue>
#include<functional>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> > 
#define vb vector<bool> 
#define vvb vector<vector<bool> > 
#define INF 11234567890123456789
using namespace std;

int main(){
	ll n; cin >> n;
	ll sum = 0;
	vl a(n); rep(i, n){
		cin >> a[i];
		sum += a[i];
	}
	ll one = a[0], two = sum-a[0];
	ll ans = abs(one - two);
	nrep(i,1, n-1){
		one += a[i];
		two -= a[i];
		ans = min(ans, abs(one - two));
	}cout << ans << endl;
	return 0;
}

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

int main()
{
    int n;
	int a[1000] = {0};

	while (1)
	{
    cin >> n;
	if (n == 0)
	{
		break;
	}
		double t = 0;
		double dist = 0;
	for ( int i = 0; i < n; i++ )
	{
		cin >> a[i];
		t += a[i];
	}
    double m = t/n;
	for ( int i = 0; i < n; i++ )
	{
		dist += (m-a[i])*(m-a[i]);
	}
    double l = sqrt( dist/n );

    cout << fixed << setprecision(8) << l << "\n" ;
	}

	return 0;
}


Measured memory_bytes: 3304
#include <iostream>
#include <cstdio> 
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int main() {
    int n,A,B;
    cin>>n>>A>>B;
    cout<<min(A,B)<<' '<<max(0,A+B-n);
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<map>
using namespace std;

int main(){
//srandom((unsigned long)time(NULL));

int d[5];
for(int i=0;i<5;i++){
    cin>>d[i];
}
int k;
cin>>k;

int x=1;

for(int i=0;i<5;i++){
    for(int j=0;j<5;j++){
        if(abs(d[i]-d[j])>k)x=0;
    }
}
if(x==0)cout<<":("<<endl;
else cout<<"Yay!"<<endl;


return 0;
}

Measured memory_bytes: 256
use proconio::input;

#[rustfmt::skip]
fn main() { std::thread::Builder::new().stack_size(128 * 1024 * 1024).spawn(solve).unwrap().join().unwrap(); }

#[proconio::fastout]
fn solve() {
    input! {
        n: i64
    }
    println!(
        "{}",
        (1..=n)
            .map(|x| x * (x % 3 != 0) as i64 * (x % 5 != 0) as i64)
            .sum::<i64>()
    )
}


Measured memory_bytes: 2292
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
vector<lli> e[10005];
int n;
lli p[3000];
lli x[3000];
bool flag = true;
pair<lli, lli> dfs(int u, int par)
{
    lli v = x[u];
    vector<pair<lli, lli>> h;
    for (auto s : e[u]) {
        if (s == par)
            continue;
        h.push_back(dfs(s, u));
    }
    lli mi = 0, ma = 0;
    for (auto& s : h) {
        if (s.first > s.second)
            swap(s.first, s.second);
        mi += s.first;
        ma += s.second;
    }
    if (mi > v) {
        flag = false;
        cout << "IMPOSSIBLE" << endl;
        exit(0);
    }
    sort(h.begin(), h.end(), [](pair<lli, lli> l, pair<lli, lli> r) -> bool {
        return l.second - l.first > r.second - r.first;
        /*        if (l.second != r.second)
            return l.second > r.second;
        return l.first < r.first;
        */
    });
    for (auto s : h) {
        if (mi + s.second - s.first <= v) {
            mi += s.second - s.first;
            ma -= s.second - s.first;
        }
    }
    return make_pair(v, ma);
}
int main()
{
    cin >> n;
    rep(i, n - 1)
    {
        cin >> p[i];
        p[i]--;
        e[i + 1].push_back(p[i]);
        e[p[i]].push_back(i + 1);
    }
    rep(i, n)
    {
        cin >> x[i];
    }
    dfs(0, -1);
    cout << "POSSIBLE" << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  set <string> v;
  int i,j,k,l,m;
   for(i=0;i<n;i++)
   {
   	string str;
   	cin>>str;

   	v.insert(str);
   }
   cout<<v.size();
   
}
  

  


Measured memory_bytes: 19192
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace debug
{
    class ProgramD
    {
        static void Main(string[] args)
        {

            //入力
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            long ans = 0;
            
            
            for (int i = 0;i < n; i++)
            {
                int temp = int.Parse(s[i]);
                while(temp >= 0)
                {
                    if (temp % 2 != 0)
                        break;

                    temp /= 2;
                    ans++;
                }

            }

            Console.WriteLine(ans);
            
        }

        //繰り返し二乗法で求める
        static long modpow(long a, long n, long MOD)
        {
            if (n == 0)
                return 1;
            if (n % 2 == 0)
            {
                long temp = modpow(a, n / 2, MOD);
                return temp * temp % MOD;
            }

            return a * modpow(a, n - 1, MOD) % MOD;
        }
    }

}


Measured memory_bytes: 13792
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
struct task
{
	char name[20];
	int time;
};
struct task queue[1000010];//队列
int main()
{
	int n,i,q,totaltime=0,len,head=1,tail=1;
	scanf("%d %d",&n,&q);
	for(i=1;i<=n;i++)
	{
		scanf("%s %d",queue[i].name,&queue[i].time);
		tail++;
	}
	while(head!=tail)
	{
		if(queue[head].time<=q)
		{
			totaltime+=queue[head].time;
			//puts(queue[head].name);
			len=strlen(queue[head].name);
			for(i=0;i<=len-1;i++)
				printf("%c",queue[head].name[i]);
			printf(" %d\n",totaltime);
			head++;
		}
		else
		{
			totaltime+=q;
			strcpy(queue[tail].name,queue[head].name);
			queue[tail].time=queue[head].time-q;
			tail++;
			head++;
		}
	}
	return 0;
}


Measured memory_bytes: 6156
from bisect import bisect_left
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans = 0
for i  in range(n-2):
    a = l[i]
    for j in range(i+1,n-1):
        b = l[j]
        ans += bisect_left(l,a+b)-j-1
print(ans)

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void Solve(){
	ll n,m;
	while(true){
		cin >> n >> m;
		if(n==0&&m==0) break;
		
		vector<ll> p;
		p.push_back(0);
		rep(i,0,n){
			ll in;
			cin >> in;
			p.push_back(in);
		}

		vector<ll> a;
		rep(i,0,p.size()){
			rep(j,0,p.size()){
				a.push_back(p[i]+p[j]);
			}
		}
		sort(a.begin(),a.end());

		ll ans=0;
		rep(i,0,p.size()){
			rep(j,0,p.size()){
				ll s=p[i]+p[j];
				int idx=upper_bound(a.begin(),a.end(),m-s)-a.begin()-1;
				if(idx==-1) continue;
				ans=max(ans,s+a[idx]);
			}
		}

		cout << ans << endl;
	}
}

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

Measured memory_bytes: 17188
num_text = list(input())
a = int(num_text[3])
b = int(num_text[2])
c = int(num_text[1])
d = int(num_text[0])
sum = 0
flg = 0
sum = d + c + b + a
if sum == 7 and flg== 0:
    print(str(d)+'+'+str(c)+'+'+str(b)+'+'+str(a) + '='+str(sum))
    flg = 1
sum = d + c + b - a
if sum == 7 and flg== 0:
    print(str(d)+'+'+str(c)+'+'+str(b)+'-'+str(a) + '='+str(sum))
    flg = 1
sum = d + c - b + a
if sum == 7 and flg== 0:
    print(str(d)+'+'+str(c)+'-'+str(b)+'+'+str(a) + '='+str(sum))
    flg = 1
sum = d + c - b - a
if sum == 7 and flg== 0:
    print(str(d)+'+'+str(c)+'-'+str(b)+'-'+str(a) + '='+str(sum))
    flg = 1
sum = d - c + b + a
if sum == 7 and flg== 0:
    print(str(d)+'-'+str(c)+'+'+str(b)+'+'+str(a) + '='+str(sum))
    flg = 1
sum = d - c + b - a
if sum == 7 and flg== 0:
    print(str(d)+'-'+str(c)+'+'+str(b)+'-'+str(a) + '='+str(sum))
    flg = 1
sum = d - c - b + a
if sum == 7 and flg== 0:
    print(str(d)+'-'+str(c)+'-'+str(b)+'+'+str(a) + '='+str(sum))
    flg = 1
sum = d - c - b - a
if sum == 7 and flg== 0:
    print(str(d)+'-'+str(c)+'-'+str(b)+'-'+str(a) + '='+str(sum))
    flg = 1
    


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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int count = 0;  
  for (int c = 0; c < C + 1; c++) {
    for (int b = 0; b < B + 1; b++) {
       for (int a = 0; a < A + 1; a++) {
       	if (500 * a +  100 * b + 50 * c == X) ++count;
       }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int
#define ld long double

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

const int N=1e6+2;

vector<int>divi(N,0);

void sieve()
{

	for(int i=1;i<=N;i++)
	{
		for(int j=i;j<=N;j+=i)
		{
			divi[j]++;
		}
	}

	for(int i=2;i<=N-1;i++)
	{
		divi[i]+=divi[i-1];
	}
}

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	
	int i,j;
	int n;
	sieve();
	cin>>n;
	d(n);
	// d(divi);
	cout<<divi[n-1]<<endl;
	

}

Measured memory_bytes: 11032
#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;

int main(){
  double x1,x2,y1,y2,n;
  cin>>x1>>y1>>x2>>y2;
  n=sqrt(pow((x1-x2),2.0)+pow((y1-y2),2.0));
  cout<<fixed<<setprecision(6);
  cout<<n<<endl;
  return 0;
}



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

int main()
{
	int h, w;
	while(true){
		cin >> h >> w;
		if(h == 0 && w == 0)
			break;
		for(int n = 1; n <= h; n++){
			for(int m = 1; m <= w; m++){
				if(n ==1 || n == h){
					cout << "#" ;
				}
				else if(m ==1 || m == w){
					cout << "#";
				}
				else{
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
}

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

int n;
bool even = false;

int main(){
    cin >> n;
    if(n % 2 == 0) even = true;
    vector<int> a(n,0), ans;
    for(int i = 0; i < n; i++) cin >> a[i];
    if(even){
        for(int j = n - 1; j >= 0; j = j - 2){
            cout << a[j] << " ";
        }
        for(int j = 0; j < n - 2; j = j + 2){
            cout << a[j] << " ";
        }
        cout << a[n - 2] << endl;
    }else{
        for(int j = n - 1; j >= 0; j = j - 2){
            cout << a[j] << " ";
        }
        for(int j = 1; j < n - 2; j = j + 2){
            cout << a[j] << " ";
        }
        if(n != 1){
            cout << a[n - 2] << endl;
        }else{
            cout << endl;
        }
    }
}

Measured memory_bytes: 2944
import random

N = int(input())
n = N

l = [6**x for x in range(1, 7)] + [9**x for x in range(1, 6)]
l.sort(reverse=True)

def prob_solver(n):
    result = 0
    for price in l:
        if n < price:
            continue
        x = random.randint(0, n // price)
        result += x
        n -= x * price
    return result + n

ans = n
for _ in range(10000):
    ans = min(ans, prob_solver(n))

print(ans)

Measured memory_bytes: 46684
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#include<climits>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<map>

using namespace std;

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

	if(a[0]!=0){
		cout<<-1;
		return 0;
	}

	for(int i=1;i<n;i++){
		if(a[i]>i || a[i-1]<(a[i]-1)){
			cout<<-1;
			return 0;
		}
	}

	long long step=0;

	for(int i=1;i<n;i++){
		if(a[i]==a[i-1]+1)
			step++;
		else
			step+=a[i];
	}

	cout<<step;
	return 0;
}

Measured memory_bytes: 1152
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
count=0
if m>n:
    print("NO")
else:
    d.sort()
    t.sort()
    for i in range(n):
        if count==m:
            break
        if t[count]==d[i]:
            count+=1
    if count==m:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 35420
from collections import defaultdict


def main():
    N = int(input())
    S = str(input())
    x = 0
    ans = 0
    for c in S:
        x += {"I": 1, "D": -1}[c]
        ans = max(ans, x)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main(){
	char S[4];
	
	cin>>S;
	int x=0;
	for(int i=0;i<3;i++){
		for(int j=i+1;j<4;j++){
			if(S[i]==S[j]){
			x++;
			}
		}
		}
	if(x==2){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	

	
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#ifndef LOCAL
struct ostdmy{template<class T>ostdmy&operator<<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
int sign(int a){
    if(a<0)return -1;
    if(a>0)return 1;
    return 0;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>>n;
    vl a(n);
    cin>>a;

    ll ans1=0,ans2=0;
    ll cs1=0,cs2=0;
    REP(i,n){
        if(i%2){
            cs1+=a[i];
            if(cs1<=0){
                ans1+=1-cs1;
                cs1=1;
            }

            cs2+=a[i];
            if(cs2>=0){
                ans2+=1+cs2;
                cs2=-1;
            }

        }else{
            cs2+=a[i];
            if(cs2<=0){
                ans2+=1-cs2;
                cs2=1;
            }

            cs1+=a[i];
            if(cs1>=0){
                ans1+=1+cs1;
                cs1=-1;
            }

        }
        cerr<<cs1<<'\t'<<cs2<<endl;

    }
    cerr<<ans1<<','<<ans2<<endl;
    cout<<min(ans1,ans2)<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////





int main() {

	ll N,K;
	cin >> N >> K;

	ll M = sqrt(N) + 1;

	ll dp[110][32000];
	ll dpp[110][32000];

	repn(j, M) {
		dp[1][j] = j;
		dpp[1][j] = N / j;
	}

	repn(i, K-1) {
		
		dp[i + 1][1] = dpp[i][1];
		repn(j, M-1) {
			dp[i + 1][j + 1] = (dp[i + 1][j] + dpp[i][j + 1])%MOD;
		}

		dpp[i + 1][M] = dp[i + 1][N / M];
		for (int j = M; j >= 2; j--) {
			dpp[i + 1][j - 1] = (dpp[i + 1][j] + (N / (j - 1) - N / j)*dp[i][j - 1]) % MOD;
		}
	

	}

	cout << dpp[K][1];

	system("PAUSE");


}


Measured memory_bytes: 53752
#include<iostream>
using namespace std;
#include<stdlib.h>

int *P, *L, *R;
bool output;

void maketree(int* A, int* B, int h)
{
    int x, m;
    x = A[0];
    if(h == 1){
        L[x] = 0; R[x] = 0; return;
    }else{
        m = 0;
        while(B[m] != A[0]) m++;
        m++;
        if(m == 1){
            L[x] = 0; R[x] = A[1]; P[A[1]] = x;
            maketree(A + 1, B + 1, h - 1);
        }else if(m == h){
            L[x] = A[1]; P[A[1]] = x; R[x] = 0;
            maketree(A + 1, B, h - 1);
        }else{
            L[x] = A[1]; P[A[1]] = x; R[x] = A[m]; P[A[m]] = x;
            maketree(A + 1, B, m - 1);
            maketree(A + m, B + m, h - m);
        }
    }
}

void postorder(int i)
{
    if(i == 0) return;
    postorder(L[i]);
    postorder(R[i]);
    if(output) cout << " ";
    cout << i;
    output = true;
}

int main()
{
    int i, n;
    cin >> n;
    P = new int [n + 1]; L = new int [n + 1]; R = new int [n + 1];
    if(P == NULL || L == NULL || R == NULL) exit(EXIT_FAILURE);

    int *A, *B;
    A = new int [n + 1]; B = new int [n + 1];
    if(A == NULL || B == NULL) exit(EXIT_FAILURE);

    for(i = 1; i <= n; i++){ cin >> A[i]; P[i] = L[i] = R[i] = 0; }
    for(i = 1; i <= n; i++){ cin >> B[i]; }

    maketree(A + 1, B + 1, n);
    delete [] A; delete [] B;

    // where is root?
    i = 1; while(P[i] > 0) i++;

    output = false;
    postorder(i);
    cout << endl;

    delete [] P; delete [] L; delete [] R;

    return 0;
}

Measured memory_bytes: 1196
import sys
from io import StringIO
import unittest

def resolve():
    n = int(input())
    s = input()
    ans = s.count('R') * s.count('G') * s.count('B')

    for i in range(n):
        for j in range(1, (n - 1)//2 + 1, 1):
            if i + 2 * j < n:
                if s[i] != s[i + j] and s[i] != s[i + 2 * j] and s[i + j] != s[i + 2 * j]:
                    ans -= 1

    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """4
RRGB"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"""
        output = """1800"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()


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

bool is_valid_route(vector<int> &route, vector<vector<bool>> &edges)
{
  for (int i = 0; i < route.size() - 1; i++)
  {
    int from = route.at(i);
    int to = route.at(i + 1);
    if (!edges.at(from).at(to))
    {
      return false;
    }
  }
  return true;
}

int main()
{
  int n_vertex, n_edge;
  cin >> n_vertex >> n_edge;

  vector<int> route(n_vertex);
  vector<vector<bool>> edges(n_vertex, vector<bool>(n_vertex));
  for (int i = 0; i < n_edge; i++)
  {
    int a, b;
    cin >> a >> b;
    edges.at(a - 1).at(b - 1) = true;
    edges.at(b - 1).at(a - 1) = true;
  }

  for (int i = 0; i < n_vertex; i++)
  {
    route.at(i) = i;
  }

  int ans = 0;
  do
  {
    if (route.at(0) != 0)
    {
      break;
    }
    if (is_valid_route(route, edges))
    {
      ans++;
    }
  }
  while (next_permutation(route.begin(), route.end()));
  cout << ans << endl;
}


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


public class Contest
{
	public static void Main()
	{

/*
		int n = a[0];
		int[][] e = new int[n][];
		for(int i=0; i<n; i++) MyRead.Array(out e[i]);

		int[] a;
		MyRead.Array(out a);

        long a,b,c,d,e,f;
        MyRead.Multi(out a, out b, out c, out d, out e, out f);

		Console.WriteLine(string.Join(' ', Array.ConvertAll(ans, x => x.ToString())));
*/

        int n;
		MyRead.Multi(out n);
		int[] a;
		MyRead.Array(out a);


		long[] ar = new long[n];
		long[] al = new long[n];

		for(int i=0; i<n; i++){
			if(i==0){
				al[i] = 0;
				ar[n-i-1] = a[n-i-1];
			}else if(i==1){
				al[i] = a[i-1];
				ar[n-i-1] = a[n-i-1]-a[n-i];
			} else{
				al[i] = al[i-2] + a[i-1]-a[i-2];
				ar[n-i-1] = ar[n-i+1] + a[n-i-1]-a[n-i];
			}
		}

		long[] ans = new long[n];
		for(int i=0; i<n; i++) ans[i] = al[i]+ar[i];


		Console.WriteLine(string.Join(" ", Array.ConvertAll(ans, x => x.ToString())));
	}


}

public static class MyRead
{
	private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
	private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
	private static T cv<T>(string s) => eq<T, int>()    ? ct<T, int>(int.Parse(s))
	                                  : eq<T, long>()   ? ct<T, long>(long.Parse(s))
	                                  : eq<T, double>() ? ct<T, double>(double.Parse(s))
	                                  : eq<T, char>()   ? ct<T, char>(s[0])
	                                                    : ct<T, string>(s);
	public static string[] Array<T>(out T[] a) {		
		var ar = Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries); 												
		a = System.Array.ConvertAll(ar, new Converter<string,T>(cv<T>));
		return ar;
	}										
	public static string[] Multi<T>(out T a) {
		var ar = Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries); 
		a = cv<T>(ar[0]);
		return ar;
	}
	public static string[] Multi<T, U>(out T a, out U b) {
		var ar = Multi<T>(out a); 
        b = cv<U>(ar[1]);
		return ar;
	}
	public static string[] Multi<T, U, V>(out T a, out U b, out V c) {
		var ar = Multi<T, U>(out a, out b); 
        c = cv<V>(ar[2]);
		return ar;
	}
	public static string[] Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
		var ar = Multi<T, U, V>(out a, out b, out c); 
        d = cv<W>(ar[3]);
		return ar;
	}
	public static string[] Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) {
		var ar = Multi<T, U, V, W>(out a, out b, out c, out d); 
        e = cv<X>(ar[4]);
		return ar;
	}
	public static string[] Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) {
		var ar = Multi<T, U, V, W, X>(out a, out b, out c, out d, out e); 
        f = cv<Y>(ar[5]);
		return ar;
	}
}




Measured memory_bytes: 32216
n = int(input())
h = list(map(int,input().split()))
ans = 1

for i in range(1,len(h)):
    flag = 0
    for j in range(i):
        if h[i]<h[j]:
            flag = 1
            break
    if flag == 0:
        ans = ans+1

print(ans)


Measured memory_bytes: 2940
#n=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
x=int(input())

ans=(x//500)*1000
md=x%500
ans+=(md//5)*5

print(ans)


Measured memory_bytes: 2940
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
#define all(x) (x).begin(),(x).end()


int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  A *= 100; B *= 100;

  vector<int> water, sugar;
    for(int a=0; A*a<=F; a++){
      for(int b=0; A*a+B*b<=F; b++){
        int num = A * a + B * b;
        auto it = find(all(water), num);
        if(it == water.end() && num != 0){
          //cout << "a:" << a << " b:" << b << " num:" << num << ln;
          water.push_back(num);
        }
      }
    }
  for(int c=0; C*c<= F/2; c++){
    for(int d=0; C*c+D*d<= F/2; d++){
      int num = C * c + D * d;
      auto it = find(all(sugar), num);
      if(it == sugar.end()){
        sugar.push_back(num);
      }
    }
  }

  sort(all(sugar));

 int maxSum = 0, maxSugar =0; double maxP = 0.0;
 for(int i=0; i<water.size(); i++){
   int wa = water[i];
   for(int j=0; j<sugar.size(); j++){
     int su = sugar[j];
     double sum = wa + su;
     double par = su * 100.0 / wa;
     if(par > E) break;
     if(sum > F) break;
     if(maxP <= par){
       maxSum = sum;
       maxP= par;
       maxSugar = su;
     }
   }
 }

 cout << maxSum << " " << maxSugar << ln;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val h = readLine()!!.split(" ").map { it.toInt() }
    var answer = 0
    for (i in 0 until n) {
        var tmp = true
        for (j in i downTo 0) {
            if (h[j] > h[i]) tmp = false
        }
        if (tmp) answer++
    }
    println(answer)
}


Measured memory_bytes: 37928
import numpy as np
import itertools

n_tate, n_yoko, n_kuro = map(int, input().split())

matrix = []
for _ in range(n_tate):
    yoko = [_ for _ in str(input())]
    yoko2 = []
    for char in yoko:
        if char == "#":
            yoko2.append(1)
        else:
            yoko2.append(0)
    matrix.append(yoko2)

matrix2 = np.array(matrix)

tmp = [0, 1]
tate_use_list  = list(itertools.product(tmp, repeat=n_tate))
yoko_use_list  = list(itertools.product(tmp, repeat=n_yoko))
# print("original")
# print(np.array(matrix))
# print()

i = 0
counter = 0
for tate_use in tate_use_list:
    for yoko_use in yoko_use_list:
#         print(i)
#         print("tate use:", tate_use)
#         print("yoko_use:", yoko_use)

        matrix3 = matrix2.copy()
        A = np.array(tate_use).reshape(-1, 1)
        B = np.array(yoko_use)

        matrix4 = matrix3 * A * B

        total = np.sum(matrix4)
        i += 1
#         print(matrix4)
#         print("total:", total)
        if total == n_kuro:
#             print("  -> OK!")
            counter += 1
#         print()
        
print(counter)

Measured memory_bytes: 27156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
const double PI = 3.14159265359;
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define INF 1000000000000
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST
int n;
cin>>n;
if(n>=30)
{
	cout<<"Yes\n";
}
else
{
	cout<<"No\n";
}
return  0;
}






Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define trace(it,mp) for(auto it = (mp).begin(); it != (mp).end(); it++)
#define fr(i,n) for(ll i=0;i<n;i++)
#define mod 1000000000
using namespace std;

// covert number to string to_string(x);
ll h(ll a[],ll n,ll k)
{
	ll dp[n+1];
	dp[0]=0;
	dp[1]=0;

	for(ll i=2;i<=n;i++)
	{
		if(i==2)
			dp[i]=abs(a[i-1]-a[i-2]);
		else
		{
			dp[i]=abs(a[i-1]-a[i-2])+dp[i-1];
			for(ll j=2;j<i && j<=k;j++)
				dp[i]=min(dp[i],abs(a[i-1]-a[i-1-j])+dp[i-j]);
		}	
	}

	return dp[n];
}


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

    ll t,a,b,c,x,y,z,n,m,k,ans;
    cin >> n >> k;

    ll arr[n];

    fr(i,n){
    	cin >> arr[i];
    }

    cout << h(arr,n,k);

    cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
}

Measured memory_bytes: 5364
//A - Iroha and Haiku (ABC Edition)
#include <stdio.h>

int a,b,c;
int cntOf5,cntOf7;

void work(int n)
{
	if (n==5)
		cntOf5++;
	if (n==7)
		cntOf7++;
}

int main()
{
	scanf("%d %d %d",&a,&b,&c);
	work(a);
	work(b);
	work(c);
	if (cntOf5==2&&cntOf7==1)
		printf("%s","YES");
	else
		printf("%s","NO");

}

Measured memory_bytes: 128
Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun i -> Scanf.scanf " %d" (fun a -> (a, i))) in
    Array.sort compare a;
    let rec loop i acc =
        if i = n then acc / 2 else
            let (_, pos) = a.(i) in
            let q = abs (pos - i) mod 2 in
            loop (i + 1) (acc + q)
    in
    loop 0 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 6784
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
re = [0] * (n+1)

c = Counter(a)

for k,v in c.items():
    re[k] = v*(v-1) // 2

s = sum(re)
for i in a:
    print(s - re[i] + (c[i]-1)*(c[i]-2) // 2)
    

Measured memory_bytes: 26780
#include <iostream>
  #include <string>
  #include <vector>
  #include <algorithm>
  #include <utility>
  #include <map>
  using namespace std;
  typedef long long ll;
  #define rep(i,n) for (int i=0;i < (int)(n);i++)

  ll dp[10001][101][2];
  const ll mod = 1e9+7;

  int main(){
    string s;
    cin >> s;
    int n = s.size();
    int D;
    cin >> D;

    dp[0][0][0] = 1;
    rep(i,n) rep(j,D) rep(k,2){
      ll nd = s[i]-'0';
      rep(d,10){
        int ni = i+1,nj = (j + d)%D,nk = k;
        if (k == 0){
          if (d > nd) continue;
          if (d < nd) nk = 1;
        }
        dp[ni][nj][nk] += dp[i][j][k];
        dp[ni][nj][nk] %= mod;
      }
    }
    int ans = dp[n][0][0] + dp[n][0][1];
    ans -= 1;
    if (ans < 0) ans += mod;
    cout << ans << endl;

    return 0;
  }


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

int main() {
    int i,j,k,l,M,N,H,W,a,x,temp ;
    string str;
    cin >> H >> W;
    vector<vector<char>> HW(H,vector<char>(W));
  	vector<vector<int>> out(H,vector<int>(W));
  
    for(i = 0 ; i < H ; i++){
      for(j = 0 ; j < W ; j++){
      	cin >> HW[i][j];
        if (HW[i][j] == '#'){
        	if(i-1 >= 0 && j-1 >= 0){
              out[i-1][j-1]++;
            }
          	if(i-1 >= 0){
              out[i-1][j]++;
            }
          	if(i-1 >= 0 && j+1 < W){
          	  out[i-1][j+1]++;
            }
          	if(j-1 >= 0){
              out[i][j-1]++;
            }
          	if(j-1 >= 0 && i+1 < H){
          	  out[i+1][j-1]++;
            }
            if(j+1 < W){
          	out[i][j+1]++;
            }
          	if(i+1 < H){
          	out[i+1][j]++;
            }
          	if(i+1 < H && j+1 < W){
          	out[i+1][j+1]++;
            }
        }
      }
    }
  	for(i = 0 ; i < H ; i++){
      for(j = 0 ; j < W ; j++){
      	if (HW[i][j] != '#'){
        	HW[i][j] = '0' + out[i][j];
          	cout << HW[i][j];
        }
        else {cout << HW[i][j];}
      }
      cout << endl;
    }
  
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = [0 for i in range(n)]
B = list(map(int, input().split()))
for i in range(len(A)):
    if i == 0:
        A[i] = B[i]
    elif i == n-1:
        A[i] = B[i-1]
    else:
        A[i] = min(B[i-1], B[i])
print(sum(A))

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define N 100200
#define INF 1000000000
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b)
{
    if(b == 0)
        return a;
    else
        return gcd(b,a%b);
}


int main()
{
    int n;
    ll a[N] = {};
    ll l[N] = {};
    ll r[N] = {};
    ll m = 0;
    cin >> n;
    FOR(i,1,n+1)
    {
        cin >> a[i];
    }

    l[0] = 0;
    r[n+1] = 0;
    FOR(i,1,n+1)
    {
        l[i] = gcd(a[i],l[i-1]);
        r[n-i+1] = gcd(a[n-i+1],r[n-i+2]);
    }

    FOR(i,1,n+1)
    {
        m = max(m,gcd(l[i-1],r[i+1]));
    }

    cout << m << "\n";

    return 0;
}

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

using namespace std;

string allReplaceString(string s, string f, string t) {
	string r;
	for (int p=0; (p = s.find(f)) != s.npos;) {
		r += s.substr(0, p) + t;
		s = s.substr(p + f.size());
	}
	return r + s;
}

int main() {
	string line;
	int n;
	cin >> n;
	cin.ignore();
	
	for (int i = 0; i < n; i++) {
		getline(cin, line);
		string ans = allReplaceString(line, "Hoshino", "Hoshina");
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1224
#include<stdio.h>

int main()
{	
	long int N, K;
	long int d,e;
	long int ans;
	scanf("%ld %ld",&N, &K);
	d=N/K;
	
	if(K%2==1)
	{
		ans=d*d*d;
	}
	else
	{
		e=(N+K/2)/K;
		ans=d*d*d+e*e*e;		
	}
	
	printf("%ld",ans);
}

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

// 頂点数、変数
int v, e;
const int MAX_N = 10010;
// 隣接リスト
vector<int> g[MAX_N];
bool used[MAX_N];
// トポロジカルソートされた数列
vector<int> ans;

void dfs(int u) {
  if(used[u]) return;
  used[u] = true;
  for(auto& i: g[u]) dfs(i);
  // 帰りがけ順で追加
  ans.push_back(u);
}

void tsort() {
  for(int i=0; i<v; ++i) dfs(i);
  reverse(ans.begin(), ans.end());
}

signed main(void)
{
  cin >> v >> e;
  for(int i=0; i<e; ++i) {
    int s, t;
    cin >> s >> t;
    g[s].push_back(t);
  }

  tsort();
  for(int i: ans) cout << i << endl;

  return 0;
}



Measured memory_bytes: 3776
#include <iostream>
    #include <math.h>
    #include <vector>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    using namespace std;

int main() {
    int N,Q; cin>>N>>Q;
    string s; cin >>s;
    int cnt=0;
    vector<int> cntc((int)s.length(),0);
    vector<pair<int,int>> lrs(Q);
    for(int i=1;i<s.length();i++){
        if( s[i]=='C' && s[i-1]=='A'){
            cnt++;
            //cout <<"i is: "<<i << " cnt is: " << cnt<<endl;
        }
        cntc[i]=cnt;
    }
    int l,r;
    for(int j=0;j<Q;j++){
        cin>>l>>r;
        lrs[j] = make_pair(l-1,r-1);
    }
    for(int j=0;j<Q;j++){
        cout<<cntc[lrs[j].second] - cntc[lrs[j].first]<<endl;
    }
    return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>
#define MAX 2000001
#define INF 10000000
#define size 20
 
int H,A[MAX];
 
void swap(int *a,int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}
 
void maxHeapify(int i){
  int l,r,largest;
  l=2*i;
  r=2*i+1;
 
  //?????????????????????????????????§????????????§?????????????????????¶
  if(l<=H&&A[l]>A[i]) largest=l;
  else largest = i;
  if(r<=H&&A[r]>A[largest]) largest=r;
 
  if(largest!=i){
    swap(&A[i],&A[largest]);
    maxHeapify(largest);
  }
}
 
int extract(){
  int max;
  if(H<1) return -INF;
  max=A[1];
  A[1]=A[H--];
  maxHeapify(1);
  return max;
}
 
void increaseKey(int i, int key){
  if(key<A[i]) return;
  A[i]=key;
  while(i>1&&A[i/2]<A[i]){
    swap(&A[i],&A[i/2]);
    i/=2;
  }
}
 
void insert(int key){
  H++;
  A[H]=-INF;
  increaseKey(H,key);
}
 
int main(){
int key;
char str[size];
 
  while(1){
    scanf("%s",str);
    if(str[0]=='e'&&str[1]=='n') break;
    if(str[0]=='i'){
      scanf("%d",&key);
      insert(key);
    } else{
      printf("%d\n", extract());
    }
  }
  return 0;
}

Measured memory_bytes: 4696
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cmath>
#include <functional>
#include <limits>

#define INT32_MAX (2147483647)

using namespace std;

int main() {
	string row;
	int n;
	cin>>n;
	for(int i=0; i<n; i++){
		int minNum=INT32_MAX, maxNum=0, buf;
		cin>>row;
		sort(row.begin(), row.end(), greater<char>());
		istringstream istr1(row);
		istr1>>buf;
		maxNum = max(maxNum, buf);
		sort(row.begin(), row.end());
		istringstream istr2(row);
		istr2>>buf;
		minNum = min(minNum, buf);
		cout<<(maxNum-minNum)<<endl;
	}
	return 0;
}

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

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin>>n;
    vector<int> h(n);
    for(int i = 0;i<n;i++)
    {
        cin>>h[i];
    }
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    if(n == 1)
    {
        cout<<dp[0]<<"\n";
        return 0;
    }
    dp[1] = abs(h[0] - h[1]);
    if(n == 2)
    {
        cout<<dp[1]<<"\n";
        return 0;
    }
    for(int i = 2;i<n;i++)
    {
        dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1], abs(h[i] - h[i-2]) + dp[i-2]);
    }
    cout<<dp[n-1]<<"\n";
    return 0;
}

Measured memory_bytes: 3948
#include<bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long Q, H, S, D, N; cin >> Q >> H >> S >> D >> N;
	vector<pair<long long, double>> v;
	map<double, long long> value;
	value[0.25] = Q;
	value[0.5] = H;
	value[1] = S;
	value[2] = D;
	v.emplace_back(Q*8, 0.25);
	v.emplace_back(H*4, 0.5);
	v.emplace_back(S*2, 1);
	v.emplace_back(D, 2);
	sort(v.begin(), v.end());
	long long ans = 0;
	for(int i = 0; i < 4; i++){
		if(N == 0) break;
		long long l = N / v[i].second;
		ans += value[v[i].second] * l;
		N -= l * v[i].second;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int k,t;cin>>k>>t;
	int a[t];
	rep(i,t) cin>>a[i];
	sort(a,a+t);
	if(t==1){
		cout<<k-1<<"\n";
		return 0;
	}
	int ans=a[t-1]-1-(k-a[t-1]);
	if(ans<0) cout<<0<<"\n";
	else cout<<ans<<"\n";
}


Measured memory_bytes: 256
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

MOD = 10 ** 9 + 7
n, k = map(int, raw_input().split())

def fact(N):
    if N <= 1:
        return 1
    return fact(N - 1) * N

if n > k:
    print 0
else:
    print (fact(k) / fact(k - n) / fact(n)) % MOD


Measured memory_bytes: 5728
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N, K;
string S;
vector<pair<char, int>> v;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  cin >> S;
  for (int i = 0; i < N;) {
    char c = S[i];
    int cnt = 1;
    i++;
    while (i < N && S[i] == c) {
      cnt++;
      i++;
    }
    v.push_back(make_pair(c, cnt));
  }

  int ans = 0;
  for (int i = 0; i < v.size(); i++) {
    ans += (v[i].second - 1);
  }

  int cnt = 0;
  for (int i = 1; i < v.size() - 1; i += 2) {
    if (cnt < K) {
      ans += 2;
    }
    cnt++;
  }
  if (cnt < K && v.size() % 2 == 0) {
    ans++;
  }

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

Measured memory_bytes: 1480
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let v:Vec<i64> = buf.split_whitespace().into_iter().map(|elem| elem.parse().unwrap()).collect();
    if v[0] < v[1] && v[1] < v[2] {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };


ll gcd(ll a, ll b){
   if (a%b == 0){
       return(b);
   }else{
       return(gcd(b, a%b));
   }
}

void solve() {
    int N; cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    ll tmp = a[0];
    rep(i, N){
        tmp = gcd(tmp, a[i]);
    }

    cout << tmp << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 5120
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
	int a = sc.nextInt();
	int b = sc.nextInt();

	String result = "NG";
	for(int i=a;i<=b;i++){
	    if(i%k==0){
		result = "OK";
		break;
	    }
	}
	System.out.print(result);
    }
}


Measured memory_bytes: 35816
#include <bits/stdc++.h>
using namespace std;
char A[15], B[15], C[15];
int main()
{
    scanf("%s%s%s", A, B, C);
    if (A[strlen(A) - 1] == B[0] && B[strlen(B) - 1] == C[0]) {
        printf("YES\n");
    }
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
//Nayeem Shahriar Joy ,Applied Physics And Electronic Engineering , University of Rajshahi.

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

  #define MAX 105000

  using namespace std;

  int main()

  {
      bool prime[MAX];

      memset(prime,true,sizeof(prime));

      long int i;

      prime[0]=false;
      prime[1]=false;

      for( i=0;i*i<MAX;i++)
      {
          if(prime[i]==true)
          {
              for(int j=i*2;j<MAX;j=j+i)
              {
                  prime[j]=false;
              }
          }
      }
      int prme[10000];

      int p=0;

      for(i=0;i<MAX;i++)

      {
          if(prime[i]==true)

          {
              prme[p]=i;
              p++;
              if(p>10000-1){
                break;
            }
          }

      }

      int n;

      while(cin>>n){

            if(n==0)

            {
                break;
            }

      int ans=0;

      for(int k=0;k<n;k++)

      {
          ans=ans+prme[k];
      }

      cout<<ans<<endl;

      }

      return 0;

  }

Measured memory_bytes: 3160
eval"D,G,*A="+`dd`.split*?,
p (0..1023).map{|b|n=e=0;s=G;A.each_slice(2){|q,c|e+=100;b&1>0?(n+=q;s-=q*e+c):Q=q*E=e;b/=2};Q&&s>0?s>Q ? 1e4:n--s/E: n}.min

Measured memory_bytes: 4356