akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
typedef long double ld;
typedef pair<ld,ld> pii;


ld calc(pii x, pii y)
{
    ld dx = (x.first - y.first) * (x.first-y.first);
    ld dy = (x.second - y.second) * (x.second - y.second);
    return (sqrt(dx+dy));
}


int main()
{
#ifndef RICARDO
    //freopen("input.inp", "r", stdin);
#endif // RICARDO
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pii> a(n);
    for(int i=0; i<n; ++i)
    {
        cin >> a[i].first >> a[i].second;
    }
    ld k=1;
    for(int i=1; i<=n; ++i) k*=i;
    ld way =1;
    for(int i=1; i<=n-1; ++i) way*=i;
    ld sum =0;
    for(int i=0 ; i<n; ++i)
        for(int j=i+1; j<n; ++j)
    {
        ld len = calc(a[j],a[i]);
        sum += len*(way)*2;
    }
    cout << setprecision(10) << fixed << sum/k;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll b, ll m) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll h = modpow(a, b / 2, m);
        return h * h % m;
    } else {
        return a * modpow(a, b - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    ll res0 = 0;
    REP(i, N) {
        cin >> A[i];
        if (i % 2 == 0) {
            res0 += A[i];
        } else {
            res0 -= A[i];
        }
    }
    vector<ll> res(N, 0);
    res[0] = res0;
    A[0] -= res0 / 2;
    A[N - 1] -= res0 / 2;
    FOR(i, 1, N, 1) {
        res[i] += A[i - 1] * 2;
        A[i] -= A[i - 1];
    }
    REP(i, N) {
        cout << res[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;

int main() {
    ll x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> e(a),r(b),t(c);
    rep(i,a) cin >> e[i];
    rep(i,b) cin >> r[i];
    rep(i,c) cin >> t[i];
    sort(all(e));
    reverse(all(e));
    sort(all(r));
    reverse(all(r));
    sort(all(t));
    reverse(all(t));
    ll ans=0;
    rep(i,x) ans+=e[i];
    rep(i,y) ans+=r[i];
    ll u=x+y;
    ll o=ans;
    x--;
    y--;
    rep(i,u){
        bool w;
        if (i>=c) break;
        if (x==-1) w=true;
        else if (y==-1) w=false;
        else if (e[x]>r[y]) w=true;
        else w=false;
        if (w){
            o+=t[i]-r[y];
            ans=max(ans,o);
            y--;
        }
        else {
            o+=t[i]-e[x];
            ans=max(ans,o);
            x--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

ll cnt[202020];

int main(){

    ll N, M;
    cin >> N >> M;
    V v(N);
    rep(i, N)cin >> v[i];
    ll sum = 0;
    rep(i, N - 1){
        ll a = v[i], b = v[i + 1];
        if(a > b)b += M;
        cnt[a + 2]++;
        cnt[b + 1]--;
        sum += b - a;
    }
    rep1(i, 202000)cnt[i] += cnt[i - 1];
    rep(i, N - 1){
        ll a = v[i], b = v[i + 1];
        if(a > b)b += M;
        cnt[b + 1] -= b - a - 1;
    }
    rep1(i, 202000)cnt[i] += cnt[i - 1];
    // cout << sum << endl;
    // rep1(i, 2 * M)cout << i << " : " << cnt[i] << endl;
    ll ans = sum;
    rep1(i, M)chmin(ans, sum - cnt[i] - cnt[i + M]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>

int main(){
	int x,y;
	int tmp;
	for(;scanf("%d%d",&x,&y),x || y;){
		if(x>y){
			tmp=x;
			x=y;
			y=tmp;
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 600
while True :
    S = input()
    
    if S == "END OF INPUT" :
        break
    
    else :
        S += " "
        N = []
        s = 0
        b = 0
        
        for i in range(len(S)) :
            if S[i] != " " :
                s += 1
            else :
                b += 1
                if b == 1 :
                    N.append(s)
                    s = 0
                    b = 0
                else :
                    N.append(0)
                    b = 0
  
        for i in range(len(N)) :
            if i == len(N) - 1 :
                print(N[i])
            else :
                print(N[i], sep = "", end = "")
            
            
        


Measured memory_bytes: 5564
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

int main(){

    int N;
    cin >> N;

    int a, b;
    for(a = 1; a < 10; a++){
        b = N / a;
        if(a * b == N){
            if(b < 10){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 256
n = int(input())
res = n
l = []
i = 2
while i * i <= n:
    while n % i == 0:
        l.append(i)
        n //= i
    i += 1
if n != 1:
    l.append(n)
l = set(l)
for i in l:
    res *= (1 - 1 / i)
print(int(res))



Measured memory_bytes: 5600
#include <stdio.h>

struct CARD{
   char mark;
   int  number;
};

int BubbleSort(struct CARD B[], int b){
   int flag;
   int i;
   int s = 0;
   struct CARD v;

   flag = 1;
   while (flag) {
      flag = 0;
      for (i = b - 1; i > 0; --i) {
         if (B[i].number < B[i - 1].number) {
            v = B[i];
			B[i] = B[i - 1];
			B[i - 1] = v;
			s = s + 1;
			flag = 1;
         }
      }
   }
   return s;
}

int SelectionSort(struct CARD C[], int c) {
   int i, j, minj;
   int s = 0;
   struct CARD v;
   
   
   for (i = 0; i < c - 1; ++i) {
      minj = i;
	  for (j = i; j < c; ++j) {
		 if (C[j].number < C[minj].number)
			minj = j;
	  }
	  if (i != minj) {
		 v = C[i];
		 C[i] = C[minj];
		 C[minj] = v;
		 s = s + 1;
	  }
   }
   return s;
}

int main() { 
   struct CARD A[150], B[150], C[150];
   int i, j, n;
   int s, judge;
   char dummy;

   scanf("%d", &n);
   scanf("%c", &dummy);
   i = 0;
   while (i < n) {
      scanf("%c%d", &A[i].mark, &A[i].number);
	  scanf("%c", &dummy);
	  B[i] = A[i];
	  C[i] = A[i];
      i++;
   }
   s = BubbleSort(B, n);
   for (i = 0; i < n; ++i) {
	   printf("%c%d", B[i].mark, B[i].number);
	   if (i != n - 1)
		   putchar(' ');
   }
   putchar('\n');
   printf("Stable\n");

   s = SelectionSort(C, n);
   for (i = 0; i < n; ++i) {
	  printf("%c%d", C[i].mark, C[i].number);
	  if (i != n - 1)
		 putchar(' ');
   }
   putchar('\n');
   judge = 1;
   for (i = 0; i < n; ++i) {
	  if (B[i].number == C[i].number && B[i].mark != C[i].mark) {
		 judge = 0;
		 printf("Not stable\n");
		 break;
	  }
   }
   if (judge)
	  printf("Stable\n");
   return 0;
}

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

#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define v(t) vector<t>
#define vv(t) vector<vector<t>>
#define vn(t,n,val) vector<t>(n,val)
#define vvn(t,r,c,val) vector<vector<t>>(r, vector<t>(c,val))
#define vvv(t) vector<vector<vector<t>>>
#define vvvn(t,l,b,h,val) vector<vector<vector<t>>>(l,vector<vector<t>>(b,vector<t>(h)))

int main() {
	sp;

	////////////////To Remove//////////////
	// freopen("../../input.txt", "r", stdin);
	// freopen("../../output.txt", "w", stdout);
	///////////////////////////////////////

	int x,y,z;
	cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y;

  	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, x;
    cin >> N >> x;
    vector<ll> a(N);
    for (ll i = 0; i < N; i++) {
        cin >> a[i];
    }

    ll ans = 0;
    for (ll i = 1; i < N; i++) {
        ll d = a[i] + a[i - 1] - x;
        if (d > 0) {
            ll op = min(d, a[i]);
            ans += op;
            d -= op;
            a[i] -= op;

            ans += min(d, a[i - 1]);
        }
    }

    cout << ans << endl;
}

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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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


int solve(){
  int r;cin>>r;

  if (r<1200) {
    cout << "ABC" << endl;
  }
  else if(r<2800){
    cout << "ARC" << endl;
  }
  else{
    cout << "AGC" << endl;
  }

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF 1000000007
#define N 100005
#define PI 3.14159265
bool compare(pair<ll,ll> i, pair<ll,ll> j) 
{
  return i.S < j.S;
}
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
}
int main()
{
  	ll n,k,a=0,b;
  	vi v;
  	cin>>n>>k;
  	rep(i,0,n)
    {
    	cin>>b;
      	v.pb(b);
    }
  	if(k>=n)
      	cout<<"0";
  	else
    {
      	sort(all(v));
      	rep(i,0,n-k)
        {
          	a+=v[i];
        }
    cout<<a;
    }
  	return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 100005;

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

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

    }
    int res = 0;
    for( int i = 1; i < n; ++i ) {
        if( a[i] == a[i - 1] ) {
            a[i] = -1;
            ++res;

        }
    }
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <utility>
#include <climits>
#include <vector>

using namespace std;

#define N 10005
#define M 20005
#define INF INT_MAX

struct edge{
	int from, to, distance, cost;
	edge(int _from, int _to, int _distance, int _cost){
		from = _from;
		to = _to;
		distance = _distance;
		cost = _cost;	
	}
	bool operator > (const edge& e) const{
		return distance == e.distance ? cost > e.cost : distance > e.distance;
	}
};

bool used[N];
int n, m;
vector<edge> E[N];
int solve(){
	int rst = 0;
	priority_queue<edge, vector<edge>, greater<edge> > que;
	fill(used, used + n, false);
	que.push(edge(0, 0, 0, 0));
	
	while(!que.empty()){
		edge p = que.top();
		que.pop();
		int v = p.to;
		if (used[v]) continue;
		used[v] = true;
		
		rst += p.cost;
		
		for (int i = 0; i < E[v].size(); i++){
			edge& e = E[v][i];
			
			que.push(edge(e.from, e.to, p.distance + e.distance, e.cost));
		}
	}
	return rst;
}

int main(){
	int from, to, distance, cost;
	while (true){
		scanf("%d %d", &n, &m);
		if (n ==0 && m == 0) break;
		for (int i = 0; i < N; i++){
			E[i].clear();
		}
		for (int i = 0; i < m; i++){
			scanf("%d %d %d %d", &from, &to, &distance, &cost);
			from--, to--;
			E[from].push_back(edge(from, to, distance, cost));
			E[to].push_back(edge(to, from, distance, cost));
		}
		int ans = solve();
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 5684
#include <iostream>                            
#include <algorithm>                           
                                               
int main()                                     
{                                              
    int a, b, c, k;                            
    std::cin >> a >> b >> c >> k;              
    for (int i = 0; i < k; i++) {              
        if (std::max({a, b, c}) == a) {        
            a <<= 1;                           
        } else if (std::max({a, b, c}) == b) { 
            b <<= 1;                           
        } else {                               
            c <<= 1;                           
        }                                      
    }                                          
                                               
    std::cout << a + b + c << std::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/detail/standard_policies.hpp>
using namespace __gnu_pbds;


using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "debug.h"
#else
    #define debug(...)
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<vector<int> > vvi;
typedef vector<vector<ii> > vvii;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define ff first
#define ss second
#define trav(a, x) for(auto& a : x) 
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define PI 3.1415926535897932384626433832795
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5;
ll gcd(ll a,ll b){if (a==0) return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
ll Abs(ll a){if(a>0)return a;return -a;}
ll Ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
double Abs(double a){if(a>0)return a;return -a;}

//*X.find_by_order(2) element at index=2
//X.order_of_key(1) how many elements strictly less than 1

#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 

inline int pow_(ll x, ll y,ll p){
  int r = 1; while(y){if(y & 1) r = r * x % p; y >>= 1; x = x * x % p;} return r;
}
inline int inv_(int x){return pow_(x, mod - 2, mod);}
inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int mul(int a, int b){return a * 1LL * b % mod;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}

int main()
{
    #ifdef LOCAL_TEST
    freopen("in.txt","r",stdin);
    //freopen("out.txt", "w", stdout);
    #else
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #endif
    ll n;
    cin>>n;
    vector<int> v;
    for(int i=1;i<=n;i++)
    {
        int a;
        cin>>a;
        v.pb(a);
    }
    vector<int> v1;
    v1.pb(v[0]);
    for(int i=0;i<v.size();i++)
    {
        if(i+1 < v.size() && v[i]!=v[i+1])
        {
            v1.pb(v[i+1]);
        }
    }
    
    ll dp[200005][2] = {0};
    dp[1][0] = 1;
    dp[1][1] = 0;
    ll pref_sum[200005] = {0};
    pref_sum[v1[0]] = 1;
    for(int i=2;i<=v1.size();i++)
    {
        dp[i][0] = (dp[i-1][1] + dp[i-1][0])%mod;
        dp[i][1] = pref_sum[v1[i-1]];
        pref_sum[v1[i-1]] = (pref_sum[v1[i-1]] + dp[i-1][1] + dp[i-1][0])%mod;
    }

    cout << (dp[v1.size()][1] + dp[v1.size()][0])%mod << "\n";    return 0;
}

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

int32_t main() {
	int n;
	cin >> n;
	if(n % 1000 == 0) cout <<"0"<< endl;
	else cout << 1000 - (n % 1000) << endl;
	return 0;
}


Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String[] tmpArray = br.readLine().split(" ");

			int n = Integer.parseInt(tmpArray[0]);
			int budget = Integer.parseInt(tmpArray[1]);

			if(n == 0 && budget == 0){
				break;
			}

			Section[] sections = new Section[n];
			for(int i = 0; i < n; i++){
				tmpArray = br.readLine().split(" ");
				sections[i] = new Section(Integer.parseInt(tmpArray[0]), Integer.parseInt(tmpArray[1]));
			}

			Arrays.sort(sections);

			int sum = 0;
			for(int i = 0; i < n; i++){
				int p = sections[i].probablity;

				int cost = Math.min(budget, sections[i].distance);

				sum += (sections[i].distance - cost)*p;
				budget -= cost;

//				System.out.println("p "+p+"budge "+budget);
//				sum += Math.max(0, p - budget);
//				budget = Math.max(0, budget - p);
			}

			System.out.println(sum);
		}
	}

}

class Section implements Comparable<Section>{
	int distance;
	int probablity;

	public Section(int d, int p){
		this.distance = d;
		this.probablity = p;
	}

	@Override
	public int compareTo(Section o) {
		// TODO ?????????????????????????????????????????????
		return -(this.probablity - o.probablity);
	}
}

Measured memory_bytes: 64884
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
    #endif
}

int32_t main()
{
	fastIO
//	inp_out();
	string s;
	cin>>s;
	for(int i=0;i<s.size();++i)
	{
		if(s[i]=='?')
			cout<<'D';
		else cout<<s[i];
	}

	return 0;
}

Measured memory_bytes: 3788
#include <stdio.h>
#include<stdlib.h>

int main(void)
{
    int A;
    int N, min, max;
     
     scanf("%d", &N);
     scanf("%d", &A);
     min = A;
     max = A;
     for (int i=1; i<N; i++)
     {
        scanf("%d", &A);
        if(min > A){ min = A; }
        if(max < A){ max = A; }
     }
     printf("%d", abs(max - min));
     return 0;
}


Measured memory_bytes: 128
# YouTube解説
MOD = 1000000007
n, k = [int(x) for x in input().split()]
d = [0] * (k + 1)

for i in range(1, k + 1):
    d[i] = pow(k // i, n, MOD)

for i in range(k, 0, -1):  # 大きいほうから
    for j in range(i * 2, k + 1, i):  # iの倍数
        # d[6] = d'[6] - d[12] - d[18] ...
        d[i] -= d[j]
        d[i] %= MOD
ans = 0
for i, item in enumerate(d):
    ans += i * item
    ans %= MOD
print(ans)


Measured memory_bytes: 11172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a,b,c,d,n,m,x[101],y[101],z,h[101],w,sum,mi,ma,ans,s,t,l,r,res,tmp,itr,p,q;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef map<int, int> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<ll,ll> > VP;

int main(void){
    cin>>n>>m;
    VP vp;
    vector<vector<ll> > v(n);
    rep(i,m){
        cin>>a>>b;
        a--,b--;
        vp.pb({a,b});
        v[a].pb(b);
    }
    rep(i,n)sort(all(v[i]));
    rep(i,m){
        cout << setfill('0') << right << setw(6) << vp[i].fi+1;
        itr = lower_bound(all(v[vp[i].fi]), vp[i].se)-v[vp[i].fi].begin();
        cout << setfill('0') << right << setw(6) << itr+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 8560
#include "iostream"
#include "string"
#include "vector"
#include "algorithm"
#include "functional"
#include "cmath"

#define INF 1000000
#define BAR_NUM 3

long calc_min_mp(std::vector<int> remain_bars, std::vector<int> current_lengths,
        std::vector<int> target_lengths, int junction_num) {
//    int current_a = current_lengths[0];
//    int current_b = current_lengths[1];
//    int current_c = current_lengths[2];
//    int target_a = target_lengths[0];
//    int target_b = target_lengths[1];
//    int target_c = target_lengths[2];

    if (remain_bars.size() == 0) {
        int current_lengths_prod = current_lengths[0] * current_lengths[1]
                * current_lengths[2];
        if (current_lengths_prod == 0) {
            return INF;
        } else {
            int length_differs_sum = 0;

            junction_num -= 3;
            for (int i = 0; i < BAR_NUM; ++i) {
                length_differs_sum += std::abs(
                        current_lengths[i] - target_lengths[i]);
            }
            return junction_num * 10 + length_differs_sum;
        }
    }

    int next_bar = remain_bars.back();
    remain_bars.pop_back();
    std::vector<int> current_lengths_tmp = current_lengths;

    long mp_when_pass_next = calc_min_mp(remain_bars, current_lengths,
            target_lengths, junction_num);

    current_lengths_tmp[0] += next_bar;
    long mp_when_join_next_a = calc_min_mp(remain_bars, current_lengths_tmp,
            target_lengths, junction_num + 1);

    current_lengths_tmp = current_lengths;
    current_lengths_tmp[1] += next_bar;
    long mp_when_join_next_b = calc_min_mp(remain_bars, current_lengths_tmp,
            target_lengths, junction_num + 1);

    current_lengths_tmp = current_lengths;
    current_lengths_tmp[2] += next_bar;
    long mp_when_join_next_c = calc_min_mp(remain_bars, current_lengths_tmp,
            target_lengths, junction_num + 1);

    return std::min( { mp_when_pass_next, mp_when_join_next_a,
            mp_when_join_next_b, mp_when_join_next_c });
}

int main() {
    // get values from input
    unsigned int n;
    int a, b, c;
    std::vector<int> l;

    std::cin >> n >> a >> b >> c;
    for (unsigned int i = 0; i < n; ++i) {
        int l_i;
        std::cin >> l_i;
        l.push_back(l_i);
    }

    // main procedure
    std::vector<int> lengths_init(3, 0);
    std::vector<int> target_lengths { a, b, c };

    int min_mp = calc_min_mp(l, lengths_init, target_lengths, 0);

    // output
    std::cout << min_mp << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, m;
    cin >> n >> m;
    n += 2;
    m += 2;
    vector<string> s(n);
    FOR(i,1,n-2){
        cin >> s[i];
        s[i] = "#" + s[i] + "#";
    }
    REP(i,m){
        s[0] += "#";
        s[n-1] += "#";
    }
    int x, y, dir;
    REP(i,n) REP(j,m){
        string sd = "v^><";
        if (sd.find(s[i][j]) == string::npos) continue;
        if (s[i][j] == 'v') dir = 0;
        if (s[i][j] == '>') dir = 1;
        if (s[i][j] == '^') dir = 2;
        if (s[i][j] == '<') dir = 3;
        x = i;
        y = j;
    }
    int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
    VVI a(n,VI(m));

    bool f = 0;
    REP(poyo,10000){
        a[x][y] = 1;
        if (s[x][y] == 'G'){
            f = 1;
            break;
        }
        int xn = x + dx[dir], yn = y + dy[dir];
        if (s[xn][yn] == '#'){
            dir = (dir + 1) % 4;
            continue;
        }
        int xr = xn + dx[(dir+3)%4], yr = yn + dy[(dir+3)%4];
        if (s[xr][yr] == '#'){
            x = xn;
            y = yn;
        }else{
            x = xn;
            y = yn;
            a[x][y] = 1;
            if (s[x][y] == 'G'){
                f = 1;
                break;
            }
            x = xr;
            y = yr;
            a[x][y] = 1;
            dir = (dir + 3) % 4;
        }
    }

    int ans = 0;
    REP(i,n) REP(j,m) ans += a[i][j];
    cout << (f ? ans : -1) << endl;

    return 0;
}

Measured memory_bytes: 3216
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int counter = 0;
		int w = sc.nextInt();
		int h = sc.nextInt();
		int n = sc.nextInt();
		int spot[][]=new int [n][2];
		
		for(int i=0; i<n; i++)
			for(int j=0; j<2; j++)
				spot[i][j]=sc.nextInt();
			
		int X=spot[0][0];
		int Y=spot[0][1];
		
		for(int i=1; i<=n;){//どこ目指してるのかな
			if(i==n) break;
			int whex=spot[i][0] - X;
			int whey=spot[i][1] - Y;
			if(whex!=0 && whey!=0){  //どっちも違う
				if(whex>0 && whey>0){ //右上
					X++;
					Y++;
					counter+=1;
				}
				else if(whex<0 && whey<0){ //左下
					X--;
					Y--;
					counter+=1;
				}
				else if(whex>0 && whey<0){ //右下
					X++;
					Y--;
					counter+=2;
				}
				else if(whex<0 && whey>0){ //左上
					X--;
					Y++;
					counter+=2;
				}
			}
			else if(whex==0 && whey!=0){ //Xは同じ
				if(whey>0) Y++;
				else if(whey<0) Y--;
				counter+=1;
			}
			else if(whex!=0 && whey==0){ //Yは同じ
				if(whex>0) X++;
				else if(whex<0) X--;
				counter+=1;
			}
			
			else if(whex==0 && whey==0){
				i++;
			}
			
			
		}
		
		System.out.println(counter);


	}

}

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

using namespace std;

typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll p,n;
    cin>>p>>n;
    ll*a=new ll[n];
    for(ll i=0;i<n;i++)
        cin>>a[i];
    ll m=a[1]-a[0];
    for(ll i=0;i<n-1;i++){
        if(i==0)
            m=max(p-a[n-1]+a[0],m);
        else
            m=max(a[i+1]-a[i],m);
    }
    cout<<p-m<<'\n';
    return 0;
}

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

int main(void){
    int n,W;
    cin >> n >> W;
    
    int v[n],w[n];
    for(int i = 0;i < n;i++)cin >> v[i] >> w[i];
    
    int dp[n+1][W+1];
    memset(dp,0,sizeof(dp));
    
    for(int i = 0;i < n;i++){
        for(int j = 0;j <= W;j++){
            if(j >= w[i]){
                dp[i+1][j] = max(dp[i][j],dp[i+1][j-w[i]]+v[i]);
            } else dp[i+1][j] = dp[i][j];
        }
    }
    
    cout << dp[n][W] << endl;
}


Measured memory_bytes: 7032
package main

import (
  "fmt"
  "os"
  "bufio"
  "strconv"
)

func main() {
  sc := bufio.NewScanner(os.Stdin)
  sc.Split(bufio.ScanWords)

  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())

  sc.Scan()
  l, _ := strconv.Atoi(sc.Text())

  zero := false
  sum := 0
  i := l
  for i = l; i < n + l; i++ {
    sum += i
    if i == 0 {
      zero = true
    }
  }

  if zero {
    fmt.Println(sum)
  } else if l < 0 {
    fmt.Println(sum - i + 1)
  } else {
    fmt.Println(sum - l)
  }

}



Measured memory_bytes: 640
// C - たくさんの数式

// bit 全探索

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	string S;
	cin >> S;

	ll ans = 0;

	for (int bits=0; bits<(1<<(S.size()-1)); bits++) {
		string val = {S[0]};
		for (int i=0; i<S.size()-1; i++) {
			if (bits & (1<<i)) {
				ans += stoll(val);
				val = {S[i+1]};
			} else {
				val.push_back(S[i+1]);
			}
		}
		ans += stoll(val);
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
    string n;

    cin >> n;

    if(n[0] == n[1] && n[1] == n[2]){
        cout << "Yes" << endl;
    }
    else if (n[1] == n[2] && n[2] == n[3]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

using namespace std;
typedef long long ll;
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define pii pair<int,int>
#define fr first
#define sc second
#define pb push_back
#define mp make_pair
#define forr(i,a,b) for(ll i=a;i<b;i++)
#define mod 1000000007
ll x,y,z,n,m,k,s=0,l=0,r=0,ans=0,cnt=0,a[10000],b[10000];
vector<ll> vec1,vec2;
vector<pll> vecp;
set<ll> st;
map<char,ll> mp1,mp2;
map<char,ll>::iterator it;
char x1[200002],x2[200002];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>x1;
cin>>x2;
n=strlen(x1);
forr(i,0,n)
mp1[x1[i]]++;
forr(i,0,n)
mp2[x2[i]]++;
for (it=mp1.begin();it!=mp1.end();++it)
{
ll g=(*it).sc;
if(g)vec1.pb(g);
}
for (it=mp2.begin();it!=mp2.end();++it)
{
ll g=(*it).sc;
if(g)vec2.pb(g);

}
sort(vec1.begin(),vec1.end());
sort(vec2.begin(),vec2.end());
forr(i,0,vec1.size())
if(vec1[i]!=vec2[i])ans=1;
if(!ans)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<pair<ll,ll>> svpl;
    char tmp = s.at(0);
    ll num = 1;
    for(i = 1;i < n;++i){
        if(s.at(i) == tmp) ++num;
        else{
            svpl.emplace_back(tmp-'0',num);
            tmp = s.at(i);
            num = 1;
        }
    }
    svpl.emplace_back(tmp-'0',num);
    ll m = svpl.size();
    ll ans = 0;
    if(svpl.front().first == 0){
        for(i = 0;i < min(m, 2*k);++i){
            ans += svpl.at(i).second;
        }
    }else{
        for(i = 0;i < min(m, 2*k+1);++i){
            ans += svpl.at(i).second;
        }
    }
    ll tmpval = ans;
    ll last;
    if(svpl.back().first == 0){
        last = m-2*k+1;
    }else{
        last = m-2*k-1;
    }
    
    for(i = 1;i <= last;++i){
        if(svpl.at(i).first == 0){
            tmpval -= svpl.at(i-1).second;
        }else{
            tmpval -= svpl.at(i-1).second;
            if(i+2*k-1 <= m-1) tmpval += svpl.at(i+2*k-1).second;
            if(i+2*k <= m-1) tmpval += svpl.at(i+2*k).second;
        }
        ans = max(ans, tmpval);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2548
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;

//try木
#define SZ 100001
struct Trie{
	int value;
	int next[26];
	Trie() {fill(next, next+26,-1);}
};
Trie trie[SZ];
int now=1;

int find(string s, int root){
	for(int i=0;s[i];++i){
		int c=s[i]-'0';
		if(trie[root].next[c]==-1){
			trie[root].next[c]=now;
			trie[now].value=c;
			now++;
		}
		root=trie[root].next[c];
	}
	return root;
}

int N;
LL L;
int ans=0;
LL dfs(int root,LL d){
	int count=0;
	LL aa=0;
	for(int i=0;i<2;i++){
		if(trie[root].next[i]!=-1){
			count++;
			aa^=dfs(trie[root].next[i],d+1);
		}
	}
	if(count==1){
		LL dd=L-d;
		LL e=1;
		while(dd%2==0){
			dd/=2;
			e*=2;
		}
		aa^=e;
	}
	return aa;
}



int main(){
	cin>>N>>L;
	Trie root;
	REP(i,N){
		string s;
		cin>>s;
		find(s,0);
	}
	if(dfs(0,0)!=0){
		cout<<"Alice"<<endl;
	}else{
		cout<<"Bob"<<endl;
	}

	return(0);
}

Measured memory_bytes: 15644
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#include <bitset>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
    int x,y;
    cin >> x >> y;
    int ans=INF;
    if(-x<=y) ans = min(ans,y-(-x)+1);
    if(x<=y) ans = min(ans,y-x);
    if(x<=-y) ans = min(ans,-y-x+1);
    if(-x<=-y) ans = min(ans,-y+x+2);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  long s;
  cin >> n >> k >> s;
  vector<long>a(n,0);
  int i;
  for(i=0;i<n;i++){
    if(i<k)a[i] = s;
    else{
      if(s<1000000000)a[i]=s+1;
      else a[i] = s-1;
    }
  }



  for(i=0;i<n;i++){
    cout << a[i] << " ";
  }
}


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

#define llong long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12


int n;
llong x;
llong int b[60];
llong int p[60];

llong run(int m,llong y){
	//printf("m=%d,y=%lld\n",m,y);
	//printf("b[m]=%lld,p[m]=%lld\n",b[m],p[m]);
	if(m==0){
		return 1;
	}else{
		if(y<=1){
			return 0;
		}else if(y<=b[m-1]+1){
			return run(m-1,y-1);
		}else if(y==b[m-1]+2){
			return run(m-1,y-2)+1;
		}else if(y<=2*b[m-1]+2){
			return run(m-1,y-b[m-1]-2)+p[m-1]+1;
		}else if(y==2*b[m-1]+3){
			//printf("ans=%lld\n",p[m]);
			return p[m];
		}
	}
}


int main(void)
{
	//変数の宣言
	
	//よく使う変数
	int i,j,k,l;
	int flag=0;
	llong int ans=0;
	int count=0;
	int temp,temp1,temp2;
	llong int max,min;
	int len;
	int sum=0;
	//データの読み込み
	scanf("%d %lld",&n,&x);
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	
	for(i=0;i<=50;i++){
		if(i==0){
			b[0]=1;
			p[0]=1;
		}else{
			b[i]=b[i-1]*2+3;
			p[i]=p[i-1]*2+1;
		}
//		printf("i=%d,b[i]=%lld,p[i]=%lld\n",i,b[i],p[i]);
	}
	
//	printf("p[%d]=%lld\n",50,p[50]);
	ans=run(n,x);
	
//	printf("計算部分終了\n");
	//出力
	
	printf("%lld",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    char a[1];
    cin >> a[0];
    if(a[0]=='A')cout << "T" << endl;
    else if(a[0]=='G') cout << "C" << endl;
    else if(a[0]=='C') cout << "G" << endl;
    else cout << "A" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define fi first
#define sec second
#define pr priority_queue
ll mod = 1000000007;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n; cin >> n;
	vector<ll> vec(n);
	ll sum = 0;
	for (ll i = 0; i < n; i++)
	{
		cin >> vec[i];
		sum = (sum + vec[i] + mod) % mod;
	}
	ll ans = 0;
	for (ll i = 0; i < n; i++)
	{
		ll v = (sum - vec[i] + mod) % mod;
		ll d = (vec[i] * v) % mod;
		ans = (ans + d + mod) % mod;
		sum = (sum - vec[i] + mod) % mod;
	}
	cout << ans << "\n";
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	rep(i, n) {
		char c;
		cin >> c;
		if (c == 'Y') {
			cout << "Four" << endl;
			return 0;
		}
	}
	cout << "Three" << endl;
	return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    ll k;
    cin >> n >> k;
    int sum = 0;
    vector<int> v(n);
    for(auto& i : v){
        cin >> i;
        sum += i;
    }

    set<int> st;
    for(int i=1; i*i<=sum; i++){
        if(sum%i == 0){
            st.insert(i);
            st.insert(sum/i);
        }
    }

    int ans = 0;
    
    for(auto d : st){
        vector<int> u(n);
        REP(i, n){
            u[i] = v[i] % d;
        }
        sort(all(u));

        int dec = k, inc = k;
        int p = -1, q = n;
        
        REP(i, n){
            if(u[i] <= dec){
                dec -= u[i];
                p = i;
            }else{
                break;
            }
        }
        RREP(i, n){
            if(d - u[i] <= inc){
                inc -= d - u[i];
                q = i;
            }else{
                break;
            }
        }

        if(q - p <= 1){
            chmax(ans, d);
        }
    }

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


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String s = sc.next();
        StringBuffer sb = new StringBuffer(s);
        String r = sb.reverse().toString();

        if(s.equals(r)){
            s = s.substring(0, (s.length() - 1) / 2);
            sb = new StringBuffer(s);
            r = sb.reverse().toString();
            if(s.equals(r)){
                System.out.println("Yes");
                return;
            }
        }

        System.out.println("No");

    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
	int a,b,c;
	cin >> a >> b >> c;

	if(a < b){
		if(b < c){
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3084
#!/usr/bin/env python
# -*- coding: utf-8 -*-

S = input().strip()
result = 0
num = list()
for i in range(len(S)):
    num.append(int(S[i]))

for b in range(2**(len(S)-1)):
    b_str = format(b, 'b').zfill(len(S)-1)
    sum = 0
    for i in range(len(num) - 1):
        if b_str[i] == '0':
            result += sum * 10 + num[i]
            sum = 0
        else:
            sum = sum * 10 + num[i]
    result += sum * 10 + num[-1]

print(result)



Measured memory_bytes: 9192
#include<stdio.h>
int main(){
  double H, W, r, x, y;
  scanf("%lf %lf %lf %lf %lf",&W, &H, &x,&y,&r);

  if(x-r<0 || y-r<0 || y+r>H || x+r>W){
    puts("No");
  }else{
    puts("Yes");
  }
  return 0;
}



Measured memory_bytes: 2148
#include<iostream>
#include<math.h>
int main()
{
  long int n;
  std::cin>>n;
  int k,h[n];
  std::cin>>k;
  long int dp[n];
  for(long int i=0;i<n;i++)
  std::cin>>h[i];
  dp[0]=0;
  dp[1]=std::abs(h[1]-h[0]);
    for(long int i=2;i<n;i++)
    {long int min=std::abs(h[i]-h[i-1])+dp[i-1];
     for(int j=2;j<=k&&j<=i;j++)
       if(min>abs(h[i]-h[i-j])+dp[i-j])
         min=std::abs(h[i]-h[i-j])+dp[i-j];
       dp[i]=min;
    }
  std::cout<<dp[n-1];
}

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

template<typename T>
struct CumulativeSum2D {
    vector<vector<T>> acc;
    CumulativeSum2D(int h = 0, int w = 0) : acc(h + 1, vector<T>(w + 1)) { }
    void add(int i, int j, int x) { acc[i + 1][j + 1] += x; }
    void build() {
        int H = acc.size(), W = acc[0].size();
        for (int i = 1; i < H; i++) for (int j = 1; j < W; j++) {
            acc[i][j] += acc[i][j - 1] + acc[i - 1][j] - acc[i - 1][j - 1];
        }
    }
    T sum(int si, int sj, int ti, int tj) {     // [si, ti) x [sj, tj)
        return acc[ti][tj] - acc[si][tj] - acc[ti][sj] + acc[si][sj];
    }
};

int main() {
    int n, k; cin >> n >> k;
    int sz = k * 2;
    CumulativeSum2D<int> acc(sz, sz);
    for (int i = 0; i < n; i++) {
        int x, y; char c; cin >> x >> y >> c;
        if (c == 'W') x += k;
        acc.add(x % sz, y % sz, 1);
    }
    acc.build();
    int ma = 0;
    for (int i = 0; i < k; i++) for (int j = 0; j < k; j++) {
        int tmp = 0;
        tmp += acc.sum(0, 0, i, j);
        tmp += acc.sum(i + k, 0, sz, j);
        tmp += acc.sum(0, j + k, i, sz);
        tmp += acc.sum(i, j, i + k, j + k);
        tmp += acc.sum(i + k, j + k, sz, sz);
        ma = max({ma, tmp, n - tmp});
    }
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 16000
#include <iostream>
using namespace std;
int main(void){
    int m,f,j,a,b;
    cin >> m >> f >> j;
    
    a=m+f;
    
    
    if(m>=j)
        cout << '0' << endl;
    else if(a>=j){
        b=j-m;
        cout << b << endl;
    }
    else
        cout << "NA" << endl;
}



Measured memory_bytes: 3096
#include<iostream>
#include<vector>
#define ll long long
using namespace std;

vector<int>decompose(ll x){
	vector<int>tmp;
	while(x)tmp.push_back(x%10),x/=10;
	return tmp;
}

ll to_number(vector<int>x){
	ll tmp=0;
	for(int i=x.size()-1;~i;--i)
	(tmp*=10)+=x[i];
	return tmp;
}

ll sum(ll x){
	ll s=0;
	while(x)s+=x%10,x/=10;
	return s;
}

inline ll f(ll x){
	vector<int>dx=decompose(x);
	double mn=1e18;ll ne=-1;
	for(int i=0;i<dx.size();++i){
		for(int d=dx[i];d<=9;++d){
			vector<int>dy=dx;
			dy[i]=d;
			for(int j=0;j<i;++j)dy[j]=9;
			ll y=to_number(dy),sy=sum(y);
			if((double)y/sy<mn)
				mn=(double)y/sy,ne=y;
		}
	}
	return ne;
}

int k;

void solve(){
	ll s=1;
	for(int i=1;i<=k;++i,s=f(s+1))
		cout<<s<<"\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin>>k;
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll N, A, B;
    cin>>N>>A>>B;
    cout<<min(A*N, B)<<endl;
    return 0;
}


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

int main() {
  int n;
  int f=1;
  cin >> n;
  while(f==1){
    if(n>=1000) n = n - 1000;
    else break;
  }
  if(n==0){
    cout << n;
    return 0;
  }
  else cout << 1000 - n ;
  
  
}

Measured memory_bytes: 3628
N, K = map(int, input().split())
dK = 2*K

MeetDemand =[[0 for y in range(dK+1)] for x in range(K+1)]
for i in range(N):
    x, y, c =input().split()
    x = int(x) % dK
    y = (int(y)+K if c=="W" else int(y)) % dK
    if K <= x:
        if 0 <= y < K:
            x -= K
            y += K
        else:
            x %= K
            y %= K
    if 0 <= y < K:
        MeetDemand[0][0] += 1
        MeetDemand[x+1][y+1] += 2
        MeetDemand[0][y+1] -= 1
        MeetDemand[x+1][0] -= 1
        MeetDemand[0][y+K+1] += 1
        MeetDemand[x+1][y+K+1] -= 2
    else:
        MeetDemand[0][y-K+1] += 1
        MeetDemand[x+1][y-K+1] -= 2
        MeetDemand[x+1][0] += 1
        MeetDemand[0][y+1] -= 1
        MeetDemand[x+1][y+1] += 2

for x in range(K):
    for y in range(1, dK):
        MeetDemand[x][y] += MeetDemand[x][y-1]
for y in range(dK):
    for x in range(1, K):
        MeetDemand[x][y] += MeetDemand[x-1][y]

Ans = max(MeetDemand[0][:dK])
for i in range(1, K):
    Ans = max(Ans, max(MeetDemand[i][:dK]))
print(Ans)

Measured memory_bytes: 82800