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

/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef long long int ll;
vector<int> ve(3006, 0);
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
// online submission
#endif
	int n;
	cin >> n;
	ll a = 7;
	for (int i = 0; i < 10000000; i++) {
		if (a%n == 0) {
			cout << i + 1;
			return 0;
		}
		else {
			a = ((a * 10) % n + 7) % n;
		}
	}
	cout << -1;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cmath>

#define rep(a, b, c) for (int a = b; a < c; a++)

using namespace std;

int main() {
    while (true) {
        int N;
        cin >> N;

        if (N == 0) break;

        N++;
        long long dp[N];
        dp[0] = 1;

        rep(i, 1, N) {
            dp[i] = dp[i - 1];
            if (i > 1) dp[i] += dp[i - 2];
            if (i > 2) dp[i] += dp[i - 3];
        }
        cout << ceil(ceil(dp[N - 1] / 10.0) / 365.0) << endl;
    }
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int H,W;
  cin >> H >> W;

  vector<string> v(H), w;

  for(int i = 0; i < H; i++){
    cin >> v[i];
  }

  w = v;

  auto check = [&v, &H, &W](int x, int y){
    if(x < 0 || x >= H) return false;
    if(y < 0 || y >= W) return false;
    if(v.at(x).at(y) == '.') return false;
    return true;
  };

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

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(v.at(i).at(j) == '#'){
        continue;
      } 
      int sum = 0;
      for(int k  = 0; k < 8; k++){
        if(check(i + dx[k], j + dy[k])){
          sum++;
        }
      }
      char c = '0' + sum; 
      w.at(i).at(j) = c;
    }
  }

  for(int i = 0; i < H; i++){
    cout << w[i] << endl;
  }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def divisor(n):
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            yield i
            yield n // i

@mt
def slv(N):
    d = [n for n in divisor(N)]
    x = d.pop()
    y = d.pop()
    return (x-1) + (y-1)


def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6464
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define pb push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T> &st){ os << "["; for(auto a : st) cout << a << ","; os << "]"; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int N,M;
vector<bool> ex;

int main(){
    cin >> N >> M;
    ex = vector<bool>(N,true);
    rep(i,M){
        int a;
        cin >> a;
        ex[a] = false;
    }

    int NN = N-1;
    vector<int> tree(N+10,-1);
    int ans=0;
    
    for(int i=NN-(N/2),j=0;i<NN;i++,j+=2){
        int l=j;
        int r=j+1;
        if(ex[l]==false and ex[r]==false){
            continue;
        }
        else if(ex[l]==false or ex[r]==false){
            tree[i] = 1;
        }
        else{
            tree[i] = 1;
            ans++;
        }
    }

    for(int i=NN-(N/2)-1;i>=0;i--){
        int l = i*2+1;
        int r = i*2+2;
//        cerr << i << " " << l << " " << r << endl;
        if(tree[l]==-1 and tree[r]==-1){
            tree[i] = -1;
        }
        else if(tree[l]==-1 or tree[r]==-1){
            tree[i] = 1;
        }
        else{
            tree[i] = 1;
            ans++;
        }
    }


    //rep(i,NN){
    //    cout << i << " " << tree[i] << endl;
    //}

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

Measured memory_bytes: 3044
#include<iostream>
#include<algorithm>

using namespace std;
 
int main(){
  int x[10],tmp,i,j;

  for(i=0; i<10; ++i)
    cin >> x[i];

  sort(x,x+10,greater<int>());

  for(i=0; i<3; ++i)
    cout << x[i] << "\n";

    return 0;
}
  

Measured memory_bytes: 1176
from collections import deque
N = int(input())
UVW = [list(map(int, input().split())) for _ in range(N-1)]
G = [{} for _ in range(N+1)]
for u, v, w in UVW:
    G[u-1][v-1] = w
    G[v-1][u-1] = w
# print(G)


distance = [-1] * N

que = deque([(0, 0)])
while que:
    c, d = que.popleft()
    distance[c] = d

    for n, w in G[c].items():
        if distance[n] == -1:
            que.append((n, d+w))

# print(distance)
print(*[d % 2 for d in distance], sep='\n')


Measured memory_bytes: 105816
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	ll n, a, b;
	cin >> n >>a >> b;
	cout << (n/(a+b))*a+min(a, (n%(a+b)));

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
const int N=1e6;
ll v[N+10];

int main()
{
  ll n;

  cin>>n;
  ll cnt=0;

  ll ara[n+1];

  vector<ll>v;

  for(ll i=0;i<n;i++)
  {
      cin>>ara[i];
      v.push_back(ara[i]);
  }
  ll mx=0;
  ll mx1=ara[0];
  mx=*max_element(ara,ara+n);

  for(ll i=1;i<n;i++)
  {
      if(mx1>=ara[i])
      {
          cnt+=mx1-ara[i];
        // mx1+=cnt;
      }
      else if(mx1<=ara[i])
      {
          mx1=ara[i];
      }
     //cout<<mx1<<" ";
  }

  //cout<<endl;
  cout<<cnt<<endl;
}


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

const int Nmax=200010;

int main() {
	ll X,Y;
	cin >> X >> Y;
	ll cnt=1;
	if(X > Y) cnt = 0;
	for(;;){
		X*=2;
		if(X > Y) break;
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

long long int pow_10(int n){
	if(n <= 0){
		return 1;
	}
	return 10 * pow_10(n - 1);
}

int main(){
	
	long long int n;
	
	while(true){
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		long long int ans = 0;
		
		bool minus;
		
		if(n < 0){
			minus = true;
		}else{
			minus = false;
		}
		
		for(int i = 0; i < 100; i++){
			if(i % 2 == 0){
				ans += pow_10(i) * ((10 + n % 10) % 10);
				if(n % 10 != 0 && minus){
					n -= 10;
				}
			}else{
				ans += pow_10(i) * ((10 - n % 10) % 10);
				if(n % 10 != 0 && !minus){
					n += 10;
				}
			}
			n /= 10;
			if(n == 0){
				break;
			}
		}
		
		cout << ans << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
const int N=105;
int a[N];
int main() {
    int n,m;
    scanf("%d%d",&n,&m);
    int tot=0;
    for(int i=1;i<=n;i++) scanf("%d",a+i),tot+=a[i];
    tot=(tot+m*4-1)/(4*m);
    for(int i=1;i<=n;i++) if(a[i]>=tot) m--;
    printf("%s",m<=0?"Yes":"No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
int c[500100];
const int K=sqrt(500100)+1;
struct Q{
	int l;
	int r;
	int num;
	Q(int l, int r, int num):l(l),r(r),num(num){}
};
vector<Q> buckets[K];
int cnt[500100];
int ans[500100];
 
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n, q;
	cin>>n>>q;
	rep(i,n)cin>>c[i];
	rep(i,q){
		int l,r;
		cin>>l>>r;
		l--;
		r--;
		buckets[l/K].eb(l,r,i);
	}
	for(int i=0;i<K;i++){
		sort(buckets[i].begin(),buckets[i].end(),[&](Q a, Q b){return a.r<b.r;});
		if(buckets[i].empty())continue;
		memset(cnt,0,sizeof(cnt));
		int cur=0;
		for(int j=buckets[i][0].l;j<=buckets[i][0].r;j++){
			cnt[c[j]]++;
			if(cnt[c[j]]==1)cur++;
		}
		ans[buckets[i][0].num]=cur;
		int pl=buckets[i][0].l;
		int pr=buckets[i][0].r;
		for(auto qr:buckets[i]){
			for(int j=pr+1;j<=qr.r;j++){
				cnt[c[j]]++;
				if(cnt[c[j]]==1)cur++;
			}
			pr=qr.r;
			for(int j=pl;j<qr.l;j++){
				cnt[c[j]]--;
				if(cnt[c[j]]==0)cur--;
			}
			for(int j=qr.l;j<pl;j++){
				cnt[c[j]]++;
				if(cnt[c[j]]==1)cur++;
			}
			pl=qr.l;	
			ans[qr.num]=cur;
		}
	}
	for(int i=0;i<q;i++){
		cout<<ans[i]<<'\n';
	}
}

Measured memory_bytes: 18552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i,j;
    int n;
    cin>>n;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    vector<P> w1,w2;
    for(i=0;i<n;i++){
        int t=0;
        int m=0;
        for(j=0;j<s[i].size();j++){
            if(s[i][j]=='(') t++;
            else t--;
            m=min(m,t);
        }
        m=-m;
        if(t>=0) w1.pb(P(m,t));
        else w2.pb(P(m+t,t));
    }
    sort(w1.begin(),w1.end());
    sort(w2.begin(),w2.end());
    reverse(w2.begin(),w2.end());

    for(i=0;i<w1.size();i++){
        //cout<<w1[i].fi<<" "<<w1[i].se<<endl;
    }
    for(i=0;i<w2.size();i++){
        w2[i].fi-=w2[i].se;
    }
    int p=0;
    for(i=0;i<w1.size();i++){
        if(w1[i].fi<=p) {
            p += w1[i].se;
        }
        else {
            cout<<"No"<<endl;
            return 0;
        }
    }
    for(i=0;i<w2.size();i++){
        if(w2[i].fi<=p) {
            p += w2[i].se;
        }
        else {
            cout<<"No"<<endl;
            return 0;
        }
    }
    if(p!=0) {
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

int main(){
  int a, b, c;
  cin >> a >> b >>c;
  int cap = a - b;
  int use = min(c,cap);
  int ans = c - use;
  cout << ans << endl;
  
  
}


Measured memory_bytes: 256
while gets
  n, x = $_.split.map(&:to_i)
  if n == 0 && x == 0
    break
  end

  n_match = 0
  1.upto(n) do |a|
    a.upto(n) do |b|
      b.upto(n) do |c|
        if (a != b && b != c && c != a) && (a+b+c == x)
          n_match += 1
        end
      end
    end
  end
  puts n_match
end



Measured memory_bytes: 6876
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll H,W,ans=0;
void Main(){
    cin>>H>>W;
    vector<string> S(H);
    For(i,0,H) cin>>S.at(i);
    vector<vector<ll>> tate(H,vector<ll> (W));
    vector<vector<ll>> yoko(H,vector<ll> (W));
    For(i,0,W){
        vector<ll> kabe;
        kabe.push_back(-1);
        For(j,0,H){
            if(S.at(j).at(i)=='#'){
                kabe.push_back(j);
            }
        }
        kabe.push_back(H);
        ll iue=0;
        For(j,0,H){
            if(kabe.at(iue+1)==j){
                tate.at(j).at(i)=0;
                iue++;
            }
            else{
                tate.at(j).at(i)=kabe.at(iue+1)-kabe.at(iue)-1;
            }
        }
    }
    For(i,0,H){
        vector<ll> kabe;
        kabe.push_back(-1);
        For(j,0,W){
            if(S.at(i).at(j)=='#'){
                kabe.push_back(j);
            }
        }
        kabe.push_back(W);
        ll ihidari=0;
        For(j,0,W){
            if(kabe.at(ihidari+1)==j){
                yoko.at(i).at(j)=0;
                ihidari++;
            }
            else{
                yoko.at(i).at(j)=kabe.at(ihidari+1)-kabe.at(ihidari)-1;
            }
        }
    }
    For(i,0,H){
        For(j,0,W){
            ans=max(ans,tate.at(i).at(j)+yoko.at(i).at(j)-1);
            //cout<<"("<<tate.at(i).at(j)<<" "<<yoko.at(i).at(j)<<")";
        }
        //cout<<endl;
    }
    cout<<ans<<endl;
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 67072
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static boolean[] isPrime=new boolean[123456*2+100];
	static{
		Arrays.fill(isPrime, true);
		isPrime[0]=isPrime[1]=false;
		for(int i=2;i*i<=isPrime.length;i++){
			if(isPrime[i]){
				for(int j=i+i;j<isPrime.length;j+=i){
					isPrime[j]=false;
				}
			}
		}
	}
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int N=cin.nextInt();
			if(N==0)break;
			int ans=0;
			for(int i=N+1;i<=N+N;i++){
				if(isPrime[i])ans++;
			}
			System.out.println(ans);
		}

	}

}

Measured memory_bytes: 20580
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
typedef long long ll;
int n;

ll a[5];

int main(void){
	scanf("%d",&n);
	ll sum=0;
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		sum+=a[i];
	}
	sort(a,a+n);
	if(n==1)printf("%lld\n",sum);
	if(n==2)printf("%lld\n",sum-1LL);
	if(n==3)printf("%lld\n",sum-3LL);
	if(n==4){
		if(a[0]>=3)printf("%lld\n",sum-6LL);
		else if(a[3]>=3)printf("%lld\n",sum-5LL);
		else printf("%lld\n",sum-4LL);
	}
	if(n==5){
		if(a[0]>=4)printf("%lld\n",sum-10LL);
		else if(a[0]==3){
			if(a[3]>=4)printf("%lld\n",sum-9LL);
			else printf("%lld\n",sum-8LL);
		}
		else{
			if(a[1]>=3)printf("%lld\n",sum-8LL);
			else if(a[3]>=3 || a[4]>=4)printf("%lld\n",sum-7LL);
			else printf("%lld\n",sum-6LL); 
		}
	}
	return 0;
}

Measured memory_bytes: 1044
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define INF 1000000000
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int N;
	cin>>N;
	vector<int>C(N);
	vector<int>S(N);
	vector<int>F(N);
	REP(i,N-1)cin>>C[i]>>S[i]>>F[i];
	//vector<int>ans(N);

	REP(i,N){
		int t=0;
		FOR(j,i,N-1){
			if(S[j]-t>0)t=S[j];
			else if(t%F[j]==0);
			else t=t+F[j]-t%F[j];
			t+=C[j];
			//if(i==1)cout<<t<<endl;
		}
		cout<<t<<endl;
	}
	//REP(i,N)cout<<ans[i]<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FASTIO std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

typedef long long ll;
const int N = 2e5 + 5, mod = 998244353;

int main () {
  int x;
  for (int i = 1; i < 6; i++) {
    cin >> x ;
    if (x == 0) {
      cout << i << endl;
      return 0;
    }
  }
}


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

int main(void) {
  int digit = 0;
  int ans = 0;
    std::string str;
    cin >> str;
  int tmp = atoi(str.c_str());
  digit = str.length();
  

    int N[digit];
    for (int i = 0; i < digit; ++i) {
        N[i] = (int)(str[i] - '0'); 
        ans += N[i];  //確認のため表示
    }
  if(ans%9 == 0)cout<<"Yes"<< endl;
  else cout<<"No"<< endl;
    return 0;
}

Measured memory_bytes: 4444
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
const int maxn = 1000050;
using namespace std;
typedef long long ll;
int p[maxn];
int main()
{
	int n;
	cin>>n;
	int x;
	int maxx=-1;
	for(int i=0;i<n;i++){
		cin>>x;
		maxx=max(maxx,x);
		p[x]++;
	}
	int num=0;
	for(int i=1;i<=maxx;i++){
		if(p[i]<=0)
		continue;
		else if(p[i]==1)
		num++;
		else {
		}
		for(int j=1;j<=maxx/i;j++){
			p[i*j]=-1;
		}
	}
	cout<<num;
	return 0;
}

Measured memory_bytes: 7528
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
d = {}
u = 0

for i in range(n):
    if a[i] in d:
        d[a[i]] += 1
    else:
        d[a[i]] = 1
        u += 1

if u == k:
    print(0)
else:
    vals = sorted(d.values(), reverse=True)
    print(sum(vals[k:]))

Measured memory_bytes: 34504
import java.util.*;

public class Main {

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

		while(true){
			int n = sc.nextInt();
			int k = sc.nextInt();
			if(n==0 && k==0) break;
			int[] a = new int[n];
			for(int i=0;i<n;i++) a[i] = sc.nextInt();
			
			int max = 0;
			int temp = 1;
			for(int p=0;p<=n-k;p++){
				temp = 1;
				for(int q=0;q<k;q++) temp *= a[p+q];
				max = Math.max(max, temp);
			}
			int maxorigin = max;
			
			int maxmax = 0;
			for(int i=0;i<n;i++){
				for(int j=i+1;j<n;j++){
					temp = a[i];
					a[i] = a[j];
					a[j] = temp;
					max = 0;
					for(int p=0;p<=n-k;p++){
						temp = 1;
						for(int q=0;q<k;q++) temp *= a[p+q];
						max = Math.max(max, temp);
					}
					maxmax = Math.max(maxmax, max);
					temp = a[i];
					a[i] = a[j];
					a[j] = temp;	
				}
			}
			
			System.out.println(maxmax-maxorigin);
		}
	}

}

Measured memory_bytes: 32072
#include <iostream>
#define ll long long
using namespace std;
const int N = 5009;
int n,k;
int p[N],c[N],sp[N],avail[N];
long long f[N][N];
int main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> p[i];
    for (int i = 1; i <= n; i++) cin >> c[i];
    for (int i = 1; i <= n; i++){
        memset(avail,0,sizeof(avail));
        int j = i , cnt = 0;
        while (avail[p[j]] == 0){
            cnt++;
            f[i][cnt] = f[i][cnt - 1] + c[p[j]];
            avail[p[j]] = 1;
            j = p[j];
        }
        sp[i] = cnt;
    }
    ll ans = -1e18;
    for (int i = 1; i <= n; i++){
        ll pos_max = 0 , val = -1e18;
         for (int j = 1; j <= min(sp[i],k); j++)
            if (f[i][j] > val){
                val = f[i][j];
                pos_max = j;
            }
        ans = max(ans,f[i][pos_max] + 1LL * ((k - pos_max)/sp[i]) * f[i][sp[i]]);
        ans = max(ans,1LL * (k/sp[i]) * f[i][sp[i]] + f[i][k % sp[i]]);
        ans = max(ans,f[i][pos_max]);
    }
    cout << ans;
}

Measured memory_bytes: 198928
#include <iostream>
#include <string>
#include <cassert>
#include <cctype>
#include <cstdio>

using namespace std;

struct Process {
    char name[11];
    int time;
};

static const int MAX = 100000;
Process queue[MAX];
int qsize = 0, qhead = 0, qtail = 0;


// 結果自体は正しいが時間がかかりすぎる
int main(void) {

    int n, q;
    cin >> n >> q;

    for (int i = 0; i < n; ++i) {
        cin >> queue[i].name >> queue[i].time;
    }
    qsize = qtail = n;

    int elapsed = 0;
    while (qhead != qtail) {
        Process p = queue[qhead++];
        qhead %= MAX;
        if (p.time - q <= 0) {
            elapsed += p.time;
            printf("%s %d\n", p.name, elapsed);
        }
        else {
            elapsed += q;
            p.time -= q;
            queue[qtail++] = p;
            qtail %= MAX;
        }
    }

    return 0;
}

Measured memory_bytes: 2708
#include <stdio.h>
int main(void) {
	
	int S;
	int h, m, s;

	scanf("%d", &S);

	h = S / 3600;
	m = (S - 3600*h)/60;
	s = S - (3600 * h + 60 * m);

	printf("%d:%d:%d\n",h,m,s);

	
	return(0);

}


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

int main() {
    int n,sum=0;
    cin>>n;
    while (n--) {
        int l,r;
        cin>>l>>r;
        sum+=r-l+1;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void) {
  char s[201], p[101];

  scanf("%s", s);
  scanf("%s", p);

  sprintf(s, "%s%s", s, s);

  puts(strstr(s, p) == NULL ? "No" : "Yes");

  return 0;
}

Measured memory_bytes: 560
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

a, b, c, k = MAP()
if a >= k:
    print(k)
elif a + b >= k:
    print(a)
else:
    print(a - (k - b - a))

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

using namespace std;

#define int long long

void solve() {
    int x;
    cin >> x;
    if (x >= 30) cout << "Yes";
    else cout << "No";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3596
int main() {
	int a[11], tmp;
	for (int i = 0; i < 3; i++) 
		__builtin_scanf("%d", &tmp),
		a[tmp]++;
	if (a[5] == 2 && a[7] == 1) __builtin_puts("YES");
	else __builtin_puts("NO");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
bool check(string S,int N){
    rep(i,0,N/2){
        if(S.at(i)!=S.at(N-1-i)){
            return false;
        }
    }
    return true;
    
}
int main(){
  string S;
  cin >> S;
  int N;
  N = S.size();

  if(N%2==1){
     if(check(S,N)){
         string F;
         string T;
         F = S.substr(0,(N-1)/2);
         T = S.substr((N+3)/2-1,(N-1)/2);
         if(check(F,(N-1)/2)&&check(T,(N-1)/2)){
             cout<<"Yes"<< endl;
         }else{
             cout << "No" << endl;
         }
         //cout << F << endl << T << endl;
     }else{
         cout << "No" << endl;
     }

  }else{
      cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,D;
    
    
    int a=0;
    cin >> N >> D;
    int kansi = D*2+1;
    int ans=0;
    while(N>a){
        a += kansi;
        ans++;
    }
    cout << ans << endl;
}

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

int main(){
  int H, W, X;
  while(1){
    cin >>H>>W;
    if(H == 0 && W ==0)break;
    else
  for (int i = 0; i < H ;i++){
    for (int j = 0; j < W ;j++){
      X = i + j;
      if(X % 2 == 0) cout << "#";
      else cout << ".";}
    cout << endl;}
  cout << endl;}
  return 0;
}


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


#define mod 1000000007
#define ull unsigned long long int
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
/* TYPE DEFINITIONS */
typedef     long long int        ll;
typedef     vector<ll>     vi;
typedef     pair<ll,ll>   pi;
 
 
 
/* MATH */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return true; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
 
ll pow(ll a,ll b,ll m)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}

ll ncr(int n, int k)  
{  
	if(k>n)return 0;
    ll res = 1;  
    if ( k > n - k )  
        k = n - k;  
    for (int i = 0; i < k; ++i)  
    {  
        res *= (n - i);  
        res /= (i + 1);  
    }  
  
    return res;  
} 
  
//
/* MACROS */
 
#define  all(A)         (A).begin() , (A).end()
#define  arrall(A,n)    (A),((A)+(n))
#define  rall(A)        (A).rbegin() , (A).rend()
#define  sz(A)          (int)(A).size()
#define  pb             push_back
#define  ppb            pop_back
#define  mp             make_pair
#define  ln(X)          (int)(X).length()
#define  square(X)      ((X)*(X))
#define  cube(X)        ((X)*(X)*(X))
#define  forn(i, n)  for (int i = 0; i < int(n); i++)
#define  forr(i, n)  for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)    for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) 
#define  deb(x)       cout << '>' << #x << ':' << x << endl;

void  solve()
{
	int n;
	cin>>n;
 
	queue<int> halo;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		halo.push(x);
	}
 
	int count=1,mini=halo.front(),maxi=halo.front();
	halo.pop();
 
	while(!halo.empty())
	{
		int now= halo.front();
		if(now<=mini and now<=maxi)
		{
			count++;
		}
 
		if(now>maxi)
		{
			maxi=now;
		}
 
		if(now<mini)
		{
			mini=now;
		}
 
		halo.pop();
	}
 
	cout<<count<<"\n";

}


int main()
{
    FastIO;
    ll t=1;
   	//cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 1024
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.next.toInt

    @annotation.tailrec
    def go(i: Int, acc: Int): Int = {
      if (i % 2 != 0) acc
      else go(i / 2, acc + 1)
    }

    val ans: Int = (1 to n).map(k => go(k, 0)).zipWithIndex.maxBy(_._1)._2 + 1
    println(ans)
  }
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_L = 212345;
ll dp[MAX_L][5];

int main2() {
  CLR(dp, 0);
  int L = nextInt();
  vector<ll> A(L);
  REP(i, L) A[i] = nextInt();
  const ll INF = 1LL << 61;
  REP(i, MAX_L) REP(j, 5) dp[i][j] = INF;
  dp[0][0] = 0;
  for (int i = 0; i < L; i++) {
    for (int j = 0; j < 5; j++) {
      ll cur = dp[i][j];
      // cout << i << " " << j << " " << cur << endl;
      if (j == 0) {
        chmin(dp[i][j+1], cur);
        chmin(dp[i+1][j], cur + abs(A[i]));
      } else if (j == 1) {
        chmin(dp[i][j+1], cur);
        ll cost = abs(A[i] - 2);
        if (A[i] >= 2) {
          if (A[i] % 2 == 0) cost = 0;
          else cost = 1;
        }
        chmin(dp[i+1][j], cur + cost);
      } else if (j == 2) {
        chmin(dp[i][j+1], cur);
        ll cost = A[i] % 2 == 0 ? 1 : 0;
        chmin(dp[i+1][j], cur + cost);
      } else if (j == 3) {
        chmin(dp[i][j+1], cur);
        ll cost = abs(A[i] - 2);
        if (A[i] >= 2) {
          if (A[i] % 2 == 0) cost = 0;
          else cost = 1;
        }
        chmin(dp[i+1][j], cur + cost);
      } else if (j == 4) {
        // chmin(dp[i][j+1], cur);
        chmin(dp[i+1][j], cur + abs(A[i]));
      }
    }
  }
  ll ans = INF;
  for (int j = 0; j < 5; j++)
    chmin(ans, dp[L][j]);
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 10112
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication23 {
    class Program {
        static void Main(string[] args) {

            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]) * int.Parse(str[1]);
            int b = int.Parse(str[2]) * int.Parse(str[3]);

            var result = Method(a, b);
            Console.WriteLine(result);

        }
        private static int Method(int a, int b) {

            int result = 0;
            if (a > b || a == b) {
                result = a;

            } else if (b > a || a == b) {
                result = b;
            }
            return result;
        }

    }
}


Measured memory_bytes: 11092
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#include<set>
#define MOD 1000000007LL
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
int main() {
    int n;
    cin>>n;
    int f[114][11]={};
    for(int i=0;i<n;i++){
        for(int j=0;j<5;j++){
            for(int k=0;k<2;k++){
                cin>>f[i][j*2+k];
            }
        }
    }
    int p[114][11]={};
    for(int i=0;i<n;i++){
        for(int j=0;j<11;j++){
            cin>>p[i][j];
        }
    }
    vector<int> a;
    for(int i=0;i<10;i++){
        a.push_back(0);
    }
    int ans=-MOD;
    for(int i=1;i<=10;i++){
        a[0]=1;
        sort(a.begin(),a.end());
        do{
            int b=0;
            for(int j=0;j<n;j++){
                int c=0;
                for(int k=0;k<10;k++){
                    if(f[j][k]==1&&a[k]==1){
                        c++;
                    }
                }
                b+=p[j][c];
            }
            ans=max(ans,b);
        }while(next_permutation(a.begin(),a.end()));
        sort(a.begin(),a.end());
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))

s = 0

l.sort()

for i in range(n-2):
    j = n-2
    k = n-1
    while i < j:
        if l[k] >= l[i] + l[j] and j < k:
            #print(0, i, j, k)
            k -= 1
        else:
            #print(1, i, j, k)
            s += k - j
            j -= 1


print(s)


Measured memory_bytes: 68712
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
	ll n,k,q; cin>>n>>k>>q;
	vector<ll> a(q), ans(n);
	map<ll,ll> mp;
	rep(i,q) {
		ll x; cin>>x; --x;
		mp[x]++;
	}
	rep(i,n) {
		if (mp[i] >= q-k+1) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 8448
n = int(input())
alturas = list(map(int, input().split()))

if n == 1:
	print(0)
else:
	atual = 0
	max_value = 0
	contador = 0
	while atual + 1 < n:
		if alturas[atual] >= alturas[atual+1]:
			contador += 1
		else:
			max_value = max(contador, max_value)
			contador = 0
		atual += 1
	max_value = max(contador, max_value)
	print(max_value)


Measured memory_bytes: 14252
# -*- coding: utf-8 -*-
"""
Created on Wed Mar  4 18:22:36 2020

@author: Kanaru Sato
"""

N, M = list(map(int, input().split()))
submits = [input().split() for i in range(0,M)]

D = {}

for ans in submits:
    if ans[1] == "AC":
        if ans[0] not in D:
            D[ans[0]] = 0

D_flag = D.copy()

for ans in submits:
    if (ans[0] in D) and (D_flag[ans[0]] == 0):
        if ans[1] == "WA":
            D[ans[0]] += 1
        if ans[1] == "AC":
            D_flag[ans[0]] = 1

if M == 0:
    print(0,0)
else:
    print(len(D), sum(D.values()))

Measured memory_bytes: 44548
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF=1e18;
const ll mod=1e9+7;

int main(){
    ll t1,t2,a1,a2,b1,b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    if(a1*t1+a2*t2==b1*t1+b2*t2){
        cout << "infinity" << endl;
        return 0;
    }
    if(a1<b1 && a2<b2){
        cout << 0 << endl;
        return 0;
    }
    if(a1>b1 && a2>b2){
        cout << 0 << endl;
        return 0;
    }
    if(a1>b1 && a2<b2){
        swap(a1,b1);
        swap(a2,b2);
    }
    if(a1<b1 && a2>b2 && a1*t1+a2*t2<b1*t1+b2*t2){
        cout << 0 << endl;
        return 0;
    }
    ll d1=(a1-b1)*t1,d2=(a2-b2)*t2;
    ll d=d1+d2;
    ll ans=(-d1-1)/d;
    ans++;
    if(-d1%d==0){
        cout << 2*ans << endl;
    }
    else{
        cout << 2*ans-1 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3596
N=int(input())
M=0;A=0;R=0;C=0;H=0
for i in range(N):
  a=input()
  if a[0]=='M':
    M+=1
  elif a[0]=='A':
    A+=1
  elif a[0]=='R':
    R+=1
  elif a[0]=='C':
    C+=1
  elif a[0]=='H':
    H+=1
L=[M,A,R,C,H]
a=0
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      a=a+L[i]*L[j]*L[k]
print(a)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

string S;
int len;
long long ans = 0;

int main(int argc, char *argv[])
{
  cin >> S;
  len = S.size();

  for (int i = 0; i < (1 << (len-1)); i++) {
    long long num = S[0]-'0';

    for (int j = 0; j < len-1; j++) {
      if (i & (1 << j)) {
        ans += num;
        num = 0;
      }
      num = num*10 + (S[j + 1]-'0');
    }

    ans += num;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 1000000007;
const int MOD = (int)1e9+7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
int dy[4] = {-2, -1};
int dx[4] = {-1, -2};

const int MAX = 1000050;
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 

ll n;

bool isValid(ll k) {
	vector<bool> v(10);
	while(k != 0) {
		v[(int)k%10] = true;
		k = k/10LL;
	}
	return v[3] && v[5] && v[7];
}

ll dfs(ll here) {
	if(here > n) {
		return 0;
	}
	int ret = 0;
	if(isValid(here)) ret++;
	ret += dfs(here*10 + 3);
	ret += dfs(here*10 + 5);
	ret += dfs(here*10 + 7);
	return ret;
}

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	cin >> n;
	cout << dfs(0) << endl;
	return 0;
}


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

#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;

using ll = long long;
using pii = pair<int, int>;

#define pb push_back
#define mp make_pair

#define NMAX 2000005
#define alfa 27

struct Trie {
	int nr[alfa];
	Trie* urm[alfa];
};
typedef Trie* T;

T create_trie()
{
	T nou;
	nou = new Trie;
	memset(nou->urm, 0, sizeof(nou->urm));
	memset(nou->nr, 0, sizeof(nou->nr));
	return nou;
}

void add_word(T p, char* s, int freq[])
{
	if (*s == '\0') {
		return;
	}
	for (int i = 0; i <= 'z' - 'a'; i++) {
		if (freq[i] >= 1) {
			p->nr[i]++;
		}
	}
	if (p->urm[*s - 'a'] == 0) {
		p->urm[*s - 'a'] = create_trie();
	}
	freq[*s - 'a']--;
	add_word(p->urm[*s - 'a'], s + 1, freq);
}


int search(T p, const char* s, char value)
{
	if (*s == '\0') {
		return p->nr[value - 'a'];
	}
	if (p->urm[*s - 'a'])
		return search(p->urm[*s - 'a'], s + 1, value);
	return 0;
}


void str_reverse(char* str) {
	char* str_end = strchr(str, 0);
	std::reverse(str, str_end);
}

char v[NMAX];

int main()
{
    ios::sync_with_stdio(false), cin.tie(0);
    // cout.setf(ios::fixed), cout.precision(20);

#ifdef LOCAL
    ifstream cin("input.txt");
#endif

	int N;
	cin >> N;
	T root = create_trie();
	int freq[alfa];
	vector <pair<string, char>> inputs;
	for (int i = 1; i <= N; i++) {
		cin >> (v + 1);
		str_reverse(v + 1);
		memset(freq, 0, sizeof(freq));
		char* p = v + 1;
		while (*p) {
			freq[*p - 'a']++;
			p++;
		}
		add_word(root, v + 1, freq);
		{
			string in(v + 1);
			char value = in.back();
			in.pop_back();
			inputs.emplace_back(in, value);
		}
	}

	long long sol = 0;
	for (const auto& input : inputs) {
		const char* p = input.first.c_str();
		// cout << p << '\n';
		sol = sol + search(root, p, input.second);
	}
	cout << sol - inputs.size() << '\n';

    return 0;
}

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

int n,m,ans;
char mp[110][110],c;
int dir[4][2] = {-1,0,1,0,0,1,0,-1};
void dfs(int x,int y)
{
	mp[x][y] = '.';
	for (int i=0;i<4;++i)
	{
		int nx = x+dir[i][0];
		int ny = y+dir[i][1];
		if (nx>=0&&nx<n&&ny>=0&&ny<m&&mp[nx][ny] == c) dfs(nx,ny);
	}
}

int main()
{
//	freopen("in.txt","r",stdin);
	while (cin>>n>>m)
	{
		if (n==0 && m==0) break;
		ans = 0;
		for (int i=0;i<n;++i)
			for (int j=0;j<m;++j)
				cin>>mp[i][j];
		for (int i=0;i<n;++i)
			for (int j=0;j<m;++j)
				if (mp[i][j] != '.')
				{
					c = mp[i][j];
					dfs(i,j);
					ans++;	
				}
		cout<<ans<<'\n';
	}
	return 0;
}


Measured memory_bytes: 3324
"""
まず貪欲的なアルゴリズムを組めるか考えてみる。
所持している宝石のうち、価値が負であるものはできるだけ、筒に入れたい。できれば価値の低い順に。
所持している宝石のうち、価値が0以上であるものは、筒に入れる意味がない。
筒にある宝石のうち、価値が正のものはできるだけ取り出したい。できれば価値の高い順に。

ここまで考えると、宝石を筒に入れる作業は最後にやればよいことがわかる。
むしろ最後に寄せないと、筒の中に残っている価値の高い宝石を取り出すときに、入れた宝石が邪魔になる。
また、最後に行うため、左から入れるか右から入れるかは関係ない。
あと入れる宝石は任意で選べるため、負の宝石のうち、価値の低いものを順番に入れれば良い。

ここまでくると、愚直にシミュレートすれば良いことがわかる。
取り出す作業をA回やる、と決める。O(min(N,K))
    左からL回、右からR(=A-L)回取り出すと決める。O(min(N,K))
        P = V[:L]+V[::-1][:R] とする。（Pは取り出した宝石の価値の配列）。
        P.sort()で価値が低い順に並べて、左から価値が負のものをK-A個まで捨てる。O(NlogN)

計算量としてはO(min(N,K)**2*NlogN)で十分高速
"""

N,K = map(int,input().split())
V = list(map(int,input().split()))

ans = 0
for A in range(min(N,K)+1):
    for L in range(A+1):
        R = A-L
        P = V[:L]+V[::-1][:R]
        P.sort()
        for i in range(min(K-A,A)):
            if P[i] < 0:
                P[i]=0
        ans = max(ans,sum(P))
print(ans)


Measured memory_bytes: 71368
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++) cin >> A[i];
    int cnt[N + 1] = {};
    for(int i = 0; i < N; i++) cnt[A[i]]++;

    for(int i = N - 1; i >= 0; i -= 2) {
        if(i == 0) {
            if(cnt[i] != 1) {
                cout << 0 << "\n";
                return 0;
            }
        } else if(cnt[i] != 2) {
            cout << 0 << "\n";
            return 0;
        }
    }

    ll ans = 1, tmp = N / 2;
    while(tmp) {
        tmp--;
        ans *= 2;
        ans %= mod;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll X;
  cin >> X;
  ll x500 = 0,x5 = 0;
  x500 = X/500;
  X %= 500;
  x5 = X/5;
  ll ans = x500 * 1000 + x5 * 5;
  cout << ans;
  
  return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)

int main(){

	lli a,b;
	cin>>a>>b;

	lli now=1;
	lli cnt=0;
	while(now<b){
		now--;
		now+=a;
		cnt++;
	}
	cout<<cnt<<endl;

	return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int dp[n+1];
    dp[n] = 0;
    for(int i=n-1; i>=0; i--){
        if(s[i]=='W') dp[i] = dp[i+1]+1;
        else dp[i] = dp[i+1];
    }
    int min_ = dp[0];
    for(int i=1; i<=n; i++){
        int lw = dp[n-i];
        int lr = i-lw;
        int rw = dp[0]-lw;
        if(lr<=rw) min_ = min(min_, rw);
        else if(lr>rw){
            min_ = min(min_, lr);
        }
    }
    cout<<min_;
    return 0;
}


Measured memory_bytes: 4548
#include<bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef long long ll;
typedef pair<ll,ll> P;
const int INF=INT_MAX / 3;
const ll LINF=LLONG_MAX / 3LL;
#define CONST 1000000007
#define EPS (1e-8)
#define PB push_back
#define MP make_pair
#define sz(a) ((int)(a).size())
#define reps(i,n,m) for(int i=(n);i<int(m);i++)
#define rep(i,n) reps(i,0,n)
#define SORT(a) sort((a).begin(),(a).end())
ll mod(ll a,ll m){return (a%m+m)%m;}
int dx[9]={0,1,0,-1,1,1,-1,-1,0},dy[9]={1,0,-1,0,1,-1,1,-1,0};
ll n,m;
int main(){
  char a,b;
  cin>>a>>b;
  bool flg = (a=='H') ? (b=='H') : (b =='D');
  cout << (flg ? 'H' : 'D') <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <math.h>
#include <iomanip>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX 100000
#define LARGENUM 1000000007
#define INF 9223372036854775807
#define ull unsigned long long 
typedef pair <ull, int> P;

int main(){
    int A, B;
    cin >> A >> B;
    cout << A * B << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
  FAST/**/
   
   char c;
   cin>>c;
   
   for(char i='A';i<='Z';i++)
        if(i == c)
        {
            cout<<"A";
            return 0;
        }
   
   cout<<"a";        
   
   
   return 0;        
}  
  
          
   

Measured memory_bytes: 3648