akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

ll modpow(ll a, ll b){
    if(b == 0) return 1;
    else if(b % 2 == 0){
        ll d = modpow(a, b/2) % MOD;
        return (d * d) % MOD;
    }
    else{
        return (a * modpow(a, b-1)) % MOD;
    }
}

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

    ll n, a, b; cin>>n>>a>>b;

    ll ans = modpow(2, n) - 1;

    ll nCa = 1;
    for(int i=0; i<a; i++){
        nCa *= (n - i);
        nCa %= MOD;
    }

    for(int i=a; i>=1; i--){
        nCa *= modpow(i, MOD - 2);
        nCa %= MOD;
    }

    ll nCb = 1;
    for(int i=0; i<b; i++){
        nCb *= (n - i);
        nCb %= MOD;
    }

    for(int i=b; i>=1; i--){
        nCb *= modpow(i, MOD - 2);
        nCb %= MOD;
    }

    ans -= nCa;
    ans += MOD;
    ans -= nCb;
    ans += MOD;

    cout << ans % MOD << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }

    static Scanner cin;

    // メンバ変数---
    int N;
    // -------------

    void calc()
    {
        N = cin.nextInt();
        int e = N / 2;
        double ret = (double)e / N;
        Write(1 - ret);
    }

    void Write(string v)
    {
        Console.WriteLine(v);
    }

    void Write(int v)
    {
        Console.WriteLine(v);
    }

    void Write(double v)
    {
        Console.WriteLine(v);
    }
    void Write(long v)
    {
        Console.WriteLine(v);
    }

    int Pow(int x, int y)
    {
        return (int)Math.Pow(double.Parse(x.ToString()), double.Parse(y.ToString()));
    }

    double Pow(double x, double y)
    {
        return Math.Pow(x, y);
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

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

int main() {
	int n; cin >> n;
	vector<int> a(n + 1), f(n + 1);
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 2; i <= n; i++) {
		f[i] = f[i - 1] + abs(a[i] - a[i - 1]);
		if (i > 2) f[i] = min(f[i], f[i - 2] + abs(a[i] - a[i - 2]));
	}
	cout << f[n] << '\n';
}


Measured memory_bytes: 4056
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord
import Data.Maybe


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    [k,n] <- r'
    v <- r n
    let v2 = v U.++ U.map (+k) v
    print $ minimum $ [  v2 U.! (s+n-1)  -  (v2 U.! s) | s<-[0..n-1]]



Measured memory_bytes: 10620
N = int(input())

def divisors(n):
    re = 0
    for i in range(1,int(n**0.5)+1):
        if n % i == 0:
            if n == i**2:
                re += 1
            else:
                re += 2
    return re
ans = 0
for i in range(1,N+1,2):
    if divisors(i) == 8:
        ans += 1
print(ans)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x;
  cin >> x;
  long long ans = 1000 * (x / 500);
  x %= 500;
  ans += 5 * (x / 5);
  cout << ans << '\n';
  return 0;
}


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

#define IL __inline__ __attribute__((always_inline))

#define For(i, a, b) for (int i = a, i##end = b; i <= i##end; ++ i)
#define FOR(i, a, b) for (int i = a, i##end = b; i < i##end; ++ i)
#define Rep(i, a, b) for (int i = a, i##end = b; i >= i##end; -- i)
#define REP(i, a, b) for (int i = (a) - 1, i##end = b; i >= i##end; -- i)

typedef long long LL;

template <class T>
IL bool chkmax(T &a, const T &b) {
  return a < b ? ((a = b), 1) : 0;
}

template <class T>
IL bool chkmin(T &a, const T &b) {
  return a > b ? ((a = b), 1) : 0;
}

template <class T>
IL T mymax(const T &a, const T &b) {
  return a > b ? a : b;
}

template <class T>
IL T mymin(const T &a, const T &b) {
  return a < b ? a : b;
}

template <class T>
IL T myabs(const T &a) {
  return a > 0 ? a : -a;
}

const int INF = 0X3F3F3F3F;
const double EPS = 1E-10, PI = acos(-1.0);

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define OK DEBUG("Passing [%s] in LINE %d...\n", __FUNCTION__, __LINE__)
/*------------------------------header------------------------------*/

int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  if ((a & 1) && (b & 1) && (c & 1)) {
    printf("%lld\n", mymin((LL)a * b, mymin((LL)b * c, (LL)c * a)));
  } else {
    puts("0");
  }
  return 0;
}


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

using namespace std;

int main(void) {
  long long i, tmp, sum_A, answer;
  long long N, CONST_VAL;
  vector<long long> A;
  
  CONST_VAL = 1000000007;
  // get input
  cin >> N;
  for(i = 0; i < N; i++) {
    cin >> tmp;
    A.push_back(tmp);
  }
  // calc answer
  answer = 0;
  sum_A = 0;
  for(i = A.size() - 1; i >= 1; i--) {
    sum_A = (sum_A + A[i])%CONST_VAL;
    answer = (answer + A[i - 1]*sum_A)%CONST_VAL;
  }
  
  // disp answer
  cout << answer << endl;
  
  return 0;
}


Measured memory_bytes: 5368
from itertools import permutations

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

for idx, pm in enumerate(permutations(range(1, N + 1))):
    if P == pm:
        a = idx
    if Q == pm:
        b = idx

print(abs(a-b))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define vi vector<int>
#define pi pair<int, int>
#define pb push_back
#define ppb pop_back
#define F frist
#define S second

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

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

    ll ans = 0;
    int n;
    cin >> n;
    for(int i = 1;i<=n;i++){
        if(i % 3 != 0 && i % 5 != 0) ans += i;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3652
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let t:f64 = read();
    let x:f64 = read();

    println!("{}", t/x);
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int N;
  cin >> N;
  cout << fixed << setprecision(6);
  if (N%2)
    cout << (N/2+1.0)/N << endl;
  else
    cout << 0.5 << endl;
  return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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 (a>b) { a=b; return 1; } return 0; }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    vector<ll> cnt(50, 0);
    for(int d=49;d>=0;d--){
        REP(i, N){
            if(A[i]>>d & 1) cnt[d]++;
        }
    }

    vector<vector<ll>> dp(51, vector<ll>(2, -1));
    dp[0][1] = 0;

    REP(d, 50){
        ll md = 49 - d;
        REP(i, 2){
            REP(j, 2){
                if(dp[d][i] == -1) continue;
                ll bit = (K>>md & 1);
                ll ni;
                if(i==0){
                    ni = 0;
                }else{
                    if(bit == j){
                        ni = 1;
                    }else if(bit < j){
                        continue;
                    }else{
                        ni = 0;
                    }
                }
                ll kei = (j==0 ? cnt[md] : N-cnt[md]);
                chmax(dp[d+1][ni], dp[d][i] + kei * (1ll<<md));
            }
        }
    }

    //cout << dp << endl;

    cout << max(dp[50][0], dp[50][1]) << endl;

    return 0;
}

Measured memory_bytes: 3964
#include <iostream>
#include <string>
using namespace std;
//Sunny, Cloudy, or Rainy

int main()
{
	string s1,s2;
	cin >> s1;
	if(s1 == "Sunny")
		s2 = "Cloudy";
	else if(s1 == "Cloudy")
		s2 = "Rainy";
	else
		s2 = "Sunny";
	cout << s2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

vll A;
vll B;
ll C;
ll N;
ll M;
ll K;

ll cntA[10]={};
ll cntB[10]={};

ll ltmp;
string stmp;
double dtmp;

vector<ll> inv,fact,invfact;
void setupCombination(ll n_max,ll mod){
    fact.resize(n_max+1);
    inv.resize(n_max+1);
    invfact.resize(n_max+1);
    fact[0]=inv[0]=invfact[0]=1;
    inv[1]=1;
    for(ll i=0;i<n_max;i++){
        fact[i+1]=fact[i]*(i+1)%mod;
        if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
        invfact[i+1]=invfact[i]*inv[i+1]%mod;
    }
}
ll getCombination(ll n,ll k,ll mod){
    if(n<0||k<0||k>n)return 0;
    return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}


int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    setupCombination(10,MOD);

    cin >> N;
    rep(ni,N){
        cin >> ltmp;
        A.push_back(ltmp);
    }
    rep(ni,N){
        cin >> ltmp;
        B.push_back(ltmp);
    }

    ll orderA=1,orderB=1;

    for( ll ni = 0 ; ni <=N-2 ; ni++ ){
        for( ll mi = ni+1 ; mi <=N-1 ; mi++ ){
            if(A[ni]>A[mi]) cntA[ni]++;
            if(B[ni]>B[mi]) cntB[ni]++;
        }
    }
    for( ll ni = 0 ; ni <=N-2 ; ni++ ){
        ll value;
        value = cntA[ni];
        orderA += value * fact[(N-1)-ni];
        value = cntB[ni];
        orderB += value * fact[(N-1)-ni];


    }

    //cout << orderA << endl;
    //cout << orderB << endl;
    cout << abs(orderA-orderB) << endl;




    

}

Measured memory_bytes: 3612
N,A,B=map(int, input().split())
#最小がA　最大がB　その区間でN個
if A>B:
    print(0)
    exit()
elif N==1 and A!=B:
    print(0)
    exit()
MAX=A+B*(N-1)
MIN=B+A*(N-1)
#print(MAX, MIN)
print(MAX-MIN+1)

Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include<map>
using namespace std;
int main()
{
    int n,m,a[100],s,c;
    map<int,int>q;
    cin>>n>>m;
    int flag=1;
    memset(a,-1,sizeof(a));
    while(m--)
    {
        cin>>s>>c;
        if(q.count(s)==0)
        {
            q[s]=c;
            a[s]=c;
        }
        else
        {
            if(q[s]!=c)
                flag=0;
        }
    }
    if(a[1]==0 && n>1)
        flag=0;
    if(flag==0)
        puts("-1");
    else
    {
        if(n>1)
        {
            for(int i=1; i<=n; i++)
            {
                if(a[i]==-1 && i==1)
                    cout<<1;
                else if(a[i]==-1 && i>1)
                    cout<<0;
                else
                    cout<<a[i];
            }
        }
        else
        {
            if(a[1]==-1)
                cout<<0;
            else
                cout<<a[1];
        }
    }
    return 0;
}


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


unsigned int N, a[200000], b[200000];

long long pow(int a, int x){
    long long ret = 1;
    for(int i = 0; i < x; i++){
        ret *= a;
    }
    return ret;
}


bool is_up(int k){
    for(int i = 0; i < N; i++){
        a[i] %= pow(2, k+1);
        b[i] %= pow(2, k+1);
    }
    sort(b, b+N);
    long long up_count = 0;
    for(int i = 0; i < N; i++){
        up_count += lower_bound(b, b+N, 2*pow(2, k) - a[i]) - lower_bound(b, b+N, pow(2, k) - a[i]);
        up_count += lower_bound(b, b+N, 4*pow(2, k) - a[i]) - lower_bound(b, b+N, 3*pow(2, k) - a[i]);
    }
    return !(up_count % 2 == 0);
}


int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    for(int i = 0; i < N; i++){
        cin >> b[i];
    }
    long long ans = 0;
    for(int k = 28; k >= 0; k--){
        if(is_up(k)){
            ans += 1 * pow(2, k);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
/*AC x
C
0

WA x
C
1

TLE x
C
2

RE x
C
3
*/


int main()
{
    int n;
    cin>>n;
    int countac =0;
    int countwa =0;
    int counttle =0;
    int countre =0;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        if(s=="AC")
            countac++;
        else if (s=="WA")
            countwa++;
        else if (s=="TLE")
            counttle++;
        else
            countre++;
    }
    cout<<"AC "<<"x "<<countac<<endl;
    cout<<"WA "<<"x "<<countwa<<endl;
    cout<<"TLE "<<"x "<<counttle<<endl;
    cout<<"RE "<<"x "<<countre<<endl;

}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
  int s;
  cin>>s;
  vector<int64_t> a(s+1,0);
  if(s==0){
    cout<<1<<endl;
  }else if(s<3){
    cout<<0<<endl;
  }else{
    a.at(0)=1;
    int64_t sum;
    for(int i=1;i<s+1;i++){
      if(i>=3){
        a.at(i)=a.at(i-3)+a.at(i-1);
        a.at(i)%=1000000007;
      }
    }
    cout<<a.at(s)<<endl;
  }
}
      

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

int stack[10000];
int TOP=-1;

void push(int x){
  ++TOP;
  stack[TOP] = x;
}

void pop(){
  stack[TOP] = 0;
  --TOP;
}

int top(){
  return stack[TOP];
}


int main(){ 
  int x;
  char s[100];
  int a,b;

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      a = top();
      pop();
      b = top();
      pop();

      push(a + b);
    } else if ( s[0] == '-' ){
      a = top();
      pop();
      b = top();
      pop();

      push(b - a);

    } else if ( s[0] == '*' ){
      a = top();
      pop();
      b = top();
      pop();

      push(a * b);

    } else {
      x = atoi(s);

      push(x);
    }
  }

  printf("%d\n",top());
  

  return 0;
}




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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

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

constexpr int MOD = 1000000007;

// O(log(p))
ll mpow(ll x, ll p) {
    if (p == 0) { return 1; }
    if (p == 1) { return x % MOD; }
    if (p % 2) { return (x * mpow(x, p - 1)) % MOD; }
    ll sub = mpow(x, p / 2);
    return (sub * sub) % MOD;
}

// O(n + log(MOD))
void prepare(vll& fac, vll& inv) {
    int n = fac.size() - 1;

    // O(n)
    fac[0] = 1;
    rep(i, 1, n + 1) { fac[i] = (i * fac[i - 1]) % MOD; }

    // O(n + log(MOD))
    inv.back() = mpow(fac.back(), MOD - 2);
    rrep(i, 0, n) { inv[i] = (inv[i + 1] * (i + 1)) % MOD; }
}

// O(1)
ll mcombination(const vll& fac, const vll& inv, int n, int r) {
    if (r == 0 || r == n) { return 1; }
    if (r == 1 || r == n - 1) { return n % MOD; }
    return (((fac[n] * inv[r]) % MOD) * inv[n - r]) % MOD;
}

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

    int n, k;
    cin >> n >> k;

    // O(n)
    vll a(n);
    rep(i, 0, n) { cin >> a[i]; }

    // O(nlog(n))
    sort(a.begin(), a.end());

    // O(n + log(MOD))
    vll fac(n + 1), inv(n + 1);
    prepare(fac, inv);

    if (k == 1) {
        cout << 0 << endl;
        return 0;
    }

    ll maxv = 0;
    rep(i, k - 1, n) {
        ll m = (mcombination(fac, inv, i, k - 1) * a[i]) % MOD;
        maxv = (maxv + m) % MOD;
    }
    ll minv = 0;
    rep(i, 0, n - k + 1) {
        ll m = (mcombination(fac, inv, n - i - 1, k - 1) * a[i]) % MOD;
        minv = (minv + m) % MOD;
    }

    ll ans = (maxv - minv) % MOD;
    if (ans < 0) { ans += MOD; }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
n = int(input())
a = list(map(int, input().split()))
s = 0
t = sum(a)
for i in range(n):
  s += a[i]
  if s - t / 2 > 0:
    break

s1 = s - a[i]    
print(min((t - s1 -s1), (s- (t - s) )))

Measured memory_bytes: 26224
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9


int main() {
	int D, G, p[11], c[11];
	cin >> D >> G;
	for (int i = 0; i < D; i++) {
		cin >> p[i] >> c[i];
	}

	int ans = 1e9;
	for (int mask = 0; mask < (1 << D); mask++) {
		int s = 0, num = 0, rest_max = -1;
		for (int i = 0; i < D; i++) {
			if (mask >> i & 1) { // ビット演算
								 // 2進法でi+1桁目が1ならtrue
				s += 100 * (i + 1) * p[i] + c[i];
				num += p[i];
			}
			else {
				rest_max = i;
			}
		}
		if (s < G) {
			int s1 = 100 * (rest_max + 1);
			int need = (G - s + s1 - 1) / s1;
			if (need >= p[rest_max]) {
				continue;
			}
			num += need;
		}
		ans = min(ans, num);
	}

	cout << ans << endl;

	return 0;
}

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

#include <vector>

#include <algorithm>

using namespace std;

#define repeat(n) for(int _ = 1; _ <= n; _++)

int main()
{
	ios::sync_with_stdio(false);
#ifdef CAI_WEI_HAN
	freopen("test.in", "r", stdin);
#endif
	
	int a, b;
	cin >> a >> b;
	
	cout << ((double)a / b);
}


Measured memory_bytes: 256
#include<cstdio>
#include<map>
#include<algorithm>
#define N 2200
#define LL long long
#define mod 1000000007
using namespace std;
typedef pair<LL,LL> PLL;
typedef map<LL,int>::iterator miter;
int n,p[N+5],pcnt,ans,cnt0;
bool vis[N+5];
map<LL,int> cnt;
map<LL,LL> iv;
void init()
{
	for(int i=2;i<=N;i++)
	{
		if(!vis[i]) p[++pcnt]=i;
		for(int j=1;i*p[j]<=N;j++)
		{
			vis[i*p[j]]=true;
			if(i%p[j]==0) break;
		}
	}
}
int main()
{
	scanf("%d",&n);
	init();
	for(int i=1;i<=n;i++)
	{
		LL a,tmp,h1=1,inv=1;
		scanf("%lld",&a); tmp=a;
		for(int j=1;j<=pcnt&&1ll*p[j]*p[j]*p[j]<=a;j++)
			if(tmp%p[j]==0)
			{
				int xcnt=0;
				while(tmp%p[j]==0) tmp/=p[j],xcnt++;
				xcnt%=3;
				for(int i=1;i<=xcnt;i++) h1*=1ll*p[j];
				for(int i=1;i<=(3-xcnt)%3;i++) inv*=1ll*p[j];
			}
		if(tmp>1) { h1*=1ll*tmp,inv*=1ll*tmp*tmp; }
		if(h1==1) { cnt0=1; continue; }
		cnt[h1]++;
		iv[h1]=inv,iv[inv]=h1;
	}
	for(miter it=cnt.begin();it!=cnt.end();it++)
		if(cnt.find(iv[it->first])==cnt.end()) ans+=it->second;
		else
		{
			ans+=max(it->second,cnt[iv[it->first]]);
			it->second=cnt[iv[it->first]]=0; 
		}
	printf("%d\n",ans+cnt0);
}

Measured memory_bytes: 18944
while True:
    n = int(input())
    if n == 0:
        break
 
    s = list(map(int, input().split()))
    m = sum(s) / n
    v = 0
    for si in s:
        v += (si - m) ** 2
    ans = (v / n) ** 0.5
    print("{:.5f}".format(ans))


Measured memory_bytes: 5668
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> broken(n + 1);
  rep(i, m)
  {
    int a;
    cin >> a;
    broken[a] = 1;
  }
  vector<int> dp(n + 1);
  const int mod = 1000000007;
  dp[n] = 1;
  for (int i = n - 1; i >= 0; i--)
  {
    if (broken[i])
    {
      // 壊れている段はルートに入らないので0でcontinue
      dp[i] = 0;
      continue;
    }
    if (i == n - 1)
    {
      dp[i] = (dp[i + 1]) % mod;
      continue;
    }
    dp[i] = (dp[i + 1] + dp[i + 2]) % mod;
  }
  cout << dp[0] << endl;
  return 0;
}

Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	long A = sc.nextLong();
    	long B = sc.nextLong();
    	long C = sc.nextLong();
    	long K = sc.nextLong();
    	System.out.println(K%2 == 0 ? A - B : B - A);
    }
}

Measured memory_bytes: 21972
def main():
    n=int(input())
    for k in range(1,450):
        if k*(k+1)==2*n:
            print("Yes")
            print(k+1)
            break
    else:
        print("No")
        return 0
    ans=[]
    cnt=1
    for i in range(k+1):
        ans.append([])
        for j in range(i):
            ans[i].append(ans[j][i-1])
        for j in range(i,k):
            ans[i].append(cnt)
            cnt+=1
    for i in ans:
        print(len(i),*i)
main()

Measured memory_bytes: 9296
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int L, R;
    cin >> L >> R;
    if(R - L >= 2019){
        cout << 0 << endl;
        return 0;
    }
    L %= 2019, R %= 2019;
    if(L > R){
        R += 2019;
    }
    int ans = 2019;
    for(int i = L; i <= R; i++){
        for(int j = i + 1; j <= R; j++){
            ans = min(ans, (i * j) % 2019);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  cin >> x;
  for(long long a = 1;a <= 500; a++) {
    for(long long b = a-1; b>= -a+1; b--) {
      if(pow(a,5) - pow(b,5) == x) {
        cout << a << " " << b << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 4100
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define ll long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const ll MOD = 1000000007;// 10^9+7
const ll INF = (1ll << 60);


//変数
struct Edge {
	ll to;
	ll cost;
};
ll n, m, s, t;
vector<vector<Edge>> yen, snuke;

using P = pair<ll, ll>;
vector<ll> dijkstra(vector<vector<Edge>>& G, int s)
{
	vector<ll> d(n, INF);
	priority_queue<P, vector<P>, greater<P>> que;
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty())
	{
		auto p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		REP(i, G[v].size())
		{
			Edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
	return d;
}


//サブ関数
//入力
void input()
{
	ll a, b, c, d;
	cin >> n >> m >> s >> t;
	s--; t--;
	yen.resize(n);
	snuke.resize(n);
	REP(i, m)
	{
		cin >> a >> b >> c >> d;
		a--; b--;
		yen[a].push_back({ b,c });
		yen[b].push_back({ a,c });
		snuke[a].push_back({ b,d });
		snuke[b].push_back({ a,d });
	}
}


//計算
void calc()
{
	const ll start = pow(10, 15);
	auto yen_graph = dijkstra(yen, s);
	auto snuke_graph = dijkstra(snuke, t);
	priority_queue<P, vector<P>, greater<P>> que;
	REP(i, n)
	{
		que.push({ yen_graph[i] + snuke_graph[i],i+1});
	}
	//que.push({ yen_graph[s],n });
	
	int year = 0;
	while (year < n)
	{
		auto best = que.top(); que.pop();
		while (best.second > year)
		{
			cout << start - best.first << endl;
			year++;
		}
	}
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 19836
N, M = gets.split(' ').map(&:to_i)

C = 2 ** N

k_arr = []
M.times do
  k_arr << gets.split(' ').map(&:to_i)
end
P = gets.split(' ').map(&:to_i)

ans = 0
0.upto(C-1) do |n|
  ok = true
  s = n.to_s(2).rjust(N, '0')
  k_arr.each_with_index do |e, i|
    sum = 0
    e[0].times do |j|
      sum += s[e[1 + j] - 1].to_i
    end
    if P[i] != sum % 2
      ok = false
      break
    end
  end
  ans += 1 if ok
end

p ans



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

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

    ll count = 0;

    for(ll i = 1; i < N; i++)
    {
        if(T <= (t[i] - t[i-1]))count += T;
        else count += t[i] - t[i-1];
    }
    count += T;

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int N;
vector<int> A(0);

int lower_bound_func(int left, int right, bool (*func)(int)) {
    // func returns true when the statement is satisfied
    // watch out for initialization of left
    while (right - left > 1) {
        int mid = left + (right - left) / 2;
        if (func(mid))
            right = mid;
        else
            left = mid;
    }
    return right;  // left for upper_bound
}

bool calc(int l) {
    int tmp = l;
    for (int i = 0; i < N - 1; i++) {
        tmp = A[i] - tmp;
    }
    return (l + tmp) >= A[N - 1];
}

int main() {
    cin >> N;

    A.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int result = lower_bound_func(-1, A[0], calc);
    // for (int i = 0; i <= A[0]; i++) {
    // if (calc(i)) {
    // cout << "true" << endl;
    // } else {
    // cout << "false" << endl;
    // }
    // }

    int tmp = result;
    for (int i = 0; i < N; i++) {
        cout << tmp * 2 << " ";
        tmp = A[i] - tmp;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3724
#include <stdio.h>
#define BTC 380000

int main(void)
{
	int n;
	scanf("%d",&n);
	
	double x[n],sum = 0;
	char u[n][3];
	
	int i;
	
	

	for(i = 0; i < n; i++){
		scanf("%lg %s",&x[i],&u[i]);
	}
	
	for(i = 0; i < n; i++){
		if(u[i][0] == 'J' && u[i][1] == 'P' && u[i][2] == 'Y'){
			sum = sum + x[i];
		}else{
			sum = sum + x[i]*BTC;
		}
	}
	
	printf("%lg\n",sum);
	
	return 0;
	
}
	
	
	
	
	
	

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
 
 
public class Main {
	
	public static void main(String[] args) throws IOException {
		Main m = new Main();
		//*
		m.input();
		m.solve();
		m.output();
		/*/
		m.debug();
		//*/
	}
	
	public void debug() {
	}
	
	//*
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	/*/
	InputUtil in = new InputUtil();
	//*/
	PrintWriter out = new PrintWriter(System.out);
	char[] S = null;
	int N = 0;
	int[] ans = null;
	
	public void input() throws IOException {
		//*
		S = br.readLine().toCharArray();
		/*/
		N = in.nextInt();
		ans = new int[N];
		for(int i=0; i<N; i++) {
			ans[i] = 0;
		}
		//*/
		
	}
	
	public void solve() throws IOException {
		S[3] = '8';
	}
	
	
	
	public void output() {
		out.println(S);
//		out.println(ans[0]==1?"Yes":"No");
		out.flush();
	}
}

//*
class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 100000;
	
	//Fields
	protected InputStream in;
	private byte[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private DataInputStream dis = null;
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {dis = new DataInputStream(this.in = in);}
	protected void initBuf(int bufsiz) {buf = new byte[bufsiz];}
	
	//buffer operation
	private void next() throws IOException {ptr++; readBuf();}
	private void readBuf() throws IOException {
		if(ptr >= max && dis.available()>0) {
			if(max>0) Arrays.fill(buf,0,max,(byte)0);
			max = dis.read(buf);
			ptr = 0;
		}
	}
	
	//Number Input Reader/Parser
	private boolean isNum(byte b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(byte b) {return b=='-'; }
 
	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		byte c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	}
 
	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}
}
//*/

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

using namespace std;

const int N = 1234567;
char st[N];
string s;

int main()
{
    cin >> s;
    int n = s.length();
    stack < int > st;
    st.push(s[0]);
    int ptr = 0;
    for(int i = 0; i < n; i++){
        if(ptr > 0 && st.top() == 'S' && s[i] == 'T'){
               // cout << "working" << endl;
                ptr--;
                st.pop();
        }
        else{
                st.push(s[i]);
                ptr++;
        }
    }
    cout << ptr << endl;
    return 0;
}


Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int MAXN = int(1e3);

void solve(long long X){
    set<ll> A;
    map<ll,ll> mA;
    set<ll> B;
    map<ll,ll> mB;
    for(ll i=0LL;i<=MAXN;i++){
        ll v = i*i*i*i*i;
        A.insert(v);
        mA[v] = i;
        B.insert(v);
        B.insert(-v);
        mB[v] = i;
        mB[-v] =-i;
    }
    // for(auto x:A){
    //     cerr <<x  << endl;
    // }
    for(auto itr = A.begin();itr!=A.end();++itr){
        ll value = *itr;
        ll remain = value-X;
        if(B.find(remain) != B.end()){
            // cerr <<"itr="<< value << endl;
            // cerr <<remain << endl;
            cout << mA[value] <<" "<< mB[remain] << endl;
            return;
        }
    }
   
    

}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
int main(){
  char x,y;
  cin>>x>>y;
  if(x>y){
    cout<<">"<<endl;
  }
  else if(x<y){
    cout<<"<"<<endl;
  }
  else {
    cout<<"="<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) { //WOOOOOOO AtCoder is HELPING!!!!!!!!!!
		//Arraylist cheese for the win
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int[] times = new int[N];
		long cap = input.nextLong();
		long extra = input.nextLong();
		long ans = 0;
		for (int i = 0; i < N; i++) {
			times[i] = input.nextInt();
		}
		Arrays.sort(times);
		for (int START = 0; START < N; START++) {
			int newSTART = START;
			for (int next = START+1; next < Math.min(N, START+cap); next++) {
				int diff = times[next]-times[START];
				if (diff>extra) break;
				else newSTART++;
			}
			ans++;
			START=newSTART;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 50520
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 4005
#define inf 1e18
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,a[maxn],x,mn[maxn][maxn],ans;

int main()
{
	n=read(); x=read(); rep(i,1,n) a[i]=read(),a[n+i]=a[i],mn[i][i]=a[i];
	rep(i,(n+1),2*n) mn[i][i]=a[i];
	rep(i,1,2*n) rep(j,(i+1),2*n) mn[i][j]=min(mn[i][j-1],a[j]); ans=inf;
	for(int k=0;k<=n-1;k++)
	{
		ll tmp=k*x;
		for(int i=1;i<=n;i++) tmp+=mn[i-k+n][i+n];
		ans=min(ans,tmp);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 125184
#include <bits/stdc++.h>
#define lli long long int

using namespace std;

lli n; 
vector<lli> stones;

lli dp[100010];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    memset(dp, -1, sizeof(dp));
    cin>>n;
    stones.resize(n);
    for(auto &x: stones)
    {
        cin>>x;
    }

    dp[0] = 0;
    dp[1] = abs(stones[0] -  stones[1]);
    for(int i = 2; i<n; i++)
    {
        dp[i] = min(  abs(stones[i] - stones[i-1]) + dp[i-1]  , abs(stones[i] - stones[i-2]) + dp[i-2]   );
    }

    cout<<dp[n-1]<<endl;

    return 0;
}

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

int main () {
    int n; cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    sort(d.begin(), d.end());
    int ans = d[d.size() / 2] - d[d.size() / 2 - 1];
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int N, K;
    cin >> N >> K;
    deque<int> dq(N);
    for(int i = 0; i < N; i++){
        cin >> dq[i];
    }
    
    int absum = min(N, K);

    
    int ans = 0;
    for(int a = 0; a <= absum; a++){
        for(int b = 0; b <= absum - a; b++){
            
            vector<int> V;
            int first = 0;
            int last = N-1;
            for(int i = 0; i < a; i++) {
                V.push_back(dq[first++]);
            }
            for(int i = 0; i < b; i++){
                V.push_back(dq[last--]);
            }
            
            if(V.size()==0) continue;
            sort(V.begin(), V.end());
            int cnt = 0;
            for(int i = 0; i < V.size(); i++){
                if(V[i] < 0 && i < K - a - b) continue;
                cnt += V[i];
            }
            
            ans = max(ans, cnt);
            
        }
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
A, B, C, D, E, F = map(int, input().split())

# 可能な水の総量
water_list = []
A_max = F // (100 * A)
B_max = F // (100 * B)
for i in range(A_max + 1):
    for j in range(B_max + 1):
        temp = 100 * A * i + 100 * B * j
        if temp <= F:
            water_list.append(temp)
water_list = list(set(water_list))

# 可能な砂糖の総量
sugar_list = []
C_max = F // (C)
D_max = F // (D)
for i in range(C_max + 1):
    for j in range(D_max + 1):
        temp = C * i + D * j
        if temp <= F:
            sugar_list.append(temp)
sugar_list = list(set(sugar_list))

# max_conc=0から始めると0%の場合を拾えなくなる. あるいは34行目で等号をつけても良い.
max_conc = -1
max_conc_water = -1
max_conc_sugar = -1
for water in water_list:
    for sugar in sugar_list:
        # 水があるか and 溶解度を超えていないか and 容器に入るか
        if water != 0 and sugar <= ((E * water) / 100) and water + sugar <= F:
            conc = (100 * sugar) / (water + sugar)
            if conc > max_conc:
                max_conc = conc
                max_conc_water = water
                max_conc_sugar = sugar

print(max_conc_water + max_conc_sugar, max_conc_sugar)
# print(max_conc)


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

vector < int > v;

int main(){
    int a_i, b_i, n, temp, t, mini, maxiD, cont = 0;

    cin>>n>>t;

    v.resize( n );

    for( a_i=0; a_i<n; a_i++ ) cin>>v[a_i];

    mini = v[0]; maxiD = 0;

    for( a_i=0; a_i<n; a_i++ ){
        mini = min( v[a_i], mini );
        maxiD = max( maxiD, v[a_i]-mini );
    }

    mini = v[0];
    for( a_i=0; a_i<n; a_i++ ){
        mini = min( v[a_i], mini );
        if( v[a_i]-mini == maxiD ) cont++;
    }

        cout<<cont<<endl;

}


Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
const char nc[20]={'0','1','2','3','4','5','6','7', '8','9','A','B','C','D','E','F','G','H','I','J'};
string ans;
int main()
{
    int m,n,k,t;
    cin>>m;
    n=-2;
    ans="";
    if(m==0){
    	cout<<0;
    	return 0;
	}
    while(m!=0){
        k=m%n;
        t=m/n;
        if(k<0)
        {
            k-=n;
            t++;
        }
        m=t;
        ans.push_back(nc[k]);
    }
    for(int i=ans.length()-1;i>=0;i--)
        cout<<ans[i];
    return 0;
}

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

using namespace std;

typedef long long ll;

const int MX = 100005;
const ll oo = 1e18;

template<typename T> void cmin(T &x, const T &y)
{
	if(y < x) x = y;
}

template<typename T> void read(T &x)
{
	x = 0;
	char c = getchar();
	bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

struct NODE
{
	int x, ida, idb;

	NODE (const int &x0 = 0, const int &ia = 0, const int &ib = 0) : x(x0), ida(ia), idb(ib) {}

	bool operator < (const NODE &t) const {return x<t.x;}
};

int n;
int a[MX], b[MX];

void input()
{
	read(n);
	for(int i=1; i<=n; i++) read(a[i]), read(b[i]);
}

int ha[MX], hb[MX];

ll calc(vector<NODE> seq)
{
	ll sum = 0;
	bool single_a = 1, single_b = 1;
	memset(ha, 0, sizeof(ha));
	memset(hb, 0, sizeof(hb));
	for(auto i : seq) ha[i.ida]++, hb[i.idb]++, sum += i.x;
	for(int i=1; i<=n; i++)
		if(ha[i] && hb[i]) return sum;
		else if(ha[i]) single_b = 0;
		else if(hb[i]) single_a = 0;
	return (single_a||single_b) ? sum : +oo;
}

void work()
{
	vector<NODE> seq, tmp;
	for(int i=1; i<=n; i++)
	{
		seq.push_back(NODE(a[i], i, 0));
		seq.push_back(NODE(b[i], 0, i));
	}
	sort(seq.begin(), seq.end());
	tmp.insert(tmp.end(), seq.begin(), seq.begin()+n);
	ll ans = calc(tmp);
	tmp.pop_back();
	tmp.push_back(*(seq.begin()+n));
	cmin(ans, calc(tmp));
	tmp.pop_back();
	tmp.push_back(*(seq.begin()+n+1));
	cmin(ans, calc(tmp));
	tmp.pop_back(), tmp.pop_back();
	tmp.push_back(*(seq.begin()+n)), tmp.push_back(*(seq.begin()+n-1));
	cmin(ans, calc(tmp));
	printf("%lld\n", ans);
}

int main()
{
	input();
	work();
	return 0;
}

Measured memory_bytes: 7024
n = int(input())
s = input()

black0 = 0
white0 = 0
for i in range(n):
    if s[i] == '#':
        black0 += 1
    else:
        white0 += 1
        
black = 0
white = 0
best = min(black0, white0)
for i in range(n):
    if s[i] == '#':
        best = min(best, black + white0 - white)
        black += 1
    else:
        white += 1
        
print(best)

Measured memory_bytes: 3628