akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
using namespace std;

int N, K;
const int N_MAX = 100001;
long long h[N_MAX];
long long t_min=1000000001, t_max=0;
long long ans = 1000000001;

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> h[i];

	sort(h, h + N);

	for (int i = 0; i < N - K + 1; i++) {
		ans = min(h[i + K-1] - h[i], ans);
	}

	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
	int n; cin >> n;
	while(n --){
		int in[3];
		for(int i = 0; i < 3; i ++) cin >> in[i];
		sort(in, in + 3);
		cout << ((in[2] * in[2] == in[1] * in[1] + in[0] * in[0]) ? "YES":"NO") << endl;
	}

	return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

int n, m;
vector<int> a[1010];
pii ed[2010];

int vis[1010];
int anc[1010];
bool found;

vector<int> v;

void dfs(int x, int last)
{
    //cout << "dfs " << x << " " << last << endl;


    vis[x] = 1;
    anc[x] = last;

    forn(i, a[x].size())
    {
        if(found) break;

        //cout << a[x][i] << endl;

        if(vis[a[x][i]] == 1)
        {
            //cout << "found " << x << endl;
            //cout << "anc" << endl;
            //Forn(j, n) cout << anc[j] << " ";
            //cout << endl;
            found = 1;
            v.pb(x);
            int now = last;

            //cout << "now = " << now << endl;

            while(now!=x && now!=0)
            {
                v.pb(now);
                now = anc[now];
                //cout << "now = " << now << endl;
            }
            break;
        }
        else if(vis[a[x][i]] == 0) dfs(a[x][i], x);
    }
    vis[x] = 2;
}

int main()
{
    cin.tie(0); ios_base::sync_with_stdio(false);
    cin >> n >> m;
    Forn(i, m)
    {
        int x, y;
        cin >> x >> y;
        a[x].pb(y);
        ed[i] = mp(x, y);
        //a[y].pb(x);
    }
    Forn(i, n)
    {
        if(!vis[i]) dfs(i, 0);
    }

    if(!found)
    {
        cout << -1 << endl;
        return 0;
    }
    reverse(v.begin(), v.end());


    while(1)
    {
        bool ok = 1;
        set<pii> s;
        set<int> sv;
        for(int i=0; i<v.size()-1; i++)
        {
            s.insert(mp(v[i], v[i+1]));
            sv.insert(v[i]);
        }
        s.insert(mp(v[v.size()-1], v[0]));
        sv.insert(v[v.size()-1]);

        int st, en;
        st = en = 0;

        Forn(i, m)
        {
            st = ed[i].F;
            en = ed[i].S;
            //cout << st << " " << en << endl;

            if(sv.count(st) && sv.count(en) && !s.count(mp(st, en)))
            {
                ok = 0;
                break;
            }
        }

        //cout << "st = " << st << ", en = " << en << endl;

        if(ok) break;



        vector<int> temp;
        forn(ii, 2) forn(i, v.size()) temp.pb(v[i]);

        /*cout << "temp" << endl;
        forn(i, temp.size()) cout << temp[i] << " ";
        cout << endl;*/

        vector<int> w;
        bool start = 0;
        forn(i, temp.size())
        {
            if(temp[i] == en) start = 1;
            if(start) w.pb(temp[i]);
            if(temp[i] == st && start)
            {
                start = 0;
                break;
            }
        }

        v.clear();
        forn(i, w.size()) v.pb(w[i]);

    }

    cout << v.size() << endl;
    forn(i, v.size()) cout << v[i] << endl;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define me(a,b) memset(a,b,sizeof(a))
using namespace std;
/*int n,m;
int vis[250][250];
char mp[250][250];
int fx[4][2]={0,1,0,-1,1,0,-1,0};
int yx,yy,mx,my,sum;
struct pointb
{
    int x,y,leny,lenm,step;
}ed[250*250];
queue<point>q;
void(int pi,int pj,int f)
{
    while(q.size())   q.pop();
    point now,kai,next;

}
int main()
{
    while(scanf("%d %d",&n,&m)!=EOF)
    {
        sum=0;
        me(ed,0);
        for(int i=0;i<n;i++)
        {
            scanf("%s",mp[i]);
            for(int j=0;j<m;j++)
            {
                if(mp[i][j]=='@')
                {
                    ed[sum].x=i;
                    ed[sum++].y=j;
                }
                else if(mp[i][j]=='Y')
                {
                    yx=i;
                    yy=j;
                }
                else if(mp[i][j]=='M')
                {
                    mx=i;
                    my=j;
                }
            }
        }
        bfs(yx,yy,0);
        bfs(mx,my,1);
        int mi=0x3f3f3f3f;
        for(int i=0;i<sum;i++)
        {
            ed[i].leny=0x3f3f3f3f;
            ed[i].lenm=0x3f3f3f3f;
        }
        for(int i=0;i<sum;i++)
        {
            mi=min(ed[i].leny+ed[i].lenm,mi);
        }
        printf("%d\n",mi);
    }
    return 0;
}
*/
int main()
{
    int a,b,t;
    while(scanf("%d %d %d",&a,&b,&t)!=EOF)
    {
        int sum=0;
        for(int i=1;i*a<=t;i++)
        {
            sum+=b;
        }
        printf("%d\n",sum);
    }
}








Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <bitset>

#include <random>
#define all(x) (x).begin(), (x).end()


using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> vec) {
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

//#define solvsh
//#define multi
#ifdef solvsh

const int MAXN = 2e5 + 20;

int per[MAXN];
ll costs[MAXN];

ll tree[MAXN];
ll inp[MAXN];
int where[MAXN];

void build(int ver, int tl, int tr) {
    if (tl == tr) {
        tree[ver] = inp[tl];
    } else {

        int mid = (tl + tr) >> 1;

        build(2 * ver, tl, mid);
        build(2 * ver + 1, mid + 1, tr);

        tree[ver] = min(tree[2 * ver], tree[2  *ver + 1]);
    }
}

ll adds[4 * MAXN];

void upd(int v, int tl, int tr, int l, int r, ll add){
    if (l > r)
        return;
    if (tl == l && tr == r){
        adds[v] += add;
        return;
    }

    auto mid = (tl + tr) >> 1;

    upd(2 * v, tl, mid, l, min(mid, r), add);
    upd(2 * v + 1, mid + 1, tr, max(mid + 1, l), r, add);

    tree[v] = min(tree[2 * v], tree[2 * v  +1]) + adds[v];
}

ll get_min(){
    return tree[1];
}


void solve() {
    int n;
    cin >> n;

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

    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> costs[i];
        sum += costs[i];
    }

    for (int i = 1; i <= n; ++i) {
        inp[i] = inp[i - 1] + costs[where[i]];
    }
    build(1, 1, n);

    ll answr = 1e18;

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

        int val = per[i];

        upd(1, 1, n, 1, val - 1, costs[i]);
        upd(1, 1, n, val, n, -costs[i]);

        answr = min(answr, get_min());
    }

    cout << answr;
}

#else

ll mod = 1e9+7;

const int MAXN = 2e5 + 9;


void solve() {
    string s;
    string t;
    cin >> s >> t;

    t.pop_back();

    if (s== t){
        cout << "Yes";
    } else {
        cout << "No";
    }

}

#endif

void multisolve() {

    int t;
    cin >> t;

    int i = 1;
    while (t--) {
        cout << "Case #" << (i++) << ": ";
        solve();
        cout << "\n";
    }
}


#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);



#ifdef multi
    multisolve();
#else
    solve();
    //    gen();
#endif

}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {
	
	int n;
	cin >> n;
	vi a(n);
	rep(i, n)cin >> a[i];
	int x = a[0];
	ll ans = 0;
	rep(i, n) {
		if (x <= a[i])x = a[i];
		else ans += x - a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 4044
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  string s;
  int a, b;
  while (cin >> s >> a >> b) {
    cout << s << ' ' << a + b << ' ' << 200 * a + 300 * b << endl;
  }
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef pair<ll,ll> pl;
 
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()
//#define max(a,b) (a>b ? a : b)
//#define min(a,b) (a<b ? a : b)
 
const int MOD = 998244353;
const int INF = 100000002;
const double PI =4*atan(1);
const double eps = 1e-7;
const long long oo = 1e18;


int main(){
  int n,m;
  cin >> n >> m;
  int ans = n*(n-1)/2 + m*(m-1)/2;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    ll N;
    cin >> N;
    ll ans = 0;
    rep(i, N) ans += (i+1)*(N-i);
    rep(i, N-1){
        ll u, v;
        cin >> u >> v;
        u--, v--;
        if(u > v) swap(u, v);
        ans -= (u+1)*(N-v);
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {	
        cin>>v[i];
    }
    int ans=0;
    for (int i = 0; i+2 < n; ++i) {
        if(v[i]<v[i+1]&&v[i+2]<v[i+1])continue;
        if(v[i]>v[i+1]&&v[i+2]>v[i+1])continue;
        ++ans;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int A, B, Q;
  cin >> A >> B >> Q;
  vector<long> S(A), T(B);
  for (auto &s : S) cin >> s;
  for (auto &t : T) cin >> t;
  for (long x; cin >> x;) {
    int it = lower_bound(S.begin(), S.end(), x) - S.begin();
    long a = S.at(max(0, it - 1)), b = S.at(min(A - 1, it));
    it = lower_bound(T.begin(), T.end(), x) - T.begin();
    long c = T.at(max(0, it - 1)), d = T.at(min(B - 1, it));
    long ans = 2e18;
    ans = min(ans, abs(x - a) + abs(a - c));
    ans = min(ans, abs(x - a) + abs(a - d));
    ans = min(ans, abs(x - b) + abs(b - c));
    ans = min(ans, abs(x - b) + abs(b - d));
    ans = min(ans, abs(x - c) + abs(c - a));
    ans = min(ans, abs(x - c) + abs(c - b));
    ans = min(ans, abs(x - d) + abs(d - a));
    ans = min(ans, abs(x - d) + abs(d - b));
    cout << ans << "\n";
  }
}

Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

typedef ll Weight;
typedef vector<vector<Weight>> Graph;
void add_edge(vector<vector<Weight>>& g, Weight from, Weight to, bool isDirected) {
	g[from].push_back(to);
	if (!isDirected) g[to].push_back(from);
}

template<class T> inline bool chmax(T& a, T b) { if (a <= b) { a = b; return true; } else return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

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

  ll l, r, d; cin >> l >> r >> d;

	cout << r/d - (l-1)/d << endl;
}

Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine()
                .Split(' ')
                .Select(x => int.Parse(x))
                .ToArray();
            var n = str[0];
            var y = str[1];
            var isOk = false;
            int sen = -1;
            int ichiman = -1;
            int gosen = -1;
            for (int i = 0; i <= n; i++)
            {
                var unti = 10000 * i;
                for (int j = 0; j <= n - i; j++)
                {
                    unti += 5000 * j;
                    var xx = n - j - i;
                    unti += 1000 * xx;
                    if (unti == y)
                    {
                        isOk = true;
                        ichiman = i;
                        gosen = j;
                        sen = xx;
                        break;
                    }
                    else
                    {
                        unti -= (5000 * j + 1000 * xx);
                    }
                }
            }
            if (isOk)
                Console.WriteLine(ichiman + " " + gosen + " " + sen);
            else
                Console.WriteLine(-1 + " " + -1 + " " + -1);
            Console.ReadLine();
        }
    }
}



Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) //fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=2e5+50;

int n,p[N],f[N],T[N],q[N]; 

bool chk(int a,int b,int c){
	return (a<b&&b<c)||(b<c&&c<a)||(c<a&&a<b); 
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	read(n);
	rep(i,1,n){
		read(p[i]);
		q[p[i]]=i;
	}
	T[n]=0,f[n]=n;
	dec(i,n-1,1){
		if(T[i+1]==0){
			if(q[i]>q[i+1]){
				T[i]=1;
				f[i]=i+1; 
			}else{
				T[i]=0; 
			}
		}else{
			if(chk(q[f[i+1]],q[i],q[i+1])){
				T[i]=T[i+1]; 
				f[i]=f[i+1];
			}else{
				T[i]=T[i+1]+1;
				f[i]=i+1; 
			}
		}
	}
	printf("%d\n",T[1]); 
	return 0;
}


Measured memory_bytes: 3328
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let a = input::<i64>();
    let b = input::<i64>();
    let c = input::<i64>();

    let ans = std::cmp::max(
        10 * a + b + c,
        std::cmp::max(10 * b + c + a, 10 * c + a + b),
    );
    println!("{}", ans);
}


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

using namespace std;
typedef long long LL;
int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
LL read() {
	LL s = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
	return s * f;
}
void put(LL x) {
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

LL gcd(LL a, LL b) {return b == 0 ? a : gcd(b, a % b);}

int main() {
	LL n = read(), x = read();
	put((LL)3LL * (n - gcd(n, x)));
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int N, L;
    cin >> N >> L;

    int minA = 100000;
    int minIndex = 100000;
    int sum = 0;
    for(int i = 1; i <= N; ++i){
        if(minA > abs(L+i-1)){
            minA = abs(L+i-1);
            minIndex = i;
        }
        sum += (L+i-1);
    }
    cout << sum-(L+minIndex-1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 2e5+5;
int h[maxn],a[maxn]; LL A[maxn], bit[maxn];

void upd(const int i, const LL v)
{
    A[i] = v;
    for (int x = i; x < maxn; x |= (x+1)) {
        bit[x] = A[x];
        for (int j = x-1; j > (x&(x+1))-1; j = (j&(j+1))-1)
            bit[x] = max(bit[x],bit[j]);
    }
}

LL get(const int i, const int j)
{
    LL ans = A[j]; int x = j;
    while (i < x) {
        for (x -= 1; x >= i + x - (x&(x+1))+1; x = (x&(x+1))-1)
            ans = max(ans,bit[x]);
        ans = max(ans,A[x]);
    }
    return ans;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
        FOR(i,0,n)
            cin >> h[i];
        FOR(i,0,n)
            cin >> a[i];
        memset(A,0,sizeof(A));
        memset(bit,0,sizeof(bit));
        FOR(i,0,n) {
            const LL x = get(0,h[i]) + a[i];
            upd(h[i],x);
        }
        LL ans = 0;
        FOR(i,0,maxn)
            ans = max(ans,A[i]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <ext/rope>
using namespace std;
using namespace __gnu_cxx;

using ci = const int;
using ld = long double;
using llint = long long;
using ullint = unsigned long long;
using pii = pair <int,int>;
using pcc = pair <char,char>;
using pll = pair <llint,llint>;
using pss = pair <string,string>;
using vi = vector <int>;
using vb = vector <bool>;
using vll = vector <llint>;
using vii = vi::iterator;

#define INF (1<<30)
#define MOD 1000000007
#define mt make_tuple
#define all(c) c.begin(), c.end()
#define ms(name,val) memset(name, val, sizeof name)
#define np nullptr
// inline functions



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

    int n, k;
    cin >> n >> k;
    vi v(n), dp(n+1, INF);

    for (int t1 = 0; t1 < n; ++t1)
        cin >> v[t1];

    dp[0] = 0;
    dp[1] = abs(v[0]-v[1]);

    for (int t1 = 2; t1 < n; ++t1)
    {
        for (int t2 = 1; t1-t2 >= 0 && t2 <= k; ++t2)
            dp[t1] = min(dp[t1], dp[t1-t2] + abs(v[t1]-v[t1-t2]));
    }

    cout << dp[n-1] << '\n';






























    return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n;
li a[111];
int main() {
    cin >> n;
    cout << ((n == 7 || n == 5 || n == 3) ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int min(int a,int b){
    return a<b?a:b;
}
int main(void){
    int N,K;
    cin >> N >> K;
    int H[N];
    for(int i=0;i<N;i++){
        cin >> H[i];
    }
    long long ans = 0;
    for(int i=0;i<N;i++){
        ans += H[i];
    }
    sort(H,H+N,greater<int>());
    for(int i=0;i<K;i++){
        if(i >= N)break;
        ans -= H[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3912
N = int(input())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

res = 0
for _, x in factorization(N):
    i = 1
    while i <= x:
        res += 1
        x -= i
        i += 1
if N == 1:
    print(0)
else:
    print(res)

Measured memory_bytes: 9404
import collections

N = int(input())
S = []

for _ in range(N):
    S.append(input())
    
c = collections.Counter(S)
m = c.most_common()
mc = m[0][1]
a = list(filter(lambda x: x[1] == mc, m))
b = sorted(a)
for e in b:
    print(e[0])


Measured memory_bytes: 49172
a,b = map(int,input().split())

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table
  
s = set(prime_decomposition(a))
t = set(prime_decomposition(b))

print(len(s&t) + 1)

Measured memory_bytes: 3060
#include <cstdio>
#include <set>
#define LL long long
using namespace std;

multiset<LL> s;
LL cl[300005], cr[300005];
int arr[300005];

int main(){
	int n; scanf("%d",&n);
	long long sum = 0;
	for(int i = 0; i < n*3; i++ ){
		scanf("%d",&arr[i]);
		s.insert(arr[i]);
		sum += arr[i];
		if(s.size()>n) sum -= *s.begin(), s.erase(s.begin());
		cl[i] = sum;
	}
	sum = 0; s.clear();
	for(int i = n*3-1; i >= 0; i-- ){
		s.insert(arr[i]);
		sum += arr[i];
		if(s.size()>n){
			auto it = s.end(); --it;
			sum -= *it; s.erase(it);
		}
		cr[i] = sum;
	}
	LL ans = -1000000000000000000ll;
	for(int i = n-1; i < n*2; i++ ){
		ans = max(ans, cl[i]-cr[i+1]);
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 10752
import java.io.*;
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.math.BigDecimal;

public class Main{

    public static void main(String[] args){
        //START

        Scanner sc=new Scanner(System.in);

        String S=sc.next();
        String[] strArray = S.split("");

        int i=0;
        for(i=0;i<3;i++){
            System.out.print(strArray[i]);
        }

        //END
    }
}



Measured memory_bytes: 35552
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int n[4];
int main() {
	for (int i = 0; i < 4; i++)
		scanf("%d", n + i);
	sort(n, n + 4);
	bool m = n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9;
	printf(m ? "YES\n" : "NO\n");
}

Measured memory_bytes: 128
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.parents = [-1] * n

        def find(self, x):
            if self.parents[x] < 0:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]

        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)

            if x == y:
                return

            if self.parents[x] > self.parents[y]:
                x, y = y, x

            self.parents[x] += self.parents[y]
            self.parents[y] = x

        def size(self, x):
            return -self.parents[self.find(x)]

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

        def members(self, x):
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]

        def roots(self):
            return [i for i, x in enumerate(self.parents) if x < 0]

        def group_count(self):
            return len(self.roots())

        def all_group_members(self):
            return {r: self.members(r) for r in self.roots()}

        def __str__(self):
            return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    n, m = LI()
    uf = UnionFind(n)

    for i in range(m):
        a, b = LI()
        a -= 1
        b -= 1
        uf.union(a, b)

    ans = len(uf.roots())-1
    print(ans)


main()





Measured memory_bytes: 74980
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/rope>

using namespace __gnu_pbds; 
using namespace __gnu_cxx;
using namespace std;
using ll = long long;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define precision(n) fixed<<setprecision(n)

#ifdef LOCAL
    #include "debug.h"
#else
    #define debug(...) 42
#endif

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}

template<typename T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update >;
template<typename T> using MinPriorityQueue = priority_queue <T, vector <T>, greater <T> >;
template<typename T> void done(T ans) {cout << ans << "\n"; exit(0);}


template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}

 

const int mod = 1e9;
const int N = 3e5 + 5;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937_64 mt(seed);

template <typename T>
long long myrand(T m) {
    long long mod = m;
    long long x = mt()%mod;

    return x;
}

int a[N];
vector <int> ans(N);
vector <int> adj[N];
multiset <int> s;

void dfs(int node, int parent = 0) {
    s.insert(a[node]);
    int del = -1;
    auto it = s.lower_bound(a[node]);
    if( ++it != s.end()) {
        del=*it;
        s.erase(it);
    }
    ans[node - 1] = s.size();
    
    for(auto child : adj[node])
        if(child != parent) 
            dfs(child,node);
    
    if(del != -1) 
        s.insert(del);

    s.erase(s.find(a[node]));
}

int main()
{
    io();
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) 
        cin >> a[i];
    for(int i = 0 ; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dfs(1);
    ans.resize(n);
    cout << ans << " ";
}




Measured memory_bytes: 35652
n = int(input())
w = list(map(int, input().split()))

ans = 10**9
for i in range(n):
    s1 = 0
    s2 = 0
    for j in range(i):
        s1 += w[j]
    for k in range(i,n):
        s2 += w[k]
    ans = min(ans, abs(s1-s2))
    
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using ll = long long;

int main() {
    vii a(3, vi(3));
    rep(i, 3) rep(j, 3) cin >> a.at(i).at(j);
    int n; cin >> n;
    vii b(3, vi(3));

    rep(i, n) {
        int x; cin >> x;
        rep(i, 3) rep(j, 3) if (a.at(i).at(j) == x)b.at(i).at(j) = 1;
    }

    bool ans = false;

    rep(i, 3) {
        int cnt = 0;
        rep (j, 3) cnt += b.at(i).at(j);
        if (cnt == 3) ans = true;
    }

    rep(i, 3) {
        int cnt = 0;
        rep (j, 3) cnt += b.at(j).at(i);
        if (cnt == 3) ans = true;
    }

    {
        int cnt = 0;
        rep (j, 3) cnt += b.at(j).at(j);
        if (cnt == 3) ans = true;
    }

    {
        int cnt = 0;
        rep (j, 3) cnt += b.at(j).at(2 - j);
        if (cnt == 3) ans = true;
    }

    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;


}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,X,Y; cin >> N >> X >> Y; --X,--Y;
    vector<int> cnt(N,0);
    for (int i=0;i<N;++i){
        for (int j=i+1;j<N;++j){
            if (j<=X||Y<=i) ++cnt[j-i];
            else if (i<=X&&X<=j&&j<=Y) ++cnt[min(j-i,X-i+1+Y-j)];
            else if (i<=X&&Y<=j) ++cnt[X-i+1+j-Y];
            else if (j<=Y) ++cnt[min(j-i,i-X+1+Y-j)];
            else ++cnt[min(j-i,i-X+1+j-Y)];
        }
    }
    for (int i=1;i<N;++i) cout << cnt[i] << '\n';
}

Measured memory_bytes: 256
a,b,c = map(int,input().split())
k = int(input())
count = 0
for i in range(k):
    if b <= a:
        b = b * 2
        count += 1
    elif a < b and c <= b:
        c = c * 2
        count += 1
    if count == k:
        break

if a < b and b < c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9184
college = Array.new(4).map { [  
                               ['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                               ['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                               ['', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
                             ] }

input = []

gets.to_i.times do
  input << gets.split(' ').map(&:to_i)
end

input.each do |e|
  b, f, r, v = e
  college[b - 1][f - 1][r] = college[b - 1][f - 1][r] + v
end

college.each_with_index do |ary, i|
  puts ary.map{ |e| e.join(' ') }.join("\n")
  break if college.size - 1 == i
  puts '#' * 20
end

Measured memory_bytes: 8768
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   ll a,b,c,d,e,k;
   cin>>a>>b>>c>>d>>e>>k;
  if(e-a<=k)
  {
      cout<<"Yay!"<<endl;
  }
  else{
    cout<<":("<<endl;
  }
  return 0;

}



Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();
        sc.close();

        long sum = 100;
        int count = 0;
        do {
            sum = (long) (sum * 1.01);
            count++;

        } while (sum < X);

        System.out.println(count);

    }

}


Measured memory_bytes: 35740
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

int e()
{
  return -1;
}

int op(int a, int b)
{
  return max(a, b);
}

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

  vector<int> a(n);
  for (auto&& e : a) {
    cin >> e;
  }

  segtree<int, op, e> seg(a);

  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      int x, v;
      cin >> x >> v;
      x--;
      seg.set(x, v);
    } else if (t == 2) {
      int l, r;
      cin >> l >> r;
      l--;
      cout << seg.prod(l, r) << endl;
    } else {
      int x, v;
      cin >> x >> v;
      x--;
      cout << seg.max_right(x, [&](auto a){return a < v;}) + 1 << endl;
    }
  }
}


Measured memory_bytes: 6120
#include <stdio.h> 
int main(){
    int n,m;
    scanf("%d%d", &n, &m);
    if(n>=m) {
        for(int i = 0;i < n;i++){
            printf("%d", m);
        }
    }
    else {
        for(int i = 0;i < m;i++){
            printf("%d", n);
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#define N 45
int main(){
  int total,i,fib[N]={1,1};
  for(i=2;i<N;i++){
    fib[i]=fib[i-1]+fib[i-2];
  }
  scanf("%d",&total);
  printf("%d\n",fib[total]);
  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<double, double >pd;
typedef pair<string, string> sP;
typedef pair<ll, pair<ll, ll>> PP;


const ll mod = 1e4;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const double eps = 1e-10;
const double PI = 3.14159265358979323846;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

ll FACT[1001100] = { 0 }, IFACT[1001100] = { 0 };

ll extgcd(ll a, ll b, ll &x, ll &y) {
	ll g = a;
	x = 1;
	y = 0;
	if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
	return g;
}
ll invMod(ll a, ll m) {
	ll x, y;
	if (extgcd(a, m, x, y) == 1) return (x + m) % m;
	else                         return 0;
}
ll mod_pow(ll x, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x%MOD;
		x = x * x%MOD;
		n >>= 1;
	}
	return res;
}
void inverse(ll N) {
	FACT[0] = 1;
	IFACT[0] = 1;
	for (int i = 1;i <= N;i++) {
		FACT[i] = FACT[i - 1] * i % MOD;
		IFACT[i] = invMod(FACT[i], MOD);
	}
}
ll combi(ll n, ll r) {
	if (n < 0 || r < 0 || r > n)return 0;
	if (r > n / 2)r = n - r;
	return FACT[n] * IFACT[n - r] % MOD*IFACT[r] % MOD;
}

int main() {	
	ll n, ans = 0;
	cin >> n;
	inverse(n);
	if (n == 2) {
		cout << 1 << endl;
		return 0;
	}
	if (n == 3) {
		cout << 4 << endl;
		return 0;
	}
	ll now = 0;
	for (int i = (n + 1) / 2;i <= n - 1;i++) {
		ll x= ((((combi(i - 1, n - i - 1)*FACT[i]) % MOD) * FACT[n - i - 1]) % MOD);
		//動かさない要素の選び方　動かす要素の順番　動かさない要素の順番
		ans += (x - now + MOD)*i % MOD;
		now = x;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
int a[1001];
int main()
{
    int n;
    cin>>n;
    int maxx=0,minx=1000;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        if(maxx<x)maxx=x;
        if(minx>x)minx=x;
    }
    cout<<maxx-minx<<endl;
    return 0;
}


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

#define FOR(i,a,n) for(int i = (a); i < (n); ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

int main() {
  int a, b; cin >> a >> b;
  int ans = 0;
  FOR(i, a, b+1) {
    if(i%10 == i/10000 && (i/10)%10 == (i/1000)%10) ans ++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

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

        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
        }
        //累積和
        long[] b = new long[n];
        long c = 0;
        for (int i = 0 ; i < n ; i++) {
            c += (long) a[i];
            b[i] = c;
        }
        int l = 0;
        int r = 2;
        long ans = Long.MAX_VALUE;
        for (int i = 1 ; i <= n - 3 ; i++) {

            long minDiff = Long.MAX_VALUE;
            for (int j = l ; j <= i - 1 ; j++) {
                long diffLeft = Math.abs(b[i] - b[j] - b[j]);
                if (diffLeft < minDiff) {
                    minDiff = diffLeft;
                    l = j;
                } else {
                    break;
                }
            }
            minDiff = Long.MAX_VALUE;
            for (int j = r ; j <= n - 2; j++) {
                long diffRight = Math.abs(b[j] - b[i] - (b[n - 1] - b[j]));
                if (diffRight < minDiff) {
                    minDiff = diffRight;
                    r = j;
                } else {
                    break;
                }
            }

            long p = b[l];
            long q = b[i] - b[l];
            long x = b[r] - b[i];
            long y = b[n - 1] - b[r];
            long max = Math.max(Math.max(p, q), Math.max(x, y));
            long min = Math.min(Math.min(p, q), Math.min(x, y));
            ans = Math.min(ans, Math.abs(max - min));
        }

        System.out.println(ans);

    }

}

Measured memory_bytes: 66232
#include<stdio.h>
#define MAX 100000
#define NIL -1
 
struct Node{
  int parent;
  int left;
  int right;
};

struct Node T[MAX];
void Print(int);

int dep;
 
int main(){
  int d, v, c, l, n, tmp;
  int i, j;

    scanf("%d", &n);
       
    for(i=0; i<n; i++){
	  T[i].parent = NIL;
	  T[i].left = NIL;
	  T[i].right = NIL;
    }

    for(i=0; i<n; i++){
      scanf("%d%d%d", &v, &d, &c);
             T[d].parent = v;
			 T[c].parent = v;
             T[v].left = d;
             T[v].right = c;
    }
       
    for(i=0; i<n; i++) Print(i);

    return 0;
}
 
int Depth(int node)
{
  if(T[node].parent == NIL) return 0;
  if(T[node].parent != NIL){
	dep++;
	Depth(T[node].parent);
  }
  return dep;
}

int Degree(int node)
{
    if(T[node].left == NIL && T[node].right == NIL) return 0;
    else if(T[node].left != NIL && T[node].right != NIL) return 2;
    else  return 1;
}

int Sibling(int node){
  if(T[node].parent == NIL) return NIL;
  else if(T[T[node].parent].left == node) return T[T[node].parent].right;
  else return T[T[node].parent].left;
}
  
int Hight(int node)
{
  int hilef = 0, hiri = 0;

  if(T[node].left != NIL) {
	hilef = Hight(T[node].left) +1;
  }
  if(T[node].right != NIL){
	hiri = Hight(T[node].right) +1;
  }
  if(hilef < hiri) return hiri;
  else return hilef;
}
 
   
void Print(int node){
  printf("node %d: ", node);
  printf("parent = %d, ", T[node].parent);
  printf("sibling = %d, ", Sibling(node));
  printf("degree = %d, ", Degree(node));
  dep=0;
  printf("depth = %d, ", Depth(node));
  printf("height = %d, ", Hight(node));
   
  if(T[node].parent == NIL) printf("root\n");
  else if(T[node].left == NIL && T[node].right == NIL) printf("leaf\n");
  else printf("internal node\n");
}

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

int N;
vector<int> p, q;

int main() {
    cin >> N;
    vector<int> p(N), q(N);
    for (int i = 0; i < N; ++i) cin >> p[i], --p[i];
    for (int i = 0; i < N; ++i) cin >> q[i], --q[i];

    // 各順列が何番目かを求める
    map<vector<int>, int> ord;
    int iter = 0;

    // スタートとなる順列
    vector<int> v(N);
    for (int i = 0; i < N; ++i) v[i] = i;

    // 順番に
    do {
        ord[v] = iter++;
    } while (next_permutation(v.begin(), v.end()));

    cout << abs(ord[p] - ord[q]) << endl;
}

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

using namespace std;

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



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int S,h,m,s;
    cin >> S;
    h = S/3600; S %= 3600;
    m = S/60; S %= 60;
    s = S;
    cout <<h<<":"<<m<<":"<<s<< endl;
    return 0;
}

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

int main(){
	ll n;
	cin>>n;
	ll a[n+1],b[n],count=0;
	rep(i,n+1)cin>>a[i];
	rep(i,n)cin>>b[i];
	rep(i,n+1){
		if(i==0){
			count+=min(a[i],b[i]);
			b[i]-=min(a[i],b[i]);
			continue;
		}
		if(i==n){
			count+=min(a[i],b[i-1]);
			continue;
		}
		count+=min(a[i],b[i-1]);
		a[i]-=min(a[i],b[i-1]);
		count+=min(a[i],b[i]);
		b[i]-=min(a[i],b[i]);
	}
	puts(count);
}


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

using namespace std;

int a[1234567];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    a[i]--;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[a[i]] == i) {
      ans++;
    }
  }
  printf("%d\n", ans / 2);
  return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        //Solve();
        WriteLine(Solve());
    }
    static string Solve()
    {
        var hw = Input.ar;
        var gred = Input.gred(hw[0]);
        var dic = new Dictionary<char, int>();
        for (var i = 0; i < Input.Alfa.Length; i++)
            dic[Input.Alfa[i]] = 0;
        for (var i = 0; i < hw[0]; i++)
            for (var j = 0; j < hw[1]; j++)
                dic[gred[i][j]]++;
        var ct = new[] { 0, 0, 0 };//4,2,1
        if (hw[0] % 2 == 0 && hw[1] % 2 == 0)
            ct[0] = hw[0] * hw[1] / 4;
        else if (hw[0] % 2 == 1 && hw[1] % 2 == 1)
        {
            ct[0] = (hw[0] / 2) * (hw[1] / 2);
            ct[1] = hw[0] / 2 + hw[1] / 2;
            ct[2] = 1;
        }
        else
        {
            ct[0] = (hw[0] / 2) * (hw[1] / 2);
            if (hw[0] % 2 == 0)
                ct[1] = hw[0] / 2;
            else ct[1] = hw[1] / 2;
        }
        var ar = new[] { 4, 2, 1 };
        foreach (var val in dic.Values)
        {
            var n = val;
            for (var j = 0; j < 3; j++)
                if (n / ar[j] > ct[j])
                {
                    n -= ct[j] * ar[j];
                    ct[j] = 0;
                }
                else
                {
                    ct[j] -= n / ar[j];
                    n %= ar[j];
                }
            if (n != 0) return "No";
        }
        return "Yes";
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 13408