akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807/2;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int n;
vector<int> ans;
int main(){
	cin>>n;
	if(n<=5){
		if(n==3){
			cout<<"2 5 63"<<endl;
		}else if(n==4){
			cout<<"2 5 20 63"<<endl;
		}else{
			cout<<"2 3 4 6 9"<<endl;
		}
		return 0;
	}
	ll co=0;
	ll n4;
	ll n6;
	for(int i=0;i<n;i++){
		if(i%4==0){
			ans.push_back(i/4*6+2);
			co=co+i/4*6+2;
		}else if(i%4==1){
			ans.push_back(i/4*6+3);
			co=co+i/4*6+3;
		}else if(i%4==2){
			ans.push_back(i/4*6+4);
			co=co+i/4*6+4;
			n4=i/4*6+10;
		}else{
			ans.push_back(i/4*6+6);
			co=co+i/4*6+6;
			n6=i/4*6+12;
		}
	}
	if(co%6==0){
		REP(i,ans.size()){
			cout<<ans[i]<<" ";
		}
	}else if(co%6==2){
		REP(i,ans.size()){
			if(ans[i]==8)continue;
			cout<<ans[i]<<" ";
		}
		cout<<n6;
	}else if(co%6==3){
		REP(i,ans.size()){
			if(ans[i]==9)continue;
			cout<<ans[i]<<" ";
		}
		cout<<n6;
	}else{
		REP(i,ans.size()){
			if(ans[i]==9)continue;
			cout<<ans[i]<<" ";
		}
		cout<<n4;
	}
	cout<<endl;
	return 0;
}

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

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToArray();

            int K = line[0];
            int X = line[1];

            if (K * 500 >= X)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
using namespace std;
#define ll long long
#include <string>
#include <algorithm>
int main()
{
	ll n,x;
	ll count=0;
	cin>>n>>x;
	ll last=0;
	ll sum,m;
	for(int i=0;i<n;i++)
	{
		cin>>m;
		sum=m+last;
		if(sum>x)
		{
			count=sum-x+count;
			last=m-(sum-x);
		}
		else
		{
			last=m;
		}
	}
	cout<<count<<endl;
	return 0;
} 


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
typedef long long          ll;
typedef unsigned long long ull;
using namespace std;

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
};

template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

int main() {
    Setup();

    int a, b, k;
    cin >> a >> b >> k;
    int ans = 1;
    vector<int> hoge;
    for(int i=1; i<=100; i++) {
        if(a % i == 0 && b % i == 0) {
            hoge.push_back(i);
        }
    }

    sort(hoge.begin(), hoge.end(), greater<int>());
    k--;
    ans = hoge[k];
    cout << ans << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
 
#include <iostream>
#include <iomanip>
#include <sstream>
 
#include <algorithm>
#include <cmath>
 
#include <string>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <valarray>

#include<cassert>//assert();
//#include <random>//xAOJ
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
 
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
/////////
using namespace::std;
/////////
/////////

void solve(){
	string str;
	cin >> str;
	str.replace(5,1," ");
	str.replace(13,1," ");
	cout << str;
}

int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(16);//
	
	solve();
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n,k;
	cin>>n>>k;
	ll a[n+1];
	for(ll i=1;i<n+1;i++)
	cin>>a[i];
	vector<int> dp(n+1,0);
	dp[1]=0;
	dp[2]=abs(a[1]-a[2]);
	for(ll i=3;i<=n;i++)
	{	ll b=10000000001;
		for(ll l=1;l<=k;l++)
		{	if(i-l<=0)
			break;
			b=min(dp[i-l]+abs(a[i]-a[i-l]),b);
		}
		dp[i]=b;
	}
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1408
S = input()
T = input()
ans = 1000000

for i in range((len(S) - len(T)) + 1):
    count = 0
    index = i
    for j, t in enumerate(T):
        if S[index] != t:
            count += 1
        index += 1
    if ans > count:
        ans = count

print(ans)

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

const int MAX = 50;

int h, w, num=0;
char field[MAX][MAX];

int dfs(int x, int y) {
	num = 0;
	for (int dx = -1; dx <= 1; dx++) {
		for (int dy = -1; dy <= 1; dy++) {
			int nx = x + dx, ny = y + dy;
			if (0 <= nx && nx < h && 0 <= ny && ny < w && field[nx][ny] == '#') num++;
		}
	}
	return num;
}

int main() {
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> field[i][j];
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (field[i][j] == '.') cout << dfs(i, j);
			else cout << '#';
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
<?php

//文字列の入力
fscanf(STDIN,"%4s",$s);


//文字列を配列にする
$array = str_split($s);

//配列の値の出現回数をカウントする
$countArray = array_count_values($array);
$max = max($countArray);
$min = min($countArray);

if($max == $min && $max == 2 && $min ==2){
    echo "Yes";
}else{
    echo "No";
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<" = "<<x
#define sp <<"  "
#define el <<endl
#define fgx cerr<<" ------------------------------------------------- "<<endl
#define LL long long
#define DB double
#define LDB long double
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
inline int read(){
	int nm=0; bool fh=true; char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) fh^=(cw=='-');
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return fh?nm:-nm;
}
#define M 2000200
#define mod 998244353
#define inv2 499122177 
inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
inline int mns(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
inline int mul(LL x,LL y){x%=mod,y%=mod; return (LL)x*(LL)y%mod;}
inline int qpow(int x,int sq){int res=1;for(;sq;x=mul(x,x),sq>>=1)if(sq&1)res=mul(res,x);return res;}
inline void upd(int &x,int y){x=((x+y>=mod)?(x+y-mod):(x+y));}
inline void dec(int &x,int y){x=((x-y<0)?(x-y+mod):(x-y));}
int n,m,fac[M],ifac[M],ans;
inline int C(int N,int K){return mul(fac[N],mul(ifac[K],ifac[N-K]));}
inline int G(int X,int Y){return C(X+Y,X);}
int main(){
	fac[0]=1,n=read(),m=read(); if(n<m) swap(n,m);
	for(int i=1;i<M;i++) fac[i]=mul(fac[i-1],i); ifac[M-1]=qpow(fac[M-1],mod-2);
	for(int i=M-1;i>0;--i) ifac[i-1]=mul(ifac[i],i);
	for(int i=0;i<m;i++) upd(ans,mul(G(i,i+n-m),G(m-i,m-i)));
	ans=mul(ans,inv2),
	ans=mul(ans,qpow(G(n,m),mod-2)),
	upd(ans,n);
	printf("%d\n",ans); return 0;
}

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

using namespace std;

template <class T,class U>
void maximize(T &x,U y){
    if(x < y)x = y;
}
template <class T,class U>
void minimize(T &x,U y){
    if(x > y)x = y;
}
template <class T>
T Abs(T x){
    return (x < (T)0 ? -x : x);
}

#define llong long long
#define MASK(i) ((1LL) << (i))
#define BIT(x,i) (((x) >> (i)) & 1)
#define all(c) (c).begin(),(c).end()
#define fn "test"    ///FILE_NAME_HERE

/*----------END_OF_TEMPLATE----------*/


namespace task{

    const int N = 2e5 + 5;
    int h[N];
    llong f[N];
    int n;
    llong c;

    struct Line{
    public:
        llong m,b;
    public:
        Line(llong _m,llong _b){
            this -> m = _m;
            this -> b = _b;
        }
        llong evalute(int x) const{
            return m * (llong)x + b;
        }
    };

    class ConvexHullTrick{
    public:
        vector <Line> hull;
    public:
        bool bad(Line la,Line lb,Line lc){
            return (lc.b - la.b) * (la.m - lb.m) <= (la.m -lc.m) * (lb.b - la.b);
        }
        void addLine(Line l){
            while(hull.size() >= 2 and bad(hull[hull.size() - 2],hull.back(),l)){
                hull.pop_back();
            }
            hull.emplace_back(l);
        }
        llong getMin(int x){
            int l = 0,r = hull.size() - 1;
            while(l < r){
                int mid = (l + r) >> 1;
                if(hull[mid].evalute(x) < hull[mid + 1].evalute(x)){
                    r = mid;
                } else {
                    l = mid + 1;
                }
            }
            return min(hull[l].evalute(x),hull[r].evalute(x));
        }
    };

    void solve(){
        cin>>n>>c;
        for(int i = 1;i <= n;++i){
            cin>>h[i];
        }
        ConvexHullTrick *cht = new ConvexHullTrick();
        cht -> addLine(Line(-2 * h[1],1LL * h[1] * 1LL * h[1]));
        for(int i = 2;i <= n;++i){
            f[i] = 1LL * h[i] * 1LL * h[i] + c + cht -> getMin(h[i]);
            cht -> addLine(Line(-2 * h[i],f[i] + 1LL * h[i] * 1LL * h[i]));
        }
        cout<<f[n];
    }
}

int main(void){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen(fn".inp","r",stdin);
    //freopen(fn".out","w",stdout);
    #endif // ONLINE_JUDGE
    task::solve();
}


Measured memory_bytes: 8688
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1e9+1
#pragma GCC optimization ("O3")
using namespace std;
const long long int N = 6999999;
#define all(x) begin(x),end(x)
int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n,ans = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i)
  {
    int c=0,a = i;
    while(a > 0)
    {
      c++;
        a = a/10;
    }
    if(c%2 != 0)
    {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
} 


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

#define f first 
#define s second 
#define pb push_back               
#define mp make_pair 

using namespace std;                    

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

const int N = (int)2e5 + 123, inf = 1e9;
const ll INF = 1e18;
int n, h, w, ans;
vector< int > v[N];
int main(){
	scanf("%d%d%d", &h ,&w, &n);
	for(int i = 0; i < n; i++){
		int x, y;
		scanf("%d%d", &x, &y);
		v[y].pb(x);
	}
	ans = h + 1;
	for(int y = 1, x = 1; y <= w; y++){
		sort(v[y].begin(), v[y].end());
		for(auto j : v[y])
			if(j > x)
				ans = min(ans, j);
			else if(j == x)
				x++;
		x++;
	}
	printf("%d", ans - 1);
	return 0;
}


Measured memory_bytes: 8704
K = int(input())
 
i, a = 0, 0
l = []
for i in range(K):
  a = (10*a + 7) % K
  l.append(a)

j, ans = 0, -1
for j in range(K):
  if l[j] == 0:
    ans = j + 1
    break
    
print(ans)

Measured memory_bytes: 48436
n=int(input())
a=list(map(int,input().split()))

kisu=[]
gusu=[]
for x in range(n):
  if (x+1)%2==1:
    kisu.append(a[x])
  else:
    gusu.append(a[x])
    
if n%2==0:
  gusu.reverse()
  ans=gusu+kisu
  
else:
  kisu.reverse()
  ans=kisu+gusu
  
ans1=[str(f) for f in ans]

ans1=' '.join(ans1)

print(ans1)

Measured memory_bytes: 36928
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    vector<long long int> table;
    long long int A,N;
    long long int answer=0;
    long long int anA=0, anB=0;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A;
        table.push_back(A);
    }
    sort(table.begin(),table.end());
    if(N%2==0){
        for(int i=N/2;i<N;i++){
            if(i==N/2){
                answer+=table[i];
            } else {
                answer+=(2*table[i]);
            }
        }
        for(int i=0;i<N/2;i++){
            if(i==N/2-1){
                answer-=table[i];
            } else {
                answer-=(2*table[i]);
            }
        }
        cout << answer;
        return 0;
    } else {
        for(int i=(N+1)/2;i<N;i++){
            anA+=(2*table[i]);
        }
        for(int i=0;i<(N+1)/2;i++){
            if(i>=(N+1)/2-2){
                anA-=table[i];
            } else {
                anA-=(2*table[i]);
            }
        }
        for(int i=(N-1)/2;i<N;i++){
            if(i<(N-1)/2+2){
                anB+=table[i];
            } else {
                anB+=(2*table[i]);
            }
        }
        for(int i=0;i<(N-1)/2;i++){
            anB-=(2*table[i]);
        }
        answer=max(anA,anB);
        cout << answer;
    }
    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,x,y;
	bool f=false;
	int c[100];
	int z[100];
	cin >>n>>m>>x>>y;
	for(int i=0;i<n;i++){
		cin>>c[i];
	}
	c[n]=x;
	for(int i=0;i<m;i++){
		cin>>z[i];
	}
	z[m]=y;
	sort(c,c+n+1);
	sort(z,z+m+1);
	if(c[n]<z[0]){
		cout<<"No War"<<endl;
	}
	else{
		cout<<"War"<<endl;
	}
}
		


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long m = sc.nextLong();
		if(Math.min(n, m) >= 3) {
			System.out.println((n - 2) * (m - 2));
		} else if(n == 2 || m == 2) {
			System.out.println(0);
		} else if(m == 1 && n == 1) {
			System.out.println(1);
		} else if(n * m <= 2 && Math.min(n, m) == 1) {
			System.out.println(0);
		} else {
			System.out.println(n * m - 2);
		}
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
using P=pair<int,int>;

vector<int> dist;
vector<int> answer;

int main(){
    int n,x,y,i;cin>>n>>x>>y;
    x--;y--;

    Graph G(n);
    for(i=0;i<n-1;i++){//Graphの作成
        G[i].push_back({i+1});
    }
    for(i=1;i<n;i++){
        G[i].push_back({i-1});
    }
    G[x].push_back({y});
    G[y].push_back({x});

    dist.assign(n,-1);
    answer.assign(n,0);

    for(int num=0;num<n;num++){//全頂点をスタート位置としてそこからの最短距離を調べる
        queue<int> que;
        que.emplace(num);//numからstart
        dist[num]=0;//start地点は距離0
        while(que.size()!=0){
            int state=que.front();
            que.pop();
            for(auto next:G[state]){
                if(dist[next]==-1){//まだ訪れていないとき
                    dist[next]=dist[state]+1;
                    que.emplace(next);
                    answer[dist[next]]++;//最短距離ごとに加算
                }
            }
        }
        dist.assign(n,-1);//初期化
    }
    
    for(i=1;i<n;i++){
        cout<<answer[i]/2<<" ";//重複して2回数えているので
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 384
N, M, Q = map(int, input().split())

# (N + 1) * (N + 1) の２次元の表を作成
# N + 1 にしておくのは、後ほど q - 1を参照するときにエラーを出さないため
x = [[0 for i in range(N + 1)] for j in range(N + 1)]

# M本ある各電車の情報を表に整理
for _ in range(M):
    l, r = map(int, input().split())
    x[l][r] += 1

# 2次元の累積和計算で表をアップデート
for i in range(1, N + 1):
    for j in range(1, N + 1):
        x[i][j] += x[i - 1][j] + x[i][j - 1] - x[i - 1][j - 1]

# 累積計算
for _ in range(Q):
    p, q = map(int, input().split())
    ans = x[q][q] - x[q][p - 1] - x[p - 1][q] + x[p - 1][p - 1]
    print(ans)


Measured memory_bytes: 15080
#include<iostream>
using namespace std;
 
int main()
{
    int H, W;
    int i, j;
 
    do{
        cin >> H >> W;
        if((H == 0) && (W == 0)) break;
 
        for(i = 0; i < H; i++){
            for(j = 0; j < W; j++){
                if((i == 0) || (i == H - 1)){
                    cout << "#";
                }else if((j == 0) || (j == W - 1)){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
 
    }while(1);
 
    return 0;
}

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

int main() {
  string s, t; cin >> s >> t;
  string ans = "No";
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  if (s < t) ans = "Yes";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;

int n; int a, b, c;
int l[10];

int dfs(int now, int sa, int sb, int sc) {
	if (now == n) {
		if (min({ sa,sb,sc }) > 0)return abs(sa - a) + abs(sb - b) + abs(sc - c) - 30;
		else return INF;
	}
	return min({ dfs(now + 1,sa,sb,sc),dfs(now + 1,sa + l[now],sb,sc) + 10,dfs(now + 1,sa,sb + l[now],sc) + 10,dfs(now + 1,sa,sb,sc + l[now]) + 10 });
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> a >> b >> c;
	rep(i, n)cin >> l[i];
	cout << dfs(0, 0, 0, 0) << endl;
	return 0;
}

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

int main()
{
	int n,m;
	cin >> n >> m;
	vector<int> ans(n,-1);
	for(int i = 0;i<m;i++)
	{
		int s,c;
		cin >> s >> c;
		s--;
		if(ans[s]==-1||ans[s]==c)
		{
			ans[s] = c;
		}
		else
		{
			cout<<-1<<endl;
			return 0;
		}
	}
	if(n==1)
	{
		{cout<<max(ans[0],0)<<endl;
		return 0;}
	}
	for(int i = 0;i<n;i++)
	{
		if(i==0)
		{
			if(ans[i]==0)
			{
				cout<<-1<<endl;
				return 0;
			}
			else
			{
				cout<<max(ans[i],1);
			}
			continue;
		}
		cout<<max(ans[i],0);
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define mp make_pair
ll inf=1e18;
ll p=1e9+7;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
   while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll i,j,h,x,y,n,m,k,t1,t2,t3;
    string s,t;
    ll f=1;
    cin>>s>>t;
    for(i=0;i<s.length();i++)
    {
        if(s[i]!=t[i])
        {
            f=0;
            break;
        }
    }
    if(f)
    cout<<"Yes";
    else
    cout<<"No";
}

Measured memory_bytes: 3656
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
    {
    int n,x,y,cnt=0;
    cin>>n;
    int max1=0;
    for (int i=1;i<=n;i++)
    {
      cin>>x>>y;
      if(x==y)
        {cnt++;
        if(cnt>=max1)
        max1=cnt;
        }
        else
        {
            cnt=0;
        }

    }
    if(max1>=3)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}



Measured memory_bytes: 3620
import sys
input = sys.stdin.readline

class Tree():
    def __init__(self,n,edge):
        self.n = n
        self.tree = [[] for _ in range(n)]
        for e in edge:
            self.tree[e[0]].append((e[1],e[2]))
            self.tree[e[1]].append((e[0],e[2]))

    def setroot(self,root):
        self.root = root
        self.parent = [None for _ in range(self.n)]
        self.parent[root] = -1
        self.depth = [None for _ in range(self.n)]
        self.depth[root] = 0
        self.distance = [None for _ in range(self.n)]
        self.distance[root] = 0
        stack = [root]
        while stack:
            node = stack.pop()
            for adj,cost in self.tree[node]:
                if self.parent[adj] is None:
                    self.parent[adj] = node
                    self.depth[adj] = self.depth[node]+1
                    self.distance[adj] = self.distance[node]+cost
                    stack.append(adj)

    def diam(self):
        u = self.distance.index(max(self.distance))
        dist_u = [None for _ in range(N)]
        dist_u[u] = 0
        stack = [u]
        while stack:
            node = stack.pop()
            for adj,cost in self.tree[node]:
                if dist_u[adj] is None:
                    dist_u[adj] = dist_u[node]+cost
                    stack.append(adj)
        return max(dist_u)

N = int(input())
E = [list(map(int,input().split())) for _ in range(N-1)]

t = Tree(N,E)
t.setroot(0)

print(t.diam())


Measured memory_bytes: 61752
#include <stdio.h>

int main(void)
{
int r, c, i, j;
int a[1000][1000];

scanf("%d %d", &r, &c);

for(i = 0; i < c; i++)
 a[r][i] = 0;

 for(j = 0; j < r; j++)
 a[i][c] = 0;

for(i = 0; i < r; i++)
{
 for(j = 0; j < c; j++)
{
 scanf("%d", &a[i][j]);
 a[i][c] += a[i][j];
}
}

for(j = 0; j < c; j++)
{
 for(i = 0; i < r; i++)
 a[r][j] += a[i][j];
}

for(i = 0; i < c; i++)
 a[r][c] += a[r][i];


for(i = 0; i <= r; i++){
 for(j = 0; j <= c; j++){
 if(j == c)
  printf("%d", a[i][j]);
 else
   printf("%d ", a[i][j]);
}
printf("\n");
}



return 0;

}




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

int main(){
int A, B, C, D;
bool f=true;
cin>>A>>B>>C>>D;
while(A>0 && C>0){
    if(f==true){
    C=C-B;
    }else{
    A=A-D;
    }
    f=!f;
}

if(f==false){
    cout<<"Yes"<<endl;
}else{
    cout<<"No"<<endl;
}
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<math.h>
int main(){
    int da=10,zhong=2,xiao=1;
    int x,a,b,c,d,i,j,k,count=0;
    scanf("%d%d%d%d",&a,&b,&c,&x);
    x/=50;
    for(i=0;i<=a;i++){
    	for(j=0;j<=b;j++){
    		for(k=0;k<=c;k++){
    			if(i*da+j*zhong+k*xiao==x){
    				count++;
				}
			}
		}
	}
	printf("%d",count);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define MAX 1000000
#define MOD 1e9
#define pb push_back
#define pairs pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pairs>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define endl '\n'
using namespace std;
/* ----------------------------------------------------------------------------------- */

#define FastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define read(x) freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define rep(i, a, n) for (int i = a; i < n; i++)
#define REP(i, a, n) for (int i = a; i <= n; i++)
#define inputArray(a,n) rep(i, 0, n) cin >> a[i];
#define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
#define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;

/* ----------------------------------------------------------------------------------- */

#define Cases  cout << "Case " << ++Case << ": ";
#define __test int tt; int Case=0; cin >> tt; while(tt--)

#define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, n){cout<<A[i][j]<<" ";}cout<<"\n";}cout<<"\n";}
#define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
#define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}

/* ----------------------------------------------------------------------------------- */

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }

struct debugger {
	typedef string::iterator si;
	static void call(si it, si ed) {}
	template<typename T, typename ... aT>
	static void call(si it, si ed, T a, aT... rest) {
		string b;
		for(; *it!=','; ++it)
			if(*it!=' ')
				b+=*it;
		cout << b << "=" << a << " ";
		call(++it, ed, rest...);
	}
};

/* ----------------------------------------------------------------------------------- */

void solve() {
	int n;
	cin >> n;
	vector<int> arr(n);
	long long int sum = 0;
	map<ll, ll> mp;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		sum += arr[i];
		mp[arr[i]]++;
	}

	int k;
	cin >> k;
	for (int i = 0; i < k; i++) {
		int a, b;
		cin >> a >> b;

		sum -= (mp[a] * a);
		sum += (mp[a] * b);
		mp[b] = mp[b] + mp[a];
		mp.erase(a);
		cout << sum << endl;
	}
}

int main() {
	solve();

	// __test {
	// 	solve();
	// }
}

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

ll solve() {
    ll N;
    cin >> N;
    ll M = 3500;
    for ( ll a = 1; a <= M; a++ ) {
        for ( ll b = a; b <= M; b++ ) {
            ll x1 = N*a*b;
            ll x2 = 4*a*b - N*(a+b);
            if ( x2 > 0 && x1 % x2 == 0 ) {
                cout << a << " " << b << " " << x1/x2 << "\n";
                return 0;
            }
        }
    }
    return 0;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int H = sc.nextInt();
    Integer[] a = new Integer[N];
    Integer[] b = new Integer[N];
    for (int i = 0; i < N; i++) {
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
    }
    sc.close();
  
    Arrays.sort(a, Comparator.reverseOrder());
    Arrays.sort(b, Comparator.reverseOrder());

    int answer = 0;

    for (int i = 0; i < N; i++) {
      if (a[0] <= b[i] && 0 < H) {
        answer++;
        H -= b[i];
      } else {
        break;
      }
    }

    if (0 < H) {
      answer += Math.ceil((double) H / a[0]);
    }

    System.out.println(answer);

  }

}

Measured memory_bytes: 86000
import numpy as np
import sys
sys.setrecursionlimit(10**9)


INF=10**18

def solve(N,A):
    maxim = 10**6+10
    spf = np.zeros(maxim+1,dtype=np.int64)

    # osa_k 
    for i in range(maxim):
        spf[i] = i
    
    i = 2
    while i*i <= maxim:
        if spf[i] != i: i += 1; continue
        j = i*i
        while j <= maxim:
            if spf[j] != j: j += i; continue
            spf[j] = i
            j += i
        
        i += 1

    pairwise = True
    allP = set()
    for a in A:

        m  = set()
        n = a
        while n > 1:
            m.add(spf[n])
            n //= spf[n]

        P = m

        no_collapse = len(allP) + len(P)
        for p in P:
            allP.add(p)
        
        res = len(allP)
        if no_collapse != res:
            pairwise = False
            break


    return pairwise

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"

    pairwise = solve(N, np.array(A))

    if pairwise:
        print("pairwise coprime")
    else:
        gcm = np.gcd.reduce(A)
        if gcm == 1:
            print("setwise coprime")
        else:
            print("not coprime")


def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')

    # basic types: https://numba.pydata.org/numba-doc/0.13/types.html
    cc.export('solve', '(i8,i8[:],)')(solve)
    cc.compile()

if __name__ == '__main__':
    # cc_export()
    try:
        from my_module import solve
    except:
        cc_export()
        exit()

    main()




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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 45;
const int mod = 1000000007;

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

// h(n, r) = c(n+r-1, r)
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
    fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
    ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
    return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main()
{
  int N, W;
  cin >> N >> W;
  vector<ll> w(N), v(N);
  rep(i,N) cin >> w[i] >> v[i];
  vector<vector<ll>> x(4);
  rep(i, N) {
    x[w[i]-w[0]].push_back(v[i]);
  }
  rep(i, 4) {
    sort(ALL(x[i]));
    reverse(ALL(x[i]));
  }
  ll ans = 0;
  for(int a = 0; a <= x[0].size(); ++a) {
    for(int b = 0; b <= x[1].size(); ++b) {
      for(int c = 0; c <= x[2].size(); ++c) {
        for(int d = 0; d <= x[3].size(); ++d) {
          if(w[0]*a+(w[0]+1)*b+(w[0]+2)*c+(w[0]+3)*d > W) continue;
          ll tmp = 0ll;
          rep(i, a) tmp += x[0][i];
          rep(i, b) tmp += x[1][i];
          rep(i, c) tmp += x[2][i];
          rep(i, d) tmp += x[3][i];
          chmax(ans, tmp);
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}

int main()
{
    int n;
    cin>>n;
    int a;
    int ans = 0;
    for (size_t i = 0; i < n; i++)
    {
        cin>>a;
        ans += a - 1;
    }
    cout << ans << endl;
    return 0;
}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N;
int A[10100], B[10100];
int C[10100];
vector<int> G[10100];
int Ans[10100];
bool visited[10100];

void bfs() {
    queue<int> que;
    int k = 0;
    que.push(0);
    while (!que.empty()) {
        int to = que.front();
        que.pop();
        if (visited[to])continue;
        Ans[to] = C[k++];
        visited[to] = true;
        for (int j:G[to]) {
            que.push(j);
        }
    }
    return;
}

signed main() {
    cin >> N;
    rep(i, N - 1) {
        cin >> A[i] >> B[i];
        --A[i], --B[i];
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }
    rep(i, N) {
        cin >> C[i];
    }
    sort(C, C + N, greater<int>());
    int ans = 0;
    rep(i, N) {
        ans += C[i];
    }
    ans -= C[0];
    cout << ans << endl;
    bfs();
    rep(i, N) {
        cout << (i ? " " : "") << Ans[i];
    }
    /*
    rep(i, N) {
        Cnt[i] = pii(G[i].size(), i);
    }
    sort(Cnt, Cnt + N, greater<pii>());
    rep(i, N) {
        int idx = Cnt[i].second;
        Ans[idx] = C[i];
    }
    int M=0;
    rep(i,N-1){
        M+=m
    }

    rep(i, N) {
        int idx = Cnt[i].second;
        Ans[idx] = C[i];
        for (int to:G[idx]) {

        }
    }
     */
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int,int>P;
typedef pair<P,int>P1;
#define fi first
#define sc second

vector<P1>query;
typedef long long ll;
int n;
int a[100005];
#define mod 998244353
int main(){
    cin >> n;
    rep(i,n){ int x; cin >> x; if(i==0&&x!=0){ puts("0"); return 0;} a[x]++; }
    if(a[0] != 1){ puts("0"); return 0;} 
    ll ans = 1;
    for(int i=1;i<=n;i++){
        rep(j,a[i]) ans = ans*a[i-1]%mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ld = long double;

constexpr int nax = 1000 * 1000 + 105;
constexpr int infty = 1000 * 1000 * 1000 + 5;
constexpr int mod = 1000 * 1000 * 1000 + 7;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  list<char> l;
  for (char c : s) l.push_back(c);
  int wynik = 0;
  while (!l.empty()) {
    char a = l.front();
    char b = l.back();
    if (a == b) {
      l.pop_front();
      if (!l.empty()) {
        l.pop_back();
      }
    } else if (a == 'x') {
      wynik++;
      l.pop_front();
    } else if (b == 'x') {
      wynik++;
      l.pop_back();
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << wynik << endl;
  return 0;
}


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

using namespace std;

int main(){
    int k,min_;
    int sum=0, mul=1;
    cin >> k;
    for (int i=1; i<=k; i++){
        for (int j=1; j<=k; j++){
            for (int l=1; l<=k; l++){
                int i1 = i;
                int j1 = j;
                int l1 = l;
                mul = 1;
                
                for (int m=2; m<=k;){
                    if( i1 % m == 0 && j1 % m == 0 && l1 % m == 0 ){
                        mul = mul*m;
                        i1 = i1 / m;
                        j1 = j1 / m;
                        l1 = l1 / m;
                        //cout << i1 << j1 << l1 << min1;
                    }
                    else m++;
                    if( i1 < m ) break;
                }
                sum += mul;
                
            }
        }
    }
    
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip> 
#include <cstring>
#include <queue>
#include <stack> 
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
int x;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> x;
	ll res = 0;
	res += x / 500 * 1000;
	res += (x % 500) / 5 * 5;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T& v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  ll n, w; in(n),in(w);
  vector<ll> W(n), V(n);
  loop(i,0,n) in(W[i]),in(V[i]);
  map<ll, int> M;
  loop(i,0,4) M[i+W[0]] = i; // 座標圧縮
  vector<ll> A[4];
  loop(i,0,n) {
    ll a = W[i], v = V[i];
    A[M[a]].push_back(v);
  }
  loop(i,0,4) {
    sort(A[i].rbegin(), A[i].rend());
  }
  vector<ll> acc[4];
  loop(i,0,4) {
    acc[i].push_back(0);
    for (auto &a: A[i]) acc[i].push_back(acc[i].back() + a);
  }
  
  ll ans = 0;
  loop(i,0,A[0].size()+1) {
    loop(j,0,A[1].size()+1) {
      loop(k,0,A[2].size()+1) {
        loop(l,0,A[3].size()+1) {
          if (i*W[0] + j*(W[0]+1) + k*(W[0]+2) + l*(W[0]+3) > w) continue;
          ans = max(ans, acc[0][i] + acc[1][j] + acc[2][k] + acc[3][l]);
        }
      }
    }
  }
  print(ans);
  
  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
    int count;
    cin >> count;

    vector<double> values;
    for (auto i = 0 ; i < count ; i++) {
        double v;
        cin >> v;
        values.push_back(v);
    }

    // 2つの要素を加算して2で割りを繰り返すので、ソートしてから処理すればよい
    sort(values.begin(), values.end());

    double sum = accumulate(values.begin(), values.end(), values[0], [] (auto a, auto b) { return (a + b) / 2.0; });
    cout << sum;
    return 0;
}



Measured memory_bytes: 632
#include<stdio.h>

int main(void) {
	int a, b, c, max, min;
	scanf("%d%d%d", &a, &b, &c);
	max = (a > b && a > c) ? a : (b > c) ? b : c;
	min = (a < b && a < c) ? a : (b < c) ? b : c;
	printf("%d", max - min);
}

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

int main() {
	long long N, K; cin >> N >> K;
	vector<long long>sum(N + 2);
	sum.at(0) = 0;
	for (long long i = 0; i <= N; i++) {
		sum.at(i + 1) = sum.at(i) + i;
	}
	long long ans = 0;
	for (long long j = K; j <= N + 1; j++) {
		ans += sum.at(N + 1) - sum.at(N + 1 - j) - sum.at(j) + 1;
	}
	cout << ans % (1000000007) << endl;
}

Measured memory_bytes: 4764
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Edge {
  int from;
  int to;
  ll cost;
  ll change;
  Edge() {;}
  Edge(int from, int to, ll cost, ll change) :
    from(from), to(to), cost(cost), change(change) {;}
  bool operator<(const Edge &rhs) const {
    if (cost != rhs.cost) { return cost > rhs.cost; }
    return change > rhs.change;
  }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

char str[10000];
int n, t;
map<string, int> mapto;
vector<vector<int> > station;
vector<vector<int> > costs;
int m;
int SIZE;

int main() {
  while (scanf("%d %d", &n, &t) > 0) {
    SIZE = 0;
    m = 0;
    mapto.clear();
    scanf("%s", str);
    mapto[str] = m++;
    scanf("%s", str);
    mapto[str] = m++;
    station.clear();
    costs.clear();
    station.resize(n);
    costs.resize(n);
    REP(i, n) {
      int k;
      scanf("%d", &k);
      SIZE += k;
      REP(j, k) {
        scanf("%s", str);
        if (!mapto.count(str)) { mapto[str] = m++; }
        station[i].push_back(mapto[str]);
      }
      REP(j, k - 1) {
        int c;
        scanf("%d", &c);
        costs[i].push_back(c);
      }
    }
    SIZE += m;
    Graph g(SIZE);
    {
      int from = m;
      REP(i, n) {
        REP(j, station[i].size()) {
          g[station[i][j]].push_back(Edge(station[i][j], from, t, 1));
          g[from].push_back(Edge(from, station[i][j], 0, 0));
          if (j != 0) {
            g[from - 1].push_back(Edge(from - 1, from, costs[i][j - 1], 0));
            g[from].push_back(Edge(from, from - 1, costs[i][j - 1], 0));
          }
          from++;
        }
      }
    }

    priority_queue<Edge> que;
    que.push(Edge(0, 0, 0, 0));
    vector<char> visit(SIZE);
    vector<ll> dist(SIZE, 1LL << 60) ;
    while (!que.empty()) {
      Edge e = que.top();
      que.pop();
      int from = e.to;
      if (visit[from]) { continue; }
      visit[from] = true;
      if (from == 1) {
        printf("%lld %lld\n", e.cost - t, e.change - 1);
        goto next;
      }
      FORIT(it, g[e.to]) {
        int to = it->to;
        ll ncost = it->cost + e.cost;
        ll nchange = it->change + e.change;
        if (visit[to]) { continue; }
        if (dist[to] < ncost) { continue; }
        dist[to] = ncost;
        que.push(Edge(from, to, ncost, nchange));
      }
    }
    puts("-1");
next:;
  }
}

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

#define ll long long
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


int main()
{
    int N,M;
    cin >> N >> M;
    
    set<int> ACs;
    multiset<int> WAs;
    
    int AC_result = 0;
    int WA_result = 0;

    rep(i,M)
    {
        int tmp;
        string result;
        cin >> tmp >> result;

        if( result == "WA" )
        {
            if( ACs.find(tmp) == ACs.end() ) WAs.insert(tmp);
        }
        else
        {
            if( ACs.find(tmp) == ACs.end() )
            {
                AC_result++;
                WA_result += WAs.count(tmp);
                WAs.erase(tmp);
            }
            ACs.insert(tmp);
        }
    }
    cout << AC_result << " " << WA_result << endl;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define pii pair<int, int>;
#define ss second
#define ff first
#define all(x) ((x).begin(), (x).end())

using namespace std;
using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;
const ll oo = 1e18;

ld ans = (ld)oo;
int n, m;
vector<int> adj[650];
vector<ld> dp(650, 0);

void funcao(int block){
    dp[n] = 0.0;
    for (int i=n-1; i>=1; i--){
        ld sum = 0.0, maxi = 0.0;
        ld num = adj[i].size();
        for (auto x : adj[i]){
            maxi = max(maxi, dp[x]);
            sum += dp[x];
        }

        if (i == block and num >= 2.0){
            sum -= maxi;
            num--;
        }

        dp[i] = sum/num + 1.0;
    }
    ans = min(dp[1], ans);
}

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

    for (int i=0; i<m; i++){
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
    }

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

    cout << fixed << setprecision(10) << ans << endl;
return 0;
}

Measured memory_bytes: 1408
def main():
    N,A,B = map(int,input().split())
    X = list(map(int,input().split()))

    ans = 0
    for i in range(N-1):
        d = X[i+1]-X[i]
        ans += min(B, A*d)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14224