akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
int recursin(int);
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a[6];
    int b[5]={0},c[4]={0};
    for(int i=0;i<6;i++){
        cin>>a[i];
        b[a[i]]++;

    }
    for(int i=1;i<5;i++){
        c[b[i]]++;
    }
    if(c[1]==2&& c[2]==2){
        cout << "YES"<<endl;
    }
    else{
        cout << "NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N,M=[int(i) for i in input().split(" ")]

cards=[]
for i in range(M):
    A,B=[int(j) for j in input().split(" ")]
    cards.append((A,B))

cards=sorted(cards)
retval=0
for c in cards[1::]:
    if c[0]<N:
        retval+=N-c[0]
print(retval)



Measured memory_bytes: 5716
program main;
var i,j,s,t : string;
    a,b : integer;
begin 
  readln(i);
  readln(a,b);
  readln(j);
  s := copy(i,1,pos(' ',i)-1); 
  t := copy(i,pos(' ',i)+1,length(i));
  if j = s then writeln(a-1,' ',b)
  else writeln(a,' ',b-1);
end.

Measured memory_bytes: 1348
//Chandigarh University
//author: shivamkr21 (pseduo coders)
#include<bits/stdc++.h>
//#include "boost/multiprecision/cpp_int.hpp"
//#define eint int1024_t
#define lli long long int
#define endl "\n"
#define vint vector<int>
#define vvint vector< vector<int> >
#define pub push_back 
#define mod 1000000007
//using namespace boost::multiprecision;
using namespace std;
int main()
{
  lli a,b,c,k,res=0;
  cin>>a>>b>>c>>k;
  if(k>a)
  {
    res=a;
    k=k-a;
    if(k>b)
    {
      res=res+0;
      k=k-b;
      if(k>c)
      {
        res=res+(-1*c);
        k=k-c;
      }
      else
      {
        res=res+(-1*k);
      }
    }
    else
    {
      res=res+0;
    }
  }
  else
  {
    res=k;
  }
  cout<<res;
  return 0;
}

Measured memory_bytes: 3652
var
N,i,F: integer;
a: array [1..100000] of integer;
BEGIN
F:= 0;
read(N);
for i:=1 to N do
begin
read(a[i]);
end;
for i:=1 to N do
begin
F:=F+(a[i]-1);
end;
writeln(F);
END.


Measured memory_bytes: 128
# -*- coding: utf-8 -*-

import math

def minkowski (x_list, y_list, p):
    """ ミンコフスキー距離 """
    
    # p=1:マンハッタン距離 / p=2:ユークリッド距離
    if p != math.inf:
        a = 0
        for x, y in zip(x_list, y_list):
            a += abs(x - y)** p
        return float(math.pow(a, 1 / p))
    
    # p=∞: チェビシェフ距離    
    else:
        d = 0
        for x, y in zip(x_list, y_list):
            if d < abs(x - y):
                d = abs(x - y)
        return float(d)

def main():
    n = int(input())
    x_list = list(map(int, input().split()))
    y_list = list(map(int, input().split()))
    p_list = [1, 2, 3, math.inf]
    
    for p in p_list:
        print(f"{minkowski(x_list, y_list, p):.6f}")

if __name__ == "__main__":
    main()
    


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

int main()
{

  int N;
  cin >> N;
  int ans = 0;

  for (int n = 1; n <= N; n+=2)
  {

    int cnt = 0;

    for (int i = 2; i <= sqrt(n); i++)
    {
      if (n % i == 0)
      {
        cnt++;
      }
    }

    int num = 1;
    for (int i = 2; i <= cnt; i++)
    {
      num *= i;
    }

    if (num + 2 == 8)
    {
      ans++;
    }
  }

  cout << ans;

  return 0;
}


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

int main(){
  int m, f, r;
  char grade;

  while(1){
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1) break;

    if (m == -1 || f == -1) grade = 'F';
    else if (m + f >= 80) grade = 'A';
    else if (65 <= m + f && m + f < 80) grade = 'B';
    else if (50 <= m + f && m + f < 65) grade = 'C';
    else if (30 <= m + f && m + f < 50) {
      grade = 'D';
      if(r >= 50) grade = 'C';
    }
    else if (m + f < 30) grade = 'F';



    cout << grade << endl;
  }

return 0;
}

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

int n;
int a[100055];

long long solve() {
	long long ret = 0;
	
	int l = 0, r = n - 1;
	int valL = a[0], valR = a[n - 1];
	
	ret += abs(a[n - 1] - a[0]);
	l++, r--;
	
	while (l <= r) {
		if (max(abs(a[l] - valL), abs(a[l] - valR)) > max(abs(a[r] - valL), abs(a[r] - valR))) {
			ret += max(abs(a[l] - valL), abs(a[l] - valR));
			
			if (abs(a[l] - valL) > abs(a[l] - valR)) {
				valL = a[l];
			} else {
				valR = a[l];
			}
			
			l++;
		} else {
			ret += max(abs(a[r] - valL), abs(a[r] - valR));
			
			if (abs(a[r] - valL) > abs(a[r] - valR)) {
				valL = a[r];
			} else {
				valR = a[r];
			}
			
			r--;
		}
	}
	
	return ret;
}
int main() {
	cin >> n;
	
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	
	if (n == 1) {
		cout << 0 << endl;
		return 0;
	}
	
	sort(a, a + n);
	
	long long res = solve();
	
	reverse(a, a + n);
	
	res = max(res, solve());

	printf("%lld\n", res);
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
namespace IO{

cs int RLEN=1<<20|1;
inline char gc(){
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob)?EOF:*ib++;
}
inline int read(){
    char ch=gc();
    int res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
    return f?res:-res;
}
inline ll readll(){
    char ch=gc();
    ll res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
    return f?res:-res;
}
inline char readchar(){
	char ch=gc();
	while(isspace(ch))ch=gc();
	return ch;
}
inline int readstring(char *s){
	int top=0;char ch=gc();
	while(isspace(ch))ch=gc();
	while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
	s[top+1]='\0';return top;
}

}
using IO::read;
using IO::readll;
using IO::readstring;
using IO::readchar; 
template<typename tp>inline void chemx(tp &a,tp b){(a<b)?(a=b):0;}
template<typename tp>inline void chemn(tp &a,tp b){(a>b)?(a=b):0;}
cs int N=6005;
string f[N];
int bel[N],pos[N],kd[N],n,cnt;
char str[N];
int main(){
	#ifdef Stargazer
	freopen("lx.in","r",stdin);
	#endif
	n=read();readstring(str);
	for(int i=1,s=0;i<=2*n;i++){
		s+=(str[i]=='a'?1:-1);
		if(!s){
			pos[++cnt]=i,kd[cnt]=(str[i]=='a');
		}
	}
	bool vt=0;
	for(int i=cnt;i;i--)
	if(kd[i]){
		vt=1;
		int c1=0,c2=0;
		for(int j=pos[i-1]+1;j<=pos[i];j++)
		if(str[j]=='a')bel[j]=++c1;else bel[j]=++c2;
		f[i]=f[i+1];
		for(int j=1;j<=c1;j++){
			string now;
			for(int k=pos[i-1]+1;k<=pos[i];k++)
			if(bel[k]>=j)now=now+str[k];
			f[i]=max(f[i],now+f[i+1]);
		}
	}
	else if(!vt){
		int c1=0,c2=0;
		for(int j=pos[i-1]+1;j<=pos[i];j++)
		if(str[j]=='a')bel[j]=++c1;else bel[j]=++c2;
		for(int r=pos[i-1]+1;;){
			while(r<=pos[i]&&str[r]=='b')r++;
			if(r>pos[i])break;
			f[i]+="ab";
			int t=bel[r];r++;
			while(bel[r]!=t)r++;
			r++;
		}f[i]+=f[i+1];
	}
	else f[i]=f[i+1];
	cout<<f[1];return 0;
}

Measured memory_bytes: 10624
// C - Exception Handling
#include <stdio.h>
#include <stdlib.h>

int compare(const void* a, const void* b){
    return *(int *)a - *(int *)b;
}

int main(void){
    int n;
    int a[200001], b[200001];
    scanf("%d", &n);
    for(int i=0; i<n; i++) scanf("%d", &a[i]);
    for(int i=0; i<n; i++) b[i] = a[i];
    qsort(b, n, sizeof(int), compare);
    int ans = b[n-1];
    for(int i=0; i<n; i++){
        if(a[i] == ans){ 
            printf("%d\n", b[n-2]); continue;
        }
        printf("%d\n", ans);
    }
    return 0;
}

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

vector<int> find_all(const std::string str, const std::string subStr) {
    std::vector<int> result;
 
    int subStrSize = subStr.size();
    int pos = str.find(subStr);
 
    while (pos != std::string::npos) {
        result.push_back(pos);
        pos = str.find(subStr, pos + subStrSize);
    }
 
    return result;
}

int main(){
  ll N;
  string S, s = "ABC";
  cin >> N >> S;
  vector<int> findVec = find_all(S, s);

  cout << findVec.size() << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int t, n;
	int i;

	for (i = 0; i < 4; i++) {
		scanf("%d%d", &t, &n);
		switch (t) {
			case 1: printf("%d\n", 6000 * n); break;
			case 2: printf("%d\n", 4000 * n); break;
			case 3: printf("%d\n", 3000 * n); break;
			case 4: printf("%d\n", 2000 * n); break;
		}
	}
	return 0; 
}

Measured memory_bytes: 600
import sys

h,w = map(int,input().split())

if h == 1 or w == 1:
	print(1)
	sys.exit()

if w % 2 == 0:
	cx0 = int(w/2)
	cx1 = cx0
else:
	cx0 = int(w/2) + 1
	cx1 = int(w/2)

if h % 2 == 0:
	print(int(h / 2) * (cx0 + cx1))
else:
	print(int(h / 2) * (cx0 + cx1) + cx0)


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

int main(){
	ll k,n; cin >> k >> n;
	vl a(n); rep(i,n)cin >> a[i];
	ll d = 0;
	rep(i,n-1)d = max(d,a[i+1] - a[i]);
	d = max(d,k - a[n-1] + a[0]);
	cout << k - d << endl;
}

Measured memory_bytes: 1792
S = list(input())
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
a = 0
mem = []
for i in query:
    if i[0] == '1':
        if a == 0:
            a = 1
        else:
            a = 0
    elif i[0] == '2':
        if i[1] == '1':
            if a == 1:
                S.append(i[2])
            else:
                #S.insert(0, i[2])
                mem.append(i[2])
        elif i[1] == '2':
            if a == 1:
                #S.insert(0, i[2])
                mem.append(i[2])
            else:
                S.append(i[2])
mem.reverse()
S[0:0] = mem
if a == 1:
    S.reverse()
# print(S)
print(''.join(S))


Measured memory_bytes: 34444
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

 int main() {
	 int a, b, c, d;
	 cin >> a >> b >> c >> d;
	 if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
		 cout << "Yes" << endl;
	 }
	 else {
		 cout << "No" << endl;
	 }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, b := intScanner(), intScanner()
	fmt.Println(larger(a-b*2, 0))
}


Measured memory_bytes: 1772
import sys
input = sys.stdin.buffer.readline
import copy

def main():
    N,x = map(int,input().split())
    a = list(map(int,input().split()))
    b = copy.deepcopy(a)
    
    ans = 10**15
    for i in range(N):
        time = i*x+sum(b)
        ans = min(ans,time)
        for now in range(N):
            b[now] = min(b[now],a[(now-i-1+N)%N])

    print(ans)

if __name__ == "__main__":
    main()
    


Measured memory_bytes: 42608
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


int main() {
	ll n;
	cin >> n;
	vector<ll> s(n),t(n);
	REP(i, n) {
		cin >> s[i];
		t[s[i] - 1] = i + 1;
	}
	REP(i, n) {
		if (i != 0)cout << " ";
		cout << t[i];
	}
	cout << endl;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/



int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    int M = s.size();

    ll ans = 0;

    ll flag = false;

    for(int i = M-1;i >= 0;i--){
        int b = s[i] - '0';
        if(flag)b++;
        if(b < 5){
            ans += b;
            flag = false;
        }else if(b == 5){
			if(i != 0){
				if(s[i-1] - '0' < 5)flag = false;
                else flag = true;
            }else{
              flag = false;
            }
          ans += 5;
        }else{
            ans += 10 - b;
          	flag = true;
        }
      //cout << ans << ' ' << s[i] << endl;
    }
  
  	if(flag)ans++;

    cout << ans << endl;


}

Measured memory_bytes: 1948
#include <stdio.h>

int min(int x,int y);
int max(int x,int y);
const int inf =100000000;

int main(){
    int n;
    scanf("%d",&n);
    int x[n];
    for (int i = 0; i <n ; ++i) {
        scanf("%d",&x[i]);
    }
   int L=x[0];int R=x[0];
    for (int i = 0; i <n ; ++i) {
        L=min(L,x[i]);
        R=max(R,x[i]);
    }
    int ans=inf;
    for (int i = L; i <=R ; ++i) {
        int cost=0;
        for (int j = 0; j <n ; ++j)
            cost+=(x[j]-i)*(x[j]-i);
            ans=min(ans,cost);
        }
    printf("%d",ans);
    return 0;
}

int min(int x,int y){
    if(x<y)
        return x;
    else
        return y;
}
int max(int x,int y){
    if(x>y)
        return x;
    else
        return y;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#include<cstring>
#include <stack>
#include <numeric>
#include<climits>
#include<set>
#include<unordered_set>
#include<iomanip>
#include<queue>
#include<unordered_map>
#define vi vector<float>
#define vl vector<long long>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define loop(i,n) for(float i=0; i<n; i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<float,float>
#define umap unordered_map<ll,float>
using namespace std;

#define xx first
#define yy second


int main() 
{ 
	ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
    	cout << "Yes";
    }else{
    	cout << "No";
    }
  	return 0;
 }

Measured memory_bytes: 256
from collections import deque
h,w=map(int,input().split())
S=[input() for _ in range(h)]
inf=float("inf")
ans=0
for i in range(h):
   for j in range(w):
      if S[i][j]=="#":
         continue
      else:
         DP=[[inf for _ in range(w)]for _ in range(h)]
         DP[i][j]=0
         que=deque([(i,j)])
         while que:
            si,sj=que.popleft()
            for ni,nj in [(si+1,sj),(si-1,sj),(si,sj+1),(si,sj-1)]:
               if 0<=ni<h and 0<=nj<w and S[ni][nj]!="#":
                  if DP[ni][nj]>DP[si][sj]+1:
                     DP[ni][nj]=DP[si][sj]+1
                     que.append((ni,nj))
                     ans=max(ans,DP[si][sj]+1)
print(ans)
                     

Measured memory_bytes: 48476
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	vector<int> arr(n);
    for(int i=0;i<n;++i)cin>>arr[i];
    sort(arr.begin(),arr.end());
    float reuslt = arr[0];
    for(int i=1;i<n;++i){
      reuslt = reuslt + arr[i];
      reuslt /= 2;
    }
    cout<<reuslt<<endl;
	return 0;
}

Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

#define NDEBUG
#include "atcoder/all"
using namespace atcoder;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    dsu uf(n);
    for(int i = 0; i < q; i++){
        int t, u, v;
        cin >> t >> u >> v;
        if(t == 0){
            uf.merge(u, v);
        }else{
            cout << uf.same(u, v) << '\n';
        }
    }
}


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

int N;
int main() 
{
    cin >> N;
    int np =N, res = 0;

    while (np > 0) res+=np%10, np/=10;
    if (N%res==0) cout << "Yes "  << endl; 
    else cout << "No "  << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N, M; 
	cin >> N >> M; 
	pair<int, int> X[100010] = {}; 	
	for(int i = 0; i < N; i++){
		cin >> X[i].first >> X[i].second; 
	}
	sort(X, X+N); 
	int used = 0; 
	long long int ans = 0; 
	for(int i = 0; i < N; i++){
		ans += (long long) X[i].first * X[i].second; 
		used += X[i].second; 
		if(used >= M){
			ans -= (long long) X[i].first * (used - M); 
			break; 
		}
	}
	cout << ans << endl; 
}

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

int main(){
  int n,i;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  int ma=a[0],mi=a[0];
  for(i=1;i<n;i++){
  	ma=max(ma,a[i]);
    mi=min(mi,a[i]);
  }
  cout<<ma-mi;
}

Measured memory_bytes: 256
N = int(input())
mod = 10**9+7
ans = 0
if N == 1:
    print(ans)
    exit()
else:
    ans = 2

memo_1 = 9*9
memo_2 = 8*8
for i in range(2,N):
    ans *= 10
    ans %= mod
    ans += (memo_1*2)%mod - (memo_2*2)%mod
    ans %= mod
    memo_1 *= 9
    memo_1 %= mod
    memo_2 *= 8
    memo_2 %= mod
print(ans)

Measured memory_bytes: 9188
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define eps 1e-9

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

const int INF = 0x7fffffff;
const int maxn = 110;
int n, Min = INF, t;
int a[maxn];

int main() {
#ifdef __AiR_H
    freopen("A.in", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // __AiR_H
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); }
    for (int i = -100; i <= 100; ++i) {
        t = 0;
        for (int j = 1; j <= n; ++j) {
            t += (a[j] - i) * (a[j] - i);
        }
        Min = min(Min, t);
    }
    printf("%d\n", Min);
#ifdef __AiR_H
    printf("Time used = %.2fs\n", (double)clock() / CLOCKS_PER_SEC);
#endif // __AiR_H
    return 0;
}


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

int main() {
  	long long int x;
  	cin>>x;
  	long long int money=100;
  	int i=0;
  	while(money<x){
     	 i++;
      	 money*=1.01;
    }
  
  	cout<<i<<endl;
  	
}

Measured memory_bytes: 3636
import Control.Applicative ((<$>))
import Data.List (elemIndices, delete)
import Data.Bool (bool)
import Data.Char (isLower)

main :: IO ()
main = solve <$> getLine >>= putStrLn

solve :: String -> String
solve s = bool "WA" "AC" $ head s == 'A' && ((== 1) . length . elemIndices 'C' . init . drop 2) s && all isLower (delete 'A' (delete 'C' s))


Measured memory_bytes: 380
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

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

    set<ll> ans;
    for(ll i=1;i*i<=n-1;++i) {
        if((n-1) % i) continue;
        ans.insert(i);
        if(i*i != n-1) ans.insert((n-1)/i);
    }

    for(ll i=2;i*i<=n;++i) {
        if(n % i) continue;
        ll nn = n;
        while(nn % i == 0) nn /= i;
        if((nn-1) % i == 0) ans.insert(i);
    }

    cout << ans.size() << endl;
}


Measured memory_bytes: 256
// VU TRUONG AN
#include <bits/stdc++.h>
#define FORX(i,x,y) for(int i = x; i <= y ; ++i)
#define FORN(i,x,y) for(int i = x; i >= y ; --i)
#define reset(x,y) memset(x,y,sizeof(x))
#define bp(i) (1 << i)
#define F first
#define S second
#define maxn 100001
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define bit(p,x) ((x>>p) & 1)
#define Task "ATC"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<db> vdb;
typedef vector<str> vstr;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdb;

const int base = 100003;
const long long MM = 1ll*MOD*MOD;
const int maxc = 2e9;

int n,a[maxn];

void Solve(){
    string s;
    cin >> s;
    if(s == "Sunny") cout << "Cloudy";
    else if(s == "Cloudy") cout << "Rainy";
    else cout << "Sunny";
}

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

    Solve();

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define rep(x,l,r) for(int x=(l),___r=(r);x<=___r;++x)
#define dep(x,r,l) for(int x=(r),___l=(l);x>=___l;--x)
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
int f[190][190][190],g[190][190][190],_f[190][190][190];
char map[190][190];
int Sx[190][190],Sy[190][190];
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	int n=gi(),m=gi();
	rep(i,1,n)scanf("%s",map[i]+1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j){
			Sx[i][j]=Sx[i-1][j]+(map[i-1][j]!=map[i][j]);
			Sy[i][j]=Sy[i][j-1]+(map[i][j-1]!=map[i][j]);
		}
	dep(i,n,1)rep(j,1,m)rep(k,j,m)f[i][j][k]=(Sy[i][j]==Sy[i][k]?map[i][j]==map[i+1][j]?f[i+1][j][k]:i:i-1);
	dep(i,m,1)rep(j,1,n)rep(k,j,n)g[i][j][k]=(Sx[j][i]==Sx[k][i]?map[j][i]==map[j][i+1]?g[i+1][j][k]:i:i-1);
	for(int _=0;;++_){
		if(f[1][1][m]==n||g[1][1][n]==m)printf("%d\n",_),exit(0);
		//update f->g;g->f
		memcpy(_f,f,sizeof f);
		rep(i,1,m)rep(j,1,n)rep(k,j,n)cxk(f[j][i][g[i][j][k]],k);
		rep(i,1,n)rep(j,1,m)rep(k,j,m)cxk(g[j][i][_f[i][j][k]],k);
		rep(i,1,n)rep(j,1,m)dep(k,m,j)cxk(f[i][j][k],f[i][j][k+1]);
		rep(i,1,m)rep(j,1,n)dep(k,n,j)cxk(g[i][j][k],g[i][j][k+1]);
		rep(i,1,n)rep(j,1,m)rep(k,1,m)if(f[i][j][k]<n)f[i][j][k]=f[f[i][j][k]+1][j][k];
		rep(i,1,m)rep(j,1,n)rep(k,1,n)if(g[i][j][k]<m)g[i][j][k]=g[g[i][j][k]+1][j][k];
	}
	return 0;
}


Measured memory_bytes: 80384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
// *start on @date: 2020-03-01 20:32 
using namespace std;
typedef long long ll;
const int maxn = 1000 + 5;
const int inf  = 0x3f3f3f3f;



int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
    int n,m,s,c;
    cin>>n>>m;
    int f = 1;

    int nums[5] = {0};
    int flag[5] = {0};
    while (m--)
    {
        cin>>s>>c;
        if(s > n )f=0;
        else
        {
            if(n!=1 && s ==1 && c==0)f=0;

            if(nums[s] == c){ //相同,跳过
                flag[s] = 1;
                continue;
            }
            

            if(         flag[s] == 1)f = 0; //到这里,肯定不同了,如果已经用过,则错误

            nums[s] = c;
            flag[s] = 1;

            
        }
    }
    if(f){

        if( n!=1&& nums[1] == 0)nums[1] = 1;
        for (int i = 1; i <= n; i++)
        {
            
            cout<<nums[i];
        }
        
    }else
    {
        cout<<-1;
    }
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
#define INF 1e5
using namespace std;

int n;
string str[11];
bool flag[11];
string use[11];
int dp[11][1<<10];
string res[11][1<<10];
string prev[11][1<<10];
int data[11][11];
bool win[11][11];
int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			cin >> str[i];
		}
		memset(flag,true,sizeof(flag));
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==j || str[i].size()>str[j].size() || !flag[j])continue;
				for(int k=0;k<=str[j].size()-str[i].size();k++){
					if(str[j].substr(k,str[i].size())==str[i])flag[i]=false;
				}
			}
		}
		int cnt=0;
		for(int i=0;i<n;i++){
			if(flag[i])use[cnt++]=str[i];
		}
		n=cnt;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==j)continue;
				for(int k=0;k<min(str[i].size(),str[j].size());k++){
					if(str[i][k]<str[j][k]){
						win[i][j]=true;
						break;
					}
					if(str[j][k]<str[i][k]){
						win[i][j]=false;
						break;
					}
				}
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==j)continue;
				int k;
				string st=use[j];
				while(use[i].substr(0,st.size())!=st){
					st=st.substr(1);
				}
				data[i][j]=st.size();
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<(1<<n);j++){
				dp[i][j]=INF;
				res[i][j]="";
				prev[i][j]="";
			}
		}
		for(int i=0;i<n;i++){
			dp[i][1<<i]=use[i].size();
			res[i][1<<i]=use[i];
		}
		for(int i=1;i<(1<<n);i++){
			for(int j=0;j<n;j++){
				if(dp[j][i]!=INF){
					for(int k=0;k<n;k++){
						if(i>>k & 1)continue;
						int cost=dp[j][i]+use[k].size()-data[j][k];
						string hika=use[j].substr(data[j][k]);
						if(dp[k][i|(1<<k)]>cost || (dp[k][i|(1<<k)]==cost && prev[k][i|(1<<k)]>hika)){
							dp[k][i|(1<<k)]=cost;
							res[k][i|(1<<k)]=use[k].substr(0,use[k].size()-data[j][k])+res[j][i];
							prev[k][i|(1<<k)]=hika;
						}
					}
				}
			}
		}
		int ansid=0;
		string ans=res[0][(1<<n)-1];
		for(int i=1;i<n;i++){
			if(dp[ansid][(1<<n)-1]>dp[i][(1<<n)-1] || (dp[ansid][(1<<n)-1]==dp[i][(1<<n)-1] && use[i]<use[ansid])){
				ansid=i;
				ans=res[i][(1<<n)-1];
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 2120
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<stack>
#include<cassert>
#define F first
#define S second
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define mem(x,y) memset(x,y,sizeof x)
#define sqr(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef double db;
const int INF=2e9;
const db eps=1e-8;
template<typename T>
inline void read(T &x)
{
	x=0; int f=1; char ch=getchar();
	while( (ch<'0' || ch>'9') && ch!='-') ch=getchar(); if(ch=='-') {f=-1; ch=getchar();}
	while(ch>='0' && ch <='9') x=x*10+ch-'0',ch=getchar();
	x*=f;
}
//==========================head template==========================
ll x,y;

signed main()
{
	read(x); read(y);
	if(x%y==0) {puts("-1"); return 0;}
	ll t=x*y/__gcd(x,y);
	printf("%lld\n",t-x);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
#define int unsigned long long

signed main() {
   int t;
    cin>>t;
    int c=0;
    int f=0;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a==b) c++;
        else c=0;
        if(c>=3) f=1;
    }
    if(f==1) cout<<"Yes\n";
    else cout<<"No\n";
    
}

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

using namespace std;

int main()
{
    long long n;
    cin>>n;
    vector <long long> a(n);
    iota(a.begin(),a.end(),1);
    do{
        for(long long i=0;i<n;i++)
        {
            if(i)
                cout<<" ";
            cout<<a[i];
        }
        cout<<endl;
    }while(next_permutation(a.begin(),a.end()));
    return 0;
}




Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring> //memset
#include <cmath>
#include <limits>
#include <queue>
using namespace std;

//TLE
/*
int main()
{
	long long N, M;

	cin >> N >> M;

	vector<long> A;
	static double log2[100010];

	for (long i = 0; i < N; i++) {
		long val;
		cin >> val;
		A.push_back(val);
	}

	std::sort(A.begin(), A.end(), std::greater<long>());

	for (unsigned int i = 0; i < N; i++) {
		log2[i] = std::log2((double)A[i]);
	}

	static unsigned int count[100010];
	memset(count, 0, sizeof(count));

	//M���̕��z
	unsigned int search_max_index = 1;
	for (unsigned int iM = 0; iM < M; iM++) {
		unsigned int arg_max = 0;
		double max = -10000000.0;
		for (unsigned int i = 0; i <= search_max_index; i++) {
			if (max < log2[i]) {
				arg_max = i;
				max = log2[i];
			}
		}

		if (arg_max >= search_max_index && arg_max < N - 1) {
			search_max_index++;
		}

		log2[arg_max] -= 1.0;
		count[arg_max] += 1;
	}

	long long result = 0;

	for (unsigned int i = 0; i < N; i++) {
		//result += (long long)A[i] / std::pow(2.0, (double)count[i]);
		result += (A[i] >> count[i]);
	}

	cout << result << endl;
}
*/


int main()
{
	long long N, M;

	cin >> N >> M;

	std::priority_queue<double> A;

	for (long i = 0; i < N; i++) {
		long val;
		cin >> val;
		A.push((double)val);
	}

	for (long i = 0; i < M; i++) {
		double discounted = A.top() / 2.0;
		A.pop();
		A.push(discounted);
	}

	long long result = 0;

	for (long i = 0; i < N; i++) {
		result += (long long)A.top();
		A.pop();
	}

	cout << result << endl;
}


//int main()
//{
//	long long N, M;
//
//	cin >> N >> M;
//
//	vector<double> A;
//
//	for (long i = 0; i < N; i++) {
//		long val;
//		cin >> val;
//		A.push_back((double)val);
//	}
//
//	for (long i = 0; i < M; i++) {
//		std::sort(A.begin(), A.end(), std::greater<double>());
//		A[0] = A[0] / 2.0;
//	}
//
//	long long result = 0;
//
//	for (long i = 0; i < N; i++) {
//		result += (long long)A[i];
//	}
//
//	cout << result << endl;
//}

//int main()
//{
//	long long N, K, Q;
//
//	cin >> N >> K >> Q;
//
//	static long w[100010];
//	memset(w, 0, sizeof(w));
//
//	//! ���͂��Ȃ��琳�𐔂̐����グ
//	for (long i = 0; i < Q; i++) {
//		long win;
//
//		cin >> win;
//
//		w[win - 1] += 1;
//	}
//
//	for (long i = 0; i < N; i++) {
//		if (Q - w[i] >= K) {
//			cout << "No" << endl;
//		}
//		else {
//			cout << "Yes" << endl;
//		}
//	}
//}


//int main()
//{
//	string S;
//
//	cin >> S;
//
//	bool bad = false;
//	for (int i = 0; i < S.size(); i++) {
//		if ((i+1) % 2 == 0) {
//			//����
//			if (S[i] == 'R') {
//				bad = true;
//				break;
//			}
//		}
//		else {
//			//�
//			if (S[i] == 'L') {
//				bad = true;
//				break;
//			}
//		}
//	}
//
//	if (bad == true) {
//		cout << "No" << endl;
//	}
//	else {
//		cout << "Yes" << endl;
//	}
//}

//int main()
//{
//	string S;
//
//	cin >> S;
//
//	if (S == "Sunny")
//	{
//		cout << "Cloudy" << endl;
//	}
//	else if(S == "Cloudy")
//	{
//		cout << "Rainy" << endl;
//	}
//	else {
//		cout << "Sunny" << endl;
//	}
//}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  string s,t;
  cin >> s >> t;
  int ans=0;
  rep(i,s.size()){
    if(s[i]!=t[i])ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3912
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    ans = (n - (n // 2)) / n
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

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

vector<string> S;

int main() {
  int H, W;
  cin >> H >> W;

  S.clear();
  for (int i = 0; i < H; ++i) {
    string str;
    cin >> str;
    S.push_back(str);
  }

  vector<vector <int> > res(H, vector<int>(W, 0));
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      for (int k = 0; k < 8; ++k) {
        int ni = i + dx[k], nj = j + dy[k];
        if (ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
        if (S[ni][nj] == '#') ++res[i][j];
      }
    }
  }

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (S[i][j] == '.') cout << res[i][j];
      else cout << '#';
    }
    cout << endl;
  }

  return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll n,d;cin>>n>>d;
  vector<ll>x(n), y(n);
  rep(i, n)cin>>x[i]>>y[i];

  int result=0;

  rep(i, n){
    if(x[i]*x[i]+y[i]*y[i]<=d*d)result++;
  }

  cout<<result<<endl;

  return 0;
}


Measured memory_bytes: 6424
#include<stdio.h>
int main()
{
	int c=0;
	char s[4],t[4];

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

	if(s[0]==t[0])
		c++;
	if(s[1]==t[1])
		c++;
	if(s[2]==t[2])
		c++;
	printf("%d",c);
	return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

int main() {
  int N , K;
  cin >> N >> K;
  int ans=0;
  rep(i,N){
    int h; cin>>h;
    if(h>=K) ans++;
  }
  cout <<ans<<endl;
}
  



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt(), i = in.nextInt();
			out.println(n-i+1);

		}
	}

	// other template
	static int min(int a, int b) {
		return Math.min(a, b);
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}

	static void fill(int[][] a, int value) {
		for (int i = 0; i < a.length; i++) {
			Arrays.fill(a[i], value);
		}
	}

	static void fill(long[][] a, int value) {
		for (int i = 0; i < a.length; i++) {
			Arrays.fill(a[i], value);
		}
	}

	static void fill(char[][] a, char c) {
		for (int i = 0; i < a.length; i++) {
			Arrays.fill(a[i], c);
		}
	}

	static int max(int a, int b) {
		return Math.max(a, b);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	// faster input template
	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21460
from copy import deepcopy

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

V = [0] + V + [0]

bag = []
value = []
for i in range(min(N,K)+1): ## 左からi個取り出す
  bag.append(V[i])
  bag_copy = deepcopy(bag)
  for j in range(min(N,K)-i+1): ## 右からj個取り出す
    bag_copy.append(V[N-j+1])
    bag_value = sum(bag_copy)
    bag_sorted = sorted(bag_copy)
    for k in range(K-i-j):
      if bag_sorted[k] < 0:
        bag_value -= bag_sorted[k]
      else:
        break
    value.append(bag_value)
    #print(i, j, bag_copy, bag_value)
    
ans = max(value)
print(ans)
    
    

Measured memory_bytes: 3444
#include<iostream>
#include<sstream>
#include<ios>
#include<iomanip>
#include<vector>
#include<list>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<map>
#include<string>
#include<numeric>
#include<set>
using namespace std;

int main(){
  long H, W;
  cin >> H >> W;
  
  if(H%3 == 0 || W%3 == 0){
    cout << 0 << endl;
    return 0;
  }

  vector<long> cands;
  cands.push_back(H);
  cands.push_back(W);
  
  // following editorial, fixing w, the width of rectangle B, to the half of W
  long w = W/2;
  long sa, sb, sc;
  long diff = 10000000000;
  for(long ha = 1; ha <= H-1; ha++){
    sa = ha*W;
    sb = (H-ha)*w;
    sc = (H-ha)*(W-w);
    diff = min(diff, max(max(sa, sb), sc) - min(min(sa, sb), sc));
  }
  cands.push_back(diff);

  // exchanging the role of H and W
  long h = H/2;
  diff = 10000000000;
  for(long wa = 1; wa <= W-1; wa++){
    sa = H*wa;
    sb = h*(W-wa);
    sc = (H-h)*(W-wa);
    diff = min(diff, max(max(sa, sb), sc) - min(min(sa, sb), sc));
  }
  cands.push_back(diff);
  
  stable_sort(cands.begin(), cands.end());

  cout << cands[0] << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  sort(ALLr(a));
  ll d[] = {0, 0};
  ll j = 0;
  REP(i, n-1){
    if(a[i] == a[i+1]){
      d[j] = a[i];
      j++;
      if(j == 2){
        cout << d[0]*d[1] << endl;
        return 0;
      }
      i++;
    }
  }
  cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int N, K; cin >> N >> K;
  //vi A(N); rep(i,N) cin >> A[i];

  cout << 1 + ((N-K)+(K-2))/(K-1) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
char s[1048576];
int x[524288];
int pre[1048576],suf[1048576],mnp[1048576],mxs[1048576];
int main()
{
	s[0]='(';
	int num=1;
	int n,l;
	scanf("%d%d",&n,&l);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&x[i]);
	}
	long long ans=l;
	for(int i=0;i<n;i++)
	{
		int t;
		scanf("%d",&t);
		int tt=t%(l<<1);
		ans+=t-tt;
		if(tt==0)
		{
			s[num]='(';
			num++;
			s[num]=')';
			num++;
			continue;
		}
		if(tt>(x[i]<<1)&&tt>((l-x[i])<<1))
		{
			s[num]='(';
			num++;
			s[num]=')';
			num++;
			ans+=(l<<1);
			continue;
		}
		ans+=l;
		if(tt>(x[i]<<1))
		{
			s[num]=')';
		}
		else if(tt>((l-x[i])<<1))
		{
			s[num]='(';
		}
		else
		{
			s[num]='?';
		}
		num++;
	}
	if(s[num-1]=='(')
	{
		s[num]=')';
		ans+=l;
		num++;
	}
	num-=2;
	pre[0]=0;
	mnp[0]=0;
	for(int i=1;i<=num;i++)
	{
		if(s[i]==')')
		{
			pre[i]=pre[i-1]-1;
		}
		else
		{
			pre[i]=pre[i-1]+1;
		}
		if(pre[i]<mnp[i-1])
		{
			mnp[i]=pre[i];
		}
		else
		{
			mnp[i]=mnp[i-1];
		}
	}
	suf[num+1]=0;
	mxs[num+1]=0;
	for(int i=num;i>=1;i--)
	{
		if(s[i]=='(')
		{
			suf[i]=suf[i+1]+1;
		}
		else
		{
			suf[i]=suf[i+1]-1;
		}
		if(suf[i]>mxs[i+1])
		{
			mxs[i]=suf[i];
		}
		else
		{
			mxs[i]=mxs[i+1];
		}
	}
	int inc=100000000;
	for(int i=0;i<=num;i++)
	{
		int p=mnp[i];
		if(pre[i]+suf[i+1]-mxs[i+1]<p)
		{
			p=pre[i]+suf[i+1]-mxs[i+1];
		}
		int s=mxs[i+1];
		if(pre[i]+suf[i+1]-mnp[i]>s)
		{
			s=pre[i]+suf[i+1]-mnp[i];
		}
		if(s-p<inc)
		{
			inc=s-p;
		}
	}
	ans+=(long long)inc*l;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 19200
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pl>    vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

int main() {
  ios_base::sync_with_stdio(0);
 ll int t, i, j, k, p, q, r, x, y, u, v, n, m;

            cin>>n;
        vector<pair<int,int>>a;
     
        fo(i,n){
            cin>>x>>y;
            a.pb({x,y});
        }
        int flag=0;
        int cnt=0;
        int ans=0;

        for(int i=0;i<n;i++){
            if(a[i].F==a[i].S){
            cnt++;    

            }
            else{
                cnt=0;

            }
            if(cnt==3){
                flag=1;
                break;
                
            }
        }    if(flag)
            cout<<"Yes"<<endl;
            else cout<<"No"<<endl;

  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;

  return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m) {
  int i, u, v;
  while (m--) {
    cin >> u >> v;
    g[u - 1].pb(v - 1);
    g[v - 1].pb(u - 1);
  }
}

void dfs(int u, int par) {
  for (int v : g[u]) {
    if (v == par) continue;
    dfs(v, u);
  }
}





Measured memory_bytes: 10880
n = STDIN.gets.to_i
A = STDIN.gets.split(" ").map(&:to_i)
def pertition(a,p,r)
  i=p-1
  x=a[r]
  for j in p..r
    if a[j] <= x
      i+=1
      tmp=a[i]
      a[i]=a[j]
      a[j]=tmp
    end
  end
  #tmp=a[r]
  #a[r]=a[i+1]
  #a[i+1]=tmp

  a[i]='['+a[i].to_s+']'
  puts a.join(" ")
end
pertition(A,0,A.length-1)

Measured memory_bytes: 17164