stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
# include "cstdio"

# include "iostream"



inline int read(){

	int s=0,w=1;

	char ch=getchar();

	while(ch<'0' || ch>'9'){

		if(ch=='-') w=-w;

		ch=getchar();

	}

	while(ch>='0' && ch<='9'){

		s=s*10+ch-'0';

		ch=getchar();

	}

	return s*w;

}



inline int n_lowbit(int x){ 

	int count=0;

	while(x){

		if(x&1){

			return count; 

		}

		count++; 

		x>>=1; 

	}

	return count; 

} 



int

	ans,

	N; 



int main(){

	N=read();

	while(N--){

		ans+=n_lowbit(read()); //更新答案 

	}

	printf("%d",ans); 

	return 0; 

} 

// Faster C++ solution for the same problem (measured speedup: 5.248111250683229x):
/*

    Name: *3 or /2 

    Author: FZSZ-LinHua

    Date: 2018 06 16

    Exec time: 2ms

    Memory usage: 256KB

    Score: 300

    Algorithm: Bit operation 

*/

# include "cstdio"



inline int read(){

	int s=0,w=1;

	char ch=getchar();

	while(ch<'0' || ch>'9'){

		if(ch=='-') w=-w;

		ch=getchar();

	}

	while(ch>='0' && ch<='9'){

		s=s*10+ch-'0';

		ch=getchar();

	}

	return s*w;

}



inline int n_lowbit(int x){	//取出含有质因子2的个数 

	int count=0;

	while(x){

		if(x&1){

			return count; 

		}

		count++; 

		x>>=1; 

	}

	return count; 

} 



int

	ans, //记录答案 

	N; 



int main(){

	N=read();

	while(N--){

		ans+=n_lowbit(read()); //更新答案 

	}

	printf("%d",ans); 

	return 0; 

}
// Slower C++ solution:
#include <cstdio>

#include <vector>

using namespace std;

int N, t; vector<int> v;

int rec(int x, int cnt) {

  if(x%2 == 1) return cnt;

  return rec(x/2, cnt+1);

}

int main() {

  int N; scanf("%d", &N);

  for(int i = 0; i < N; i++) {

    scanf("%d", &t);

    if(t%2 == 0) v.push_back(t);

  }

  int sum;

  for(int x : v) sum += rec(x, 0);

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

}

// Faster C++ solution for the same problem (measured speedup: 4.8539512499024715x):
#include <cstdio>

using namespace std;

int N, t, ans;

int main() {

  int N; scanf("%d", &N);

  for(int i = 0; i < N; i++) {

    scanf("%d", &t);

    while(t%2==0) {t/=2; ans++;}

  }

  printf("%d", ans);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){

    string s;

    cin >> s;

    if(s=="AKIHABARA"){

        cout << "YES" << endl;

        return 0;

    }

    string t = s;

    int n=t.size();

    rep(i,n+1){

        t.insert(t.begin()+i,'A');

        if(t=="AKIHABARA"){

            cout << "YES" << endl;

            return 0;

        }

        rep(j,n+2){

            string u = t;

            u.insert(u.begin()+j,'A');

            if(u=="AKIHABARA"){

                cout << "YES" << endl;

                return 0;

            }

            rep(k,n+3){

                string v = u;

                v.insert(v.begin()+k,'A');

                if(v=="AKIHABARA"){

                    cout << "YES" << endl;

                    return 0;

                }

                rep(l,n+4){

                    string w = v;

                    w.insert(w.begin()+l,'A');

                    if(w=="AKIHABARA"){

                        cout << "YES" << endl;

                        return 0;

                    }

                    w = v;

                }

                v = u;

            }

            u = t;

        }

        t = s;

    }

    cout << "NO" << endl;

 }

// Faster C++ solution for the same problem (measured speedup: 2.1058135632894865x):
#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){

    string s;

    cin >> s;

    vector<string> e={"", "A"};

    for (auto a:e){

        for (auto b:e){ 

            for (auto c:e){ 

                for (auto d:e)  {

                    if (s == a + "KIH" + b + "B" + c + "R" + d) {

                    cout << "YES" <<endl;

                    return 0;

                    } 

                }

            }

        }

    }

    cout << "NO" <<endl;

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <deque>

#include <math.h>

#include <set>

#include <iomanip>

#include <time.h>

#include <list>

#include <stdio.h>

#include <queue>

#include <map>

#include <algorithm>

#include <assert.h>

#include <memory.h>



#define mk make_pair

#define sc second

#define fr first

#define pb emplace_back

#define all(s) s.begin(), s.end()

#define sz(s) ( (int)s.size() )



using namespace std;



string z = "AKIHABARA", o = "A";



bool check(string s)

{

    if (sz(s) == 9)

        return s == z;



    string em, suf = s;



    for (int i = 0; i <= sz(s); i++)

    {

        for (int j = 0; j < sz(o); j++)

        {

            if (check( em + o[j] + suf ) )

                return true;

        }

        if (i < sz(s))

            em += s[i],

            suf.erase(0, 1);

    }

    return false;

}



string s;



main ()

{

    cin >> s;

    if (sz(s) > 9 )

        puts("NO");

    else if (check(s))

        puts("YES");

    else

        puts("NO");

}


// Faster C++ solution for the same problem (measured speedup: 1.09091258148858x):
#include <bits/stdc++.h>

using namespace std; 

string s;

int main() {

	cin>>s;

	if(s=="KIHBR"||s=="KIHBRA"||s=="KIHBAR"||s=="KIHBARA"||s=="KIHABR"||s=="KIHABRA"||s=="KIHABAR"||s=="KIHABARA"||s=="AKIHBR"||s=="AKIHBRA"||s=="AKIHBAR"||s=="AKIHBARA"||s=="AKIHABR"||s=="AKIHABRA"||s=="AKIHABAR"||s=="AKIHABARA")

		puts("YES");

	else	puts("NO");

	return 0;

}
// Slower C++ solution:
#include <stdio.h>

#include <math.h>

int main(){

	

	int H, W, N;

	int max, min;

    scanf("%d%d%d", &H, &W, &N);



	if(H>W){

		printf("%.0f", ceil(N*1.0/H));

	} else {

		printf("%.0f", ceil(N*1.0/W));

	}

	return 0;	

}

// Faster C++ solution for the same problem (measured speedup: 1.1484069177476361x):
#include <stdio.h>

int main() {

	int r,c;

	scanf("%d",&r);

	scanf("%d",&c);

	int N;

	scanf("%d",&N);

	

	if (r < c)

	{

		r = c;

	}

	

	if ( N%r == 0 )

	{

		printf("%d\n",N/r);

	} 

	else if ( N%r != 0)

	{

		printf("%d\n",(N/r)+1);

	}



    return 0;

}
// Slower C++ solution:
#include <stdio.h>

#include <math.h>

int main(){

	

	int H, W, N;

	int max, min;

    scanf("%d%d%d", &H, &W, &N);



	if(H>W){

		printf("%.0f", ceil(N*1.0/H));

	} else {

		printf("%.0f", ceil(N*1.0/W));

	}

	return 0;	

}

// Faster C++ solution for the same problem (measured speedup: 1.14797341969113x):
#include<stdio.h>



int main()

{

	int row, col, n;

	scanf("%d %d %d", &row, &col, &n);

	

	int bucket;

	if (row >= col)

	{

		bucket = row;

	}

	

	else

	{

		bucket = col;

	}

	

	int i = 0, j;

	int count = 0;

	

	while (i < n)

	{

		count++;

		i += bucket;

	}

	

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

	

	return 0;

}
// Slower C++ solution:
#include <stdio.h>

#include <math.h>

int main(){

	

	int H, W, N;

	int max, min;

    scanf("%d%d%d", &H, &W, &N);



	if(H>W){

		printf("%.0f", ceil(N*1.0/H));

	} else {

		printf("%.0f", ceil(N*1.0/W));

	}

	return 0;	

}

// Faster C++ solution for the same problem (measured speedup: 1.1479792130478215x):
#include<stdio.h>

int main()

{

    int h,w,n,omen;

    scanf("%d %d %d",&h,&w,&n);

    if(h > w) omen = h;

    else omen = w;

    int hitung = 1;

    for(int i = omen;i<n;i += omen)

    hitung++;

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

    return 0;

}
// Slower C++ solution:
#include <stdio.h>

#include <math.h>

int main(){

	

	int H, W, N;

	int max, min;

    scanf("%d%d%d", &H, &W, &N);



	if(H>W){

		printf("%.0f", ceil(N*1.0/H));

	} else {

		printf("%.0f", ceil(N*1.0/W));

	}

	return 0;	

}

// Faster C++ solution for the same problem (measured speedup: 1.1518421645268058x):
#include<stdio.h>

int main (){

	int ha;

	int wa;

	int na;

	int hasil;

	

	scanf("%d", &ha);

	scanf("%d", &wa);

	scanf("%d", &na);

	

	if(ha>=wa){

        if(na%ha == 0) {

            hasil = na/ha;

        } else {

            hasil = na/ha+1;

        }

    } else {

        if(na%wa == 0) {

            hasil = na/wa;

        } else {

            hasil = na/wa+1;

        }

    }

    printf("%d", hasil);

	return 0;

}
// Slower C++ solution:
#include <stdio.h>

#include <math.h>

int main(){

	

	int H, W, N;

	int max, min;

    scanf("%d%d%d", &H, &W, &N);



	if(H>W){

		printf("%.0f", ceil(N*1.0/H));

	} else {

		printf("%.0f", ceil(N*1.0/W));

	}

	return 0;	

}

// Faster C++ solution for the same problem (measured speedup: 1.152215887805218x):
#include <stdio.h>

int main(){

	

	int H, W, N;

	int max, min;

    scanf("%d%d%d", &H, &W, &N);



	if(H>W){

		printf("%d", (N - 1) / H + 1);

	} else {

		printf("%d", (N - 1) / W + 1);

	}

	return 0;	

}
// Slower C++ solution:
#include <stdio.h>

#include <math.h>

int main(){

	

	int H, W, N;

	int max, min;

    scanf("%d%d%d", &H, &W, &N);



	if(H>W){

		printf("%.0f", ceil(N*1.0/H));

	} else {

		printf("%.0f", ceil(N*1.0/W));

	}

	return 0;	

}

// Faster C++ solution for the same problem (measured speedup: 1.1466489895083327x):
#include<stdio.h>

int main()

{

int H,W,N;

int P=0,C=0;

scanf("%d", &H);

scanf("%d", &W);

scanf("%d", &N);

if(H > W)

{

    P = H;

}  

else

{

    P = W;

}

int i = 0; 

do

{

    C++;

    i = i +P;

}

while(i < N);

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

return 0;

}
// Slower C++ solution:
#include <stdio.h>

#include <math.h>

int main(){

	

	int H, W, N;

	int max, min;

    scanf("%d%d%d", &H, &W, &N);



	if(H>W){

		printf("%.0f", ceil(N*1.0/H));

	} else {

		printf("%.0f", ceil(N*1.0/W));

	}

	return 0;	

}

// Faster C++ solution for the same problem (measured speedup: 1.1480568626172523x):
#include <stdio.h>



int main()

{

    int h, w, n, j, hasil=0;

    scanf("%d%d%d", &h,&w,&n);

    if(h>w){

        j=h;

    }else{

        j=w;

    }

    for(int i=0;i<n;i=i+j){

        hasil++;

    }

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

    return 0;

}
// Slower C++ solution:
#include <stdio.h>

#include <math.h>

int main(){

	

	int H, W, N;

	int max, min;

    scanf("%d%d%d", &H, &W, &N);



	if(H>W){

		printf("%.0f", ceil(N*1.0/H));

	} else {

		printf("%.0f", ceil(N*1.0/W));

	}

	return 0;	

}

// Faster C++ solution for the same problem (measured speedup: 1.1516739606405422x):
#include <stdio.h>

int main ()

{

	int H, W, N;

	scanf ("%d", &H);

	scanf ("%d", &W);

	scanf ("%d", &N);

	if (H < W)

	{

		H=W;

	}

	if (N % H == 0){

		printf ("%d", N/H);

	}

	else if (N % H != 0){

		printf ("%d", (N/H) + 1);

	}

return 0;

}
// Slower C++ solution:
#include<iostream>



using namespace std;

int main(){

   int x, y;

   cin >> x >> y;

   int hi = max(x, y);

   int n;

   cin >> n;

   int op;

   if(n % hi == 0)

    op = (n / hi);

   else op = (n / hi) + 1;

   cout << op;

}


// Faster C++ solution for the same problem (measured speedup: 5.246960107525371x):
#include <stdio.h>

int main(){

	

	int h,w,n,bank = 0;

	scanf("%d %d %d" , &h, &w, &n);

	

	while (n > 0){

		

		if(h > w){

			n -= h;

		}

		else{

			n -= w;

		}

		bank++;

	}

	

	printf("%d" , bank);

	

	

	return 0;

}
// Slower C++ solution:
#include<iostream>



using namespace std;

int main(){

   int x, y;

   cin >> x >> y;

   int hi = max(x, y);

   int n;

   cin >> n;

   int op;

   if(n % hi == 0)

    op = (n / hi);

   else op = (n / hi) + 1;

   cout << op;

}


// Faster C++ solution for the same problem (measured speedup: 5.255269323196384x):
#include <stdio.h>



int main (){

	

	int h, w, n;

	scanf("%d %d %d", &h, &w, &n);

	

	int tot;

	

	if(h>=w) {

        if(n%h == 0) {

            tot = n/h;

        } else {

            tot = n/h+1;

        }

    } else {

        if(n%w == 0) {

            tot = n/w;

        } else {

            tot = n/w+1;

        }

    }

	printf("%d", tot);

	

	return 0;

}
// Slower C++ solution:
#include<iostream>



using namespace std;

int main(){

   int x, y;

   cin >> x >> y;

   int hi = max(x, y);

   int n;

   cin >> n;

   int op;

   if(n % hi == 0)

    op = (n / hi);

   else op = (n / hi) + 1;

   cout << op;

}


// Faster C++ solution for the same problem (measured speedup: 5.235966534801472x):
#include <stdio.h>



int main() {

	int a, b, c;

	

	scanf("%d %d %d", &a, &b, &c);



	int ctr = 0;

	int sum = 0;

	

	while (c > sum) {

		if(b >= a) {

			sum += b;

			ctr++;

		}

		else {

			sum += + a;

			ctr++;

		}

	}

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

	return 0;

}
// Slower C++ solution:
#include<iostream>



using namespace std;

int main(){

   int x, y;

   cin >> x >> y;

   int hi = max(x, y);

   int n;

   cin >> n;

   int op;

   if(n % hi == 0)

    op = (n / hi);

   else op = (n / hi) + 1;

   cout << op;

}


// Faster C++ solution for the same problem (measured speedup: 5.22979732829228x):
#include <stdio.h>



int main() {

    int h,w,n;

    scanf("%d", &h);

    scanf("%d", &w);

    scanf("%d", &n);

    int counter = 0;

    int sum = 0;

    while (n > sum){

        if(w >= h){

            sum += w;

            counter++;

        }else if(h > w){

            sum+= h;

            counter++;

        }

    }

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

    

    return 0;

}
// Slower C++ solution:
#include<iostream>



using namespace std;

int main(){

   int x, y;

   cin >> x >> y;

   int hi = max(x, y);

   int n;

   cin >> n;

   int op;

   if(n % hi == 0)

    op = (n / hi);

   else op = (n / hi) + 1;

   cout << op;

}


// Faster C++ solution for the same problem (measured speedup: 5.246518479056858x):
#include<stdio.h>

int main()

{

    int baris,kolom,n,i= 0;

    int tamp,count =0;

    scanf("%d %d %d",&baris, &kolom, &n);

    if(baris>kolom)

	{

        tamp=baris;

    }else

	{

        tamp=kolom;

    }

    for(i=0;i<n;i=i+tamp)

	{

        count++;

    }

    printf("%d",count);

    

    

    return 0;

}
// Slower C++ solution:
#include<iostream>



using namespace std;

int main(){

   int x, y;

   cin >> x >> y;

   int hi = max(x, y);

   int n;

   cin >> n;

   int op;

   if(n % hi == 0)

    op = (n / hi);

   else op = (n / hi) + 1;

   cout << op;

}


// Faster C++ solution for the same problem (measured speedup: 5.229806314589667x):
#include <stdio.h>



int main(){

    int h,w,n;

    scanf("%d", &h);

	scanf("%d", &w);

	scanf("%d", &n);

  

    int ans = 0, count = 0;

   

    while (n > ans){

        if(w >= h){

            ans += w;

            count++;

        }else if(h>w){

            ans += h;

            count++;

        }

    }

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

    return 0;

}
// Slower C++ solution:
#include<iostream>



using namespace std;

int main(){

   int x, y;

   cin >> x >> y;

   int hi = max(x, y);

   int n;

   cin >> n;

   int op;

   if(n % hi == 0)

    op = (n / hi);

   else op = (n / hi) + 1;

   cout << op;

}


// Faster C++ solution for the same problem (measured speedup: 5.252000689779387x):
#include <stdio.h>

int main() {

	int baris, kolom, n;

	scanf("%d",&baris);

	scanf("%d",&kolom);

	scanf("%d",&n);

	

	int max;

	baris > kolom ? max = baris : max = kolom;

	

	n % max == 0 ? printf("%d",n/max) : printf("%d",(n/max)+1);

	return 0;

}
// Slower C++ solution:
#include<iostream>

using namespace std;

int main(){

    int a,b,c,d;

    cin>>a>>b>>c;

    d=max(a,b);

    cout<<(c+d-1)/d;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.241202568680948x):
#include<stdio.h>

int mx(int x,int y){return x>y?x:y;}

main()

{

	int x,y,z;scanf("%d%d%d",&x,&y,&z);

	printf("%d\n",(z+mx(x,y)-1)/mx(x,y));

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

using namespace std;

int a[61],f[61][61][201][2];

int main ()

{

	int n,m,i,j,k;

	scanf("%d%d",&n,&m);

	for(i=1;i<=n;++i) scanf("%d",&a[i]);

	for(k=1;k<=m;++k)

	  for(i=1;i<=n;++i)

	    for(j=i;j<=n;++j)

	    {

	    	if(k!=1)

	    	{

	    		f[i][j][k][0]=max(f[i+1][j][k-2][0],f[i+1][j][k-2][1]);

	    		f[i][j][k][1]=max(f[i][j-1][k-2][0],f[i][j-1][k-2][1]);

			}

			f[i][j][k][0]=max(f[i][j][k][0],f[i+1][j][k-1][0]+a[i]);

			f[i][j][k][0]=max(f[i][j][k][0],f[i+1][j][k-1][1]+a[i]);

			f[i][j][k][1]=max(f[i][j][k][1],f[i][j-1][k-1][0]+a[j]);

			f[i][j][k][1]=max(f[i][j][k][1],f[i][j-1][k-1][1]+a[j]);

		}

	printf("%d",max(f[1][n][m][0],f[1][n][m][1]));

}

// Faster C++ solution for the same problem (measured speedup: 5.101350287613091x):
#include<cstdio>

#include<vector>

#include<algorithm>



using namespace std;

const int maxn=105;

int v[maxn],plate[maxn];



int main(){

    int n,k,r;

    scanf("%d %d",&n,&k);

//    vector<int> v(n),plate(n);

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

        scanf("%d",&v[i]);

    }

    r=min(n,k);

    int ans=0;

    for(int A=0;A<=r;++A){

        for(int B=0;B<=r-A;++B){

            int i,j;

            for(i=0;i<A;++i){

                plate[i]=v[i];

            }

            for(j=0;j<B;++j){

                plate[i+j]=v[n-1-j];

            }

            sort(plate,plate+A+B);

            i=0;

            while(i<k-(A+B)&&plate[i]<0){

                ++i;

            }

            int tmp=0;

            while(i<A+B){

                tmp+=plate[i++];

            }

            ans=max(ans,tmp);

        }

    }

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

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<vector>





using namespace std;

int n,k;

long long num[55];

long long hand[55];

vector<long long> q;





bool cmp(long long a,long long b){

    return a>b;

}





long long solve(int l,int r){

    while(!q.empty())q.clear();

    long long ans=0;

    for(int i=1;i<=l;i++){

        ans+=num[i];

        q.push_back(num[i]);

    }

    for(int i=n;i>=n-r+1;i--){

        ans+=num[i];

        q.push_back(num[i]);

    }

    sort(q.begin(),q.end(),cmp);

    for(int i=0;i<k-r-l;i++){

        if(q.empty()) break;

        ans-=min(q[q.size()-1],(long long ) 0);

        q.pop_back();

    }

    return ans;

}





int main(){

    cin>>n>>k;

    for(int i=1;i<=n;i++){

        cin>>num[i];

    }

    long long maxn=0;

    for(int i=0;i<=k;i++){

        for(int j=0;j+i<=min(n,k);j++){

            maxn=max(solve(i,j),maxn);

        }

    }

    cout<<maxn;

}

// Faster C++ solution for the same problem (measured speedup: 5.187296531759477x):
#include<cstdio>

#include<vector>

#include<algorithm>



using namespace std;

const int maxn=105;

int v[maxn],plate[maxn];



int main(){

    int n,k,r;

    scanf("%d %d",&n,&k);

//    vector<int> v(n),plate(n);

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

        scanf("%d",&v[i]);

    }

    r=min(n,k);

    int ans=0;

    for(int A=0;A<=r;++A){

        for(int B=0;B<=r-A;++B){

            int i,j;

            for(i=0;i<A;++i){

                plate[i]=v[i];

            }

            for(j=0;j<B;++j){

                plate[i+j]=v[n-1-j];

            }

            sort(plate,plate+A+B);

            i=0;

            while(i<k-(A+B)&&plate[i]<0){

                ++i;

            }

            int tmp=0;

            while(i<A+B){

                tmp+=plate[i++];

            }

            ans=max(ans,tmp);

        }

    }

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

    return 0;

}
// Slower C++ solution:
/*|In The Name Of Allah|*/



#include <bits/stdc++.h>



using namespace std;



const int N = 111;

const int M = 11;



int n;

int k;

int v[N];

int mem[N][N][N];



int go(int l , int r , int stp){

    if(stp < 0)

        return -1e9;

    if(l > r || stp == 0)

        return 0;

    if(~mem[l][r][stp])

        return mem[l][r][stp];

    int ret = 0;

    int c1 , c2 , c3 , c4;

    c1 = go(l + 1 , r , stp - 1) + v[l];

    c2 = go(l , r - 1 , stp - 1) + v[r];

    c3 = go(l + 1 , r , stp - 2);

    c4 = go(l , r - 1 , stp - 2);

    return mem[l][r][stp] = max(0 , max(max(c1 , c2) , max(c3 , c4)));

}



int main(){

    scanf("%d%d" , &n , &k);

    for(int i = 1; i <= n; i++){

        scanf("%d" , &v[i]);

    }

    memset(mem , -1 , sizeof mem);

    printf("%d\n" , max(go(1 , n , k) , 0));

}


// Faster C++ solution for the same problem (measured speedup: 6.6181791019137135x):
#include<bits/stdc++.h>

typedef long long ll;

#define dbg          cout<<"Freak"<<endl;

#define dbgg(i)      cout<<i<<endl;

#define N            1e9+7;

using namespace std;

ll t;

ll arr[200005];

int main()

{

    ll a,b,c,d,e,f,g,i,j,k,sum;

    vector<ll>v;

    cin>>a>>b;

    for(i=1;i<=a;i++)cin>>arr[i];

    f=0;

    for(i=0;i<=a;i++)

    {

        for(j=0;j<=a;j++)

        {

            d=b-i-j;

            sum=0;

            v.clear();

            if(d<0||i+j>b||i+j>a)continue;

            for(k=1;k<=i;k++)

            {

                v.push_back(arr[k]);

                sum+=arr[k];

            }

            for(k=a;k>a-j;k--)

            {

                v.push_back(arr[k]);

                sum+=arr[k];

            }

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

            for(k=0;k<i+j&&d!=0;k++)

            {

                if(v[k]>=0)break;

                sum=sum-v[k];

                --d;

            }

            f=max(sum,f);

        }

    }

    cout<<f<<endl;

    return 0;

}
// Slower C++ solution:
/*|In The Name Of Allah|*/



#include <bits/stdc++.h>



using namespace std;



const int N = 111;

const int M = 11;



int n;

int k;

int v[N];

int mem[N][N][N];



int go(int l , int r , int stp){

    if(stp < 0)

        return -1e9;

    if(l > r || stp == 0)

        return 0;

    if(~mem[l][r][stp])

        return mem[l][r][stp];

    int ret = 0;

    int c1 , c2 , c3 , c4;

    c1 = go(l + 1 , r , stp - 1) + v[l];

    c2 = go(l , r - 1 , stp - 1) + v[r];

    c3 = go(l + 1 , r , stp - 2);

    c4 = go(l , r - 1 , stp - 2);

    return mem[l][r][stp] = max(0 , max(max(c1 , c2) , max(c3 , c4)));

}



int main(){

    scanf("%d%d" , &n , &k);

    for(int i = 1; i <= n; i++){

        scanf("%d" , &v[i]);

    }

    memset(mem , -1 , sizeof mem);

    printf("%d\n" , max(go(1 , n , k) , 0));

}


// Faster C++ solution for the same problem (measured speedup: 6.712440983361058x):
#include<iostream>

#include<cstdio>

#include<algorithm>

#define maxn 100

using namespace std;

int n,l,r,a[maxn],p,b[maxn],cnt,sum,ans=0;

int main(){

	scanf("%d%d",&n,&p);

	for(int i=1;i<=n;i++)

		scanf("%d",&a[i]);

	for(int i=0;i<=min(n,p);i++){//Ò»¹²½øÐÐÁË¼¸´ÎÈ¡µÄ²Ù×÷ 

		for(int j=0;j<=i;j++){

			int lnum=j,rnum=i-j;

			cnt=0;sum=0;

			for(int k=1;k<=lnum;k++){

				b[++cnt]=a[k];

				sum+=a[k];

			}

			for(int k=n;k>=n-rnum+1;k--){

				b[++cnt]=a[k];

				sum+=a[k];

			}

			sort(b+1,b+cnt+1);

			for(int k=1;k<=min(p-i,cnt);k++){

				if(b[k]>=0)break;

				sum-=b[k];

			}

			ans=max(ans,sum);

		}

	}

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

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#define N 110

using namespace std;

int a[N],dp[N][N][N],n,m;

int main(){

	memset(dp,-128/3,sizeof(dp));

	scanf("%d%d",&n,&m);

	for(int i=1;i<=n;i++)

		scanf("%d",&a[i]); 

	dp[0][n+1][0]=0;

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

		for(int j=n+1;j>i;j--)

			for(int k=0;k<=m;k++){

				dp[i+1][j][k+1]=max(dp[i+1][j][k+1],dp[i][j][k]+a[i+1]);

				dp[i][j-1][k+1]=max(dp[i][j-1][k+1],dp[i][j][k]+a[j-1]);

				if(a[i+1]<0)

					dp[i+1][j][k+2]=max(dp[i+1][j][k+2],dp[i][j][k]);

				if(a[j-1]<0)

					dp[i][j-1][k+2]=max(dp[i][j-1][k+2],dp[i][j][k]);

			}

	int ans=0;

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

		for(int j=i+1;j<=n+1;j++)

			for(int k=0;k<=m;k++)

				ans=max(ans,dp[i][j][k]);

	cout<<ans;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.565604376348646x):
#include<iostream>

#include<cstdio>

#include<algorithm>

#define maxn 100

using namespace std;

int n,l,r,a[maxn],p,b[maxn],cnt,sum,ans=0;

int main(){

	scanf("%d%d",&n,&p);

	for(int i=1;i<=n;i++)

		scanf("%d",&a[i]);

	for(int i=0;i<=min(n,p);i++){//Ò»¹²½øÐÐÁË¼¸´ÎÈ¡µÄ²Ù×÷ 

		for(int j=0;j<=i;j++){

			int lnum=j,rnum=i-j;

			cnt=0;sum=0;

			for(int k=1;k<=lnum;k++){

				b[++cnt]=a[k];

				sum+=a[k];

			}

			for(int k=n;k>=n-rnum+1;k--){

				b[++cnt]=a[k];

				sum+=a[k];

			}

			sort(b+1,b+cnt+1);

			for(int k=1;k<=min(p-i,cnt);k++){

				if(b[k]>=0)break;

				sum-=b[k];

			}

			ans=max(ans,sum);

		}

	}

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

	return 0;

}