akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int)N;i++)
#define p(s) cout<<(s)<<endl
#define ck(n,a,b) ((a)<=(n)&&(n)<=(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf=1e9;

int a[30];
int main() {
	string s;
	cin>>s;
	int cnt;
	int ans=101,mx=0;
	for(int j='a';j<='z';j++){
		cnt=0;
		mx=0;
		REP(i,0,s.size()){
			if(s[i]!=j){
				cnt++;
			}else{
				mx=max(mx,cnt);
				cnt=0;
			}
		}
		mx=max(mx,cnt);
		ans=min(ans,mx);
	}
	p(ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0; i<N; i++)
#define lint long long
#define square_vector(name,N,M) vector<vector<lint>>name(N,vector<lint>(M,0))
#define sort(V) sort(V.begin(),V.end())

int main() {
  int N;
  cin >> N;
  vector<int> BBB(N+1,0);
  int po;
  rep(i,N-1) {
    cin >> po;
    BBB[po]++;
  }
  rep(i,N) {
    cout << BBB[i+1] << endl;
  }
  return 0;
}

Measured memory_bytes: 4048
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        for(int i = 1;;i++){
            int x = sc.nextInt();
            if(x == 0){
                break;
            }
            System.out.println("Case "+i+": "+x);
            
        }
        sc.close();
    }
}


Measured memory_bytes: 41368
#include<iostream>
#include<vector>
using namespace std;
vector<int> ans;
int n, b[102];
void rmv(int pos){
    for (int i=pos+1;i<=n;i++)
        b[i-1] = b[i];
    n--;
}
int main(void){
    cin >> n;
    for (int i=1;i<=n;i++)
        cin >> b[i];
    while(n>0){
        bool found = false;
        for (int i=n;i>=1;i--){
            if (b[i]==i) {
                rmv(i);
                ans.push_back(i);
                found = true;
                break;
            }
        }
        if (!found) {
            cout << -1 << endl;
            return 0;
        }
    }
    for (int i=ans.size()-1;i>=0;i--){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include<map>
#include<set>
using namespace std;

int main() {
    map<string, int> m;
    int n, maxv = 0;
    string s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s;
        m[s]++;
        maxv = max(maxv, m[s]);
    }
    for (map<string, int>::iterator it = m.begin();it != m.end();it++) {
        pair<string, int> item = *it;
        if (item.second == maxv) cout << item.first << endl;
    }
}


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

int main(){
	string s;
	cin >> s;
	int size = (int) s.length();
	char first = s[0];
	if (size == 1) {cout << s; return 0;}
	bool flag = true;
	
	for (int i =1; i< size; i++){
		if (s[i] != '9') flag = false;
	}
	if (!flag) {cout << (int) (first-'0')-1+(size-1)*9; return 0;}
	else {cout << (int) (first-'0') + (size-1)*9; return 0;}
	
	

	
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=11,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

char s[MAXn][MAXn];
bool vis[MAXn][MAXn];
int main(){
    IOS();
    int n,m;
    cin >> n >> m;
    int lstmx = 0;
    bool fg = true;
    for (int i=0;i<n;++i) {
        int mx = 0;
        for (int j=0;j<m;++j) {
            cin >> s[i][j];
            if (s[i][j] == '#') {
                mx = max(mx,j);
                if (lstmx > j) {
                    fg = false;
                }
            }
        }
        lstmx = mx;
    }
    if (fg) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}


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

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String lineA = br.readLine();
		String lineB = br.readLine();
		String lineH = br.readLine();
		int a = Integer.parseInt(lineA);
		int b = Integer.parseInt(lineB);
		int h = Integer.parseInt(lineH);
		System.out.println((a + b) * h / 2);
	}
}


Measured memory_bytes: 8148
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
/*int p = 998244353;*/
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define sq(a) (a)*(a)
#define rev(s) reverse(s.begin(),s.end())
#define end_pr(s) cout << s <<endl;return 0
#define itn int
int RE() {
	vel v(3, 2);
	return v.at(4);
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a,p - 2);
}
vel dis(int mid1, vvel &way) {
	int n = way.size();
	vel dist(n, -1); dist[mid1] = 0;
	queue<int> q;
	q.push(mid1);
	while (!q.empty()) {
		int st = q.front(); q.pop();
		rep(i, way[st].size()) {
			int to = way[st][i];
			if (dist[to] == -1) {
				dist[to] = dist[st] + 1;
				q.push(to);
			}
		}
	}
	return dist;
}
pin most_far(int now, int n, vvel &way) {
	vel dist1 = dis(now, way);
	pin ans = mkp(-1, 0);
	rep(i, n) {
		if (dist1[i] > ans.first) { ans = mkp(dist1[i], i); }
	}
	return ans;
}

template<typename T>
V<T> uni(V<T> &v) {
	if (v.size() == 0) { return v; }
	sor(v);
	V<T> ans(1, v[0]);
	for (int i = 1; i < v.size(); i++) {
		if (v[i] != v[i - 1]) { ans.push_back(v[i]); }
	}
	v = ans;
	return v;
}
int s_gcd(int a, int b) {
	if (b == 0) { return a; }
	return s_gcd(b, a%b);
}
int gcd(int a, int b) {
	if (a < b) { swap(a, b); }
	return s_gcd(a, b);
}
vel par;
vel dp;
vvel chi;
int top(int i) {
	if (par[i] < 0) { return i; }
	int ans = top(par[i]);
	par[i] = ans;
	return ans;
}
void merge(int x, int y) {
	par[y] += par[x];
	par[x] = y;
	chi[y].push_back(x);
}
void solve(int now_pot) {
	for (auto x : chi[now_pot]) {
		dp[x] += dp[now_pot];
		solve(x);
	}
}
signed main() {
	int n; cin >> n;
	V<qin> edge(n - 1);
	rep(i, n - 1) {
		int a, b, c; cin >> a >> b >> c;
		a--; b--;
		edge[i] = mkp(c, mkp(a, b));
	}
	par = vel(n, -1);
	dp = vel(n, 0);
	chi = vvel(n);
	vel ans(n,0);
	sor(edge); rev(edge);
	rep(i, n - 1) {
		int c = edge[i].first;
		pin ed = edge[i].second;
		int x = ed.first;
		int y = ed.second;
		x = top(x); y = top(y);
		if (chi[x].size()<chi[y].size()) { swap(x, y); }
		int szx = par[x] * -1;
		int szy = par[y] * -1;//par[x]=yにあとでする
		ans[y] += szx * c;
		for (auto st : chi[y]) {
			dp[st] += szx * c;
		}
		dp[x] += szy * c;
		merge(x, y);
	}
	solve(top(0));
	int ret = 0;
	rep(i, n) {
		cout << ans[i] + dp[i] << endl;
	}
}


Measured memory_bytes: 14976
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(long long i=0; i<x;i++)
#define mod 1000000007
#define INF 10000000000000000
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


struct UnionFind {
	vector<int> par;
  
  UnionFind(int N): par(N){
  	for(int i=0;i<N;i++) par[i] =i;
  }
};





int main(){
  ios::sync_with_stdio(false);
  
  int N,W;
  cin>>N>>W;
  ll w[N],v[N];
 
  
  rep(i,N) cin>>w[i]>>v[i];
  ll dp[W+1];
  rep(j,W+1) dp[j] =0;
  
  for(int i=0;i<N;i++){
   for(int j=W;j>=w[i];j--){		
      if(j==w[i]){
      	dp[j] =max(dp[j],v[i]);
      }else if(dp[j-w[i]] != 0){
      	dp[j] = max(dp[j],dp[j-w[i]] +v[i]);
      }
   }
  }
  
  ll ans=0;
  rep(i,W+1) ans = max(ans,dp[i]);
  
  cout<<ans;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h> 
    using namespace std;
    typedef long long ll;
    const int N=2e5+5;
    const int mod=1e9+7;
    ll ans;
    int n;
    ll A[N];
    ll B[N];
    int main()
    {
        ios::sync_with_stdio(false);
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>A[i];
            B[i]=B[i-1]+A[i];
        }
        for(int i=1;i<=n;i++)
            ans=(ans+(A[i]*((B[n]-B[i])%mod))%mod)%mod;
        cout<<ans<<endl;
    }

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

int main(){
  	int N, M, cnt=0;
  	cin >> N >> M;
  	double A[N], sum=0;
  	for(int i=0; i<N; i++){
    	cin >> A[i];
      	sum+=A[i];
    }
  	double sum2=sum/(4*M);
  
  	for(int i=0; i<N; i++){
    	if(A[i]>=sum2){
        	cnt++;
        }
    }
  	if(cnt>=M){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }
	return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<string,ll> P;

void Main() {
  ll n;
  R n;
  P a[n];
  rep(i,n) cin >> a[i].F >> a[i].S;
  string s;
  R s;
  int ans=0,f=0;
  rep(i,n) {
    if(f) ans+=a[i].S;
    if(a[i].F==s) f=1;
  }
  pr(ans);
}

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


Measured memory_bytes: 256
n, k = map(int, input().split())
ps = list(map(int, input().split()))

# expectancy 1 + 2 + ... + p / p = p * (p + 1) / p / 2 = (p + 1) / 2

sum_max = 0
for i in range(k - 1, n):
    if i == k - 1:
        sum_now = sum(ps[:i + 1])
    else:
        sum_now = sum_now + ps[i] - ps[i - k]
    sum_max = max(sum_max, sum_now)

print((sum_max + k) / 2)

Measured memory_bytes: 24548
#include"bits/stdc++.h"
#include<cstring>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
 
int main(){
	int n;
	map<int,int>mp;
	cin>>n;
	vector<int>a(n);
	rep(i,n-1){
		cin>>a[i];
		mp[a[i]]++;
	}
	// for(auto p:mp){
	// 	cout<<p.second<<endl;
	// }
	for(int i=1;i<=n;++i){
		cout<<mp[i]<<endl;
	}
}

Measured memory_bytes: 13444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n;
  bool a = true;
  in(n);
  vector<string> s(n);
  rep(i, n)
    in(s[i]);
  rep(i, n - 1){
    if(s[i][s[i].size() - 1] != s[i + 1][0])
      a = false;
  }
  rep(i, n - 1){
    rep2(j, i + 1, n){
      if(s[i] == s[j])
        a = false;
    }
  }
  if(a)
    out("Yes");
  else
    out("No");
  memi;
}

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

namespace ConsoleApplication2
{
    class Program
    {



        public static void Main(string[] args)
        {
            var NM = System.Console.ReadLine().Split();
            int N = int.Parse(NM[0]);
            int M = int.Parse(NM[1]);

            bool[] from1 = new bool[N+1];
            bool[] toN = new bool[N+1];

            for (int i = 0; i < M; i++)
            {
                var ab = System.Console.ReadLine().Split();
                int a = int.Parse(ab[0]);
                int b = int.Parse(ab[1]);

                if (a == 1)
                {
                    from1[b] = true;
                    if (toN[b] == true)
                    {
                        System.Console.WriteLine("POSSIBLE");
                        return;
                    }
                }

                if (b == N)
                {
                    toN[a] = true;
                    if (from1[a] == true)
                    {
                        System.Console.WriteLine("POSSIBLE");
                        return;
                    }
                }
            }

            System.Console.WriteLine("IMPOSSIBLE");
        }
    }
}











Measured memory_bytes: 15408
#include <bits/stdc++.h>
using namespace std;
int n;
long long s, mn = 1e9 + 1;
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		long long a, b;
		scanf("%lld%lld", &a, &b);
		s += a;
		if(a > b) {
			mn = min(mn, b);
		}
	}
	if(mn == 1e9 + 1) {
		printf("%d\n", 0);
	} else {
		printf("%lld\n", s - mn);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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
import random

#--------ピ　ザ　群　最　適　化------------------------------

#評価関数: 　双対問題
def criterion(x, y):
    z=xo*x+yo*y

    if x>a or y>b or x+y>2*c or x<0 or y<0:
        z=-z
    
    return z

#粒子の位置の更新を行う関数
def update_position(x, y, vx, vy):
 
    new_x = x + vx
    new_y = y + vy

    return new_x, new_y

#粒子の速度の更新を行う関数
def update_velocity(x, y, vx, vy, p, g, w=1, ro_max=0.5,v_max=10):
    #パラメーターroはランダムに与える
    ro1 =random.uniform(0, ro_max)
    ro2 =random.uniform(0, ro_max)
    #粒子速度の更新を行う
    new_vx = int((w * vx + ro1 * (p["x"] - x) + ro2 * (g["x"] - x)))
    new_vy = int((w * vy + ro1 * (p["y"] - y) + ro2 * (g["y"] - y)))
    if abs(new_vx)>v_max:
        new_vx=int(v_max*new_vx/abs(new_vx))
    if abs(new_vy)>v_max:
        new_vy=int(v_max*new_vy/abs(new_vy))

    #print(new_vx, new_vy)
    return new_vx, new_vy
    
def main():
    N = 2000  #粒子の数
    x_min, x_max = 0, a
    y_min, y_max = 0, b
    #粒子位置, 速度, パーソナルベスト, グローバルベストの初期化を行う
    ps = [{"x": random.randint(x_min, x_max), 
        "y": random.randint(y_min, y_max)} for i in range(N)]
    vs = [{"x": 0, "y": 0} for i in range(N)]

    personal_best_positions = list(ps)
    personal_best_scores = [criterion(p["x"], p["y"]) for p in ps]

    best_particle = personal_best_scores.index(max(personal_best_scores))
    global_best_position = personal_best_positions[best_particle]

    T = 100  #制限時間(ループの回数)
    for t in range(T):
        for n in range(N):
            x, y = ps[n]["x"], ps[n]["y"]
            vx, vy = vs[n]["x"], vs[n]["y"]
            p = personal_best_positions[n]
            #粒子の位置の更新を行う
            new_x, new_y = update_position(x, y, vx, vy)
            ps[n] = {"x": new_x, "y": new_y}
            #粒子の速度の更新を行う
            new_vx, new_vy = update_velocity(
                new_x, new_y, vx, vy, p, global_best_position)
            vs[n] = {"x": new_vx, "y": new_vy}
            #評価値を求め, パーソナルベストの更新を行う
            score = criterion(new_x, new_y)
            if score > personal_best_scores[n]:
                personal_best_scores[n] = score
                personal_best_positions[n] = {"x": new_x, "y": new_y}
        #グローバルベストの更新を行う
        best_particle = personal_best_scores.index(max(personal_best_scores))
        global_best_position = personal_best_positions[best_particle]
#        print(max(personal_best_scores), global_best_position["x"], global_best_position["y"])

    #最適解
    return max(personal_best_scores), global_best_position["x"], global_best_position["y"]


#--------------------------------------------------------------

a, b, c, xo, yo = [int(i) for i in input().split()]
#a, b, c, xo, yo = 1500, 2000, 500, 90000, 100000
best=-100000000
xx=0
yy=0
for i in range(3):
    kouho_best, kouho_x, kouho_y=main()
    if best<kouho_best:
        best=kouho_best
        xx=kouho_x
        yy=kouho_y

print(best)



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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<(a-c)*(b-d)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long  N,D;
	cin>>N>>D;
	long long a,b;
	long long ans=0;
	for(int i=1;i<=N;i++)
	{
		cin>>a>>b;
		if(a*a+b*b<=D*D) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
using ll = long long;

int main() {
  ll N, C;
  std::cin >> N >> C;
  std::vector<std::pair<ll, ll>> xv(N);
  std::vector<ll> pnt_right(N);
  std::vector<ll> pnt_left(N);
  for (int i = 0; i < N; ++i) {
    ll x, v;
    std::cin >> x >> v;
    xv[i] = std::make_pair(x, v);
  }
  std::sort(
      xv.begin(), xv.end(),
      [](std::pair<ll, ll> i, std::pair<ll, ll> j) -> bool { return i.first < j.first; }
  );
  long long ans = 0ll;
  long long cur = 0ll;
  long long prev_pos = 0ll;
  for (int i = 0; i < N; ++i) {
    cur += xv[i].second - (xv[i].first - prev_pos);
    prev_pos = xv[i].first;
    ans = std::max(ans, cur);
    pnt_right[i] = ans;
  }
  cur = 0ll;
  prev_pos = C;
  long long ans2 = 0ll;
  for (int i = N - 1; i >= 0; --i) {
    cur += xv[i].second - (prev_pos - xv[i].first);
    prev_pos = xv[i].first;
    ans2 = std::max(ans2, cur);
    pnt_left[i] = ans2;
  }
  ans = std::max(ans, ans2);
  for (int i = 0; i < N - 1; ++i) {
    ans = std::max(ans, pnt_right[i] + pnt_left[i + 1] - xv[i].first);
  }
  for (int i = 0; i < N - 1; ++i) {
    ans = std::max(ans, pnt_right[i] + pnt_left[i + 1] - (C - xv[i + 1].first));
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 3328
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

x,y = gets.split.map(&:to_i)

flag = false
0.upto(x) do |tsuru|  # 0,1,2
  kame = x - tsuru
  if ((tsuru*2) + (kame*4)) == y
    flag = true
  end
end

puts flag ? "Yes" : "No"

# 1 1

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

#define MAX 120000
#define INF 1000000001;

int main() {
  int N, K, n, min = INF;
  int h[MAX], flag[MAX];

  std::cin >> N >> K;

  for(int i=0; i<N; ++i)
    std::cin >> h[i];

  std::sort(h, h+N);

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

  std::cout << min << "\n";

  return 0;
}


Measured memory_bytes: 640
h,w,k = gets.split(" ").map(&:to_i)

#読み込み
board = []
h.times do
    row = gets.chomp.split("").slice(0,w).map{|c| c=="." ? 0 : 1}
    board.push(row)
end


#行・列の組み合わせ
def combs(count)
    cells = Array.new(count){|i| i}
    cells_com = []
    for c in  (0..count-1) do
        com = cells.combination(c).to_a
        cells_com = cells_com.concat(com)
    end
    return cells_com
end

row_set = combs(h)
col_set = combs(w)

case_count  = 0

row_set.each {|rows|
    col_set.each{|cols|
        black_count = 0
        for r in (0..h-1) do
            if !rows.include?(r)
                for c in (0..w-1) do
                    black_count += board[r][c] unless cols.include?(c)
                end
            end
        end
        case_count += 1 if black_count == k
    }
}

puts case_count


Measured memory_bytes: 14160
import math
n = int(input())


def koch(n, p1, p2):
    if n == 0:
        return
    s, t, u = [0, 0], [0, 0], [0, 0]
    s[0], s[1] = (2 * p1[0] + p2[0]) / 3, (2 * p1[1] + p2[1]) / 3
    t[0], t[1] = (p1[0] + 2 * p2[0]) / 3, (p1[1] + 2 * p2[1]) / 3
    u[0] = (t[1] - s[1]) * math.sin(math.radians(60)) + (t[0] - s[0]) * math.cos(math.radians(60)) + s[0]
    u[1] = (t[1] - s[1]) * math.cos(math.radians(60)) - (t[0] - s[0]) * math.sin(math.radians(60)) + s[1]

    koch(n - 1, p1, s)
    print('{:.8f}'.format(s[1]), '{:.8f}'.format(s[0]))
    koch(n - 1, s, u)
    print('{:.8f}'.format(u[1]), '{:.8f}'.format(u[0]))
    koch(n - 1, u, t)
    print('{:.8f}'.format(t[1]), '{:.8f}'.format(t[0]))
    koch(n - 1, t, p2)


p1 = [0, 0]
p2 = [0, 100]
print('{:.8f}'.format(p1[1]), '{:.8f}'.format(p1[0]))
koch(n, p1, p2)
print('{:.8f}'.format(p2[1]), '{:.8f}'.format(p2[0]))



Measured memory_bytes: 5856
def main():
    n = int(input())
    s = input().rstrip()
    i = 0
    b_count = 0
    w_count = 0
    # Comsume left whites
    while i < len(s):
        if s[i] == '.':
            i += 1
        else:
            break

    #Consume right blacks
    j = len(s) - 1
    while j > i:
        if s[j] != '.':
            j -= 1
        else:
            break

    # Compute baseline count
    left = i
    right = j
    while i <= j:
        if s[i] == '.':
            w_count += 1
        i += 1
            

    i = left
    min_count = w_count
    count = w_count
    while i <= right:
        if s[i] == '.':
            count -= 1
        else:
            count += 1
        i += 1
        if count < min_count:
            min_count = count

    print(min_count)

if __name__ == "__main__":
    main()

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

using namespace std;

int main()
{
    int64_t N, A, B, C;
    std::cin >> A >> B;

    char c = 'x';
    if (A * B == 15) {
        c = '*';
    }
    else if (A + B == 15) {
        c = '+';
    }
    std::cout << c << std::endl;

    return 0;
}


Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

void solve() {
    ll n, d, a;
    cin >> n >> d >> a;
    vector<pair<ll, ll>> mon(n);
    for (int i=0; i<n; i++) {
        cin >> mon.at(i).first >> mon.at(i).second;
    }
    sort(mon.begin(), mon.end());
    vector<ll> buf(n), pla(n);
    for (int i=0; i<n; i++) {
        pla.at(i) = mon.at(i).first;
    }
    ll res = 0;
    ll cur = 0;
    for (int i=0; i<n; i++) {
        if (buf.at(i) > 0) {
            cur -= buf.at(i);
        }
        mon.at(i).second -= cur;
        if (mon.at(i).second > 0) {
            res += mon.at(i).second / a + (mon.at(i).second % a != 0);
            cur += a * (mon.at(i).second / a + (mon.at(i).second % a != 0));
            int dis = upper_bound(pla.begin(), pla.end(), pla.at(i) + 2*d) - pla.begin();
            if (dis < n) buf.at(dis) += a * (mon.at(i).second / a + (mon.at(i).second % a != 0));
        }
    }
    cout << res << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 6528
A,B = map(int,input().split())
if A > B:
    A,B = B,A

def no_tax(tax,tax_r):
    origin,min,max = 0,0,0
    while int(origin*tax_r) < tax:
        origin += 1
    min = origin
    while int(origin*tax_r) <= tax:
        origin += 1
    max = origin-1
    return (min,max)

A_min,A_max,B_min,B_max = \
no_tax(A,0.08)[0],no_tax(A,0.08)[1],no_tax(B,0.1)[0],no_tax(B,0.1)[1]

if A_min <= B_max and B_min <= A_max:
    print(max(A_min,B_min))
else:
    print(-1)


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

typedef long long ll;

int main(){
    ll n,i=1,temp=0,ans=1;
    cin>>n;
    while(1){
        if(i>n)
            break;
        i=i*2;
        temp++;
    }
    for(int j=1;j<=temp;j++){
        ans=ans*2;
    }
    cout<<ans-1;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

void swap(int &x,int &y){
	int tmp;
	tmp = x;
	x = y;
	y = tmp;
}

int main(int argc,char *argv[]){
	int A1,A2,A3;
	std::cin >> A1 >> A2 >> A3;	
	//ascending order (A1>A2>A3)
	if(A1<A2) swap(A1,A2);
	if(A1<A3) swap(A1,A3);
	if(A2<A3) swap(A2,A3);
	std::cout << (A1-A3) << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
unsigned long long int k,a,b;
unsigned long long int curr=1;
cin>>k>>a>>b;
if(b<=a){
    cout<<k+1;
}
else{
    while(k>0){
        if(curr<a){
            k--;
            curr++;
        }
        else if((b-a)>1){
            if(k<2){
                k--;
                curr++;
            }
            else{
            k=k-2;
            curr=curr+b-a;}
        }
        else{
            k--;
            curr++;
        }
    }
    cout<<curr;
}
return 0;}


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

int main() {
    vector<int> vnum1, vnum2;
    vector<char> vop;
    int num1, num2, i, N = 0;
    char op;

    cin >> num1 >> op >> num2;
    vnum1.push_back(num1);
    vop.push_back(op);
    vnum2.push_back(num2);
    while(vop[N] != '?') {
        cin >> num1 >> op >> num2;
        vnum1.push_back(num1);
        vop.push_back(op);
        vnum2.push_back(num2);
        ++N;
    }

    for(i=0; i<N; ++i) {
        switch(vop[i]) {
            case '+':
                cout << vnum1[i] + vnum2[i] << endl;
                break;
            case '-':
                cout << vnum1[i] - vnum2[i] << endl;
                break;
            case '*':
                cout << vnum1[i] * vnum2[i] << endl;
                break;
            case '/':
                cout << vnum1[i] / vnum2[i] << endl;
                break;
            default:
                break;
        }
    }

    return 0;
}

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

int main() {
  int n; std::cin >> n;
  std::vector<int> a(n);
  for (int i = 0; i < n; ++i) std::cin >> a[i];
  std::sort(a.begin(), a.end());
  bool ok = true;
  for (int i = 0; i < a.size()-1; ++i) {
    if (a[i] == a[i+1]) ok = false; 
  }
  if (ok) std::cout << "YES" << std::endl;
  else std::cout << "NO" << std::endl;
  
  return 0;
}

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

using namespace std;

#define int long long

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    vector<int> a;
    int cnt = 0;
    char c = '<';
    for (auto el : s)
    {
        if (el == c)
        {
            ++cnt;
        }
        else
        {
            a.push_back(cnt);
            c = el;
            cnt = 1;
        }
    }
    a.push_back(cnt);
    if (a.size() % 2)
    {
        a.push_back(0);
    }
    int ans = 0;
    for (int i = 0; i < a.size() / 2; ++i)
    {
        int t = max(a[2 * i], a[2 * i + 1]);
        int t2 = min(a[2 * i], a[2 * i + 1]) - 1;
        ans += t * (t + 1) / 2ll;
        ans += t2 * (t2 + 1) / 2ll;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3352
import java.util.*;

class Main {

    static void solve (int n) {
        int[][] jpeg = new int [n][n];
        int x = 0;
        int y = 0;
        boolean ascending = true;

        for (int i = 1; i <= n * n; i++) {
            jpeg[x][y] = i;
            if ( ascending && y == 0 && x != n-1 )  {
                x += 1;
                ascending = false;
            } else if ( (!ascending) && x == 0 && y != n-1) {
                y += 1;
                ascending = true;
            } else if ( ascending && x == n-1) {
                y += 1;
                ascending = false;
            } else if ( (!ascending) && y == n-1) {
                x += 1;
                ascending = true;
            } else if (ascending) {
                x += 1;
                y -= 1;
            } else {
                x -= 1;
                y += 1;
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.printf("%3d", jpeg[j][i]);
            }
            System.out.println("");
        }
    }


    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);
        int times = 1;

        while (true) {
            int n = sc.nextInt();
            if (n == 0) break;

            System.out.printf("Case %d:\n", times);
            solve(n);
            times += 1;
        }

    }
}

Measured memory_bytes: 12000
//
// Created by 10940 on 2020/7/5.
//

#include <bits/stdc++.h>
using namespace std;

int main () {
    int T;
    cin >> T;
    map<string, int> a;
    while (T--) {
        string str;
        cin >> str;
        a[str]++;
    }
    cout << "AC x " << a["AC"] << endl;
    cout << "WA x " << a["WA"] << endl;
    cout << "TLE x " << a["TLE"] << endl;
    cout << "RE x " << a["RE"] << endl;



    return 0;
}

Measured memory_bytes: 3636
// Kagami Mochi
package main

import ("fmt")

func contains(s []int, e int) bool{
  for _, v := range s{
    if e == v{
      return true
    }
  }
  return false
}

func main(){

  var N int
  fmt.Scan(&N)

  d := make([]int, N)
  for i:=0; i<N; i++{
    fmt.Scan(&d[i])
  }

  // fmt.Println(N,d)
  var set []int
  for i:=0; i<N; i++{
    contain := contains(set, d[i])
    if contain{
      continue
    }else{
      set = append(set, d[i])
    }
  }

  fmt.Println(len(set))
}


Measured memory_bytes: 512
#include <stdio.h>
int main(int argc, char *argv[])
{
	int a,a2,a3,t;
	scanf("%d%d%d",&a,&a2,&a3);
	if(a>a2) {t=a;a=a2;a2=t;}
	if(a>a3) {t=a;a=a3;a3=t;}
	if(a2>a3)	{t=a2;a2=a3;a3=t;}
	printf("%d\n",a3-a);
	return 0;
}

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

int main() {
	int h1, m1, h2, m2, k;
	scanf("%d%d%d%d%d", &h1, &m1, &h2, &m2, &k);
	printf("%d\n", (h2*60+m2)-(h1*60+m1)-k);
}


Measured memory_bytes: 3816
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Ans[2] = {"No", "Yes"};
string ANS[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll x, c;
    cin >> x >> c;
    cout << x * x - c;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int q,a,b;
    std::list<int> lst;
    auto itr = lst.end();
    cin >> q;
    for (int i=0;i<q;i++) {
        cin >> a;
        if ( a==0 ) {
            cin >> b;
            itr = lst.insert(itr,b);
        } else if ( a==1 ) {
            cin >> b;
            if ( b>0 ) {
                for (int j=0;j<b;j++) {
                    ++itr;
                }
            } else if ( b<0 ) {
                for (int k=0;k<abs(b);k++) {
                    --itr;
                }
            }
        } else if ( a==2 ) {
            itr = lst.erase(itr);
            /*
            if (*itr==0) {
                itr = lst.end();
            }
            */
        }
    }
    for (itr=lst.begin();itr!=lst.end();++itr) {
        cout << *itr << endl;
    }
}


Measured memory_bytes: 18620
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

X, Y, Z, K = mapint()
Xs = list(mapint())
Ys = list(mapint())
Zs = list(mapint())
Xs.sort(reverse=True)
Ys.sort(reverse=True)
Zs.sort(reverse=True)

x, y, z = 0, 0, 0
from heapq import heappop, heappush
Q = []
heappush(Q, (-(Xs[x]+Ys[y]+Zs[z]), (x, y, z)))
s = set()
s.add((x, y, z))
for _ in range(K):
    ans, (x, y, z) = heappop(Q)
    print(-ans)
    origin = [x, y, z]
    for i in range(3):
        xyz = origin[:]
        xyz[i] += 1
        x, y, z = xyz
        if x>=X or y>=Y or z>=Z: continue
        if not tuple(xyz) in s:
            heappush(Q, (-(Xs[x]+Ys[y]+Zs[z]), (x, y, z)))
            s.add((x, y, z))          

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

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

  ll N; cin >> N;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];

  ll cnt = 0;
  for (ll i = 0; i < N; i++) {
    ll minj = i;
    for (ll j = i; j < N; j++) {
      if (A[j] < A[minj]) minj = j;
    }
    if (minj != i) {
      swap(A[i], A[minj]);
      cnt++;
    }
  }
  cout << A[0]; for (int i = 1; i < A.size(); i++) { cout << ' ' << A[i]; }
  cout << '\n' << cnt << '\n';
  return 0;
}


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

using namespace std;

#define int long long

void solve() {
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    int p[n + 1];
    p[0] = 0;
    for (int i = 1; i <= n; ++i) p[i] = p[i - 1] + (s[i] - '0');
    int tc = 0;
    vector <int> ans;
    while (tc < n) {
        if (tc + m >= n) {
            ans.push_back(n - tc);
            break;
        }
        int l = 0, r = m + 1;
        while (l < r - 1) {
            int mid = (l + r) / 2;
            //cout << tc << ' ' << mid << ' ' << p[tc + mid] - p[tc] << '\n';
            if (p[tc + m] - p[mid + tc - 1] == m - mid + 1) r = mid;
            else l = mid;
        }
        if (l == 0) {
            cout << -1;
            return;
        }
        ans.push_back(l);
        tc += l;
    }
    for (int i = 0; i < ans.size(); ++i) cout << ans[ans.size() - i - 1] << ' ';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 2248
/*
    In the name of
        "ALLAH"
    And say "AL-HAMD-U-LILLAH"
*/

#include<bits/stdc++.h>
#define   ll   long long
#define   llu  unsigned long long
#define   _    printf("\n")
int      take() {
    int n;
    scanf("%d",&n);
    return n;

}
double  ttake() {
    double n;
    scanf("%lf",&n);
    return n;
}
ll     takes() {
    ll n;
    scanf("%lld",&n);
    return n;

}

#define  Int            take()
#define  Dnt            ttake()
#define  LL             takes()
#define  done           {return 0;}
#define  fr(i,x,n,a)    for(int i=x;i<=n;i+=a)
#define  FR(a,b,x)      for(int i=(a);i<=(b);i+=(x))
#define  rfr(i,x,n,a)   for(int i=x;i>=n;i--)
int      cas;
#define  print          printf("Case %d:",++cas)
#define  vi             vector<int>
#define  vl              vector<ll>
#define  pb              push_back
#define  pii             pair<int,int>
#define  vii             vector<pii>
#define  pll             pair<ll,ll>
#define  pil             pair<int,ll>
#define  pli             pair<ll,int>
#define  mk              make_pair
#define  fill(x,v)       memset(x,v,sizeof x)

using    namespace      std;

bool     approximatelyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     essentiallyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     definitelyGreaterThan(float a, float b, float epsilon) {
    return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     definitelyLessThan(float a, float b, float epsilon) {
    return (b - a) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
#define  STR            {struct info}
#define  dbg(x)         {cout<<"ekhane"<<x<<endl;}
#define  SS             second
#define  FF             first
#define  PQ             priority_queue
#define  great          greatest
#define  less           lesser
#define  mii            map<int,int>
#define  mil            map<int,ll>
#define  mll            map<ll,ll>
#define  msb            map<string,bool>
#define  V              vector
#define  M              100005
#define  pf             printf
//////////////////////////////////////////


int main(){

    int n = Int , arr[ n + 1 ] ;
    fr( i , 1 , n , 1 ) arr[ i ] = Int ;
    sort( arr + 1 , arr + 1 + n ) ;
    pf("%d ",arr[ n ] ) ;
    int x = arr[ n ] / 2 , d = 0 , mx = arr[ n ] , mxV = arr[ n ] ;

    fr( i , 1 , n - 1 , 1 ){
        int u = abs( arr[ i ] - x ) ;
        //cout<<arr[ i ]<<"  u="<<u<<endl;
        if( u <= mx ) {
                mx = u ;
                 mxV = arr[ i ] ;
        }
    }
    pf("%d\n",mxV ) ;
    done;
}




Measured memory_bytes: 640
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{
	char s1,s2;
	cin >> s1 >> s2;
	cout << ((s1 == 'H') ^ (s2 == 'H') == false ? "H" : "D") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

int main() {
  ll n,m;cin >> n >> m;
  vector<int> divisors;
  int p=(int)pow(m,0.5)+1;
  reps(i,p){
    if(m%i==0){
      divisors.pb(i);
      if(m/i != i) {divisors.pb(m/i);}
    }
  }

  sort(ALL(divisors));
  for(auto s:divisors){
    if(s>=n){cout << (m/s);return 0;}
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vl = vector<ll>;
using vvl = vector<vl >;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

#define TR ","
#define TS " "
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define rpt(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

ll gcd(int a, int b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

void printVector(const vector<ll>& vec) {
    for (ll value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(ll n, ll k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    ll S, t=0, ans=0; cin >> S;

    COMinit();

    while (S >= 3) {
        S -= 3;
        ans = (ans + COM(S+t, t)) % MOD;
        ++t;
    }
    if (ans >= 0) {
        cout << ans << endl;
    }
    else {
        cout << ans + MOD << endl;
    }

}

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

long long f(long long n){
    if(n % 2 == 0){
        if(n/2 % 2 == 0){
            return n;
        }
        else{
            return 1^n;
        }
    }
    else{
        if((n+1)/2 % 2 == 0){
            return 0;
        }
        else{
            return 1;
        }
    }
}


int main(){
    long long a, b;
    cin >> a >> b;
    if(a == 0){
        cout << f(b) << endl;
        return 0;
    }
    long long ans = f(b)^f(a-1);
    cout << ans << endl;
    return 0;
}

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


int getint(){
    int n;
    scanf("%d",&n);
    return n;
}

vector<int> getints(int n){
    vector<int> a(n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    return a;
}

int main(void){
    int N=getint();
    int x=getint();
    vector<int> a=getints(N);
    lli c=0;
    int before=0,after=0;
    for(int i=0;i<N;i++){
      after=a[i];
      if(before+after>x){
        c+=before+after-x;
        a[i]-=before+after-x;
      }
      before=a[i];
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 640
from itertools import accumulate
from math import ceil
N = int(input())
A = list(map(int, input().split()))


class BinaryIndexedTree:
    def __init__(self, n):
        self.size = n
        self.bit = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= (i & -i)
        return s

    def add(self, i, x):
        while i <= self.size:
            self.bit[i] += x
            i += (i & -i)

    def reset(self):
        self.bit = [0] * (self.size + 1)


# BIT準備
BIT = BinaryIndexedTree(N)
# 答えをにぶたん
lo, hi = -1, max(A) + 1  # sample2などに対応するためにhiを設定
while hi - lo > 1:
    m = (hi + lo) // 2

    # m以上かどうかで分類
    binary = [(1 if a >= m else -1) for a in A]
    binary = list(accumulate(binary))

    # BITの初期化
    BIT.reset()

    # 和が0以上となる連続部分列を数える
    tmp = 0

    # 転倒数っぽくやる
    binary_sorted = {b: i for i, b in enumerate(sorted(binary), start=1)}
    ans = 0
    for j, b in enumerate(binary):
        tmp += BIT.sum(binary_sorted[b]) + (b >= 0)
        BIT.add(binary_sorted[b], 1)

    # 連続する部分列の個数の半分以上和が0以上となる区間が存在するかで場合分け
    if tmp >= ceil(((N * (N + 1)) / 2) / 2):
        lo = m
    else:
        hi = m

print(lo)


Measured memory_bytes: 131388
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << x << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x) for(int i = 0; i < (sizeof(x)/sizeof(x[0])); i++){ cout << (x[i]) << " ";} cout << endl;

typedef long long ll;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    if(N <= 999){
        print("ABC");
    }else{
        print("ABD");
    }
}

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var ab = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var a = ab[0];
        var b = ab[1];
        
        Console.WriteLine(new [] { a + b, a - b, a * b }.Max());
    }
}


Measured memory_bytes: 13396