akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;

	int w, h, n;
	double[] as, ps, qs;

	void run(){
		w=sc.nextInt();
		h=sc.nextInt();
		n=sc.nextInt();
		as=new double[n];
		ps=new double[n];
		qs=new double[n];
		for(int i=0; i<n; i++){
			as[i]=sc.nextInt();
			ps[i]=sc.nextInt();
			qs[i]=sc.nextInt();
		}
		solve();
	}

	void solve(){
		TreeSet<Double> set=new TreeSet<Double>();
		for(int i=0; i<n; i++){
			for(int j=i+1; j<n; j++){
				// ai * x2 - 2ai*pi + ai*pi^2 + qi
				double a=as[i]-as[j];
				double b=-2*as[i]*ps[i]+2*as[j]*ps[j];
				double c=as[i]*ps[i]*ps[i]+qs[i]-(as[j]*ps[j]*ps[j]+qs[j]);
				for(double x : quad(a, b, c)){
					set.add(x);
				}
			}
			double a=as[i];
			double b=-2*as[i]*ps[i];
			double c=as[i]*ps[i]*ps[i]+qs[i];
			for(double x : quad(a, b, c)){
				set.add(x);
			}
		}
		set.add(0.0);
		set.add(w*1.0);
		for(; set.lower(0.0)!=null;){
			set.remove(set.lower(0.0));
		}
		for(; set.higher(w*1.0)!=null;){
			set.remove(set.higher(w*1.0));
		}
		double ans=0;
		int m=(int)1e7; // 分割個数
		Double[] xs=set.toArray(new Double[0]);
		// debug(xs);
		int sumsum=0;
		for(int j=0; j<xs.length-1; j++){
			double x1=xs[j], x2=xs[j+1], mid=(x1+x2)/2;
			// debug(j, x1, x2);
			int k=0;
			for(int i=0; i<n; i++){
				if(val(i, mid)>val(k, mid)){
					k=i;
				}
			}
			// debug("k", k);
			if(val(k, mid)<0){
				continue;
			}
			int d=(int)(m*(x2-x1)/w+1);
			d=100000;
			sumsum+=d;
			double h=(x2-x1)/d;
			double sum=0;
			sum+=dval(k, x1);
			for(int i=1; i<=d/2-1; i++){
				sum+=2*dval(k, x1+2*i*h);
			}
			for(int i=1; i<=d/2; i++){
				sum+=4*dval(k, x1+(2*i-1)*h);
			}
			sum+=dval(k, x2);
			sum*=h/3;
			// debug(sum);
			ans+=sum;
		}
//		debug(sumsum);
//		debug(ans);
		println(String.format("%.20f", ans));
	}

	double val(int i, double x){
		return as[i]*(x-ps[i])*(x-ps[i])+qs[i];
	}

	double dval(int i, double x){
		double dif=2*as[i]*(x-ps[i]);
		return sqrt(1+dif*dif);
	}

	double[] quad(double a, double b, double c){
		if(a==0)
			return new double[]{-c/b};
		double D=b*b-4*a*c;
		if(D<0)
			return new double[0];
		if(D==0)
			return new double[]{-b/(2*a)};
		return new double[]{(-b-sqrt(D))/(2*a), 2*c/(-b-sqrt(D))};
	}

	void println(String s){
		System.out.println(s);
	}

	void debug(Object... os){
		System.err.println(deepToString(os));
	}

	public static void main(String[] args){
		new Main().run();
	}

}

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

using namespace std;

int main(void)
{
  int n,m;
  int inp;
  cin>>n>>m;

  for(int i=0;i<m;i++)
  {
    cin>>inp;
    n-=inp;
  }

  if(n>=0)
  {
    cout<<n<<endl;
  }
  else
  {
    cout<<-1<<endl;
  }
}


Measured memory_bytes: 3620
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTS(s) printf("%s\n",(s))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

typedef long long ll;
int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a)>(b) ? (a) : (b);
}

int main() {
	char S[100000];
	scanf("%s", S);
	int len = strlen(S);
	int l=len/2-1, r=(len+1)/2;
	char p = S[(len - 1) / 2];
	while(l>=0) {
		if (S[l] != p||S[r] != p) {
			break;
		}
		l--; r++;
	}
	if (l >= 0) {
		PRINTD(Max(l, (len - 1) - l));
	}
	else {
		PRINTD(len);
	}
}

Measured memory_bytes: 256
n,w = map(int,input().split())
v = [0]*n
for i in range(n):
    v[i] = list(map(int,input().split()))
dp =  [[0 for j in range(w+1)] for i in range(n+1)]
for i in range(n):
    for j in range(w+1):
        if j - v[i][0] >= 0:
            if dp[i][j-v[i][0]] + v[i][1] > dp[i][j]:
                dp[i+1][j] = dp[i][j-v[i][0]] + v[i][1]
        dp[i+1][j] = max(dp[i+1][j],dp[i][j])
print(dp[-1][-1])

Measured memory_bytes: 173704
#include <stdio.h>

int map[50][50], island[50][50];
int ans;

void dfs(int y, int x, int flg) {
	int i, j;
	
	if(x < 0 || y < 0 || x >= 50 || y >= 50 || map[y][x] != 0) { return; }
	
	if(flg) {
		if(island[y][x]) {
			map[y][x] = 1;
			for(i = -1; i <= 1; i ++) {
				for(j = -1; j <= 1; j ++) {
					dfs(y + i, x + j, 1);
				}
			}
		}
		else {
			return;
		}
	}
	else {
		map[y][x] = 1;
		if(island[y][x]) {
			ans ++;
			for(i = -1; i <= 1; i ++) {
				for(j = -1; j <= 1; j ++) {
					dfs(y + i, x + j, 1);
				}
			}
		}
		else {
			for(i = -1; i <= 1; i ++) {
				for(j = -1; j <= 1; j ++) {
					dfs(y + i, x + j, 0);
				}
			}
		}
	}
	return;
}

int main() {
	int i, j, w, h;
	while(scanf("%d %d", &w, &h)) {
		if(w == 0 && h == 0) { break; }
		
		ans = 0;
		for(i = 0; i < 50; i ++) {
			for(j = 0; j < 50; j ++) {
				map[i][j] = -1;
				island[i][j] = 0;
			}
		}
		
		for(i = 0; i < h; i ++) {
			for(j = 0; j < w; j ++) {
				scanf("%d", &island[i][j]);
				map[i][j] = 0;
			}
		}
		
		for(i = 0; i < h; i ++) {
			for(j = 0; j < w; j ++) {
				dfs(i, j, 0);
			}
		}
		
		printf("%d\n", ans);
	}
		
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;

int main() {
    int n, k;
    cin>>n>>k;
    vector<int> stone(n);
    for (int i=0;i<n;i++)
        cin >> stone[i];

    vector<int> dp(n, INF);
    dp[0] = 0;

    for (int i = 0; i < n; i++)
        for (int j = i + 1; j <= i + k; j++)
            if(j<n)
                dp[j] = min(dp[j], dp[i] + abs(stone[j] - stone[i]));

    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 4012
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <cctype>
#include <stack>
#include <map>
#include <cstring>
#include <sstream>
#include <set>
#include <list>
#include <fstream>
#include <iomanip>
#include<assert.h>

#define ll long long
#define ull unsigned long long
#define op                            \
	std::ios::sync_with_stdio(false); \
	std::cin.tie(0);

const int INF = 0x3f3f3f3f;
const int maxn = (100 + 10);
const int mod = (1e9 + 7);

int main()
{
	int r;
	scanf("%d",&r);
	printf("%d\n",r*r);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <bitset>
#include <sstream>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <climits>
using namespace std;

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

ll n, a, b;
vector<int> h;
bool check(ll k) {
    ll cnt = 0;
    for (int i = 0; i < n; ++i) {
        ll tmp = h[i] - k * b;
        if (tmp <= 0) continue;
        int need = (tmp + (a - b - 1)) / (a - b);
        cnt += need;
        if (k < cnt) return false;
    }
    return true;
}

int main() {
    cin >> n >> a >> b;
    h.resize(n);
    ll l, r = 0;
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
        sum += h[i];
        r += (h[i] + a - 1) / a;
    }

    l = sum / (a + (n - 1) * b);
    while (l < r) {
        ll mid = l + (r - l) / 2;
        if (check(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l;

    return 0;
}

Measured memory_bytes: 640
main :-
	read_num(A),
	read_num(B),
        read_num(C),
        read_num(D),
        read_num(E),
        nth1(Index, [A, B, C, D, E], 0),	
	write(Index),
	nl,
        halt.


read_str(S) :-
        read_string(current_input, ' \n', '', _, S).

read_num(N) :-
	read_str(S),
	number_string(N, S).

:- main.


Measured memory_bytes: 8036
n,m = gets.chomp.split(' ').map{|n| n.to_i}
route = Array.new(m)
ans = Array.new(n, 0)

m.times do |r|
  a,b = gets.chomp.split(' ').map{|n| n.to_i}
  route[r] =  [a,b]
end

route.each do |r|
  (0..1).each do |i|
    ans[r[i] - 1] += 1
  end
end

puts ans

Measured memory_bytes: 1788
#include <cstdio>

char arr[3][20];

int main(){
	scanf("%s%s%s", arr[0], arr[1], arr[2]);
	printf("%c%c%c", 'A' + arr[0][0] - 'a', 'A' + arr[1][0] - 'a', 'A' + arr[2][0] - 'a');
	return 0;
}

Measured memory_bytes: 128
def e_friendships(N, K):
    if K > (N - 1) * (N - 2) // 2:
        return -1

    ans_edge = []
    for i in range(2, N + 1):
        ans_edge.append((1, i))  # スターの構成

    def append_edge(t, lst=[], count=0):  # t回最短距離が2の頂点を消すように辺を追加
        for i in range(2, N):
            for j in range(i + 1, N + 1):
                if count == t:
                    return lst
                lst.append((i, j))
                count += 1
        return lst

    ans_edge += append_edge((N - 1) * (N - 2) // 2 - K)
    ans = [(len(ans_edge),)] + ans_edge
    return '\n'.join([' '.join(map(str, row)) for row in ans])

N, K = [int(i) for i in input().split()]
print(e_friendships(N, K))

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

using namespace std;
struct nodS
{
    int in=0,len=0;
    vector<int> v;
};
int n,m,ans,i,x,y;
nodS nod[100005];
queue<int> q;
int main()
{
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        cin>>x>>y;
        nod[x].v.push_back(y);
        nod[y].in++;
    }

    for(i=1;i<=n;i++)
    {
        if(!nod[i].in)
            q.push(i);
    }

    while(!q.empty())
    {
        int p=q.front();
        q.pop();
        ans=max(ans, nod[p].len);

        for(int it : nod[p].v)
        {
            nod[it].len=max(nod[it].len, nod[p].len+1);
            nod[it].in--;
            if(!nod[it].in)
                q.push(it);
        }
    }

    cout<<ans;
    return 0;
}


Measured memory_bytes: 9668
n = int(input())
A = list(map(int,input().split()))
 
maxA = max(A)
ans = 0
flag = [0]*(maxA+1)
 
# print(flag)
for a in A:
    for ax in range(a,maxA+1,a):
        flag[ax] +=1
 
# print(flag)
for a in set(A):
    if flag[a] == 1:
        ans += 1
print(ans)

Measured memory_bytes: 39512
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <bitset>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)

using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

    ll i,j,h;
    ll Q,M,K,P,A,B,N,X;



   int ans;
  

    vector<int> aa;
    ll a,b;
    
    int x=0;
    int temp;

    cin >>N;
    rep(i,N){
        cin >> temp;
        x=x^temp;
        aa.push_back(temp);
    }
    rep(i,N){
ans =   aa[i]^x;
        cout<<ans;
        if(i!=N-1)cout<<' ';
    }


   
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3764
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
#include<numeric>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0])
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

using namespace std;
typedef long long ll;



int main(void) {
	int n;
	cin >> n;
	int ans = n + (n*n) + (n*n*n);
	cout << ans;


	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;

int main() {
    int k;
    cin >> k;
    string s;
    cin >> s;
    if(s.size() <= k) {
        cout << s << endl;
    } else {
        s = s.substr(0, k);
        cout << s << "..." << endl;
    }
}


Measured memory_bytes: 3632
mod = 10 ** 9 + 7
n, k = map(int, input().split())
red = n - k

factorial = [1] * (n + 1)
for i in range(1, n + 1):
    factorial[i] = i * factorial[i-1] % mod

def comb(n, k):
    x = factorial[n] % mod
    y = (factorial[n-k] * factorial[k]) % mod
    y2 = pow(y, mod-2, mod)
    return int(x * y2) % mod


for i in range(1, k+1):
    if red + 1 < i:
        print(0)
    else:
        print((comb(red + 1, i) * comb(k-1, i-1)) % mod)


Measured memory_bytes: 3444
N, Q = map(int, input().split())
left = N
up = N
ans = (N-2)**2
lefts = [N]*(N+1)
ups = [N]*(N+1)

for _ in range(Q):
    num, x = map(int, input().split())
    if num == 1:
        if x < left:
            for i in range(x, left):
                ups[i] = up
            left = x
        ans -= ups[x] - 2
    else:
        if x < up:
            for i in range(x, up):
                lefts[i] = left
            up = x
        ans -= lefts[x] - 2
    # print("*", _, ans)

print(ans)

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

int main(){
    ll n,m;
    cin>>n>>m;
    vector<pair<ll,ll>> ab(n);

    rep(i,n){
        ll a,b;
        cin>>a>>b;
        ab[i]=make_pair(a,b);
    }
    sort(ab.begin(),ab.end());
    ll num=m;
    ll ans=0;
    rep(i,n){
        if(num>ab[i].second){
            ans+=ab[i].first*ab[i].second;
            num-=ab[i].second;
        }
        else{
            ans+=ab[i].first*num;
            break;
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 4764
ret = []
while True:
    x, y = map(int, raw_input().split())
    if x == y == 0:      
        break
    if x < y:
        #ret += ['%s %s' % (x,y)]
        print('%s %s' % (x,y))
    else:
        #ret += ['%s %s' % (y,x)]
        print('%s %s' % (y,x))
#for r in ret:
    #print(r)

Measured memory_bytes: 6360
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
#include<list>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
typedef long long ll;

const int MAX_A = 100000;
ll cnt[MAX_A + 1];

int main() {
	int n;
	ll k;
	cin >> n >> k;
	REP(i, n) {
      	int a, b;
		cin >> a >> b;
		cnt[a] += b;
	}
	for (int i = 1; i <= MAX_A; i++) {
		if (k <= cnt[i]) {
			cout << i << endl;
			break;
		}
		k -= cnt[i];
	}
	return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(100000)

N = int(input())

E = [[] for _ in range(N + 1)]
for a, b, c in [[int(i) for i in input().split()] for _ in range(N - 1)]:
    E[a].append((b, c))
    E[b].append((a, c))


Q, K = [int(i) for i in input().split()]
dist = [0] * (N + 1)
def dfs(cur, parent, d):
    dist[cur] = d
    for to, cost in E[cur]:
        if to == parent:
            continue
        dfs(to, cur, d + cost)
dfs(K, -1, 0)

for x, y in [[int(i) for i in input().split()] for _ in range(Q)]:
    print(dist[x] + dist[y])

Measured memory_bytes: 215584
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

int n;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> n;
  int ans = 0;
  if (n == 1) {
    ans = 1;
  } else {
    ans = (int)pow(n, 3);
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  while(cin>>n,n){
    cin>>m;
    int ans=0,k=0;
    char p='O',c;
    for(int i=0;i<m;i++){
      cin>>c;
      if(p!=c)k++;
      else if(c=='I')k=1;
      else k=0;
      if(c=='I'&&k>=n*2+1)ans++;
      p=c;
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

#define x first
#define y second
#define pb push_back
#define mp make_pair

#define all(a) (a).begin(), (a).end()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    int ans =0 ;
    for (int i = 0; i < n / 2; i++) ans += s[i] != s[n - i - 1];
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)                                 //g++ template.cpp -o template.exe
#define zeroes(x) memset(x,0,sizeof(x))                                        //all elements to 0  |  \   \0
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;







bool sortbysec(const pair<int,int> &a,                         //sorting of elements wrt second
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 

bool sortinrev(const pair<int,int> &a,                   //sorting in descending wrt first 
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 
bool sortinrevsec(const pair<int,int> &a,                  //sorting in dsc wrt second
               const pair<int,int> &b) 
{ 
       return (a.second > b.second); 
} 




int main()
{
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif



    
 ll n,d,sum=0,x,y;
 cin>>n>>d;

 d=d*d;
 while(n--)
 {
  cin>>x>>y;
  if(x*x+y*y<=d)
    sum++;


 }
 cout<<sum<<endl;

  



  return 0;
}

Measured memory_bytes: 3628
def solve(n, l):
    for i in range(n-1):
        a = min(l)
        l.remove(min(l))
        b = min(l)
        l.remove(min(l))
        l.append((a + b)/2)
    return l

def main():
    n = int(input())
    l = list(map(int, input().split(" ")))
    print(*solve(n, l))

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  vector<long> foo(N, 0);
  rep (i, N) cin >> foo[i];
  rep (i, N-1) foo[i+1] += foo[i];
  long ans = abs(foo[N-1] - foo[0] * 2);
  rep (i, N-1) {
    long tmp = abs(foo[N-1] - foo[i] * 2);
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a;
  cin >> a;
  int b = (a + 1) / 2;
  printf("%.12lf\n", (double) b / a);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int A,B,C,D;
  scanf("%d\n%d\n%d\n%d",&A,&B,&C,&D);
  if(A>B) A=B;
  if(C>D) C=D;
  printf("%d\n",A+C);
  return 0;
}

Measured memory_bytes: 1716
#include<iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

#define LOCAL  1
#define UPLOAD 2

using namespace std;

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    vector<int> d;
    for(int i=0;i<N;i++){
        int dd;
        cin >> dd;
        d.push_back(dd);
    }
    std::sort(d.begin(), d.end());

    int ret = d[N/2] - d[N/2 - 1];

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 1020
def merge(A, left, mid, right):
    global count
    banpei = 1000000001
    L = A[left:mid] + [banpei]
    R = A[mid:right] + [banpei]

    i, j = 0, 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    count += right - left


def merge_Sort(A, left, right):
    if 1 < right - left:
        mid = (left + right) // 2
        merge_Sort(A, left, mid)
        merge_Sort(A, mid, right)
        merge(A, left, mid, right)

n = int(input())
A = list(map(int, input().split()))
count = 0
merge_Sort(A, 0, n)
print(*A)
print(count)

Measured memory_bytes: 63804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  int n;
  string s, t;
  cin >> n >> s >> t;

  for (int i = 0; i < n; i++) {
    cout << s[i] << t[i];
  }
  cout << endl;
}

Measured memory_bytes: 3560
#include <iostream>

#define ll long long 

using namespace std;

int main() {
	ll n, m, l;
	ll a[100][100], b[100][100], c[100][100] = { 0 };

	cin >> n >> m >> l;

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

	for(int i = 0;i < m;i++) {
		for(int j = 0;j < l;j++) {
			cin >> b[i][j];
		}
	}

	for(int i = 0;i < n;i++) {
		for(int j = 0;j < l;j++) {
			for(int k = 0;k < m;k++) {
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}

	for(int i = 0;i < n;i++) {
		for(int j = 0;j < l;j++) {
			cout << (j == 0 ? "" : " ") << c[i][j];
		}

		cout << endl;
	}

	return 0;
}



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

#define cc(x) cout << (x) << endl
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<long long> vll;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

const ll inf = 1LL<<58;
const int iinf = 1<<30;

int main(){
    ll n, m;
    cin >> n >> m;
    vll p(m), y(m);
    vll yoder[n+1];
    rep(i,m){
        cin >> p[i] >> y[i];
        yoder[p[i]].push_back(y[i]);
    }
    rep(i,n){
        sort(all(yoder[i+1]));
    }
    rep(i,m){
        cout << setfill('0') << right << setw(12) << p[i]*1000000 + ll(lower_bound(all(yoder[p[i]]), y[i]) - yoder[p[i]].begin() + 1) << endl;
    }
}

Measured memory_bytes: 8576
import sys
from functools import reduce

def main(n, m, k, a, b):
    """ main
    """

    bestScore = 0
    _k = 0
    _ai = 0

    while True:
        if _ai >= n or _k + a[_ai] > k:
            bestScore = _ai
            break
        else:
            _k = _k + a[_ai]
            _ai = _ai + 1

    _bi = 0

    while _bi < m:
        _k = _k + b[_bi]

        while _k > k and _ai - 1 >= 0:
            _k = _k - a[_ai - 1] 
            _ai = _ai - 1

        if _k > k:
            break

        _bi = _bi + 1

        if _ai + _bi > bestScore:
            bestScore = _ai + _bi

    return bestScore

if __name__ == "__main__":
    N, M, K = map(int, sys.stdin.readline().split(" "))
    A = list(map(int, sys.stdin.readline().split(" ")))
    B = list(map(int, sys.stdin.readline().split(" ")))

    print(main(N, M, K, A, B))

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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll a,b;
	cin>>a>>b;
	cout<<6-a-b<<"\n";
	return 0;
}


// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""



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

int main() {
    int X; cin >> X;
    int a500 = X / 500;
    X %= 500;
    int a5 = X /5;
    cout << a500 * 1000 + a5 * 5 << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>
#include <sstream>
#include <queue>
using namespace std;

#define x first
#define y second
#define ll long long
#define ld long double
#define pii pair<int,int>
#define wh(x) (x).begin(),(x).end()
#define ri(x) int x;cin>>x;
#define rii(x,y) int x,y;cin>>x>>y;
#define rl(x) ll x;cin>>x;
#define rv(v) for(auto&_cinv:v) cin>>_cinv;
#define wv(v) for(auto&_coutv:v) cout << _coutv << ' '; cout << endl;
#define ev(v) for(auto&_cerrv:v) cerr << _cerrv << ' '; cerr << endl;
#define MOD 1000000007

namespace std { 
template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}};
}
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

int main(int,char**) {
    ios_base::sync_with_stdio(false);

    int N; cin >> N;
    vector<int> A(N); rv(A);
    vector<ll> R(N, 0);
    vector<pii> X(N);
    for (int i = 0; i < N; i++) {
        X[i] = {-A[i], i};
    }
    sort(wh(X));
    int i = 0;
    int f = N;
    int s = -1000000001;
    while (i < N) {
        R[f] += (ll)i*(X[i].x - s);
        f = min(f, X[i].y);
        s = X[i].x;
        while (i < N && X[i].x == s) ++i;
    }

    R[f] -= (ll)N * s;
    for (int i = 0; i < N; i++) {
        cout << R[i] << '\n';
    }
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
const int limit = 50;
int n, m;
int a[limit], b[limit];
bool graph[limit][limit];
bool visited[limit];

void df(int v) {
    visited[v] = true;
    for (int v2 = 0; v2 < n; ++v2) {
        if (graph[v][v2] == false) continue;
        if (visited[v2] == true) continue;
        df(v2);
	}
}

int main(void) {
  cin>>n>>m;
  for(int i = 0; i < m; ++i) {
	cin >> a[i] >> b[i];
	a[i]--, b[i]--;
	graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }
  int ans=0;
  for(int i=0;i<m;i++){
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;
    for(int j=0;j<n;j++) visited[j]=false;
    df(0);
    bool bridge=false;
    for(int j=0;j<n;j++) if(visited[j]==false) bridge=true;
    if(bridge) ans+=1;
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    
  }
  cout<<ans<<endl;
  return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
   int a,b,k,i;

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

   for(i=a;i<=b;i++){
      if((i<a+k)||(i>b-k))
         printf("%d\n",i);
   }
   return 0;
}


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

int main()
{
	int n,A,B;
	cin>>n>>A>>B;
	int t1=0,t2=0,t3=0;
	for (int i=1;i<=n;i++) {
		int x; scanf("%d",&x);
		if (x<=A) t1++;
		if (x>A && x<=B) t2++;
		if (x>B) t3++;
	}
	cout<<min(t1,min(t2,t3));
	return 0;
}

Measured memory_bytes: 256
import numpy as np
X = []

N, D = map(int, input().split())
X = np.array([list(map(int, input().split())) for _ in range(N)])
ans = 0

for i in range(N - 1):
    for j in range(i + 1, N):
        if np.sqrt(np.sum((X[i] - X[j]) ** 2)).is_integer() == True:
            ans += 1

print(ans)

Measured memory_bytes: 12512
P = 10**9 + 7

K = int(input())
S = input()
L = len(S)

d = [0]*(L+K+1)
d[0] = 1
for i in range(1, L+K+1):
    d[i] = (d[i-1]*i)%P

ans = 0
for i in range(K+1):
    temp = pow(26, i, P) * pow(25, K-i, P)
    temp %= P
    temp *= d[L-1+K-i]
    temp %= P
    temp *= pow(d[L-1], P-2, P)
    temp %= P
    temp *= pow(d[K-i], P-2, P)
    temp %= P
    ans += temp
    ans %= P

print(ans)

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

const ll MAX_N = 15;

const ll INF = 1LL << 50;

ll dp[1010][(1LL<<MAX_N)];

//dp[i][mask]は、i(0-index)番目までの鍵でmaskの鍵を開けるのにかかる最小費用

void chmin( ll &a, ll b){ if( a > b){ swap(a,b);} return;}

int main(){
 ll N,M; cin >> N >> M;
  
  vector<pair<ll,ll>> key(M); //第一成分が金額、第二成分が開けられる宝箱を示す
  
  for(ll i = 0; i < M; i++){
    ll a,b; cin >> a >> b; 
   key[i].first = a; ll mask = 0LL;
    for(ll j = 0; j < b; j++){ ll c; cin >> c; mask |= 1LL << c-1;}
    key[i].second = mask;
  }
  
  for(ll i = 0; i < 1010; i++){
    for(ll j = 0; j < (1LL<<MAX_N); j++){
      dp[i][j] = INF;
      if( j == 0){ dp[i][j] = 0;} //明らかに、何も開けないのにかかる最小コストは0
    }
  } //初期化
  
  for(ll i = 0; i < M; i++){dp[i][key[i].second] = key[i].first;}
  
  
 for(ll k = 1; k < M; k++){
   for(ll j = 0; j < 1LL<<N; j++){
     chmin(dp[k][j], dp[k-1][j]); //k番目の鍵を使わないとき
     chmin(dp[k][j|key[k].second], dp[k][j]+key[k].first);
   }
 }
  
  ll res = dp[M-1][(1LL<<N)-1];
  if( res == INF){ cout << -1 << endl;}
  else{ cout << res << endl;}
   

  
return 0;}
  
 

Measured memory_bytes: 258816
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const ll MOD = 1e9+7;


#define REP(i, N) for (ll i = 0; i < (N); i++)
#define REPP(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((ll)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<ll>>

using namespace std;


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

    double n;
    cin >> n;


    cout << n*2*3.141592 << endl;




    return 0;
}

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

int main(){
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k-1] << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF (1<<29)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
#define MX (1<<17)
ll S,K,O,M,t,G[MX],W;
int N,A[MX],T[MX],I;
int go(int d){
    if(d==K)return 0;
    ll U=d-K,B=N;
    if(U%B)puts("NO"),exit(0);
    return abs(U/B);
}
int main(void){
    scanf("%d",&N),ga(N,A),A[N]=*A,O=N*(N+1ll)/2;
    if(N==1)return puts("YES"),0;
    F(N)S+=A[i];
    if(S%O)return puts("NO"),0;
    K=S/O;
    F(N)W+=T[(i+1)%N]=go(A[i+1]-A[i]);
    F(N*2){
        I=i%N;
        if(T[I]>0)t+=T[I],T[I]=-T[I];
        else t+=T[I],M-=abs(T[I])*N;
        M+=t,G[I]+=M;
    }
    F(N)if(G[i]^A[i])return puts("NO"),0;
//    if(W^K)return puts("NO"),0;
    puts("YES");
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <limits>
#include <utility>

typedef struct{int a, b, n;} Edge;

int solve(std::vector<Edge> &e, std::vector<int> &c)
{
    const int n = e.size() + 1;
    int max = 0;
    std::vector<int> edgeColorFromParent(n, 0);

    // 昇順ソート
    std::sort(e.begin(), e.end(), [](auto const &lhs, auto const &rhs){
        return lhs.a < rhs.a;
    });

    int lastParent = -1;
    int nextColor = 1;
    for (int i = 0; i < n - 1; i++) {
        const int parent = e[i].a;
        const int child = e[i].b;
        const int parentEdgeColor = edgeColorFromParent[parent];
        if (lastParent != parent) {
            lastParent = parent;
            nextColor = 1;
        }
        while(nextColor == parentEdgeColor) {nextColor++;}
        edgeColorFromParent[child] = nextColor;
        c[e[i].n] = nextColor;
        max = std::max(max, nextColor);
        nextColor++;
    }

    return max;
}

int main(int argc, char *argv[])
{
    int n;
    std::vector<Edge> e;
    std::vector<int> c;
    long long ans;

    std::cin >> n;
    e.resize(n - 1);
    c.resize(n - 1);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        std::cin >> a >> b;

        a--;
        b--;

        e[i].a = a;
        e[i].b = b;
        e[i].n = i;
    }

    ans = solve(e, c);

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

    for (int i = 0; i < n - 1; i++) {
        std::cout << c[i] << std::endl;
    }

    return 0;
}


Measured memory_bytes: 2176
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(200000)
import collections
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template

def reverse(s: str):
    return s[::-1]

def main():
    S = input().rstrip()
    # ss = set()
    # ss.add(S)
    # for K in range(2, len(S) + 1):
    #     for i in range(len(S) - K + 1):
    #         news = ''.join([S[0:i], reverse(S[i:i + K]), S[i + K:]])
    #         print(news, i, K, end="")
    #         if news not in ss:
    #             ss.add(news)
    #             print("")
    #         else:
    #             print("*")
    # print(len(ss))
    d = collections.defaultdict(int)
    for x in S:
        d[x] += 1
    # print(d)
    minum = 0
    for i in d:
        minum += d[i] * (d[i] - 1) // 2
    print(len(S) * (len(S) - 1) // 2 - minum + 1)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 40176
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<cstdlib>
#include<cmath>
#define range(i,a,b) for(int i = (a); i <= (b); i++)
#define rrange(i,a,b) for(int i = (a); i >= (b); i--)
#define rep(i,b) for(int i = 1; i <= (b); i++)
#define rrep(i,b) for(int i = (b); i >= 1; i--)
#define all(a) (a).begin(), (a).end()
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long ll;
const int N=2e5+11;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001LL;
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int n,q,a,b,pos;
ll ans=LLINF,x[N],tag,mn[2][N<<2],w[N],dp[2][N];
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
ll ll_read(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
void update(int k){
	if(dp[0][mn[0][k<<1]]<=dp[0][mn[0][k<<1|1]]) mn[0][k]=mn[0][k<<1];else mn[0][k]=mn[0][k<<1|1];
	if(dp[1][mn[1][k<<1]]<=dp[1][mn[1][k<<1|1]]) mn[1][k]=mn[1][k<<1];else mn[1][k]=mn[1][k<<1|1];
}
void build(int k,int l,int r){
	if(l==r){
		if(l==a) mn[0][k]=mn[1][k]=a,dp[0][a]=abs(x[1]-b)-a,dp[1][a]=abs(x[1]-b)+a,w[a]=abs(x[1]-b);
		else if(l==b) mn[0][k]=mn[1][k]=b,dp[0][b]=abs(x[1]-a)-b,dp[1][b]=abs(x[1]-a)+b,w[b]=abs(x[1]-a);
		else mn[0][k]=mn[1][k]=0,w[l]=dp[0][l]=dp[1][l]=LLINF;
		return;
	}
	int mid=(l+r)>>1;
	build(k<<1,l,mid);build(k<<1|1,mid+1,r);
	update(k);
}
int query(int k,int l,int r,int L,int R,int flag){
	if(L<=l&&r<=R) return mn[flag][k];
	int mid=(l+r)>>1,t1=0,t2=0;
	if(L<=mid) t1=query(k<<1,l,mid,L,R,flag);
	if(R>mid) t2=query(k<<1|1,mid+1,r,L,R,flag);
	if(dp[flag][t1]<dp[flag][t2]) return t1;
	else return t2;
}
void change(int k,int l,int r,int to,ll add){
	if(l==r){
		mn[0][k]=l;mn[1][k]=l;w[l]=add;dp[0][l]=add-l;dp[1][l]=add+l;
		return;
	}
	int mid=(l+r)>>1;
	if(to<=mid) change(k<<1,l,mid,to,add);
	else change(k<<1|1,mid+1,r,to,add);
	update(k);
}
int main(){
//	freopen("ex.in","r",stdin);
	n=read();q=read();a=read();b=read();
	dp[0][0]=dp[1][0]=LLINF;
	rep(i,q) x[i]=ll_read();
	build(1,1,n);
	range(i,2,q){
		tag+=abs(x[i]-x[i-1]);
		ll now=0,pre=0;int j;
		j=0;
		if(1<=x[i]) j=query(1,1,n,1,x[i],0);
		if(j){
			now=w[x[i-1]]+tag;
			pre=dp[0][j]+tag-abs(x[i]-x[i-1])+x[i];
			if(pre<now) change(1,1,n,x[i-1],pre-tag);
		}
		j=0;
		if(x[i]+1<=n) j=query(1,1,n,x[i]+1,n,1);
		if(j){
			now=w[x[i-1]]+tag;
			pre=dp[1][j]+tag-abs(x[i]-x[i-1])-x[i];
			if(pre<now) change(1,1,n,x[i-1],pre-tag);
		}
	}
	rep(i,n) ans=min(ans,w[i]+tag);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 18944
#include <stdio.h>

int main()
{
	int n;
	char s[128];
	char t[128];
	scanf( "%u", &n );
	scanf( "%s", s );
	scanf( "%s", t );
	for ( int i = 0 ; i < n ; i++ ) {
		printf("%c",s[i]);
		printf("%c",t[i]);
	}
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
 
	public static void main(String[] args) {
		Scanner stdIn =new Scanner(System.in);
		long X =stdIn.nextLong();
		long Y=100;
		long i;
		
		for(i=0;Y<X;i++) {
			Y=(long) (Y*1.01);
			Y=Y/1;
		}
		System.out.println(i);
		
		
	}
 
}

Measured memory_bytes: 35616
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define N 200100
#define mod 1000000007
#define MOD 998244353
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
#define INF 100000000000000000
#define pii pair<int,int>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

signed main()
{
    
    speed
    long double a,b,n;
    cin>>a>>b>>n;
    
    if(n<b){
    	int ans=floor(a*n/b);
    	cout<<ans<<endl;
    	return 0;
    }
    else{
    	int ans=floor(a*(b-1)/b);
    	int xd=floor(-a/b);
    	int com=a+xd;

    	ans=max(ans,com);
    	cout<<ans<<endl;

    }
   
    



    

    

 
    return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 510000;
const double pi=acos(-1);
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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;
    }
}

// 二項係数計算
long long COM(int n, int 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(){
  COMinit();
  int h,w,a,b;
  cin >> h >> w >> a >> b;
  ll ans=0;
  for(ll i=b;i<w;i++){
    ll num = COM(h-a-1+i,i)*COM(w+a-2-i,a-1);
    ans+=num;
    ans%=MOD;
  }
  cout << ans%MOD << endl;
}


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

int main(){
  int c1=0,c2=0;
  string s;
  cin >> s;
  r(i,s.size()){
    if(s.at(i)=='0')c1++;
    else c2++;
  }
  cout << min(c1,c2)*2<<endl;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
    int n, i=0;
    cin >> n;
    int a[100];
    while(cin>>a[i]){
         i++;
    }
    for(i=n-1; i>=0; i--){
        if(i!=n-1) cout << " ";
        cout << a[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3104
import           Control.Monad
import           Control.Applicative

main :: IO ()
main = do
  a <- getLine
  b <- getLine

  putStrLn $ f a b

f :: String -> String -> String
f a b | length a > length b = "GREATER"
      | length a < length b = "LESS"
      | otherwise           = f' a b

f' :: String -> String -> String
f' "" "" = "EQUAL"
f' (a : as) (b : bs) | toInt [a] > toInt [b] = "GREATER"
                     | toInt [a] < toInt [b] = "LESS"
                     | otherwise             = f as bs

toInt s = read s :: Int

Measured memory_bytes: 892
N, K = map(int, input().split())
h = sorted([int(input()) for i in range(N)])

hmax = 0
hmin = 0
ans = 10**10
for i in range(N - K + 1):
    hmax = h[i + K - 1]
    hmin = h[i]
    if hmax - hmin < ans:
        ans = hmax - hmin
print(ans)


Measured memory_bytes: 14156
import java.util.Scanner;

import javax.sql.rowset.serial.SerialArray;

public class Main {

		public static void main(String[] args){
			
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			// スペース区切りの整数の入力
			String str = sc.next();
			String[] strArray = str.split("");
		 
			System.out.println(strArray[1].toString() 
                                             + (strArray.length - 3) + strArray[strArray.length - 1].toString());

		}
}


Measured memory_bytes: 20948
/*********************************************************************************\
*  _________  _      _  ________  _       _       __       ________               *
* |___   ___|| |    | ||  ______|| |     | |     /  \     |  ____  |              *
*     | |    | |    | || |______ | |_____| |    / /\ \    | |____| |              *
*     | |    | |    | ||______  ||  _____  |   / /__\ \   |  __  __|              *
*     | |    | |____| | ______| || |     | |  / ______ \  | |  \ \                *
*     |_|    |________||________||_|     |_| /_/      \_\ |_|   \_\               *
*  ________       __      ________  _    __       __       ________               *
* |  ______|     /  \    |  ____  || |  / /      /  \     |  ____  |              *
* | |______     / /\ \   | |____| || |_/ /      / /\ \    | |____| |              *
* |______  |   / /__\ \  |  __  __||  __ \     / /__\ \   |  __  __|              *
*  ______| |  / ______ \ | |  \ \  | |  \ \   / ______ \  | |  \ \                *
* |________| /_/      \_\|_|   \_\ |_|   \_\ /_/      \_\ |_|   \_\               *
*                                                                                 *
*                                                                                 *
*   Department of Computer Science & Engineering                                  *
*   Student ID : 18CSE035                                                         *
*   Bangabnadhu Sheikh Mujibur Rahman Science & Technology University,Gopalgonj.  *
*                                                                                 *
\*********************************************************************************/

//Now Write to Code ___________________________


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

const int N = (int) 1e5 + 5;



int main() 
{
	int N;

	cin >> N;
	if(N%2 == 0)
	{
		cout << N/2 << endl;
	}
	else
	{
		cout << (N/2)+1 << endl;
	}


	return 0;
}

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

using namespace std;

int main() {
    int n;  cin >> n;
    long long ans = 0;
    vector<long long> a(n+1), b(n);
    int i;
    for (i = 0; i < n+1; i++)
        cin >> a[i];
    for (i = 0; i < n; i++)
        cin >> b[i];
    
    for (i = 0; i < n; i++) {
        ans += min(a[i], b[i]);
        b[i] -= min(a[i], b[i]);
        ans += min(a[i+1], b[i]);
        a[i+1] -= min(a[i+1], b[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

typedef long long ll;

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

// const int C ;
// const int M = 1000000007;

int N, K;
ll a[100010];
ll memo[100010];
ll positive[100010];

ll sum(int i) { // i から i+K-1 までの和
  return memo[i+K] - memo[i];
}
ll positive_sum(int i, int j) { // i から j-1 までの和
  return positive[j] - positive[i];
}

int main () {
  cin >> N >> K;
  for (auto i = 0; i < N; i++) {
    cin >> a[i];
  }
  memo[0] = 0;
  for (auto i = 1; i <= N; i++) {
    memo[i] = memo[i-1] + a[i-1];
  }
  positive[0] = 0;
  for (auto i = 1; i <= N; i++) {
    if (a[i-1] >= 0) {
      positive[i] = positive[i-1] + a[i-1];
    } else {
      positive[i] = positive[i-1];
    }
  }
  ll ans = 0;
  for (auto i = 0; i < N-K+1; i++) {
    /*cerr << "i = " << i << endl;
    cerr << positive_sum(0, i) << " + "
         << sum(i) << " + "
         << positive_sum(i+K, N) << endl;*/
    ans = max(ans, positive_sum(0, i) +
              max(sum(i), (ll)0) + positive_sum(i+K, N));
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
R = []
for i in range(N):
  l = V[i] - C[i]
  R.append(l)
cost = 0
for r in R:
  if r > 0:
    cost += r
print(cost)
  


Measured memory_bytes: 3060