akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a)
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;

inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=500005;
//i_am_noob
int x,n,a;
set<int> st;

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> x >> n;
    rep(n){
        cin >> a;
        st.insert(a);
    }
    rep(10000000){
        if(!st.count(x-i)){
            print1(x-i);
            return 0;
        }
        if(!st.count(x+i)){
            print1(x+i);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#define SIZE 100006
typedef struct mk{
    int b;
    struct mk *next;
}data;
data *input[SIZE],node[SIZE];
int id = 0;
data *New(int b){
    data *tm = &node[id++];
    tm->b = b;
    tm->next = NULL;
    return tm;
}
data *insert(data *root, int b){
    if(root==NULL) return New(b);
    data *tm = New(b);
    tm->next = root;
    return tm;
}
int len = 0,heap[SIZE];
void swap(int *x,int *y){
    int t = *x;
    *x = *y;
    *y = t;
}
int minChild(int *ar,int len,int r,int lf,int rt){
    if(lf<len && ar[r]<ar[lf]) r = lf;
    if(rt<len && ar[r]<ar[rt]) r = rt;
    return r;
}
void heapify(int *ar, int len,int r){
    int c = minChild(ar,len,r,r*2+1,r*2+2);
    if(c!=r){
        swap(&ar[r],&ar[c]);
        heapify(ar,len,c);
    }
}
int getTop(int len){
    int ret = heap[0];
    heap[0] = heap[len];
    heapify(heap,len, 0);
    return ret;
}
void Insert(int v,int len){
    heap[len]=v;
    while(len>0 && heap[(len-1)/2]<heap[len]){
        swap(&heap[len],&heap[(len-1)/2]);
        len = (len-1)/2;
    }
}
void MRoy(){
    int n,m,a,b,length = 0;
    for(int i = 0;i<SIZE;i++) input[i] = NULL;
    scanf("%d%d",&n,&m);
    for(int i = 0;i<n;i++){
        scanf("%d %d",&a,&b);
        input[a] = insert(input[a],b);
    }
    int Ans = 0;
    for(int i = 0;i<m;i++){
        data *tm = input[i+1];
        while(tm!=NULL){
            // printf("%d ",tm->b);
            Insert(tm->b,length);
            length++;
            tm=tm->next;
        }
        if(length){
            Ans += getTop(--length);
        }
            // printf("%d\n",Ans);
    }
    printf("%d\n",Ans);
    return;
}
int main(){
    MRoy();
    return 0;
}

Measured memory_bytes: 2944
import Control.Monad

main :: IO ()
main = do
  n <- readLn
  m <- readLn
  ls <- replicateM m readLn
  mapM_ print $ solve [1..n*2] ls n

solve :: [Int] -> [Int] -> Int -> [Int]
solve deck [] _ = deck
solve deck (x:xs) n
  | x == 0 = solve (riffle deck) xs n
  | otherwise = solve (kCut x deck) xs n
  where
    riffle :: [Int] -> [Int]
    riffle deck = alter (take n deck) (takeOther n deck)
      where
        alter :: [Int] -> [Int] -> [Int]
        alter [] [] = []
        alter (x:xs) (y:ys)= x:y:(alter xs ys)
    kCut :: Int -> [Int] -> [Int]
    kCut x deck = (takeOther x deck) ++ (take x deck)
    takeOther :: Int -> [Int] -> [Int]
    takeOther 0 xs = xs
    takeOther n (x:xs) = takeOther (n-1) xs

Measured memory_bytes: 5536
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n\r\t', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

get_numbers(0, []).
get_numbers(N, [X|Xs]) :- 
    get_number(X), 
    N2 is N - 1, 
    get_numbers(N2, Xs).

put_numbers([]).
put_numbers([X|Xs]) :-
    writeln(X),
    put_numbers(Xs).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    length(S, L),
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==

    between(L,U,X): L <= X <= U
    nth0(I, Xs, Y), nth1(I, Xs, Y): (Xs,Y) -> I, (I, Xs) -> Y 

    sort(Key, Order, List, Sorted): Keyは通常0?, Orderは=なしが重複削除，=は重複保持
    \+ P(X) : not P(X)

    sum_list(Xs, Sum)

    orは!忘れに注意(末尾再帰なら直前)
*/

f(['A','B','C'|Xs], Z) :- f(Xs, Z2), Z is Z2 + 1.
f([_|Xs], Z) :- f(Xs, Z).
f([], 0).

main :-
    get_number(N),
    get_chars(S),
    f(S, Z),
    writeln(Z).

    % statistics(inferences, IC), writeln(IC).


Measured memory_bytes: 8172
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	long long int a,b,c,d,ar[10];
	cin>>a>>b>>c>>d;
	ar[0]=a*d;
	ar[1]=a*c;
	ar[2]=b*c;
	ar[3]=b*d;
	sort(ar,ar+4);
	cout<<ar[3]<<endl;
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
const int N=100005;
int n,a[4][N],b[N],ans[2];
void NO() {puts("No");exit(0);}
int main()
{
	n=read();
	for(RI i=1;i<=3;++i)
		for(RI j=1;j<=n;++j) {
			a[i][j]=read();
			int x=(a[i][j]-1)%3+1,y=(a[i][j]+2)/3;
			if((i!=2&&x==2)||(i==2&&x!=2)) NO();
			if((j&1)^(y&1)) NO();
		}
	for(RI j=1;j<=n;++j) {
		int x=(a[1][j]-1)%3+1,y=(a[1][j]+2)/3;
		if((a[2][j]+2)/3!=y||(a[3][j]+2)/3!=y) NO();
		if(x==1&&(a[3][j]-1)%3+1!=3) NO();
		if(x==3&&(a[3][j]-1)%3+1!=1) NO();
		if(x==3) ans[j&1]^=1;
		b[j]=y;
	}
	for(RI i=1;i<=n;++i)
		while(b[i]!=i) ans[(i&1)^1]^=1,swap(b[i],b[b[i]]);
	if(ans[0]||ans[1]) NO();
	puts("Yes");
	return 0;
}

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

int FSOD(int n){
  
  int sum = 0;
  while(n>0){
    sum += n%10;
    n /=10;
  }
  return sum;
}

//関数が出来た

int main(){
  int N,A,B;
  cin>>N>>A>>B;
  int total = 0;
  //自然数1からチェックして一致したらiの数を足すって意味ですね
  //i=0でも問題はない無駄だけど
  for(int i=1;i<=N;i++){
    int sum=FSOD(i);
  	if(sum>=A&&sum<=B) {
      total+=i;
  	}
  }
  cout <<total <<endl;
  return 0;
    

}


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

#define INF INT_MAX/2;
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long ;

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

   int N,M;
   cin>>N>>M;
   vector<int>a(M),b(M);
   for(int i=0;i<M;i++)cin>>a[i]>>b[i];
   int ans = 0;
   bool update = true;
   while(update){
      update = false;
      for(int i=1;i<=N;i++){
         int sum = 0;
         int node = 0;
         for(int j=0;j<M;j++){
            if(a[j] == i){
               sum++;
               node = j;
            }
            if(b[j] == i){
               sum++;
               node = j;
            }
         }
         if(sum==1){
            ans++;
            update = true;
            a[node] = 0;
            b[node] = 0;
         }
      }
   }
   cout<<ans<<endl;
   return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#else
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  void solve() {
    map<i64, int> mp;
    mp[0] = 0;
    for (i64 i = 1; i <= 1000; ++i) {
      mp[i * i * i * i * i] = i;
      mp[-i * i * i * i * i] = -i;
    }
    i64 x;
    cin >> x;
    for (auto i : mp) {
      i64 a = i.first - x;
      if (mp.count(a)) {
        cout << i.second << " " << mp[a] << '\n';
        return;
      }
    }
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

Measured memory_bytes: 3756
// https://atcoder.jp/contests/

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int n;

  cin >> n;

  cout << n / 3 << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
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; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }


int main(){
    ll x;
    cin>>x;
    bool q=false;
    rep(i,1,2000){
        rep(j,1,2000){
            if(q)break;
            ll t=powl(i-1000,5)-powl(j-1000,5);
            if(t==x){cout<<i-1000<<" "<<j-1000;q=true;break;}
        }
        if(q)break;
    }
}


Measured memory_bytes: 3692
k = int(input())
a = [[1, 2, 3, 4, 5, 6, 7, 8, 9]]
A = [1, 2, 3, 4, 5, 6, 7, 8, 9]

for j in range(9):
    b = []
    for i in a[-1]:
        I = str(i)
        if I[-1] != '9':
            b.append(i*10 + int(I[-1])+1)
        b.append(i*10 + int(I[-1]))
        if I[-1] != '0':
            b.append(i*10 + int(I[-1])-1)
    a.append(b)
    A += b
ans = sorted(A)
print(ans[k-1])

Measured memory_bytes: 52188
s = int(input())

answer = 1
an = {1:s}
i = 2
while(True):
  if an[i-1]%2 == 0:
    if (an[i-1]//2) in an.values():
      answer = i
      break
    else :
      an[i] = an[i-1]//2
  else :
    if (3*an[i-1]+1) in an.values():
      answer = i
      break
    else :
      an[i] = 3*an[i-1]+1
  i += 1  
      
print(answer)

Measured memory_bytes: 9140
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N,L;
    cin>>N>>L;
    vector<string> s(N);
    REP(i,N) cin>>s[i];
    sort(All(s));
    for(auto a:s)cout<<a;
    cout<<endl;
}


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

using namespace std;

const int N = 303, mod = 1e9 + 7;

int dp[2][N][N];

vector< pair< int, int > > con[N];

void add(int & le, int ri) {
  le += ri;
  if (le >= mod) le -= mod;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int l, r, x;
    scanf("%d %d %d", &l, &r, &x);
    con[r].emplace_back(l, x);
  }
  int c = 0, b = 1;
  dp[0][0][0] = 3;
  for (auto it : con[1]) {
    if (it.second > 1) dp[0][0][0] = 0;
  }
  for (int i = 1; i < n; i++) {
    swap(b, c);
    memset(dp[c], 0, sizeof dp[c]);
    for (int j = 0; j <= i; j++) {
      for (int k = 0; k <= j; k++) {
        if (dp[b][j][k] == 0) continue;
        int cur = dp[b][j][k];
        add(dp[c][j][k], cur);
        if (j > k) {
          add(dp[c][i][k], cur);
          if (k > 0)
            add(dp[c][i][j], cur);
          else
            add(dp[c][i][j], cur);
        }
        else
          add(dp[c][i][k], cur * 2 % mod);
      }
    }
    for (int j = 0; j <= i; j++) {
      for (int k = 0; k <= j; k++) {
        if (dp[c][j][k] == 0) continue;
        bool ok = 1;
        for (auto c : con[i+1]) {
          int x = c.second, l = c.first;
          if (x == 1) {
            if (l <= j) ok = 0;
          }
          else if (x == 2) {
            if (l > j || l <= k) ok = 0;
          }
          else {
            if (l > k) ok = 0;
          }
          if (!ok) break;
        }
        if (!ok) dp[c][j][k] = 0;
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++)
      ans = (ans + dp[c][i][j]) % mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int a,b,k;
int main()
{
	cin>>a>>b>>k;
	for(int i=100;i>=1;i--)
		if(a%i==0&&b%i==0)
		{
			k--;
			if(!k)
			{
				cout<<i;
				return 0;
			}
		}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = Integer.parseInt(sc.next());
        int X = Integer.parseInt(sc.next());

        StringBuilder stringBuilder = new StringBuilder();
        for (int i = X - K + 1; i <= X + K - 1; i++) {
            stringBuilder.append(i)
                    .append(" ");
        }
        System.out.println(stringBuilder.toString());
    }
}

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

int main(){
    int n;
    cin >> n;
    vector<vector<pair<int,int>>> array(n);
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        vector<pair<int,int>> arr(a);
        for(int j=0;j<a;j++){
           cin >> arr.at(j).first >> arr.at(j).second;
        }
        array.at(i) = arr;
    }
    int max = -1;
    for(int tmp=0; tmp < ( 1 << n); tmp++){
        bool flag = true;
        int cnt = 0;
        bitset<15> s(tmp);
        for(int i=0;i<n;i++){
            if(s.test(i)){
                cnt++;
                //cout << cnt << endl;
                vector<pair<int,int>> syougen_array = array.at(i);
                int size = syougen_array.size();
                for(int j=0;j<size;j++){
                    pair<int,int> syougen = syougen_array.at(j);
                    int person = syougen.first;
                    int honest = syougen.second;
                    if(honest == 1){
                        if(!s.test(person-1)){
                            flag = false;
                            break;
                        }
                    }else {
                        if(s.test(person-1)){
                            flag = false;
                            break;
                        }
                    }
                }
                
            }
            if(!flag) break;
            
        }
        if(flag){
            if(max < cnt) max = cnt;
        }else{
            continue;
        }
    }

    cout << max << endl;
}

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

typedef long long LL;

int n;
int a[200007];
LL s[200007];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    s[i] = s[i - 1] + a[i];
  }
//  for (int i = 1; i <= n; i++) printf("%I64d ", s[i]);
//  puts("");

  LL ans = abs(s[n] - s[1] * 2);
  for (int i = 2; i < n; i++) {
    ans = min(ans, abs(s[n] - s[i] * 2));
  }
  printf("%lld", ans);

  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define Ios cin.tie(0);ios_base::sync_with_stdio(0)
#define endl '\n'
#define fixeddecimals cout.setf(ios::fixed); cout.precision(18)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i>=b;i--)
#define iter(it,a) for(auto it=a.begin();it!=a.end();it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define ri(X) cin>>X
#define rii(X, Y) cin>>X>>Y
#define riii(X, Y, Z) cin>>X>>Y>>Z
#define dri(X) int X; cin>>X
#define drii(X, Y) int X, Y; cin>>X>>Y
#define driii(X, Y, Z) int X, Y, Z; cin>>X>>Y>>Z
#define vi vector<int>
#define vvi vector<vector<int> >
#define vvii vector<vector<pair<int,int> > >
#define pii pair<int,int> 
#define piii pair<int,pair <int,int> >
#define preturn(X) cout<<X<<endl<<flush; return 0
typedef long long ll;
//typedef int64_t ll; 
ll MOD=1e9+7;

int a[100000+1]; 
ll ans[100000+1];
map<int,pair<int,ll> > h;

int main(){
	int n;
	cin>>n;
	h[0]=mp(0,0);
	rep(i,1,n+1){
		ans[i]=0;
		cin>>a[i];
		if(h[a[i]].F==0){
			h[a[i]].F=i;
			h[a[i]].S = 1;
		}
		else{
			h[a[i]].F=min(h[a[i]].F,i);
			h[a[i]].S++;
		}
	}
	auto it = h.end();
	it--;
	auto it1 = it;
	it1--;
	while(1){
		ans[(*it).S.F]+=( ((*it).F - (*it1).F) * ((*it).S.S) );
		auto temp = it;
		temp--;
		if((*temp).F == 0){
			break;
		}
		(*temp).S.S += ((*it).S.S); 
		(*temp).S.F = min((*temp).S.F,(*it).S.F);
		it--;
		it1--;
	}
	rep(i,1,n+1){
		cout<<ans[i]<<endl;
	}
}

Measured memory_bytes: 8448
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		//入力を繰り返す
		Scanner sc = new Scanner(System.in);

		String  C= sc.next();
		char[] charary=C.toCharArray();
		//入力した次の文字を出力
		int ans = charary[0] + 1;
		System.out.println((char)ans);
	}

}


Measured memory_bytes: 35632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, ll> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1e+9;

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

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

    ll res = 0;
    for(int d = 0; d < 60; ++d){
        ll one_cnt = 0, zero_cnt = 0;
        for(int i = 0; i < n; ++i){
            if((a[i] >> d) & 1) ++one_cnt;
            else    ++zero_cnt;
        }
        ll tmp = ((ll)1 << d) % mod;
        ll cnt = one_cnt * zero_cnt % mod;
        tmp = tmp * cnt % mod;
        res = (res + tmp) % mod;
    }
    cout << res << endl;
}


Measured memory_bytes: 2560
#include <stdio.h>
int main(void) {
int x,y,z,e,m;
while(1){
	scanf("%d",&e);
	if(e==0)break;
	m=1000001;
	for(z=0;z*z*z<=e;z++){
		for(y=0;z*z*z+y*y<=e;y++){
			x=e-z*z*z-y*y;
				if((z*z*z+y*y+x==e)&&(z+y+x<m))m=x+y+z;
			
		}
	}
	printf("%d\n",m);
}
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 10000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
// input vector
template<typename T>
void invec(vector<T> &A){for(T& a : A) cin >> a;}


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

int N, K; cin >> N >> K;
VI V(N); invec(V);
int R = min(N, K);

i64 maxi = 0;
VI A;
// 操作A,Bの回数で全探索．
rep(a, 0, R + 1) {
    if (a) A.push_back(V[a - 1]);
    VI AB = A;
    rep(b, 0, R - a + 1){
        if (b) AB.push_back(V[N - 1 - b + 1]);
        if (a || b){
            int CD = min(K - a - b, a + b); // 操作C,Dの可能回数．
            i64 own = accumulate(ALL(AB), 0LL);
            sort(ALL(AB));
            rep(i, 0, CD) if (AB[i] < 0) own -= AB[i];
            maxi = max(maxi, own);
        }
    }
}

cout << maxi << "\n";
}
// 書いて考える．場合分け
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int K;
LL ten[20];

int S(LL v) {
  int ret = 0;
  rep(i, 20) {
    if (v/ten[i] == 0) return ret;
    ret += v/ten[i]%10;
  }
  return ret;
}

int main() {
  scanf("%d", &K);
  rep(i, 9) {
    printf("%d\n", i+1);
    K--;
    if (K == 0) return 0;
  }

  ten[0] = 1;
  reps(i, 1, 20) {
    ten[i] = ten[i-1] * 10LL;
  }

  LL cur = 10;
  int d = 2;
  while (K > 0) {
    rep(i, d) {
      if (cur > ten[i] * S(cur)) {
        int f = cur/ten[i]%10;
        cur += (9 - f) * ten[i];
      }
    }
    printf("%lld\n", cur);
    cur++;
    while (cur >= ten[d]) d++;
    --K;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, x;
    cin >> N >> x;
    int a[100010];
    rep(i, N) cin >> a[i];
    int ans = 0;
    rep(i, N - 1) {
        if (a[i] + a[i + 1] > x) {
            ans += min(a[i + 1], a[i] + a[i + 1] - x);
            a[i + 1] -= min(a[i + 1], a[i] + a[i + 1] - x);
            if (a[i] + a[i + 1] > x) {
                ans += a[i] + a[i + 1] - x;
                a[i] -= a[i] + a[i + 1] - x;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define umap unordered_map

const int MOD = 1e9 + 7;

int madd(int a, int b){
	a += b;
	if (a >= MOD) a -= MOD;
	return a;
}

int msub(int a, int b){
	a -= b;
	if (a < 0) a += MOD;
	return a;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n; cin >> n;
	vvi A = vvi(n, vi(n, 0));
	rep(i, n){
		rep(j, n){
			int x; cin >> x;
			if (x) A[i][j] = 1;
		}
	}
	vll dp = vll(1 << n, 0);
	dp[0] = 1;
	for(int mask = 0; mask < (1 << n)-1; mask++){
		int next = popcount(mask);
		for(int cand = 0; cand < n; cand++){
			int bcand = (1 << cand);
			if (A[next][cand] and !(mask & bcand)){
				int nmask = mask ^ bcand;
				dp[nmask] = madd(dp[nmask], dp[mask]);
			}
		}
	}
	cout << dp[(1<<n)-1];
}

Measured memory_bytes: 19568
/*input

*/
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
#define mid ((l+r)/2)
#define pr pair<int,int>
#define long long long
using namespace std;
const int N = 200005;
const int mod = 1e9 + 7;
vector<int> G[N];
int children[N], pchildren[N];
long ans[N], dp[N], pDp[N];
long fact[N];
int n;
void init(){
	up(i,1,n) dp[i] = children[i] = 1;
	fact[0] = 1;
	for(int i=1;i<=n;++i) fact[i] = (fact[i-1] * i * 1LL) % mod;
}
long power(long x, long n){
	long ans = 1;
	for(int i=0;i<31;++i){
		if (bits(n, i)) ans = (ans * x) % mod;
		x = (x * x) % mod;
	}
	return ans;
}
long inv(long num, long den){
	return (num * power(den, mod - 2)) % mod;
}
long C(int k,int n){
	int num = fact[n];
	int den = (fact[k] * fact[n-k]) % mod;
	return inv(num, den);
}
void precal(int u, int par){
	for (auto v: G[u]){
		if (v == par) continue;
		precal(v, u);
		children[u] += children[v];
	}
	int remaider = children[u] - 1;
	for(auto v : G[u]){
		if (v == par) continue;
		// cout << children[v] << ' ' << remaider << '\n';
		long cur = (1LL * dp[v] * C(children[v], remaider)) % mod;
		dp[u] = (dp[u] * cur) % mod;
		remaider -= children[v];
	}
}
void rollback(int u,int v){
	pDp[u] = dp[u]; pDp[v] = dp[v];
	pchildren[u] = children[u]; pchildren[v] = children[v];
}
void dfs(int u, int par){
	ans[u] = dp[u];
	for (auto v: G[u]){
		if (v == par) continue;
		rollback(u,v);
		dp[u] = inv(dp[u], (dp[v] * C(children[v], children[u]-1)) % mod);
		children[u] -= children[v];
		children[v] += children[u];
		long mul = (dp[u] * C(children[u], children[v] - 1)) % mod;
		dp[v] = (dp[v] * mul) % mod;
		dfs(v, u);
		dp[u] = pDp[u]; dp[v] = pDp[v];
		children[u] = pchildren[u]; children[v] = pchildren[v];
	}
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	up(i,1,n-1){
		int u,v; cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	init();
	precal(1,0);
	// solve
	dfs(1, 0);
	for(int i=1;i<=n;++i) cout << ans[i] << '\n';
}

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

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop0(i,n) for(int i=0; i<(n); i++)
#define loop1(i,n) for(int i=1; i<=(n); i++)
#define fori(a,b,i) for(int i=(a); i<=(b); i++)
#define ford(a,b,i) for(int i=(a); i>=(b); i--)
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ign cin.ignore(numeric_limits<streamsize>::max(),'\n')

#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"
#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef map<int,int> MCI;
typedef unordered_map<int,int> UMII;
typedef unordered_map<char,int> UMCI;
typedef set<int> SI;
typedef long long int llint;

// Display Map
//~for (auto const& pair: m) {
//~std::cout << "{" << pair.first << ": " << pair.second << "}\n";
//~}

// Extract word(w) from sentence(s)
//~stringstream str(s);
//~string w;
//~while(str >> w){
//~// w is your word
//~}

//Memset Syntax
// memset(array, value,sizeof(array)) val is 0,-1 or bool only

// To get accurate precision
//~cout.precision(20);

int main() {
    fast_io;
	llint n;
	cin >> n;
	vector<llint> v(n);
	unordered_map<llint, llint> m; 
	for(auto &i : v) cin >> i;
	for (llint i = 0; i < n; i++) m[v[i]]++;  
	llint q;
	cin >> q;
	llint sum = accumulate(v.begin(),v.end(),(long long)0);;
	
	for(llint i = 0; i < q; i++){
		llint a,b;
		cin >> a >> b ;
		
		sum = sum - (1LL*a*m[a]) +(1LL*b*m[a]);
		
		m[b] += m[a];
		
		m[a] = 0;

		cout << sum << endl;		
	}
	
}


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

using ll = long long;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x) for (auto&& v : (x))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))

int main() {
  ll n;
  cin >> n;
  vector<ll> p(n), q(n), t(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];
  rep(i, n) t[i] = i + 1;
  ll i = 0, pi, qi;
  do {
    if (t == p) pi = i;
    if (t == q) qi = i;
    ++i;
  } while (next_permutation(t.begin(), t.end()));
  cout << abs(pi - qi) << endl;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

bool check(vector<int>& v, string s)
{
  int n = s.size();
  for (int i = 2; i < n; ++i) {
    if (s[i - 1] == 'o') {
      if (v[i - 1] == 0) { v[i] = v[i - 2]; }
      else { v[i] = 1 - v[i - 2]; }
    }
    else if (s[i - 1] == 'x') {
      if (v[i - 1] == 0) { v[i] = 1 - v[i - 2]; }
      else { v[i] = v[i - 2]; }
    }
  }

  vector<int> w = v;
  w.push_back(v[0]);
  w.push_back(v[1]);
  string t = s;
  t.push_back(s[0]);
  t.push_back(s[1]);
  for (int i = 1; i <= n; ++i) {
    if (t[i] == 'o') {
      if (w[i] == 0) {
        if (w[i - 1] != w[i + 1]) { return false; }
      }
      else {
        if (w[i - 1] == w[i + 1]) { return false; }
      }
    }
    else if (t[i] == 'x') {
      if (w[i] == 0) {
        if (w[i - 1] == w[i + 1]) { return false; }
      }
      else {
        if (w[i - 1] != w[i + 1]) { return false; }
      }
    }
  }
  return true;
}

int main()
{
  int N; scanf("%d", &N);
  string s; cin >> s;

  bool done = false;
  vector<int> ans;
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < 2; ++j) {
      vector<int> tmp(N);
      tmp[0] = i; tmp[1] = j;
      if (check(tmp, s)) {
        ans = tmp;
        done = true;
        break;
      }
    }
    if (done) { break; }
  }

  if (not done) {
    printf("-1\n");
  }
  else {
    string sw = "SW";
    for (int i = 0; i < N; ++i) {
      printf("%c", sw[ans[i]]);
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 1744
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;

vector<P> G;
signed main(){
	int h, w, n;
	scanf("%lld%lld%lld", &h, &w, &n);
	
	for(int i = 0;i < n;i++){
		int x[2], y[2];
		scanf("%lld%lld%lld%lld", &y[0], &x[0], &y[1], &x[1]);
		if(y[0] && y[0] != h && x[0] && x[0] != w)continue;
		if(y[1] && y[1] != h && x[1] && x[1] != w)continue;
		
		for(int j = 0;j < 2;j++){
			if(y[j] == 0)G.push_back(P(x[j], i));
			else if(x[j] == w)G.push_back(P(1+w+y[j], i));
			else if(y[j] == h)G.push_back(P(2+h+w+(w-x[j]), i));
			else if(x[j] == 0)G.push_back(P(3+2*w+h+(h-y[j]), i));
		}
	}
	sort(G.begin(), G.end());
	
	stack<int> st;
	for(int i = 0;i < G.size();i++){
		int p = G[i].second;
		if(!st.empty()){
			if(st.top() == p)st.pop();
			else st.push(p);
		}else st.push(p);
	}
	if(st.empty())printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 6128
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
const int MOD=1000000007;
int s[100003],d[100003];
int main(){
      int n,l;
      cin>>n>>l;
      priority_queue<P> Q;
      REP(i,n){
            cin>>d[i+1];
            Q.push(P(d[i+1],i+1));
      }
      int ans=0;
      while(!Q.empty()){
            P p=Q.top();Q.pop();
            s[p.second]=max(s[p.second-1],s[p.second+1])+(l-p.first);
            ans=max(ans,s[p.second]);
      }
      cout<<ans<<endl;
}

Measured memory_bytes: 2760
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val nd = inputs(0).split(" ").map(_.toInt)
  val n = nd(0)
  val d = nd(1)
  val tail = inputs.tail

  println(solve(n, d, tail))

  def solve(n: Int, d: Int, tail: Seq[String]): Int = {
    var count = 0
    tail.foreach { line =>
      val xy = line.split(" ").map(_.toInt)
      val base = Math.sqrt( Math.pow(xy(0).toDouble, 2D) + Math.pow(xy(1).toDouble, 2D))
      if(base <= d.toDouble) {
        count = count + 1
      }
    }

    count
  }
}

Measured memory_bytes: 76152
#include <iostream>

#include <fstream>

#include <vector>
#include <set>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

#include <algorithm>
#include <iomanip>
#include <cmath>
#include <random>
#include <cstdlib>
#include <ctime>
#include <utility>

using namespace std;

ifstream in("input.txt");
ofstream out("output.txt");

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define F first
#define S second
#define forcin(n, a) for(int i = 0; i < n; ++i) {cin >> a[i];}
#define forcout(n, a) for(int i = 0; i < n; ++i) {cout << a[i] << " ";}
#define PI acos(-1)
#define forup(st, fin) for(int i = st; i < fin; ++i)
#define fordown(st, fin) for(int i = st; i >= fin; --i)
#define reverse_all(v) reverse(v.begin(), v.end())
#define sort_all(v) sort(v.begin(), v.end())
#define sort_allr(v) sort(v.rbegin(), v.rend())

///#define cin in
///#define cout out
///#define int long long

const ll MAXL = 1e18;
const int N = 10005000;
const int MAXN = 1e9 + 7;

int n;

int get_val(int a) {
    int sum = 0;
    while (a) {
        sum += a % 10;
        a /= 10;
    }
    return sum;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand(time(NULL));
    cin >> n;
    int ans = MAXN;
    for (int i = 1; i <= n / 2; ++i) {
        int a = i, b = n - i;
        ans = min(ans, get_val(a) + get_val(b));
    }
    cout << ans << "\n";
    return 0;
}
/*
5 3 4 3 1 -1
 */

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

int main()
{
    int n;
    cin >> n;
    int cake = 4, donut = 7;
    rep(i, 30) {
        rep(j, 30) {
            int value = cake * i + donut * j;
            if (value == n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, M;
  while (cin >> N >> M) {
    vector<ll> A(N);
    for (ll& x : A) cin >> x;
    priority_queue<ll> Q;
    for (ll x : A) Q.push(x);
    for (int i = 0; i < M; i++) {
      ll x = Q.top();
      Q.pop();
      Q.push(x / 2);
    }
    ll res = 0;
    while (!Q.empty()) {
      res += Q.top();
      Q.pop();
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 2168
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        String t = scan.next();
        scan.close();

        int ans = t.length();
        for (int i = 0; i <= s.length() - t.length(); i++) {
            int diff = 0;
            for (int j = 0; j < t.length(); j++) {
                if (s.charAt(i + j) != t.charAt(j)) {
                    diff++;
                }
            }
            ans = Math.min(ans, diff);
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 35596
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	long long n;
	cin >> n;

	cout << (n + 1) * n / 2 - n << endl;



	return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    while (k--) {
        if (a > 0) {
            ans++;
            a--;
        } else if (b > 0) {
            b--;
        } else {
            ans--;
            c--;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

#define MAX_V 1145
typedef pair<int, int> pii;
typedef long long ll;
const ll MOD = ((1e9) + 7);

int N, cmp[MAX_V];
bool used[MAX_V];
vector<int> G[MAX_V], rG[MAX_V], vs;

void add_edge(int from, int to)
{
    G[from].push_back(to);
    rG[to].push_back(from);
}

void dfs(int v)
{
    used[v] = 1;
    for (int i = 0; i < (int)G[v].size(); i++) {
	if (!used[G[v][i]]) {
            dfs(G[v][i]);
        }
    }
    vs.push_back(v);
}

void rdfs(int v, int k)
{
    used[v] = 1;
    cmp[v] = k;
    for (int i = 0; i < (int)rG[v].size(); i++) {
	if (!used[rG[v][i]]) {
            rdfs(rG[v][i], k);
        }
    }
}

int scc()
{
    memset(used, 0, sizeof(used));
    vs.clear();
    for (int v = 0; v < N; v++) {
	if (!used[v]) {
            dfs(v);
        }
    }
    memset(used, 0, sizeof(used));
    int k = 0;
    for (int i = vs.size() - 1; i >= 0; i--) {
	if (!used[vs[i]]) {
            rdfs(vs[i], k++);
        }
    }
    return k;
}

vector<int> nG[MAX_V];
ll memo[MAX_V];

ll solve(int v)
{
    ll &res = memo[v];
    if (res != -1) return res;
    res = 1;
    for (int i = 0; i < (int)nG[v].size(); i++) {
        res *= solve(nG[v][i]);
        res %= MOD;
    }
    res += 1;
    return res % MOD;
}

int main()
{
    int M, a, b;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> a >> b; a--; b--;
        add_edge(a, b);
    }
    
    auto K = scc();
    
    set<pii> st;
    int deg[MAX_V] = {};
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < (int)G[i].size(); j++) {
            int from = cmp[i], to = cmp[G[i][j]];
            if (from != to && st.count(pii(from, to)) == 0) {
                st.insert(pii(from, to));
                nG[to].push_back(from);
                deg[from]++;
            }
        }
    }
    
    memset(memo, -1, sizeof(memo));
    ll res = 1;    
    for (int i = 0; i < K; i++) {
        if (deg[i] == 0) {
            res *= solve(i);
            res %= MOD;
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3324
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#define endl "\n"
using namespace std;

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

  int a, b;
  char op;

  cin >> a >> op >> b;

  if (op==43)
  {
    cout << a + b << endl;
  }
  else
  {
    cout << a - b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii;
import std.typecons, std.functional;
import std.algorithm, std.container;

void main()
{
    auto N = scanElem;
    auto M = scanElem;
    auto Q = scanElem;

    long[501][501] table;
    foreach(i; 0..M)
    {
        long l = scanElem;
        long r = scanElem;
        table[r][l] += 1;
    }
    foreach(x; 1..501)
    {
        foreach(y; 1..501)
        {
            table[x][y] += table[x-1][y];
            table[x][y] += table[x][y-1];
            table[x][y] -= table[x-1][y-1];
        }
    }
    foreach(i; 0..Q)
    {
        long p = scanElem;
        long q = scanElem;
        writeln(table[q][q] - table[p-1][q] - table[q][p-1] + table[p-1][p-1]);
    }
}

void scanValues(TList...)(ref TList list)
{
    auto lit = readln.splitter;
    foreach (ref e; list)
    {
        e = lit.fornt.to!(typeof(e));
        lit.popFront;
    }
}

T[] scanArray(T = long)()
{
    return readln.split.to!(long[]);
}

void scanStructs(T)(ref T[] t, size_t n)
{
    t.length = n;
    foreach (ref e; t)
    {
        auto line = readln.split;
        foreach (i, ref v; e.tupleof)
        {
            v = line[i].to!(typeof(v));
        }
    }
}

T scanElem(T = long)()
{
    string res;
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        res ~= cast(char) c;
        c = getchar;
    }
    return res.strip.to!T;
}

template fold(fun...) if (fun.length >= 1)
{
    auto fold(R, S...)(R r, S seed)
    {
        static if (S.length < 2)
        {
            return reduce!fun(seed, r);
        }
        else
        {
            import std.typecons : tuple;

            return reduce!fun(tuple(seed), r);
        }
    }
}

struct Factor
{
    long n;
    long c;
}

Factor[] factors(long n)
{
    Factor[] res;
    for (long i = 2; i ^^ 2 <= n; i++)
    {
        if (n % i != 0)
            continue;

        int c;
        while (n % i == 0)
        {
            n = n / i;
            c++;
        }
        res ~= Factor(i, c);
    }
    if (n != 1)
        res ~= Factor(n, 1);

    return res;
}

bool isPrime(long n)
{
    if (n <= 1)
        return false;
    if (n == 2)
        return true;
    if (n % 2 == 0)
        return false;
    for (long i = 3; i ^^ 2 <= n; i += 2)
        if (n % i == 0)
            return false;
    return true;
}


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

int main()
{
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  
  int dp[n];
  memset(dp,0,sizeof(dp));
  dp[0]=0;
  dp[1]=abs(arr[1]-arr[0]);
  for(int i=2;i<n;i++)
  {
  	int f=dp[i-1]+abs(arr[i]-arr[i-1]);
  	int s=dp[i-2]+abs(arr[i]-arr[i-2]);
    dp[i]=min(f,s);
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
// ABC171B - 

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

typedef unsigned long long int ull;
typedef long long int ll;

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

	sort(A.begin(), A.end());

	int ans = 0;
	for (int i = 0; i < K; i++) {
		ans += A[i];
	}

	cout << ans << endl;

	return 0;
}


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

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] A = new int[h][w];
		int[][] B = new int[h][w];
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				A[i][j] = sc.nextInt();
			}
		}
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				B[i][j] = sc.nextInt();
			}
		}
		boolean[][][] dp = new boolean[h][w][6400];
		dp[0][0][(int)Math.abs(A[0][0] - B[0][0])] = true;
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				if(i + j == 0) continue;
				for(int k = 0; k < 6400; k++) {
					if((i > 0 && dp[i-1][j][k]) || (j > 0 && dp[i][j-1][k])) {
						int k1 = (int)Math.abs(k + A[i][j] - B[i][j]);
						if(k1 < 6400) {
							dp[i][j][k1] = true;
						}
						int k2 = (int)Math.abs(k + B[i][j] - A[i][j]);
						if(k2 < 6400) {
							dp[i][j][k2] = true;
						}
					}
				}
			}
		}
		int min = 6400;
		for(int k = 0; k < 6400; k++) {
			if(dp[h-1][w-1][k])
				min = Integer.min(k, min);
		}
		System.out.println(min);
	}
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch(IOException e) {
				throw new RuntimeException(e);
			}
		}
	}

}


Measured memory_bytes: 82412
#include <stdio.h>
  
int main(void) {
    char c;
    int A[26]= {0},i,j;
      
    while(scanf("%c", &c) != EOF){
        for (j=0; j<26; j++){
            if(c == 'a'+j || c == 'A'+j){
                A[j]++;
            }
        }
    }
    for(i=0; i<26; i++){
        printf("%c : %d\n", 'a'+i, A[i]);
    }
      
    return 0;
}

Measured memory_bytes: 540