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

using namespace std;

using int64 = long long;

int64 latte[51], malta[51];

int N;
int64 X;

int64 rec(int N) {
  if(X <= 0) {
    return 0;
  }

  if(N == -1) {
    return 0;
  }
  if(X >= latte[N]) {
    X -= latte[N];
    return malta[N];
  } else {
    int64 ret = 0;
    X--;
    ret += rec(N - 1);
    if(X > 0) {
      ret++;
      X--;
    }
    ret += rec(N - 1);
    X--;
    return ret;
  }
}

int main() {
  cin >> N >> X;
  latte[0] = 1;
  malta[0] = 1;
  for(int i = 1; i < 51; i++) {
    latte[i] = latte[i - 1] * 2 + 3;
    malta[i] = malta[i - 1] * 2 + 1;
  }
  cout << rec(N) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
    int a,b;
    cin >> a >> b;
    cout << max(a*b, max(a+b, a-b)) << endl;
}


Measured memory_bytes: 256
import math

A,B = map(int, input().split())
ans = int(0)
if B==0:
  ans = 0
else:
  N = math.floor(math.log2(B)+1)
  
  A_mod = A % 4
  B_mod = B % 4
  if A_mod < 2:
    if B_mod ==1 or B_mod == 2:
      ans += 1
  else:
    if B_mod ==3 or B_mod == 0:
      ans += 1

  for i in range(2,N+1):
    A_mod = A % (2**i)
    B_mod = B % (2**i)
    if A_mod < 2**(i-1):
      if B_mod >= 2**(i-1):
        ans += ((B_mod+1)%2)*(2**(i-1))
    else:
      if B_mod < 2**(i-1):
        ans += (A_mod%2)*(2**(i-1))
      else:
        ans += ((A_mod+B_mod+1)%2)*(2**(i-1))

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
    #define ll  long long int
    #define N 100000
    #define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
    #define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
    #define po pop_back
    #define pb push_back
    #define lb lower_bound
    #define fi first
    #define se second
    #define debug(x) cout << #x << " = " << x << endl
    #define ub upper_bound
    #define ibs ios_base::sync_with_stdio(false)
    #define cti cin.tie(0)
    #define all(x) x.begin(),x.end()
    #define PI 3.14159265
    #define cot cout.tie(0)
    using namespace std;
      /**
        * @author :: Sawlani
        *
        */
        char grid[1001][1001];
        ll dp[1001][1001]={0};
        const ll M=1e9+7;
        int main()
        {
           // freopen("input.txt","r",stdin);
            ll h,w;
            cin >> h >> w;

             f(i,1,h){
            f(j,1,w){
                cin >> grid[i][j];
            }

          }


          dp[1][1]=1;
          f(i,1,h)
          {
              f(j,1,w)
              {
                  if(i==1&&j==1)
                    continue;
                  if(grid[i][j]=='.')
                  {
                     if(i==1)
                    dp[i][j]=dp[i][j-1];
                    else if(j==1)
                       dp[i][j]=dp[i-1][j];
                    else
                      dp[i][j]=(dp[i-1][j]+dp[i][j-1])%M;

                   }

             }
          }

           cout << dp[h][w] << endl;
        }


Measured memory_bytes: 9088
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	final int ALPHA_NUM=26;
	Scanner in = new Scanner(System.in);
	int[] cnt = new int[ALPHA_NUM];
	
	for(int i=0;i<ALPHA_NUM;i++)cnt[i]=0;
	    
	while(in.hasNext()){
	    String str = in.next();
	    for(int i=0;i<str.length();i++){
		char ch= str.charAt(i);

		if(('a'<= ch && ch<='z')|| ('A'<= ch && ch<='Z')){
		    if(Character.isUpperCase(ch))cnt[ch-(int)'A']++;
		    else if(Character.isLowerCase(ch))cnt[ch-(int)'a']++;
		}
	    }
	}
	    for(int i=0;i<ALPHA_NUM;i++)System.out.println((char)((int)'a'+i)+" : "+cnt[i]);
	
    }
}



Measured memory_bytes: 26076
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <iomanip>

typedef long long ll;

using namespace std;

int main() {
    int r;
    cin >> r;
    
    cout << r * r << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
//#define NDEBUG
int main(void){
	using namespace std;
	static const int INPUT_N_MIN = 0;
	static const int INPUT_N_MAX = 10000;
	static const int INPUT_A_MIN = -1000000;
	static const int INPUT_A_MAX =  1000000;
	int ans_min = INPUT_A_MAX;			/* 最小値 */
	int ans_max = INPUT_A_MIN;			/* 最大値 */
	long ans_sum = 0;					/* 合計値 100000*1000まで対応のためlong */
	int input_n = 0;
	/* 整数の個数nを入力 */
	cin >> input_n;
	
	/* 入力値の前提条件 最大・最小の制限*/
	assert (INPUT_N_MIN < input_n && input_n <= INPUT_N_MAX);
	
	int input_a[input_n];
	
	/* 計算する整数a群を入力 */
	for (int i = 0; i < input_n; i++){
		
		/* 入力値の前提条件 最大・最小の制限*/
		cin >> input_a[i];
		assert (INPUT_A_MIN <= input_a[i] && input_a[i] <= INPUT_A_MAX);
		
		/* 最大・最小値の更新判定 */
		if(input_a[i] < ans_min){
			ans_min = input_a[i];		/* 最小値更新 */
		}
		if(input_a[i] > ans_max){
			ans_max = input_a[i];		/* 最大値更新 */
		}
		
		/* 合計値に加算 */
		ans_sum = ans_sum + static_cast<long>(input_a[i]);
	}
	
	/* 出力 */
	cout << ans_min << " " << ans_max << " " << ans_sum << endl;
	
	return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;

    vec sq;
    for (int i = 1; i * i <= n; i++) {
        sq.push_back(i * i);
    }
    cout << sq.back() << endl;
    return 0;
}

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

const int N = 310;
int n, ans = 0;
char a[2*N][2*N];

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            scanf(" %c", &a[i][j]);
            a[i+n][j] = a[i][j+n] = a[i+n][j+n] = a[i][j];
        }
    }
    for(int k = 0; k < n; k++) {
        bool exact_match = true;
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) exact_match &= (a[i][j+k] == a[j][i+k]);
        }
        ans += exact_match*n;
    }
    printf("%d", ans);
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if (a < b * 2) {
      System.out.println(0);
    } else {
      System.out.println(a - b * 2);
    }

  }
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


int main(){
    long long A;
    scanf("%lld",&A);
    cout << (3 * A * A) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define ll unsigned long long
using namespace std;

int main(){
    int N,K,T;
    cin >> N >> K;
    vector<int>d(N,0);
    ll m = 100;
    for(int i=0; i<K; i++){
        cin >> T;
        int tmp;
        for(int j=0; j< T; j++){
            cin >> tmp;
            d[tmp-1] = 1;
        }
    }
    int ans = 0;
    for(int i=0; i<N; i++){
        if(d[i]==0)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3148
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define endl "\n"
#define X first
#define Y second
#define pii pair<int,int>
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)

const int maxn=2e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

ll poww(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));}
ll n;
ll q[maxn];
ll nw=1;
ll ted;
int main(){
	migmig;
	vector <int> v;
	cin>>n;
	for (int i=0;i<n;i++)
	{
		cin>>q[i];
	}
	
	for (int i=0;i<n;i++){
		if (q[i]==nw){
			nw++;
		}else{
			ted++;
		}
	}
	if(nw==1){
		cout<<"-1";
	}else{
		cout<<ted;
	}
	return 0;
}



Measured memory_bytes: 1792
#include<stdio.h>
#include<algorithm>
int F(int x){return x/100*60+x%100;}
int main()
{
	int n,p,q,k,s,t,i;
	while(scanf("%d%d%d",&n,&p,&q),q)
	{
		int a[1441]={0};
		p=F(p);q=F(q);
		for(i=0;i<n;++i)
		{
			for(scanf("%d",&k);k--;)
			{
				scanf("%d%d",&s,&t);
				for(s=F(s),t=F(t);s<t;++s)++a[s];
			}
		}
		for(t=0,i=p;i<q;i+=s+1)
		{
			for(s=0;s+i<q;++s)
			{
				if(a[s+i]==n)
				{
					t=std::max(t,s);
					break;
				}
			}
		}
		printf("%d\n",std::max(t,s));
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N; cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    if (to_string(i).size() % 2 == 1) ans++;
  }

  cout << ans << endl;
}

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

using namespace std;

#define FOR(i,a,b)		for(int i=(a),_b=(b);i<(_b);++i)
#define FORD(i,a,b)		for(int i=(a),_b=(b);i>(_b);--i)
#define pb			push_back
#define mp			make_pair
#define	all(c)			(c).begin(),(c).end()
#define	present(c,x)		((c).find(x) != (c).end())
#define	cpresent(c,x)		(find(all(c),x) != (c).end())
#define	endl			'\n'

typedef long long		ll;
typedef unsigned long long	ull;
typedef unsigned char	 	byte;
typedef vector<int>		vi;
typedef pair<int, int>		pii;
typedef pair<ll, ll>		pll;
typedef vector<pii>		vpii;

const int MX = 22;
const int MOD = 1000000007;

ll dp[MX][(1<<MX)];
bool match[MX][MX];
int n;

ll solve(int idx, int mask)
{
	if (idx == n && ((1<<n)-1 == mask)) return 1;
	if (dp[idx][mask] > -1) return dp[idx][mask];
	ll ret = 0;

	FOR(i,0,n) {
		if (match[idx][i] && !((1<<i)&mask)) {
			ret += solve(idx+1,mask|(1<<i));
		}
	}
	return dp[idx][mask] = ret%MOD;
}

int main(int argc, char *argv[])
{
#ifdef	HTRINH_UNIT_TEST
	freopen(argv[1],"r",stdin);
	ifstream cin(argv[1]);
#endif
#if 0
	ofstream cout(argv[2]);
#endif
	ios :: sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;
	FOR(i,0,n) FOR(j,0,n) cin >> match[i][j];
	FOR(i,0,n) FOR(j,0,(1<<n)) dp[i][j] = -1;
	cout << solve(0,0) << endl;
	return 0;
}


Measured memory_bytes: 387328
import math
import functools

law = 10 ** 9 + 7
def mul_mod(x, y):
  return x * y % law

def prod_mod(seq):
  return functools.reduce(mul_mod, seq, 1)
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
  
def comb(n, k):
  return prod_mod(i for i in range(n - k + 1, n + 1)) * mod_inv(prod_mod(i for i in range(1, k + 1)), law) % law

if __name__ == "__main__":
  
  x, y = sorted(map(int, input().split()), reverse=True)
  
  if (x + y) % 3 != 0:
    print(0)
  else:
    print(comb((x + y) // 3, x - (x + y) // 3))


Measured memory_bytes: 3572
# ARC073C - Sentou (ABC060C)
def main():
    n, t = list(map(int, input().rstrip().split()))
    lst = list(map(int, input().rstrip().split()))
    ans, cur = 0, lst[0]
    for i in lst[1:]:
        ans += min(t, i - cur)
        cur = i
    ans += t
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 26836
//do not think about past and stay in this moment
//organize and work - Abhinav IIITA
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define int long long
#define ld long double
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end() 
const ld pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void fx(vector<int> &a,int n, int m){

}

// -----------------------------------------------------------------------

int arr[3000000];
void input(int n){
	for(int i=0;i<n;++i)
	cin>>arr[i];
}

// -----------------------------------------------------------------------



void q1(){
	
	int a=0,b=0;
	int t;
	for(int i=0;i<3;++i){
		cin>>t;
		if(t==5)
		a++;
		else if(t==7)
		b++;
	}
	if(a==2 && b==1)
	cout<<"YES\n";
	else 
	cout<<"NO\n";
}
// -----------------------------------------------------------------------


void q2(){
	int n,l;
	cin>>n>>l;
	vector<string> v(n);
	for(int i=0;i<n;++i)
	cin>>v[i];
	sort(all(v));
	for(int i=0;i<n;++i)
	cout<<v[i];
	cout<<endl;
}

// -----------------------------------------------------------------------

void q3(){
	int n,k;
	cin>>n>>k;
	int brr[10];
	for(int i=0;i<10;++i)
	brr[i]=1;
	while(k--){
		int t;
		cin>>t;
		brr[t]=0;
	}
	while(true){
		int cpy=n+1;
		bool fg=true;
		while(n!=0){
			int xp=n%10;
			n/=10;
			if(!brr[xp])
			fg=false;
		}
		if(fg){
			cout<<cpy-1;
			return ;
		}
		n=cpy;
	}
}


// -----------------------------------------------------------------------

void q4(){
	int h,w,A,b;
	cin>>h>>w>>A>>b;
	vector<int> a(w),ret(w),res(w-b);
	for(int i=0;i<w;++i)
	a[i]=1; ret[0]=1;
	int n,m;n=w;m=h-A-1;
	while(m--){
		for(int i=1;i<n;++i){
			ret[i]=ret[i-1]+a[i];
		}
		for(int i=0;i<n;++i){
			a[i]=ret[i];
		}
		ret[0]=1;
	}
	for(int i=0;i<n;++i)
	cout<<a[i]<<" ";
	cout<<endl;
	res[0]=a[b];
	for(int i=b+1;i<n;++i)
	res[i-b]=res[i-b-1]+a[i];
	m=A-1;	ret[0]=res[0];	n=n-b;
	while(m--){
		for(int i=1;i<n;++i){
			ret[i]=ret[i-1]+res[i];
		}
		for(int i=0;i<n;++i){
			res[i]=ret[i];
		}
	} 
	cout<<res[n-1];
}

// -----------------------------------------------------------------------


int32_t main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
	//cin>>t;
	while(t--)
	q3();
	return 0;
}


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

using namespace std;

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

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

    int n;cin>>n;
    vector<P> v;
    for(int i=0;i<n;i++)
    {
        int x,y;cin>>x>>y;
        v.emplace_back(x,y);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++)
    {
        cout << v[i].first << " " << v[i].second << endl;
    }
}



Measured memory_bytes: 3864
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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 int INF = 1e9;

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }

    // 集合をマージする
    // すでに同じ集合ならfalseが返る
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (data[y] < data[x]) swap(x, y);  // マージテク
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    // ある要素がどの集合に属しているかを答える
    int root(int x) {
        // 根に直接つなぎ直す
        return data[x]<0 ? x : (data[x]=root(data[x]));
    }

    // ある集合の大きさを答える
    int size(int x) {
        return -data[root(x)];
    }
};


int main(){
    LL N, M;
    cin >> N >> M;
    vector<LL> a(M), b(M);
    for(int i=0; i<M; i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }

    UnionFind UF(N);
    vector<LL> ans(M, 0);
    // 不便さ
    ans[M-1] = N*(N-1)/2;

    for(int i=M-1; i>0; i--){
        if(UF.root(a[i]) == UF.root(b[i])){
            ans[i-1] = ans[i];
            continue;
        }
        // オーバーフローに注意
        ans[i-1] = ans[i] - 1LL*UF.size(a[i])*UF.size(b[i]);

        UF.merge(a[i], b[i]);
    }
    for(int i=0; i<M; i++) cout << ans[i] << endl;
}

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

const int N = 2e5 + 9, INF = 0x3f3f3f3f;

int f[N], g[N], n, nf[N], ng[N], d[N];
long long ans;
bool is[N], nis[N];
char s[N];
vector<int>V[N];

void Gx (int &f, int &g, int _f) {
	if (_f >= f) g = f, f = _f;
	else if (_f >= g) g = _f;
}

void Dfs (int u, int fa) {
	if (s[u] == '1') is[u] = 1;
	for (auto v : V[u]) if (v != fa) {
		Dfs(v, u);
		is[u] |= is[v];
		if (is[v] && f[v] < d[u]) d[u] = f[v];
		Gx(f[u], g[u], f[v]);
	}
	++f[u]; ++g[u]; ++d[u];
}

void Dfs2 (int u, int fa) {
	if (nf[u] < 1) nf[u] = 1;
	Gx(f[u], g[u], nf[u]);
	nis[u] |= (s[u] == '1');
	if (nis[u] && nf[u] < d[u]) d[u] = nf[u];
	int a = nf[u], b = 0; bool o = nis[u];
	for (auto v : V[u]) if (v != fa) {
		Gx(nf[v], ng[v], a + 1);
		nis[v] |= o;
		Gx(a, b, f[v] + 1);
		if (is[v]) o |= 1;
	}
	a = b = o = 0;
	for (int i = V[u].size() - 1, v; ~i; --i) if ((v = V[u][i]) != fa) {
		Gx(nf[v], ng[v], a + 1);
		nis[v] |= o;
		
		Gx(a, b, f[v] + 1);
		if (is[v]) o |= 1;
	}
	
	for (auto v : V[u]) if (v != fa) {
		Dfs2(v, u);
	}
}

int main () {
	memset(d, 0x3f, sizeof d);
	scanf("%d", &n);
	for (int i = 1, u, v; i < n; ++i) scanf("%d%d", &u, &v), V[u].emplace_back(v), V[v].emplace_back(u);
	scanf("%s", s + 1);
	if (n == 1) return printf("%d\n", s[1] == '1'), 0;
	if (n == 2) return printf("%d\n", (s[1] == '1') + (s[2] == '1') + (s[1] == '1' || s[2] == '1')), 0;
	Dfs(1, 0);
	Dfs2(1, 0);
 	for (int i = 1; i <= n; ++i) {
 		if (s[i] == '1') d[i] = 1;
	 	ans += max(min(g[i], f[i] - 2) - (d[i] - 1) + 1, 0);
	 }
//	 for (int i = 1; i <= n; ++i) printf("%d%c", f[i], i==n?'\n':' ');
//	 for (int i = 1; i <= n; ++i) printf("%d%c", g[i], i==n?'\n':' ');
//	 for (int i = 1; i <= n; ++i) printf("%d%c", d[i], i==n?'\n':' ');
	printf("%lld\n", ans + 1);
	return 0;
}

Measured memory_bytes: 25216
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int res;
int s,r;
vector<int> v;

void solve(int n){
	int d = 0;
	for(int i=0;i<min(n,r);i++){
		if(v[i]>=0) continue;
		d += v[i];
	}
	s -= d;
	//cout<<s<<" : ";
	//for(int i=0;i<v.size();i++) cout<<v[i]<<" ";
	//cout<<endl;
	res = max(res,s);
	return;
}

int main() {
	// your code goes here
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	
	for(int i=1;i<=min(k,n);i++){
		
		for(int l=0;l<=i;l++){
			v.clear();
		    s = 0;
			for(int j=0;j<l;j++) { v.push_back(a[j]); s += a[j]; }
			for(int h=n-1;h>=n-i+l;h--)  { v.push_back(a[h]); s += a[h]; }
			
				sort(v.begin(),v.end());
		r = k-i;
		solve(i);
		}
	
	}
	
	cout<<res;
	return 0;
}

Measured memory_bytes: 256
class Node(object):
    def __init__(self, c):
        self.c = c
        self.left = None
        self.right = None

def print_node(node):
    print node.c
    if node.left != None:
        print_node(node.left)
    if node.right != None:
        print_node(node.right)

def calc_node(node):
    if node.c in ('+', '-', '/', '*'):
        if node.c == '+':
            return calc_node(node.left) + calc_node(node.right)
        if node.c == '-':
            return calc_node(node.left) - calc_node(node.right)
        if node.c == '*':
            return calc_node(node.left) * calc_node(node.right)
    else:
        return int(node.c)

def make_node(s):
    global pos
    node = Node(s[pos])
    if s[pos] in ('+', '-', '*'):
        pos += 1
        node.right = make_node(s)
        pos += 1
        node.left = make_node(s)
    return node

s = raw_input().split()
s.reverse()
#print s
pos = 0
n = make_node(s)
#print_node(n)
print "%d" % calc_node(n)

Measured memory_bytes: 6488
import sys
if __name__ == "__main__":
  s = input()
  for i in range(1, len(s)+1):
    if i % 2 == 0:
      if s[i-1] == "R":
        print("No")
        sys.exit()
    else:
      if s[i-1] == "L":
        print("No")
        sys.exit()

  print("Yes") 

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()

using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;


signed main(){
    string s,t; cin >> s >> t;
    if(s.size()<t.size()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    for(int i=s.size()-t.size();i>=0;i--){
        bool ok=1;
        rep(j,t.size()){
            if(s[i+j]!=t[j]&&s[i+j]!='?') ok=0;
        }
        if(ok){
            rep(j,s.size()){
                if(j==i){
                    cout << t;
                    j+=t.size()-1;
                }
                else if(s[j]=='?') cout << "a";
                else cout << s[j];
            }
            return 0;
        }
    }
    cout << "UNRESTORABLE" << endl;
}


Measured memory_bytes: 256
N = int(input())
S = input()

x = S.count("R")
y = S.count("G")

total = x*y*(N-x-y)

count = 0
for i in range(N):
    texta = S[i]
    for j in range(i,int((N-1+i)/2)+1):
        if S[j] != texta:
            textb = S[j]
            if S[2*j-i] != texta and S[2*j-i] !=textb:
                count += 1

print(total - count)
    

Measured memory_bytes: 68052
#include<iostream>
#include<cstdio>
#include<cctype>
using namespace std;

int main(){
    int co[40]={};
    int i,j;
    char al[40]="abcdefghijklmnopqrstuvwxyz";
    char ch;
    while(scanf("%c", &ch) != EOF){
        if(isupper(ch)){
            ch=tolower(ch);
        }
        for(i=0;i<26;i++){
            if(ch==al[i]){
                co[i]+=1;
            }
        } 
    }
    for(j=0;j<26;j++){
        cout<<al[j]<<" : "<<co[j]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3152
#include<iostream>
#include<vector>
#include<string>
#include<climits>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<queue>
#include<math.h>

int main(){
	long long n;
	long long ans;

	std::cin>>n;

	ans= (n-1)*n/2;

	std::cout<<ans<<std::endl;

	return 0;
		
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007ll
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    li n;
    cin >> n;
    li odd = (n + 1) / 2;
    printf("%.12f\n", odd * 1.0 / n);

    return 0;
}


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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(b+a<c+d)
    cout<<"Right"<<endl;
  if(a+b>c+d)
  	cout<<"Left"<<endl;
  if(a+b==c+d)
    cout<<"Balanced"<<endl;  
}

Measured memory_bytes: 256
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new File("c:\\0519-in7.txt"));
		while (scan.hasNext()) {
			int n = scan.nextInt();
			if (n == 0)
				break;
			int m = scan.nextInt();

			Match match = new Match(n);
			for (int i = 0; i < m; i++)
				match.add(scan.nextInt(), scan.nextInt());
			for (int i = 0; i < n; i++)
				System.out.println(match.getTopOrder());
			System.out.println(match.getDefined());
		}

		scan.close();
		System.exit(0);
	}

}

class Match {
	class Team {
		int loseCnt = 0;
		List<Integer> winTo = new ArrayList<Integer>();
	}

	Team[] team;
	boolean vague = false;

	public Match(int n) {
		team = new Team[n + 1];
		for (int i = 1; i < team.length; i++)
			team[i] = new Team();
	}

	public int getDefined() {
		if (vague)
			return 1;
		else
			return 0;
	}

	public int getTopOrder() {
		int top = 0;
		for (int i = 1; i < team.length; i++) {
			if (team[i].loseCnt == 0) {
				if (top != 0) {
					vague = true;
					break;
				}
				top = i;
				team[i].loseCnt = -1;
				if (vague)
					break;
			}
		}
		for (int i = 0; i < team[top].winTo.size(); i++)
			team[team[top].winTo.get(i)].loseCnt--;
		return top;
	}

	public void add(int winner, int loser) {
		team[loser].loseCnt++;
		team[winner].winTo.add(loser);
	}
}

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

int main(){
  int n,k;
  cin >> n >> k;
  vector<long long> a(210000);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  
  for(int i=0;i<n-k;i++){
    if(a[i]<a[i+k]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}




Measured memory_bytes: 4840
T = int(input())


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


for i in range(T):
    a, b, c, d = map(int, input().split())
    if a < b:
        print('No')
    elif d < b:
        print('No')
    elif c >= b:
        print('Yes')
    else:
        g = gcd(b, d)
        if b - g + a % g > c:
            print('No')
        else:
            print('Yes')

Measured memory_bytes: 3064
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
typedef pair<int,int> P;
typedef pair <int, P> P2;
#define mp make_pair
#define ft first
#define sd second

int d, n;
int t[200];
P2 p[200];
P c[200];
int s[200][2];

int main() {
	
	cin >> d >> n;
	
	REP(i, d) cin >> t[i];
	REP(i, n) cin >> p[i].sd.ft >> p[i].sd.sd >> p[i].ft;
	
	sort(p, p+n);
	
	int k;
	REP(i, d) {
		k = 0;
		while(t[i] < p[k].sd.ft || t[i] > p[k].sd.sd) {
			k++;
		}
		c[i].ft =  p[k].ft;
	}
	
	k = n-1;
	REP(i, d) {
		k = n-1;
		while(t[i] < p[k].sd.ft || t[i] > p[k].sd.sd) {
			k--;
		}
		c[i].sd =  p[k].ft;
	}
	
	s[0][0] = 0;
	s[0][1] = 0;
	
	FOR(i, 1, d) {
		s[i][0] = max(s[i-1][0]+abs(c[i-1].ft-c[i].ft), s[i-1][1]+abs(c[i-1].sd-c[i].ft));
		s[i][1] = max(s[i-1][0]+abs(c[i-1].ft-c[i].sd), s[i-1][1]+abs(c[i-1].sd-c[i].sd));
	}
	
	int res = max(s[d-1][0], s[d-1][1]);
	
	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 1168
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class B
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (N, K) = Scanner.Scan<int, int>();
            var snuke = new bool[N];
            for (var i = 0; i < K; i++)
            {
                var d = Scanner.Scan<int>();
                var A = Scanner.ScanEnumerable<int>().ToArray();
                for (var j = 0; j < d; j++)
                {
                    snuke[A[j] - 1] = true;
                }
            }

            Console.WriteLine(snuke.Count(x => !x));
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 29208
nmxy = list(map(int, input().split(' ')))
x = nmxy[2]
y = nmxy[3]
xs = list(map(int, input().split(' ')))
ys = list(map(int, input().split(' ')))
if max(xs) < min(ys) and x < min(ys) and min(ys) <= y:
    print('No War')
else:
    print('War')

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

int partition(vector<int>& A, int p, int r) {
  int x = A[r];
  int i = p - 1;
  for (int j = p; j < r; ++j) {
    if (A[j] <= x) {
      ++i;
      swap(A[i], A[j]);
    }
  }
  swap(A[i + 1], A[r]);
  return i + 1;
}

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; ++i) cin >> A[i];
  int p = partition(A, 0, n - 1);
  for (int i = 0; i < n; ++i) {
    if (i == p) {
      cout << "[" << A[i] << "]" << " ";
      continue;
    } else if (i == n - 1) {
      cout << A[i] << endl;
    } else {
      cout << A[i] << " ";
    }
  }
}



Measured memory_bytes: 3116
#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue> 
#include<cmath>
#include<utility>
#include<set>
#define M 1000000007
using namespace std;
int main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int n, k;
  long long x=0;
  cin >> n >> k;
  int h[n];
  for(int i = 0; i  <n; i++)
    cin >> h[i];
  sort(h, h+n);
  for(int i = 0; i < n-k; i++)
    x+=h[i];
  cout << x << '\n';
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
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;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(3 * n);
    for(int i = 0; i < 3 * n; i++) {
        cin >> a[i];
    }
    // 前半
    priority_queue<ll, vector<ll>, greater<ll>> que1;
    ll sum1 = 0;
    vector<ll> ans1(n + 1, 0);
    for(int i = 0; i < n; i++) {
        que1.push(a[i]);
        sum1 += a[i];
    }
    ans1[0] = sum1;
    for(int i = n; i < 2 * n; i++) {
        if(que1.top() < a[i]) {
            sum1 += a[i] - que1.top();
            que1.pop();
            que1.push(a[i]);
        }
        ans1[i - (n - 1)] = sum1;
    }
    // 後半
    priority_queue<ll> que2;
    ll sum2 = 0;
    vector<ll> ans2(n + 1, 0);
    for(int i = 2 * n; i < 3 * n; i++) {
        que2.push(a[i]);
        sum2 += a[i];
    }
    ans2[n] = sum2;
    for(int i = 2 * n - 1; i >= n; i--) {
        if(que2.top() > a[i]) {
            sum2 += a[i] - que2.top();
            que2.pop();
            que2.push(a[i]);
        }
        ans2[i - n] = sum2;
    }
    ll ans = -LLINF;
    for(int i = 0; i < n + 1; i++) {
        chmax(ans, ans1[i] - ans2[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9496
import sys
# sys.setrecursionlimit(100000)
from functools import lru_cache


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, x = input_int_list()
    layer_size = [1]
    p_cnt = [1]

    for _ in range(50):
        layer_size.append(layer_size[-1] * 2 + 3)
        p_cnt.append(p_cnt[-1] * 2 + 1)

    @lru_cache(None)
    def L(level, x):
        if x == 1:
            if level == 0:
                return 1
            else:
                return 0
        l = layer_size[level - 1]
        p = p_cnt[level - 1]
        if x <= l + 1:
            return L(level - 1, x - 1)
        elif x == l + 2:
            return p + 1
        elif x <= 2 + l * 2:
            return p + 1 + L(level - 1, x - l - 2)
        else:
            return 2 * p + 1
    print(L(n, x))
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 67384
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
int n, pos[maxn + 10], t[maxn + 10], f[maxn + 10];
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		int x; scanf("%d", &x); pos[x] = i;
	}
	for (int i = n - 1; i >= 1; --i) {
		if (!t[i + 1]) {
			if (pos[i] < pos[i + 1]) t[i] = 0;
			else {
				t[i] = 1; f[i] = i + 1;
			}
		} else {
			int x = pos[f[i + 1]], y = pos[i], z = pos[i + 1];
			if ((x < y) + (y < z) + (z < x) == 2) {
				t[i] = t[i + 1]; f[i] = f[i + 1];
			} else {
				t[i] = t[i + 1] + 1; f[i] = i + 1;
			}
		}
	}
	printf("%d", t[1]);
}


Measured memory_bytes: 9216
#include <stdio.h>

int main(void){

	int a,b,c,i;

	while(scanf("%d %d", &a, &b) != EOF){
		c = a + b;
		for(i = 0; c != 0; i++) c /= 10;
		printf("%d\n", i);
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int N, M;
bool X[5000][5000];
int W[5000], L[5000];
pair<int, int>P[5000];
bool F = true;
int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 0; i < M; i++){
		int A, B;
		scanf("%d%d", &A, &B);
		X[A - 1][B - 1] = 1;
		W[A - 1]++;
		L[B - 1]++;
	}
	for (int LC = 0; LC < N; LC++){
		int cou = 0;
		int LCi;
		for (int i = 0; i < N; i++){
			if (L[i] == LC){
				cou++;
				LCi = i;
			}
		}
		if (cou >= 2){
			F = false;
			break;
		}
		else if (cou == 1){
			for (int i = 0; i < N; i++){
				if (i == LCi)continue;
				if (!X[LCi][i] && !X[i][LCi]){
					X[LCi][i] = 1;
					W[LCi]++;
					L[i]++;
				}
			}
		}
	}
	for (int WC = 0; WC < N; WC++){
		int cou = 0;
		int WCi;
		for (int i = 0; i < N; i++){
			if (W[i] == WC){
				cou++;
				WCi = i;
			}
		}
		if (cou >= 2){
			F = false;
			break;
		}
		else if (cou == 1){
			for (int i = 0; i < N; i++){
				if (i == WCi)continue;
				if (!X[WCi][i] && !X[i][WCi]){
					X[WCi][i] = 1;
					W[WCi]++;
					L[i]++;
				}
			}
		}
	}
	
	if (!F){
		for (int LC = 0; LC < N; LC++){
			int LCi = -1;
			for (int i = 0; i < N; i++){
				if (L[i] == LC){
					LCi = i;
					for (int j = 0; j < N; j++){
						if (j == i)continue;
						if (!X[LCi][j] && !X[j][LCi]){
							X[LCi][j] = 1;
							W[LCi]++;
							L[j]++;
						}
					}
				}
			}
		}
	}
	for (int i = 0; i < N; i++){
		P[i] = make_pair(L[i], i);
	}
	sort(P, P + N);
	for (int i = 0; i < N; i++)printf("%d\n", P[i].second+1);
	if (F)printf("0\n");
	else printf("1\n");
	return 0;
}

Measured memory_bytes: 25692
#include <iostream>
#include <algorithm>
#include <queue>
#include <tuple>
#include <stack>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define INF INT_MAX>>1 //要climits#includ

typedef long long ll;

using namespace std;

int main(void){
	int n, m; cin >> n >> m;
	int a[100001];
	fill(a, a+100001, 1);
	int first = 0, last = n;
	for(int i=0; i<m; i++){
		int r, l; cin >> l >> r;
		for(int j=first; j<l; j++) a[j] = 0;
		for(int j=r+1; j<=last; j++) a[j] = 0;
		first = l;
		last = r+1;
	}
	int ans = 0;
	for(int i=1; i<=n; i++){
		ans += a[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

#define FOR(i,m,n) for(int i=(m); i<(n); i++)
#define REP(i,n) for(int i=0; i<(n); i++)
#define RFOR(i,n,m) for(int i=(n);i>=(m); i--)
#define RREP(i,n) for(int i=(n-1); (i)>=0; i--)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << endl
// #define int long long 

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30)-1);
const ll linf = (1LL<<60);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct mint 
{
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int h[110000];
ll dp[110000];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    REP(i,n) cin >> h[i];
    dp[0] = 0;
    FOR(i,1,n)
    {
        dp[i] = linf;
        FOR(j,1,k+1)
        {
            if(i-j>=0)dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j])) ;
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>

//ダイスの構造体
typedef struct{
	int top;
	int bottom;
	int right_side;
	int left_side;
	int front;
	int back;
}Dice;

//関数プロトタイプ宣言
void moving_north(int *top, int *bottom, int *front, int *back);
void moving_east(int *top, int *bottom, int *right_side, int *left_side);
void rotate_right(int *front, int *back, int *right_side, int *left_side);
int dice_comparison(Dice dice[], int index1, int index2);

int main(void)
{
	Dice dice[100];

	//iとjはループ変数、flagは2つ以上のダイスが等しいか表す
	int i, j, count, flag;

	flag = 0;
	scanf("%d", &count);
	for(i = 0; i < count; i++){
		scanf("%d %d %d %d %d %d", 
			  &dice[i].top, &dice[i].front, &dice[i].right_side, &dice[i].left_side, &dice[i].back, &dice[i].bottom);
	}

	for(i = 0; i < count; i++){
		for(j = (i + 1); j < count; j++){
			if(dice_comparison(dice, i, j)){
				flag = 1;
				break;
			}
		}
		//無駄な繰り返しを省略
		if(flag){
			break;
		}
	}

	//1組でも等しければ "No" と出力する
	if(flag){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}

	return 0;
}

//北側に転がす関数
void moving_north(int *top, int *bottom, int *front, int *back)
{
	int temp;

	//各面の値をずらす
	temp = *top;
	*top = *front;
	*front = *bottom;
	*bottom = *back;
	*back = temp;
}

//東側に転がす関数
void moving_east(int *top, int *bottom, int *right_side, int *left_side)
{
	int temp;

	//各面の値をずらす
	temp = *top;
	*top = *left_side;
	*left_side = *bottom;
	*bottom = *right_side;
	*right_side = temp;
}

//上面と下面を軸とし右側へ回転する関数
void rotate_right(int *front, int *back, int *right_side, int *left_side)
{
	int temp;

	//各面の値をずらす
	temp = *front;
	*front = *left_side;
	*left_side = *back;
	*back = *right_side;
	*right_side = temp;
}

//全てのダイスを比較する関数
int dice_comparison(Dice dice[], int index1, int index2)
{
	int i, j;

	for(i = 0; i < (4 * 4); i++){
		for(j = 0; j < 4; j++){
			//2つのダイスの目が全て等しければ1を返す
			if((dice[index1].top == dice[index2].top) && (dice[index1].bottom == dice[index2].bottom) && (dice[index1].front == dice[index2].front) &&
				(dice[index1].back == dice[index2].back) && (dice[index1].right_side == dice[index2].right_side) && (dice[index1].left_side == dice[index2].left_side)){
					return 1;
			}
			//ダイスの向きを変える
			rotate_right(&dice[index2].front, &dice[index2].back, &dice[index2].right_side, &dice[index2].left_side);
		}

		//ダイスを北側に転がし、ダイスが1周する度に東側に転がす
		moving_north(&dice[index2].top, &dice[index2].bottom, &dice[index2].front, &dice[index2].back);
		if((i > 0) && (i % 4 == 0)){
			moving_east(&dice[index2].top, &dice[index2].bottom, &dice[index2].right_side, &dice[index2].left_side);
		}
	}

	return 0;
}


Measured memory_bytes: 2108
#include <stdio.h>
#include <stdlib.h>

struct node{
	int key;
	int left;
	int right;
};

void insert(struct node*, int, int);
void print1(struct node*, int);
void print2(struct node*, int);

int main()
{
	char s[10];
	struct node *t;
	int m;
	int a;

	scanf("%d", &m);
	t=(struct node*)malloc(sizeof(struct node)*m);

	int count=0;
	for(int i=0; i<m; i++){
		scanf("%s", &s);
		if(s[0]=='i'){ scanf("%d", &a); insert(t, count, a); count++; }
		if(s[0]=='p'){
			if(count>0) print1(t, 0);
			printf("\n");
			if(count>0) print2(t, 0);
			printf("\n");
		}
	}
	
	return 0;

}

void print1(struct node *t, int p)
{
	if(t[p].left>=0) print1(t, t[p].left);
	printf(" %d", t[p].key);
	if(t[p].right>=0) print1(t, t[p].right);
}

void print2(struct node *t, int p)
{
	printf(" %d", t[p].key);
	if(t[p].left>=0) print2(t, t[p].left);
	if(t[p].right>=0) print2(t, t[p].right);
}

void insert(struct node *t, int count, int z)
{
	int x=0, y;
	if(count<1) x=-1;

	t[count].key = z;
	t[count].left = -1;
	t[count].right= -1;

	while(x>=0){
		y = x; // ???????¨????
		if(z < t[x].key)
			x = t[x].left; // ?????????????§????
		else 
			x = t[x].right; // ?????????????§????
	}

	if(count<1){}
	else if(z < t[y].key){
		t[y].left = count; // z ??? y ?????????????????????
	}
	else {
		t[y].right = count; // z ??? y ?????????????????????
	}
}

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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int n;
  cin >> n;
  int sum[n];
  REP(i,n) {
    int tmp;
    cin >> tmp;
    if(i) {
      sum[i] = sum[i-1] + tmp;
    } else {
      sum[i] = tmp;
    }
  }
  int ans = LLONG_MAX;
  REP(i,n-1) {
    int tmp = abs(sum[n-1] - 2 * sum[i]);
    ans = min(ans, tmp);
  }
  cout << ans;
  
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

using std::pair;
using std::vector;
using std::string;
 
typedef long long ll;
typedef pair<int, int> pii;

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 100;

int a[N + 5];
int n, m, ans;

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(n);
    for(int i = 1; i <= n; ++i) {
        read(a[i]);
        if(a[i] == a[i-1]) {
            ++ m;
        } else {
            ans += m / 2, m = 1;
        }
    }
    ans += m / 2;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, i, color[4]={0, 0, 0, 0}, res=0;
  cin >> N;
  for (i=0; i<N; i++) {
    char c;
    cin >> c;
    if (c=='P') color[0]=1;
    if (c=='W') color[1]=1;
    if (c=='G') color[2]=1;
    if (c=='Y') color[3]=1;
  }
  for (i=0; i<4; i++) res+=color[i];
  if (res<4) cout << "Three\n";
  else cout << "Four\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int tHp, tAt, aHp, aAt;
  cin >> tHp >> tAt >> aHp >> aAt;
  while (1) {
    aHp-=tAt;
    if (aHp<=0) {
      printf("Yes\n");
      return 0;
    }
    tHp-=aAt;
    if (tHp<=0) {
      printf("No\n");
      return 0;
    }
  }
  
}

Measured memory_bytes: 3648