stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main()

{



		int h,a;

		cin>>h>>a;

		int ans=h/a;

		h=h%a;

		if(h>0)

		ans++;

		cout<<ans;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

int main()

{

	int H,A;

	scanf("%d%d",&H,&A);

	H%A<=0?printf("%d",H/A):printf("%d",H/A +1);//kalo yang pertama kondisi contoh 10/5 jdi habis kalo kondisi kedua contoh 10/4 jdi sisa dan harus ditambah 1 kali atatck

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;

int main(){

   int H,i;

   int a;

   cin>>H;

   cin>>a;

   for(i=1;a<H;i++){

       H-=a;

   }

   cout<<i;

}




// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

int a,b,value;



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

if(a<=b){

    printf("1");

}

else if(a>b){

    value=(a-1)/b+1;

    printf("%d",value);

}

return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;



int main()

{

    int h,a;

    int counter = 0;

    cin>>h >> a;

    for(; h>0;)

    {

        h = h - a ;

        counter = counter +1;



    }

    cout<<counter<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

int a,b,value;



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

if(a<=b){

    printf("1");

}

else if(a>b){

    value=(a-1)/b+1;

    printf("%d",value);

}

return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;



int main()

{

	





int H ,A,i=0;

cin>>H >>A ;

while (H>0) {

H=H-A;



i++;

 }

cout<< i << endl;

return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

int a,b,value;



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

if(a<=b){

    printf("1");

}

else if(a>b){

    value=(a-1)/b+1;

    printf("%d",value);

}

return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int main()

{

    int a,b;

    cin>>a>>b;



    cout<<(a+b-1)/b;

    return 0;



}




// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

int a,b,value;



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

if(a<=b){

    printf("1");

}

else if(a>b){

    value=(a-1)/b+1;

    printf("%d",value);

}

return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cmath>

using namespace std;

int main()

{

    float h,a;

    cin >> h >> a;

    cout << ceil(h/a) <<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

int a,b,value;



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

if(a<=b){

    printf("1");

}

else if(a>b){

    value=(a-1)/b+1;

    printf("%d",value);

}

return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int main(){

	int h,a;

	cin >> h >> a;

	

	cout << (h+a-1)/a << endl;

	

	

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(){

int a,b,value;



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

if(a<=b){

    printf("1");

}

else if(a>b){

    value=(a-1)/b+1;

    printf("%d",value);

}

return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;



int main()

{

    int H,A;

    cin>>H>>A;

    cout<<((H%A==0)?(H/A):((H/A)+1));

    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main() {

    int H,A;

    scanf("%d%d",&H,&A);

    H%A<=0?printf("%d",H/A):printf("%d",H/A +1);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



int main() {



    double a,b;

    cin>>a>>b;

    cout<<int(ceil(a/b));

    

    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main() {

    int H,A;

    scanf("%d%d",&H,&A);

    H%A<=0?printf("%d",H/A):printf("%d",H/A +1);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
//----------------------Shanu Garg here---------------------

//-------------Search on youtube : Shanu Garg---------------

//-Studying at National Institute of Technology Delhi(NITD)-

//---------------------From Delhi, India--------------------



#include<bits/stdc++.h>

#include<algorithm>

using namespace std;



#define f(i,n) for(auto i=0;i<n;i++)

#define fr(i,n) for(auto i=n-1;i>=0;i--)

#define fs(i,a,b,c) for(auto i=a;i!=b;i+=c)

#define fl(i,x) for(auto i : x)

#define nl cout<<"\n";

#define ll long long int

#define vi vector<int>

#define pr pair<ll, ll>

#define vll vector<pr>

#define vl vector<ll>

#define mid(a,b) ((a+b)/2)

#define pb push_back

#define LCM(a,b) ((a*b)/__gcd(a, b))

const int INF = 0x3f3f3f3f, mod = 1e9 + 7;



class triplet{ll f, s, t;};



vl in(ll n){vl v;ll x;

    f(i,n)

    cin>>x, v.pb(x%mod);

    return v;}

void out(vl v){fl(i,v)cout<<i;}

void out(vl v, char ch){

    fl(i,v)

    cout<<i<<ch;}



void solve(){

    ll n, a;

    cin>>n>>a;

    ll ans=0;

    ans += (n%a) ? 1 : 0;

    cout<<(n/a)+ans;

}



int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    solve();

   return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>



int main() {

    int H,A;

    scanf("%d%d",&H,&A);

    H%A<=0?printf("%d",H/A):printf("%d",H/A +1);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;

const  int maxn = 10005;

int a[maxn];

int s(int k)

{

	int ans=0;

	if(k%2==1) return 0;

	while(k%2==0)

	{

		ans++;k/=2;

	}

	return ans;

	

	

}

int main()

{

	int n,j;

	int ans=0;

	cin>>n;

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

	{

		cin>>j;

		ans+=s(j);

	}

	cout<<ans;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

const int maxn=10010;

int n;

int main()

{

    //freopen("1.txt","r",stdin);

    while (scanf("%d",&n)!=EOF)

    {

        int t,ans=0;

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

        {

            scanf("%d",&t);

            while (t%2==0)

            {

                ans++;

                t/=2;

            }

        }

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

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;



int main(){

    int n,a[10005]={},cnt=0;

    bool flag=true;

    cin>>n;

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

        cin>>a[i];

        while(a[i]%2==0){

            cnt++;

            a[i]/=2;

        }

    }

    cout<<cnt<<endl;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

using namespace std;



int main(){

    int n,a,cnt=0;

    scanf("%d",&n);

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

        scanf("%d",&a);

        while(1){

            if(a&1){

                break;

            }

            cnt++;

            a>>= 1;

        }

    }

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

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <bitset>

using namespace std;



int main(){

    int n,a[10005]={},cnt=0;

    cin>>n;

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

        cin>>a[i];

        while(a[i]%2==0){

            cnt++;

            a[i] = a[i] >> 1;

        }

    }

    cout<<cnt<<endl;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

using namespace std;



int main(){

    int n,a,cnt=0;

    scanf("%d",&n);

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

        scanf("%d",&a);

        while(1){

            if(a&1){

                break;

            }

            cnt++;

            a>>= 1;

        }

    }

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

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;



int main(){

    int n,a,cnt=0;

    cin>>n;

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

        cin>>a;

        while(1){

            if(a&1){

                break;

            }

            cnt++;

            a>>= 1;

        }

    }

    cout<<cnt<<endl;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

using namespace std;



int main(){

    int n,a,cnt=0;

    scanf("%d",&n);

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

        scanf("%d",&a);

        while(1){

            if(a&1){

                break;

            }

            cnt++;

            a>>= 1;

        }

    }

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

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
# include "cstdio"

# include "iostream"



using namespace std;



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, 

    a; 



int main(){

    scanf("%d",&N);

    while(N--){

        scanf("%d",&a);

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

    }

    printf("%d",ans); 

    return 0; 

} 

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

int n,ans,x;

void read(int &x)

{

    int f=1;x=0;char s=getchar();

    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}

    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}

    x*=f;

}

int PD(int x)

{

	int count=0;

    while(x){

        if(x&1){

            return count; 

        }

        count++; 

        x>>=1; 

    }

    return count; 

}

int main()

{

	read(n);

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

	{read(x);

		ans+=PD(x);

	}

	printf("%d",ans);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

using namespace std;



int main() {

  int n; cin >> n;

  vector<int> a(n);

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

  

  int ans = 0;

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

    int temp = a[i];

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

      if (temp % 2 == 0) {

        temp /= 2;

        ans++;

      } else {

        break;

      }

    }

  }

  

  cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

using namespace std;



int main() {

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

  

  int ans = 0;

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

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

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

      if (temp % 2 == 0) {

        temp /= 2;

        ans++;

      } else {

        break;

      }

    }

  }

  

  printf("%d", ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
# 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; 

} 

// Optimized solution to the same problem (faster):
/*

    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; 

} 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

 }

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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");

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;	

}

// Optimized solution to the same problem (faster):
#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;	

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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]));

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
/*|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));

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem: