akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                int N = sc.nextInt();
                int[] A = new int[N];
                for (int i = 0; i < N; i++) {
                        A[i] = sc.nextInt();
                }
                for (int k = 0; k < N; k++) {
                        System.out.print(A[k]);
                        if (k!=N-1) {
                                System.out.print(" ");
                        } else {
                                System.out.print("\n");
                        }
                }
                for (int i = 1; i < N; i++) {
                        int v = A[i];
                        int j = i - 1;
                        while (j >= 0 && A[j] > v) {
                                A[j+1] = A[j];
                                j--;
                        }
                        A[j+1] = v;
                        for (int k = 0; k < N; k++) {
                                System.out.print(A[k]);
                                if (k!=N-1) {
                                        System.out.print(" ");
                                } else {
                                        System.out.print("\n");
                                }
                        }
                }
        }
}

Measured memory_bytes: 34192
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'

ll mod = 1e9+7;
ll modpow(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1) res = (res * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return res;
}


int main() {
	#ifdef shiven
	freopen("test.in", "r", stdin);
	#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	ll n; cin >> n;
	ll ans = ((modpow(10, n) - 2*modpow(9, n) + modpow(8, n)) % mod + mod) % mod;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3652
#include <iostream>

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

  double denominator = 0;
  for (int i = 0; i < N; ++i) {
    unsigned int a;
    std::cin >> a;
    denominator += 1.0 / a;
  }

  std::cout << 1.0 / denominator << std::endl;

  return 0;
}


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

int d[310][310];

void dijk(int st, long long l, int n, vector<vector<pair<int, long long>>> &e) {
    vector<long long> v(n, 1e16);
    set<pair<long long, int>> s;
    s.insert({0, st}); v[st] = 0;
    while (!s.empty()) {
        auto f = *s.begin();
        s.erase(s.begin());
        int curr = f.second;
        long long currl = f.first;
        if (v[curr] < currl) continue;
        if (st != curr) d[st][curr] = 1;
        for (auto &iter : e[curr]) {
            auto to = iter.first;
            auto w = iter.second;
            if (v[to] > w + currl && w + currl <= l) {
                v[to] = w + currl;
                s.insert({v[to], to});
            }
        }
    }
}

int main() {
    int n, m; long long l; cin >> n >> m >> l;
    vector<vector<pair<int, long long>>> e(n);
    for (int i = 0; i < m; i++) {
        int a, b; long long c; cin >> a >> b >> c;
        a--; b--;
        e[a].emplace_back(b, c);
        e[b].emplace_back(a, c);
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i != j) d[i][j] = 1e9;
        }
    }
    for (int i = 0; i < n; i++) dijk(i, l, n, e);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }
    int q; cin >> q;
    while (q--) {
        int s, t; cin >> s >> t; s--; t--;
        if (d[s][t] == 1e9) cout << -1 << "\n";
        else cout << max(d[s][t]-1, 0) << "\n";
    }
    return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int n , m;
const int N = 1e6 + 1;
long long int fac[N] , mod = 1e9 + 7;
long long int bin(long long int val , int y){
    if(y == 0)return 1;
    long long int temp = bin(val , y / 2);
    if(y % 2 == 0)
        return temp * temp % mod;
    return (temp * temp % mod ) * val % mod;
}
int main(){
    cin >> n >> m;
    fac[0] = 1;
    for(int i = 1 ; i < N ; i++)
        fac[i] = fac[i - 1] * i % mod;
    long long int ans = 0;
    for(int i = 0 ; i <= n ; i++){
        int j = (n - i) / 2;
        if( (n - i) % 2 == 1 )continue;
        if(i * 2 + j != m )continue;
        ans += (fac[i + j] * bin(fac[i] , mod - 2) % mod ) * bin(fac[j] , mod - 2) % mod;
        ans %= mod;
    }
    cout << ans ;
    return 0;
}

Measured memory_bytes: 8064
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll n;
vector<ll> a;
vector<vector<ll>> edge;

ll dfs(ll v,ll p){
    if(p!=-1 && edge[v].size()==1){return a[v];}
    ll sum=0;
    ll MX=0;
    ll can=0;
    for(auto &i:edge[v]){
        if(i==p){continue;}
        ll ret=dfs(i,v);
        if(ret==-1){return -1;}
        sum+=ret;
        MX=max(MX,ret);
    }
    if(MX*2<=sum){
        can=sum/2;
    }
    else{
        can=sum-MX;
    }
    if(sum<a[v] || sum-a[v]>can){return -1;}
    return sum-(sum-a[v])*2;
}


int main(){
    cin>>n;
    a.resize(n);
    edge.resize(n);
    for(auto &i:a){cin>>i;}
    for(int i=1;i<n;i++){
        ll a,b;
        cin>>a>>b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    if(edge[0].size()==1){
        cout<<(dfs(0,-1)==a[0]?"YES":"NO")<<endl;
    }
    else{
        cout<<(dfs(0,-1)==0?"YES":"NO")<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 11776
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int a[N];
int cnt[N];
int main(void)
{   int n,m;
    cin>>n>>m;
    if(n >= m)
        cout<<n-m<<endl;
    else cout<<"0"<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using P = pair<int,int>;

int main(){
    int n;
    while(cin>>n,n){
        vector<P> V;
        V.clear();
        for(int i=0;i<n;i++){
            int hh,mm,ss;
            cin>>hh;
            cin.ignore();
            cin>>mm;
            cin.ignore();
            cin>>ss;
            cin.ignore();
            int ts = hh*3600+mm*60+ss;
            V.emplace_back(ts,+1);
            cin>>hh;
            cin.ignore();
            cin>>mm;
            cin.ignore();
            cin>>ss;
            cin.ignore();
            int te = hh*3600+mm*60+ss;
            V.emplace_back(te,-1);
        }
        sort(V.begin(), V.end());
        int ans=0,cnt=0;
        for(auto v:V){
            cnt+=v.second;
            //cout<<cnt<<endl;
            ans=max(ans,cnt);
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3244
#include <iostream>
#include <vector>
#include <boost/integer/common_factor_rt.hpp>
using namespace std;
int main() {
  int K;
  cin >> K;
  vector<int> v(3);
  int total=0;
  for(int c=1;c<=K;c++){
  for(int b=1;b<=K;b++){
  for(int a=1;a<=K;a++){
    v[0] = a;
    v[1] = b;
    v[2] = c;
  	total+= boost::integer::gcd_range(v.begin(), v.end()).first;
  }
  }
  }
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i = 0; i < n; i++){
    cin>>a[i];
  }
  sort(a,a+n);
  int sum=0;
  for(int i = n-1; i >= 0; i--){
    if(i%2==(n-1)%2)sum+=a[i];
    else sum-=a[i];
  }
  cout<<sum<<endl;
  return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#define B (4)
#define F (3)
#define R (10)

int main(void) {
	int room[B][F][R] = {};
	int i, num, b, f, r, v;
	scanf("%d", &num);
	for (i = 0; i < num; i++) {
		scanf("%d %d %d %d", &b, &f, &r, &v);
		room[b - 1][f - 1][r - 1] += v;
	}
	for (b = 0; b < B; b++) {
		if (b) {
			printf("####################\n");
		}
		for (f = 0; f < F; f++) {
			for (r = 0; r < R; r++) {
				printf(" %d", room[b][f][r]);
			}
			putchar('\n');
		}
	}

	return 0;
}

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

int main(){
int a,b,c,d,e;
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
(b%d)?(b=b/d+1):(b=b/d);
(c%e)?(c=c/e+1):(c=c/e);
printf("%d\n",a-max(b,c));
}

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

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int a[100010];

void solve() {

  int n;
  cin >> n;
  map<int,int> mp;
  REP(i,n) {
    cin >> a[i];
    mp[a[i]]++;
  }
  if (mp.size() == 1 && a[0] == 0) {
    cout << "Yes" << endl;
    return;
  }
  if (mp.count(0)) {
      if (mp.size() != 2) {
        cout << "No" << endl;
        return;
      }
      map<int,int>::iterator itr = mp.begin();
      int a = (*itr).second;
      int aa = (*itr).fi;
      itr++;
      int b = (*itr).second;
      int bb = (*itr).fi;
      if (((a == b * 2) && (bb == 0)) || ((b == a * 2) && (aa == 0))) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
      return;
  }
  if (mp.size() != 3) {
    cout << "No" << endl;
    return;
  }
      bool f = 1;
      map<int,int>::iterator itr = mp.begin();
      int a = (*itr).second;
      int aa = (*itr).fi;
      itr++;
      int b = (*itr).second;
      int bb = (*itr).fi;
      itr++;
      int c = (*itr).second;
      int cc = (*itr).fi;
      f &= ((a == b) && (b == c));
      f &= (((aa^bb) == cc) || ((aa^cc) == bb) || ((bb^cc) == aa));
      // cout << aa << " " << a << endl;
      // cout << bb << " " << b << endl;
      // cout << cc << " " << c << endl;
      // cout << (aa^bb == cc) << endl;
      // cout << (aa^cc == bb) << endl;
      // cout << (cc^bb == aa) << endl;
    if (f) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
}

int main(int argc, char *argv[]){

  /* Regular */
  int case_num = 1;
  if (argc > 1 && stoi(argv[1])) cin >> case_num;
  REP(case_no, case_num) {
    cerr << endl << "case " << case_no + 1 << endl;
    solve();
  }
  
  // /* AOJ */
  // solve();
  return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=55;
int n;
lint val[N];

namespace utils{
	template <class T> inline void apn(T &x,const T y){x>y?x=y:0;}
	template <class T> inline void apx(T &x,const T y){x<y?x=y:0;}
	inline lint nxi(){
		lint x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

bool invld(){
	for(int i=1; i<=n; ++i){
		if(val[i]>=n) return 1;
	}
	return 0;
}

int main(){
	n=nxi();
	for(int i=1; i<=n; ++i){
		val[i]=nxi();
	}
	lint ans=0;
	while(invld()){
		for(int i=1; i<=n; ++i){
			lint res=val[i]/n;
			if(!res) continue;
			val[i]-=res*n;
			for(int j=1; j<=n; ++j){
				if(i!=j) val[j]+=res;
			}
			ans+=res;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define ll long long int
#define lim 100010
#define mod 1e9+7
#define INF 1e9
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define ABS(x) ((x)>0?(x):-(x))

typedef struct{
	int ind,num;
}data;
int comp(const void *a,const void *b){return ((data*)b)->num - ((data*)a)->num;}

int compare(const void *a,const void *b){return *(int*)a-*(int*)b;}

int main(void){
	int n;
	scanf("%d",&n);
	int A[n+2],B[n+1];
	for(int i=1;i<=n+1;i++)scanf("%d",&A[i]);
	for(int i=1;i<=n;i++)scanf("%d",&B[i]);
	ll max=0;
	for(int i=1;i<=n;i++){
		if(B[i]>A[i]){
			if(B[i]>A[i]+A[i+1]){
				max+=A[i]+A[i+1];
				A[i]=0;
				A[i+1]=0;
			}else{
				max+=B[i];
				A[i+1]-=B[i]-A[i];
			}
		}else{
			max+=B[i];
			A[i]-=B[i];
		}
	}
	printf("%lld",max);
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
int main()
{
	set<string>S;
	string s;
	int k,n;
	cin>>s>>k;
	n=s.size();
	for(int i=0;i<n;i++)for(int j=0;i+j<n&&j<6;j++)S.insert(s.substr(i,j+1));
	int p=0;
	for(auto x:S)
	{
		if(p==k-1)
		{
			cout<<x<<endl;
			return 0;
		}
		p++;
	}
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int X; cin >> X;
	cout << (X >= 30 ? "Yes" : "No") << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 3648
class UnionFind(val size: Int) {
    private val vec = IntArray(size){-1}
    fun find(a: Int): Int {
        return if (vec[a] < 0) a else find(vec[a]).also{vec[a] = it}
    }
    fun same(a: Int, b: Int): Boolean {
        return find(a) == find(b)
    }
    fun unite(a: Int, b: Int): Unit {
        val ar = find(a)
        val br = find(b)
        if (ar == br) return
        if (vec[ar] < vec[br]) {
            vec[ar] += vec[br]
            vec[br] = ar
        }else {
            vec[br] += vec[ar]
            vec[ar] = br
        }
    }
}

fun main(args: Array<String>?) {
    val n = readLine()!!.toInt()
    val values = readLine()!!.trim().split(' ').map(String::toInt) + 0
    val sorted = values.indices.sortedByDescending(values::get)
    val uft = UnionFind(n)
    var prev = -1
    var current = 0
    var max = 0
    for (i in sorted) {
        if (prev != values[i])
            max = java.lang.Math.max(max, current)
        if (values[i] == 0) break
        ++current
        if (i - 1 >= 0 && values[i - 1] >= values[i] && !uft.same(i, i - 1)) {
            --current
            uft.unite(i, i - 1)
        }
        if (i + 1 < n && values[i + 1] >= values[i] && !uft.same(i, i + 1)) {
            --current
            uft.unite(i, i + 1)
        }
        prev = values[i]
    }
    println(max)
}


Measured memory_bytes: 79304
N,X = (int(i) for i in input().split(' '))
 
L = [1]
P = [1]
for i in range(N):
    L.append(2*L[i] + 3) # 総枚数
    P.append(2*P[i] + 1) # パティ数
 
# print(L)
# print(P)

# レベルlv バーガのx層目までにパティは何枚あるか？
def find_level(lv, x):
    
#    print(lv, x)
    if lv == 0:
        return 1
    # lvレベルバーガの真ん中の層
    midlv = L[lv-1] + 2
    
    # 最上層
    if x == L[lv]:
#        print('最上層')
        ret = P[lv]
    # 最上層から真ん中
    elif x < L[lv] and x > midlv:
#        print('最上層〜真ん中')
        ret = find_level(lv-1,x - midlv) + 1 + P[lv-1]
    # ちょうど真ん中
    elif x == midlv:
#        print('真ん中')
        ret = 1 + P[lv-1] 
    # 真ん中〜最下層
    elif x < midlv and x > 1:
#        print('真ん中〜最下層')
        ret = find_level(lv-1, x - 1)
    # 最下層
    else:
#        print('最下層')
        ret = 0
        
    return(ret)

r = find_level(N, X)
print(r)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=1000000007;
	static List<int>[] li;
	static int[] h,ans;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		li=new List<int>[s[0]+1];
		h=Enumerable.Repeat(-1,s[0]+1).ToArray();
		ans=new int[s[0]];
		for(int i=1;i<=s[0];i++){li[i]=new List<int>();}
		for(int i=0;i<s[1];i++){
			int[] e=sc.Ia;
			li[e[0]].Add(e[1]);
			li[e[1]].Add(e[0]);
		}
		int q=sc.I;
		int[][] a=new int[q][];
		for(int i = 0;i<q;i++) {a[i]=sc.Ia;}
		for(int i = q-1;i>=0;i--) {Fu(a[i][0],a[i][1],a[i][2]);}
		Console.WriteLine(String.Join("\n",ans));
	}
	static void Fu(int a,int g,int c){
		if(h[a]<g){h[a]=g;}
		if(ans[a-1]==0){ans[a-1]=c;}
		if(g==0){return;}
		for(int i=0;i<li[a].Count;i++){
			if(h[li[a][i]]<g-1){Fu(li[a][i],g-1,c);}
		}
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

Measured memory_bytes: 35228
#include<stdio.h>

int main(){
  int x,fi[100],top=0;
  char s[7];
  int c;


  while( scanf("%s", s) != EOF ){
    if(s[0]=='\n')break;
    //if((c=getchar())=='\n')break;
    if ( s[0] == '+' ){
      fi[top-1]=fi[top]+fi[top-1];
      top--;
    }
    else if ( s[0] == '-' ){
      fi[top-1]=fi[top-1]-fi[top];
      top--;
    }
    else if ( s[0] == '*' ){
      fi[top-1]=fi[top]*fi[top-1];
      top--;
    }
    else {
      x = atoi(s);
      fi[top+1]=x;
      top++;
    }
    //printf("ssss\n");
  }

  printf("%d\n",fi[top]);

  return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <stack>

using namespace std;

int n, k, d[15], bit[15];

int main() {
    scanf("%d%d", &n, &k);
    for(int i = 1, x ; i <= k ; ++ i) {
        scanf("%d", &x);
        d[x] = 1;
    }
    for(int i = n, p, w ; (w = i, p = 1) ; ++ i) {
        while(w) {
            bit[p ++] = w % 10;
            w /= 10;
        }
        for(int j = 1 ; j < p ; ++ j) {
            if(d[bit[j]]) {
                goto nxt;
            }
        }
        printf("%d\n", i);
        break;
    nxt:;
    }
}

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int arr[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 << arr[k-1] << endl;

    return 0;
}


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

struct Node { int p, l, r; };
Node T[100000];
int depth[100000];

void SetDepth(int node, int d) {
  depth[node] = d;
  if (T[node].r != -1) SetDepth(T[node].r, d);
  if (T[node].l != -1) SetDepth(T[node].l, d + 1);
}

void PrintChildren(int node) {
  int c = T[node].l;
  cout << "[";
  while (c != -1) {
    if (c == T[node].l) cout << c;
    else cout << ", " << c;
    c = T[c].r;
  }
  cout << "]" << endl;
}

void Print(int node) {
  cout << "node " << node << ": ";
  cout << "parent = " << T[node].p << ", ";
  cout << "depth = " << depth[node] << ", ";
  if (T[node].p == -1) cout << "root, ";
  else if (T[node].l == -1) cout << "leaf, ";
  else cout << "internal node, ";
  PrintChildren(node);
}

int main() {
  int n; cin >> n;
  for (int i = 0; i < n; i++) T[i] = {-1,-1,-1};

  for (int i = 0; i < n; i++) {
    int id, k; cin >> id >> k;

    int node = id;
    for (int j = 0; j < k; j++) {
      int c; cin >> c;
      if (j == 0) T[node].l = c;
      else T[node].r = c;

      node = c;
      T[node].p = id;
    }
  }

  int root = 0;
  for (int i = 0; i < n; i++) if (T[i].p == -1) root = i;
  SetDepth(root, 0);

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

  return 0;
}


Measured memory_bytes: 7744
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 30;
const double EPS = 1e-10;
const double pi = 3.14159265359;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------



int n, m;
int a[55], b[55], c[55], d[55];

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

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

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

	for (int i = 0;i < n;i++) {
		int D = INF;
		int CP = 0;
		for (int j = 0;j < m;j++) {
			if (D > (abs(a[i] - c[j]) + abs(b[i] - d[j])) ) {
				CP = j;
				D = (abs(a[i] - c[j]) + abs(b[i] - d[j]));
			}
		}
		cout << CP + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
from heapq import *

n,m,s,t=map(int,input().split())
s-=1
t-=1
INF=10**19
Gyen=[[]for i in range(n)]
Gsnu=[[]for i in range(n)]
for i in range(m):
  u,v,a,b=map(int,input().split())
  u-=1
  v-=1
  Gyen[u].append([v,a])
  Gyen[v].append([u,a])
  Gsnu[u].append([v,b])
  Gsnu[v].append([u,b])

def dijkstra(G,s):
  d=[INF]*n
  d[s]=0
  visited={s}
  que=[(0,s)]
  while(que):
    p=heappop(que)
    v=p[1]
    visited.add(v)
    for node,cost in G[v]:
      if (node not in visited) and d[node]>d[v]+cost:
        d[node]=d[v]+cost
        heappush(que,(d[node],node))
  return d

yen=dijkstra(Gyen,s)
snu=dijkstra(Gsnu,t)
ans=10**15
ans_list=[]
for i in reversed(range(n)):
  ans=min(ans,yen[i]+snu[i])
  ans_list.append(10**15-ans)
print(*ans_list[::-1], sep='\n')


Measured memory_bytes: 135116
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    string s;
    int count=0;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='+')count++;
        else count--;
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int x[170010],y[170010],M;
void put(int a,int b){
	M++;
	x[M]=a;
	y[M]=b;
}
int main(){
	int n,i,j;
	scanf("%d",&n);
	for(i=0;6*i+1<n;i++){
		if(6*i+1<n){
			for(j=0;j<n;j+=2)put(6*i+1,j);
		}
		if(6*i+3<n)put(6*i+3,0);
		if(6*i+4<n){
			for(j=1;j<n;j+=2)put(6*i+4,j);
		}
		if(6*i+5<n)put(6*i+5,0);
	}
	if(n%6==4){
		for(i=2;i<n;i+=2)put(n-1,i);
	}
	if(n%6==1){
		for(i=2;i<n;i+=2)put(n-2,i);
	}
	printf("%d\n",M);
	for(i=1;i<=M;i++)printf("%d %d\n",x[i],y[i]);
}

Measured memory_bytes: 2688
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
    int count = 0;
    int c,d;
    for(int i = a; i <= b; i++) {
        if(i/10000 == i%10) {
            c = i/1000;
            d = i%100;
            if(c/10 == d%10 && c%10 == d/10) {
                count++;
            }
        }
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
S=input()
N=len(S)
goukei=0
for i in range(2 **(N-1)):
    T=[]
    T.append(S[0])
    for j in range(N-1):
        if ((i >> j) & 1):
            #print(i,j)のjbitがONの意味
            #print(i,j)
            T.append("+")
            T.append(S[j+1])
        else:
            T.append(S[j+1])
    
    #T.append(S[N-1])
    #print(T)
    tmp=[]
    for m in T:
        if m!="+":
            tmp.append(m)
        else:
            Z=[str(a) for a in tmp]
            Z="".join(Z)
            goukei+=int(Z)
            tmp=[]
    Z=[str(a) for a in tmp]
    Z="".join(Z)
    goukei+=int(Z)
    
print(goukei)

Measured memory_bytes: 74120
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N;

int main() {
    cin >> N;

    vvi A(10, vi(10));
    for (int i = 1; i <= N; i++) {
        int r = i % 10;
        int l = to_string(i)[0] - '0';
        // cout << l << ' ' << r << endl;
        A[r][l]++;
    }

    int ans = 0;
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            ans += A[i][j] * A[j][i];
        }
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) std::cin>>(P)
#define IN2(P1,P2) std::cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) std::cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) std::cin>>V[I]
#define OUT(P) std::cout<<P<<std::endl
#define OUT2(P1,P2) std::cout<<P1<<" "<<P2<<std::endl
#define OUT3(P1,P2,P3) std::cout<<P1<<" "<<P2<<" "<<P3<<std::endl
#define OUTS(I,N,V) REP(I,N) std::cout<<V[i]<<std::endl
#define ALL(C) (C).begin(),(C).end()
using namespace std;
using namespace __gnu_pbds;
int N;
const int MAX_N = 100001;
int dp[MAX_N];
int n;
int i;
inline void solve(){
  IN(N);
  UP(i,1,N)dp[i]=N;
  dp[0]=0;
  UP(n,1,N){
    for(int pow6=1;pow6<=n;pow6*=6)dp[n]=min(dp[n],dp[n-pow6]+1);
    for(int pow9=1;pow9<=n;pow9*=9)dp[n]=min(dp[n],dp[n-pow9]+1);
  }
  OUT(dp[N]);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 640
import copy

N, K = map(int, input().split())
a = list(map(int, input().split()))

ans = []
for i in range(2**N):
    s = a.copy()
    cnt = 0
    tmp = 1
    henkou = [False for _ in range(N)]
    for j in range(N):
        if((i >> j)&1):
            henkou[j] = True
    bill = s[0]
    for k in range(1, N):
        if(henkou[k]):
            if(bill >= s[k]):
                cnt += bill-s[k]+1
                s[k] = bill+1
                bill = s[k]
                tmp += 1
            else:
                bill = s[k]
                tmp += 1
        else:
            if(bill < s[k]):
                bill = s[k]
                tmp += 1
    if(tmp >= K):
        ans.append(cnt)
print(min(ans), end='\n')

Measured memory_bytes: 3700
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/
 
#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, n, a) for (int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(false); cin.tie(0) 
#define F first
#define S second
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)5e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

int n, a[55], b[55];
bool used[55];
set < int > have;
void dfs(int x) {
	used[x] = 1;
	for(auto &to : have) if(!used[x%to]) dfs(x%to);
}

inline bool can() {
	rep(i, 1, n) {
		memset(used, 0, sizeof used);
		dfs(a[i]);
		if(!used[b[i]]) {
			return 0;
		}
	}
	return 1;
}

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	onlycin;
	cin >> n;
	rep(i, 1, n) cin >> a[i];
	rep(i, 1, n) cin >> b[i];
	ll res = 0;
	rep(i, 1, 50) have.insert(i);
	per(i, 50, 1) {
		have.erase(i);
		if(!can()) {
			res += (1ll << i*1ll);
			have.insert(i);
		}
	}
	if(!can()) res = -1;
	cout << res << nxtl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;


public class Main {

	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		int[] box = new int[n];
		for(int i = 0 ; i < n ; i++) {
			box[i] = Integer.parseInt(sc.next());
		}

        Arrays.sort(box);

        int ans = 0;
        for(int i = 0 ; i < k ; i++) {
        	ans += box[i];
        }
        System.out.println(ans);
	}
}




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

using namespace std;

const int MOD = 1e9 + 7;
const long long INF = 1e18;
const int MaxN = 21;

int dp[MaxN][1 << MaxN];

int a[MaxN][MaxN];
int n;

inline void up(int & x, int y)
{
    x += y;
    if(x >= MOD)
        x -= MOD;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);

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

    for(int i = 0; i < n; ++i)
        if(a[0][i])
            dp[0][1 << i] = 1;

    for(int i = 1; i < n; ++i)
    {
        for(int j = 0; j < n; ++j)
            if(a[i][j])
                for(int prevMask = 0; prevMask < (1 << n); ++prevMask)
                    if(!(prevMask & (1 << j)))
                        up(dp[i][prevMask | (1 << j)], dp[i - 1][prevMask]);
    }

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

    return 0;
}



Measured memory_bytes: 168192
#include<bits/stdc++.h>
using namespace std;                                                            
#define pb push_back                                                            
#define mp make_pair                                                                                                                                
#define sqr(a) ((a) * (a))                                                      
#define io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);   
#define co() cout.precision(10);                                                
#define F for(li i=0;i<n;i++)
#define fo(i,a,n) for(i=a;i<n;i++)
#define ne cout<<"\n"; 
#define test int t;cin>>t;while(t--)
//#define oj #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif

typedef long long li;
typedef long double ld;

const li mod = 1000000007;

 
int main()
{
    io();
    li n=10001;
    li a[n]={0},i,j,k,f=0;
    for(i=1;i<=200;i++)
    {
    	for(j=1;j<=200;j++)
    	{
    		for(k=1;k<=200;k++)
    		{
    			li x=(i*i*1LL)+(j*j*1LL)+(k*k*1LL)+(i*j*1LL)+(j*k*1LL)+(k*i*1LL);
    			if(x>=n)
    			{f=1;break;}
    		    a[x]++;

    		}
    	    //if(f==1)break;
    	}
    	//if(f==1)break;
    }	
li z;
    cin>>z;
    for(i=1;i<=z;i++)
    	cout<<a[i]<<"\n";
}

Measured memory_bytes: 3720
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n];
    // for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = n - 1; i >= 0; i--) cin >> a[i];
    for(int i = 0; i < n; i++) {
        if (i == n - 1) {
            cout << a[i] << endl;
        } else {
            cout << a[i] << ' ' ;
        }
    }
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

//#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

typedef long long ll;
//typedef pair<ll, ll> P;

//static const ll MOD = 1000000007;
//static const ll INF = 100000000;
#define PI 3.14159265359

int main() {
    double ans = 0;

    // input
    double R;
    cin >> R;

    // process
    ans = R * PI * 2;

    cout << ans;

    return 0;
}


Measured memory_bytes: 3228
public class Main {
    public static void main(String[] args) {
        int n = new java.util.Scanner(System.in).nextInt();
        int a;
        if(n % 1000 == 0) {
            a = n / 1000;
        } else {
            a = (n / 1000) + 1;
        }
        int b = a * 1000;
        int result = b - n;
        System.out.println(result);
    }
}

Measured memory_bytes: 35684
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

typedef long long ll;
typedef pair<int, int> iP;

map< char, int > R;

void makeR() {
  R['I'] = 1; R['V'] = 5; R['X'] = 10; R['L'] = 50; R['C'] = 100;
  R['D'] = 500; R['M'] = 1000;
}

int main(){
 
  string s;
  makeR();
  while(cin >> s) {
    int res = 0;
    for(int i = 0; i < s.size() - 1; i++) {
      if(R[s[i]] < R[s[i + 1]]) res -= R[s[i]];
      else res += R[s[i]];
    }
    cout << res + R[s[s.size() - 1]]<< endl;
  }
}

Measured memory_bytes: 1188
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();

      if(a== 5 && b == 7 && c ==5){
      	System.out.println("YES");
      }else if(a== 5 && b== 5 &&c ==7){
      	System.out.println("YES");
      }else if(a == 7 && b == 5&& c ==5){
      	System.out.println("YES");
      }else{
      	System.out.println("NO");
      }
    }
}

Measured memory_bytes: 35792
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

const int MAX=50;
ll binom[MAX+1][MAX+1];

void calc_binom(){
	binom[1][0]=1;
	binom[1][1]=1;
	for(int i=2; i<=MAX; i++) binom[i][0]=1;
	for(int i=2; i<=MAX; i++){
		for(int j=1; j<=i; j++){
			binom[i][j]=binom[i-1][j-1]*i/j;
		}
	}
	return;
}

int main(){
	calc_binom();

	int n, a, b;
	cin >> n >> a >> b;
	ll v[n];
	for(int i=0; i<n; i++) cin >> v[i];
	sort(v, v+n, greater<ll>());

	int cnt1=0, cnt2=0, cnt3=0;
	for(int i=0; i<n; i++){
		if(v[i]==v[0]) cnt1++;
		if(v[i]>v[a-1]) cnt2++;
		if(v[i]==v[a-1]) cnt3++;
	}

	double ave;
	ll select=0;
	if(cnt1>=a){
		ave=(double)v[0];
		for(int i=a; i<=min(cnt1, b); i++){
			select+=binom[cnt1][i];
		}
	}else{
		ll sum=0;
		for(int i=0; i<a; i++) sum+=v[i];
		ave=(double)(sum)/a;
		select=binom[cnt3][a-cnt2];
	}

	printf("%.9f\n", ave);
	cout << select << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
 
#define sl(x) scanf("%ld", &x)
#define ss(x) scanf("%s", x)
#define pl(x) printf("%ld\n", x)
#define ps(x) printf("%s\n", x)
 
#define INF 100000000000
#define MOD 1000000007
 
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))

long path[401][401];
 
void init() {
	long i, j;
	
	for(i=1;i<=400;i++) {
		for(j=1;j<=400;j++) {
			if(i == j) {
				path[i][j] = 0;
			} else {
				path[i][j] = INF;
			}
		}
	}
}

int main() {
	long N, M;
	long a[1001], b[1001], c[1001];
	long i, j, k;
	long tmp;
	long ans;
	
	init();
	
	sl(N); sl(M);
	ans = M;
	for(i=1;i<=M;i++) {
		sl(a[i]); sl(b[i]); sl(c[i]);
		path[a[i]][b[i]] = c[i];
		path[b[i]][a[i]] = c[i];
	}
	
	for(i=1;i<=N;i++)
		for(j=1;j<=N;j++)
			for(k=1;k<=N;k++)
				path[j][k] = MIN(path[j][k], path[j][i] + path[i][k]);
	
	for(k=1;k<=M;k++) {
		/*
		for(i=1;i<=N;i++) {
			if(path[i][a[k]] + c[k] == path[i][b[k]]) {
				ans--;
				break;
			}
		}
		*/
		for(i=1;i<=N;i++) {
			for(j=1;j<=N;j++) {
				if(i == j) continue;
				if(path[i][j] == path[i][a[k]] + path[b[k]][j] + c[k]) {
					ans--;
					goto NEXT;
				}
			}
		}
	  NEXT:;
	}
	
	pl(ans);
	
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<bits/stdc++.h>
#include<array>
using namespace std;
#define int long long
#define fast_cin ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define endl "\n"
#define with_tests int t; cin >> t; while(t--){ solve(); cout << endl; }
#define without_tests solve(); cout << endl;
#define CEIL(x, y) (ll)ceil((long double)(x)/(long double)(y))
#define epsilon 1e-9 
typedef long long ll;
const int mod = 1e9+7;
const int N = 1e5+1;

void solve(){
    
    int n, k;
    cin >> n;
    vector<array<int, 3>> h(n), dp(n);

    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++){
            cin >> h[i][j];
        }
    }
    dp[0][0] = h[0][0], dp[0][1] = h[0][1], dp[0][2] = h[0][2];
    for(int i=1; i<n; i++){
        for(int j=0; j<3; j++){
            dp[i][j] = max(dp[i-1][(j+1)%3] + h[i][j], dp[i-1][(j+2)%3] + h[i][j]);
        }
    }
    int ans = max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
    cout << ans;

}

int32_t main(){

    fast_cin;
    // with_tests;
    without_tests;

    return 0;
}


Measured memory_bytes: 7880
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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;
}

const int INF = 1e9;
const long long LINF = 1e18;

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

    int ans = 0;
    for (int i = 0; i < N; i++) {
        int hi;
        cin >> hi;

        if (hi >= K) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
a = Array.new(32)
a[0] = 1
(1..32).each{|i|
  a[i]  = a[i-1]
  a[i] += a[i-2] if i >= 2
  a[i] += a[i-3] if i >= 3
}

while true
  n = gets.to_i
  break if n == 0
  puts (a[n]*1.0/(365*10)).ceil
end

Measured memory_bytes: 8520
N, K = map(int, input().split())
P = list(map(int, input().split()))

def expectation(N):
    # exp = 0
    # for i in range(1, N+1):
    #     exp += i/N
    # return exp
    return N/2+0.5

Ps = []
s = 0
for p in P:
    s += p
    Ps.append(s)
    
cmax = Ps[K-1]
max_sp = 0

for ix in range(1, N-K+1):
    csum = Ps[ix+K-1] - Ps[ix-1]
    if cmax < csum:
        max_sp = ix
        cmax = csum

ans = 0
for ix in range(max_sp, max_sp+K):
    ans += expectation(P[ix])

print(ans)

Measured memory_bytes: 31736
let greedy l m = 
	let rec greedy l m sum = 
    	if m = 0 then sum else
    	match l with
        	[] -> sum
            | (x, y, z) :: rest -> greedy rest (m - 1) (sum + x + y + z)
    in greedy (List.sort (fun (x, y, z) (x2, y2, z2) -> x2 + y2 + z2 - x - y - z) l) m 0
let change l x y z = 
	let rec change l ret = 
    	match l with
        	[] -> ret
            | (x2, y2, z2) :: rest -> change rest ((x2 * x, y2 * y, z2 * z) :: ret)
    in change l []
let max l = 
	let rec max l ret = 
    	match l with
        	[] -> ret
            | first :: rest -> max rest ((fun x y -> if x < y then y else x) first ret)
    in max l 0
let ans l m = 
	max (List.rev_map (fun x -> greedy x m) [
    	change l 1 1 1; change l 1 1 (-1); change l 1 (-1) 1; change l 1 (-1) (-1);
        change l (-1) 1 1; change l (-1) 1 (-1); change l (-1) (-1) 1; change l (-1) (-1) (-1)])
let getList n = 
	let rec getList n l = if n = 0 then l 
    	else getList (n - 1) (Scanf.scanf " %d %d %d" (fun x y z -> (x, y, z) :: l))
    in getList n []
let calc = Scanf.scanf "%d %d" (fun n m -> ans (getList n) m)
let main = print_int calc
	

Measured memory_bytes: 4864
from collections import defaultdict
def main():
    s = list(input())
    K = int(input())
    lowercase = [chr(i) for i in range(97, 97+26)]
    en = []
    for i in range(26):
        en.append(26-i)
    dic = defaultdict(int)

    for i,j in zip(lowercase,en):
        dic[i] = j

    for i in range(len(s)):
        if s[i]=="a":
            pass
        else:
            now = dic[s[i]]
            if now<=K:
                s[i]="a"
                K -= now
            else:
                pass
    K %= 26
    s[-1] = chr(ord(s[-1])+K)
    print("".join(s))

if __name__ == '__main__':
    main()

Measured memory_bytes: 49392
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << endl; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "abc165_e.cpp"

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

  int n, m;
  cin >> n >> m;
  vi ans(n);
  REP(i, n) { ans[i] = i + 1; }
  if (n % 2 != 0) {
    REP(i, m) { cout << ans[i] << " " << ans[n - 1 - i] << "\n"; }
  } else {
    int w = m;
    int itr = 0;
    int rs = w;
    while (w > 0) {
      cout << ans[itr] << " " << ans[w + itr] << "\n";
      if (w == 1)
        return 0;
      cout << ans[rs + itr + 1] << " " << ans[rs + 1 + itr + (w - 1)] << "\n";
      w -= 2;
      itr++;
    }
  }
}


Measured memory_bytes: 3872
import java.util.*;

public class Main{
	
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int X = sc.nextInt();
    int Y = sc.nextInt();
    if(N<=K){
    	System.out.println(N*X);
    } else{
    	System.out.println(K*X + (N-K)*Y);
    }
  }
}

Measured memory_bytes: 21716
c = gets.to_i
plan = true

c.times do
  t, x, y = gets.split(" ").map(&:to_i)
  time = t
  distance = x + y

  if t < x + y
    plan = false
    break
  elsif time % 2 != distance % 2
    plan = false
    break
  end
end

puts 'Yes' if plan
puts 'No' if !plan

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    int res = 1;
    while(b > 0){
        if(b&1) res = m(m(res)*m(a));
        a = m(m(a)*m(a));
        b >>= 1;
    }
    return res;
}
signed main(){
    fast();
    char c;
    cin >> c;
    if(c >= 'a' && c <= 'z')    cout << 'a' << endl;
    else cout << 'A' << endl;
    cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    ll n, k;
    cin >> n >> k;

    vl a(n);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }

    vl yakusu;  // yakusu[i] : sumのi番目(iは0-index)の約数
    for(ll i = 1; i*i <= sum; i++) {
        if(sum%i == 0) {
            yakusu.pb(i);
            if(i*i != sum) {
                yakusu.pb(sum/i);
            }
        }
    }

    ll ans = 1;
    rep(I, yakusu.size()) {
        ll d = yakusu[I];
        vl r(n);
        rep(i, n) {
            r[i] = a[i]%d;
        }
        sort(all(r));

        ll tot = 0;
        rep(i, n) {
            tot += r[i];
        }

        ll l = n - tot/d;
        ll need = 0;
        rep(i, l) {
            need += r[i];
        }
        
        if(need <= k) {
            ans = max(ans, d);
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n ;
    while(scanf("%d",&n)!=EOF){
    int a[n],b[n], x=0;
    int i,j;
    for(i=0;i<n;i++)
    {
        a[i]=i+1;
        scanf("%d",&b[i]);
    }
    for(j=0;j<n;j++)
    {
        if(a[j]!=b[j])
        {
            x++;
        }
        else
            continue;
    }
    if(x>2)
        printf("NO\n");
    else
        printf("YES\n");

    }

return 0;
}


Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int64_t X;
  cin >> X;
  int64_t FH = X / 500;
  int64_t F = (X - FH * 500) / 5;
  int64_t answer = (FH * 1000) + (F * 5);
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
// 1186.cpp - Integral Rectangles
#include <iostream>
using namespace std;

inline bool lt(int h1, int w1, int h2, int w2)
{
    int d1 = h1 * h1 + w1 * w1;
    int d2 = h2 * h2 + w2 * w2;

    if (d1 != d2)
        return d1 < d2;
    return h1 < h2;
}

int main()
{
    ios::sync_with_stdio(false);

    int H, W;
    while (cin >> H >> W, H | W) {
        int ans_h = 150, ans_w = 150;

        for (int w = 1; w <= 150; ++w) {
            for (int h = 1; h < w; ++h) {
                if (lt(H, W, h, w) && lt(h, w, ans_h, ans_w)) {
                    ans_h = h;
                    ans_w = w;
                }
            }
        }

        cout << ans_h << " " << ans_w << endl;
    }
}

Measured memory_bytes: 1196