akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
	//Implement solution here.
			int n = ni();
			long[] a = nal(n + 1);
			long[] b = nal(n);
			long result = 0;
			for(int i = 0; i < n; i++) {
				if(a[i] <= b[i]) {
					result += a[i];
					b[i] -= a[i];
					a[i] = 0;
				}else {
					result += b[i];
					a[i] -= b[i];
					b[i] = 0;
				}
				
				if(a[i + 1] <= b[i]) {
					result += a[i + 1];
					b[i] -= a[i + 1];
					a[i + 1] = 0;					
				} else {
					result += b[i];
					a[i + 1] -= b[i];
					b[i] = 0;
				}				
			}			
			System.out.println(result);
	}

    //Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
        String debugDataPath = System.getenv("DD_PATH");        
        if(debugDataPath != null){
            try{
            	br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
            }catch(Exception e){
                throw new RuntimeException(e);
            }
        } 
        solve();
	}

    //Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
    //Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
    //Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
    //Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
    //Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
    //Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 44724
#include<bits/stdc++.h>
#define ll long long
#define N 100005
using namespace std;
int n,x,a[N];
ll ans;
int main() {
    scanf("%d %d",&n,&x);
    for(int i=1;i<=n;i++) {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<=n;i++) {
        if(a[i]+a[i+1]>x) {
            int m=min(a[i]+a[i+1]-x,a[i+1]);
            ans+=m;
            a[i+1]-=m;
        }
    }
    printf("%lld",ans);
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] nums = new int[N];

        for(int i=0; i<N ;i++){
            nums[i] = scan.nextInt();
        }

        int min = Integer.MAX_VALUE;
        for(int i=-100;i<=100;i++){
            int sumSquare = 0;
            for(int j=0;j<N;j++){
                sumSquare +=  (nums[j] - i) * (nums[j] - i);
            }

            if(sumSquare < min){
                min = sumSquare;
            }
        }

        System.out.println(min);
    }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, x;
  cin >> n >> x;
  
  if(x == 1 || x == 2 * n - 1){
    cout << "No\n";
    return 0;
  }
  
  if(n == 2){
    cout << "Yes\n1\n2\n3\n";
    return 0;
  }
  
  vector<int> a(2 * n + 10, 0), ans(2 * n - 1, 0);
  if(x == 2){
    ans.at(n - 1) = 2;
    a.at(2)++;
    ans.at(n - 2) = 3;
    a.at(3)++;
    ans.at(n) = 1;
    a.at(1)++;
    ans.at(n + 1) = 4;
    a.at(4)++;
  }
  else{
    ans.at(n - 1) = x;
    a.at(x)++;
    ans.at(n - 2) = x - 1;
    a.at(x - 1)++;
    ans.at(n) = x + 1;
    a.at(x + 1)++;
    ans.at(n + 1) = x - 2;
    a.at(x - 2)++;
  }
  
  int now = 1;
  for(int i = 0; i < 2 * n - 1; i++){
    if(ans.at(i) == 0){
      if(a.at(now) == 0){
        ans.at(i) = now;
        a.at(now)++;
        now++;
      }
      else{
        now++;
        i--;
      }
    }
  }
  
  cout << "Yes\n";
  for(int i = 0; i < 2 * n - 1; i++){
    cout << ans.at(i) << '\n';
  }
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    string s;
    cin >> s;
    int ans = 0;
    rep(i, 4) {
        if (s[i]=='+') ans++;
        else ans--;
    }
    
    cout << ans << endl;
    return 0;
}


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

#define ARG4(_1, _2, _3, _4, ...) _4
#define rep(...) ARG4(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define REP(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(...) ARG4(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define RREP(i, a) RFOR(i, 0, a)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (int)(a); --i)
#define ALL(c) (c).begin(), (c).end()
#define TEN(n) ((ll)(1e##n))
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define let const auto
#define USE_T template <typename T>
#define USE_Ti template <typename T = int>
#define USE_TU template <typename T, typename U>

USE_Ti using duo = std::pair<T, T>;
USE_Ti using vec = std::vector<T>;
using ll = long long;
// clang-format off
USE_TU inline bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE_TU inline bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE_Ti inline T in(){T x;std::cin>>x;return x;}
USE_Ti inline vec<T> in(int n){vec<T> v;v.reserve(n);rep(i,n)v.pb(in<T>());return v;}
USE_T inline void in(T*x,int n){rep(i,n)x[i]=in<T>();}
struct IoSetup {
  IoSetup(){
    using namespace std;
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<setprecision(10);
    cerr<<setprecision(10);
  }
} iosetup;
// clang-format on
// }}}
using namespace std;
const int inf = 1001001001;
const ll infll = 1001001001001001001ll;
const int dd[] = {0, 1, 0, -1, 0};

signed main() {
  int H = in(), W = in();
  vec<vec<int>> G(H, vec<int>(W, inf));
  REP(i, H) {
    string s;
    cin >> s;
    REP(j, W) {
      if (s[j] == 'c') G[i][j] = 0;
    }
  }
  REP(i, H) {
    FOR(j, 1, W) { chmin(G[i][j], G[i][j - 1] + 1); }
  }
  REP(i, H) {
    REP(j, W) {
      if (j) cout << " ";
      if (G[i][j] == inf) G[i][j] = -1;
      cout << G[i][j];
    }
    cout << endl;
  }
  return 0;
}

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

int max(int a, int b){
    if(a > b){
        return a;
    }else{
        return b;
    }
}

int main(){
    int N,x;
    scanf("%d", &N);
    if(N%111 == 0){
        printf("%d", N);
    }else{
        x = N/111 + 1;
        x *= 111;
        printf("%d", x);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;

ll combi(ll a,ll b)
{
    ll ret=1;
    for(ll i=a;i>a-b;i--)
    {
        ret*=i;
    }
    for(ll i=b;i>0;i--)
    {
        ret/=i;
    }
    return ret;
}

int main()
{
    string s;
    cin>>s;
    int n=s.length();
    vector<ll > dp(n+1,0);
    ll ans =0;
    int ten=1;
    for(int i=n-1;i>=0;i--)
    {
        dp[i]=(dp[i+1]+(s[i]-'0')*ten%2019)%2019;
        ten*=10;
        ten%=2019;
    }
    vector<int> p(2019,0);
    for(int i=n;i>=0;i--)
    {
        ans+=p[dp[i]];
        p[dp[i]]++;
    }
    cout<<ans;
}


Measured memory_bytes: 5136
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;


public class MyProgram
{	

    public static void Main()
	{
	    int[] n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int N = n[0];
        int R = N;
        int C = 0;
        int T = 0;
        for(int i = 0 ; i <= N; i++)
        {
            C = 0;
            T = i;
            while(T > 0)
            {
                C += T % 6;
                T /= 6;
            }
            
            T =  N - i;
            
            while(T > 0)
            {
                C += T % 9;
                T /= 9;
            }
            
            if(R > C) R = C;
            
        }
        
        Console.WriteLine(R);

	}
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N, K, x = 1, a, b;
 cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
    a = x * 2;
    b = x + K;
    
    if (a <= b) {
      x = a;
    }
    
    else {
      x = b;
    }
  }
  
  cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ge(a, b) get<(b)>((a))
#define SZ(x) (x).size()
#define ft front()
#define bk back()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
    if (DEBUG) std::cerr
const int xd[4] = {0, 1, 0, -1}, yd[4] = {1, 0, -1, 0};
template <typename t>
bool ckmin(t& a, const t& b) {
    return a > b ? a = b, true : false;
}
template <typename t>
bool ckmax(t& a, const t& b) {
    return a < b ? a = b, true : false;
}

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

    int n;
    string s;
    cin >> n >> s;
    vi sR(n + 1, 0), sG(n + 1, 0), sB(n + 1, 0);
    R0F (i, n - 1) {
        sR[i] = sR[i + 1] + (s[i] == 'R');
        sG[i] = sG[i + 1] + (s[i] == 'G');
        sB[i] = sB[i + 1] + (s[i] == 'B');
    }
    // dout << "sR:" << endl;
    // for (int i : sR) dout << i << endl;
    // dout << "sG:" << endl;
    // for (int i : sG) dout << i << endl;
    // dout << "sB" << endl;
    // for (int i : sB) dout << i << endl;
    ll sum = 0;
    F0R (m, n) {
        ll last = sum;
        F0R (f, m) {
            if (s[f] == s[m]) continue;
            ll lastl = sum;
            char l = '?';
            for (char c : {'R', 'G', 'B'}) {
                if (c != s[f] && c != s[m]) {
                    l = c;
                    break;
                }
            }
            dout << "  " << f << ": " << l << endl;
            vi* suf = &sR;
            if (l == 'G') suf = &sG;
            if (l == 'B') suf = &sB;
            assert(l != '?');
            sum += (*suf)[m + 1];
            if (m + (m - f) < n) {
                sum -= s[m + (m - f)] == l;
                // if (s[m + (m - f)] == l) {
                //     dout << "huu?" << endl;
                //     --sum;
                // }
            }
            dout << sum - lastl << endl;
        }
        dout << m << ": " << sum - last << endl;
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3712
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 998244353

def main():
    N, A, B, K = map(int, input().split())

    a = [None] * (N+1)
    inva = [None] * (N+1)
    a[0] = 1
    
    for i in range(1, N+1):
        a[i] = i * a[i-1] % m
    
    inva[N] = pow(a[N],m-2,m)
    for i in range(N):
        inva[N-i-1] = inva[N-i] * (N-i) % m

    ans = 0
    for i in range(N+1):
        if (K-A*i) % B == 0:
            j = (K-A*i)//B
            if 0 <= j <= N:
                tmp1 = (a[N] * inva[i] % m) * inva[N-i] % m
                tmp2 = (a[N] * inva[j] % m) * inva[N-j] % m
                ans += tmp1 * tmp2 % m
                ans %= m
    print(ans)

if __name__ == "__main__":
    main()


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

#define FOR(a,b,c) for (int a=(b);a<(c);++a)
#define REP(i,n) FOR(i,0,n)
#define ll long long
#define pii pair<int,int>
#define x first
#define y second
#define pb push_back
#define lf double

using namespace std;

const int MAX = (int)1e6 + 5;

int main(){
	int n;
	scanf ("%d",&n);
	printf ("%.6lf\n",2*n*3.141592653);
	
	
	return 0;
}


Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int a,b,h; cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
    return 0;
}


Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import copy
import math
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def zz(): return list(map(int, sys.stdin.readline().split()))


def z(): return int(sys.stdin.readline())


def S(): return sys.stdin.readline()[:-1]


def C(line): return [sys.stdin.readline() for _ in range(line)]


N, M = zz()
A = [S() for i in range(N)]
B = [S() for i in range(M)]


def check(lis_a, lis_b):
    for a, b in zip(lis_a, lis_b):
        # print(a, b)
        if (a != b):
            return False
    return True


for i in range(N - M+1):
    for j in range(N-M+1):
        ok = 0
        for line in range(M):
            # print(A[i+line][j:j+M], B[line])
            if (A[i+line][j:j+M] != B[line]):
                break
            else:
                ok += 1
        if (ok == M):
            print('Yes')
            exit()
print('No')


Measured memory_bytes: 70088
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int N=100010;
int compare_int(const void *a, const void *b)
{
    return *(long long int*)b - *(long long int*)a;
}
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}

int main(){
	int n, m;
//	long long int  a[N];
//	int b[N]=0;
	cin>>n>>m;
	int ans;
	ans=n-m+1;


	cout<<ans<<endl;









//	qsort(b, 5, sizeof(long long int), compare_int);
/*	rep(i, 5){
		if((b[i]-1)%10<k){
			k=b[i]%10;
		}
		ans=ans+(b[i]+9)/10;
	}
	anss=ans*10+k-10;
	if(k==0){
		anss=anss+10;
	}
	cout<<anss<<endl;




/*	qsort(b, 5, sizeof(int), compare_int);
	if(b[4]-b[0]>k){
		printf(":(\n");
	}
	else{
		printf("Yay!\n");
	}
		rep(i, n){
		ans=c;
		rep(j, m){
			cin>>imp;
			ans=ans+imp*b[j];
		}
		if(ans>0){
			anss++;
		}
	}
	cout<<anss<<endl;
}*/
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n, c;
int d[30][30];
int a[500][500];
int cnt[3][30];
int iwakan[3][30];

signed main() {
	int i, j, k;
	
	cin >> n >> c;
	rep(i, c) rep(j, c) cin >> d[i][j];
	rep(i, n) rep(j, n) { cin >> a[i][j]; a[i][j]--; }
	
	rep(i, n) {
		rep(j, n) {
			int type = (i + j) % 3;
			cnt[type][a[i][j]]++;
		}
	}
	
	rep(i, 3) {
		rep(j, c) {	//色jで合わせる
			rep(k, c) {
				iwakan[i][j] += cnt[i][k] * d[k][j];
			}
		}
	}
	
	int ans = 1e+15;
	rep(i, c) {
		rep(j, c) {
			rep(k, c) {
				if (i == j) continue;
				if (j == k) continue;
				if (k == i) continue;
				int ssum = iwakan[0][i] + iwakan[1][j] + iwakan[2][k];
				ans = min(ans, ssum);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2176
N,M = gets.split.map(&:to_i)
path = Hash.new{|h,k| h[k] = Array.new}
M.times do
  a,b = gets.split.map(&:to_i)
  path[a] << b
  path[b] << a
end

queue = [1]
mark = {1 => 0}
loop do
  break if queue == []
  i = queue.shift

  (path[i]).each do |j|
    next unless mark[j].nil?
    mark[j] = i
    queue << j
  end
end

puts "Yes"
(2..N).each{|i| puts mark[i]}

Measured memory_bytes: 40040
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
     ll int i,n,t,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d;

     cin>>n;
     ll int ara[n];
     for(i=0;i<n;i++){
        cin>>ara[i];
        p=ara[i];l=0;
        while(p%2==0){
           sum++;
           p/=2;
        }
     }
     cout<<sum<<endl;

     return EXIT_SUCCESS;
}



Measured memory_bytes: 3684
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main //implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        long mod=1000000007;
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        
        int n=sc.nextInt();
        char c[]=sc.getCharSet();
        char x=c[0];
        int a=1;
        for (int i = 1; i < c.length; i++) {
			if(x!=c[i]) {
				a++;
				x=c[i];
			}
		}

        out.println(a);
     	out.flush();
    }
    
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}


class P {
	int x, y, d;
	P(int  x, int y, int d) {
	  this.x=x;
	  this.y=y;
	  this.d=d;
	}
}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//        return p.a-a;//des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() throws IOException{
        return this.nextString().toCharArray();
    }    
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 24916
import scala.io.StdIn.readLine
import Math.sqrt

object Main {

  def main(args: Array[String]) = {
      val n = readLine.split(" ").map(_.toInt)
      var cnt = 0
      for(i <- n(0) to n(1))
          if(n(2) % i == 0)
              cnt += 1
      println(cnt)
  }
}

Measured memory_bytes: 43828
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    ll n, m;
    cin >> n >> m;
    vector< pair<ll, ll> > V(n, make_pair(0LL,0LL));
    REP(i, n) cin >> V[i].first >> V[i].second;
    sort(ALL(V));
    // REP(i,n) cout <<i << " "<< V[i].first << " " << V[i].second << endl;
    ll ans=0;
    REP(i,n){
        // cout << i << "にいて，もう " << m << "個かいたい．お金はまだ"<<ans << endl;
        if(m >= V[i].second ) {
            ans += V[i].first * V[i].second;
            m -= V[i].second;
        }
        else {
            ans+= V[i].first * m;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll D;
    cin >> D;
    int c[26];
    for (ll i = 0; i < 26; i++) {
        cin >> c[i];
    }
    int s[365][26];
    for (ll i = 0; i < D; i++) {
        for (ll j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }

    int t[365];
    for (ll i = 0; i < D; i++) {
        cin >> t[i];
        --t[i];
    }

    int last[26] = {};
    int ans = 0;
    for (ll i = 0; i < D; i++) {
        ans += s[i][t[i]];
        last[t[i]] = i + 1;
        for (ll j = 0; j < 26; j++) {
            ans -= c[j] * (i + 1 - last[j]);
        }
        cout << ans << "\n";
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000000000000000
#define mod 1000000007
#define IO                  \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);// freopen("output.txt","w",stdout);freopen("input.txt","r",stdin);
using namespace std;	
int main()
{
	IO
	int n,k;
	cin>>n>>k;
	ll arr[n];
	for(int i=0;i<n;i++)cin>>arr[i];
	ll dp[n];
	for(int i=0;i<n;i++)dp[i]=INF;
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		for(int ii=1;ii<=k&&ii+i<n;ii++)
		{
			dp[i+ii]=min(dp[i+ii],dp[i]+abs(arr[i]-arr[i+ii]));
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

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

int main()
{
    int n,W;
    cin>>n>>W;
    
    int val[n],wt[n];
    int tot_val=0;
    
    for(int i=0;i<n;i++)
    {
        cin>>wt[i]>>val[i];
        tot_val+=val[i];
    }
    
    int dp[n+1][tot_val+1];
    
    for(int i=0;i<=n;i++)
        for(int j=0;j<=tot_val;j++)
            dp[i][j]=1000000001;
    
    for(int i=0;i<=n;i++)
        dp[i][0]=0;
        
    for(int i=1;i<=tot_val;i++)
        dp[0][i]=1000000001;
        
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=tot_val;j++)
        {
            if(j-val[i-1]>=0)
                dp[i][j]=min(wt[i-1]+dp[i-1][j-val[i-1]],dp[i-1][j]);
            else
                dp[i][j]=dp[i-1][j];
        }
    }
    
    for(int i=tot_val;i>=0;i--)
        if(dp[n][i]<=W)
        {
            cout<<i;
            break;
        }
    
    return 0;
}

Measured memory_bytes: 42868
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  bool b=false;
  if(n%10==9)b=true;
  n/=10;
  if(n==9)b=true;
  if(b)cout<<"Yes";
  else cout<<"No";
  return 0;
}

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

int main(){
	int N, K; cin>>N>>K;
	vector<int> A(N); rep(i, N) cin>>A[i];
	int ng = 0, ok = 1e9; // (ng,ok] = (l,r]
	while(ok - ng > 1){
		auto f = [&](int m){
			int c = 0;
			rep(i, N) c += (A[i] - 1) / m;
			return c <= K;
		};
		int m = (ok + ng) / 2;
		if(f(m)) ok = m; else ng = m;
	}
	cout<< ok <<endl;
}


Measured memory_bytes: 4052
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
int const MAXN=110, MAXK=110000;
int n, k, v[MAXN];
bool dp[MAXK];
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>v[i];
	for(int i=1;i<=k;i++){
		bool possible=false;
		for(int j=0;j<n && i-v[j]>=0 && !dp[i];j++)
			if(!dp[i-v[j]])
				dp[i]=true;
	}
	cout<<(dp[k]?"First":"Second");
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL

using ll = long long;
template<typename T>
using vec = vector<T>;
using P = pair<ll, ll>;

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
	fill((T *)array, (T *)(array + N), val);
}

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


int main(){
	IOS;
	int n;
	ll sum0 = 0, sum1 = 0;
	cin >> n;
	vec<ll> a(n),t(n),s(n);
	REP(i,n)cin >> a[i];
	sort(ALL(a));
	REP(i,n){
		if(i == 0){
			s[i] = -1;
			t[i] = 1;
		}
		else if(i == n - 1){
			if(i % 2 == 0){
				s[i] = -1;
				t[i] = 1;
			}
			else{
				s[i] = 1;
				t[i] = -1;
			}
		}
		else if(i % 2 == 0){
			s[i] = -2;
			t[i] = 2;
		}
		else {
			s[i] = 2;
			t[i] = -2;
		}
	}
	sort(ALL(s));
	sort(ALL(t));
	REP(i,n){
		sum0 += a[i] * s[i];
		sum1 += a[i] * t[i];
	}
	dump(max(sum0,sum1));
}

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

using namespace std;

pair <int, int> p[100005];

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

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i].first;
        p[i].second = i;
    }

    sort(p + 1, p + n + 1);

    for (int i = 1; i <= n; i++) {
        cout << p[i].second << " ";
    }
    return 0;
}



Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
using lint=long long;
using namespace std;

int main()
{
	lint N,W;
	lint w[110]={},v[110]={};
	lint dp[110][100010]={};
	
	cin >> N >> W;
	for(int i=1;i<=N;i++)
		cin >> w[i] >> v[i];
	
	for(int i=0;i<110;i++)
		for(int j=0;j<100010;j++)
			dp[i][j]=1e9+7;
	for(int i=0;i<=N;i++)
		dp[i][0]=0;
	
	for(int i=1;i<=N;i++)
	{
		for(int j=0;j<=100000;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(j-v[i]>=0)
				dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
		}
	}
	
	for(int i=100000;i>=0;i--)
	{
		if(dp[N][i]<=W)
		{
			cout << i << endl; 
			break;
		}
	}
	return 0;
}

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

const ll INF = 1001001001;

const double PI=3.141592653;

const ll sosu = 1000000007;//大きい素数

//提出のときに言語がc＋＋似合っていることを確認する

ll f(ll x){
  if(x==1) return 1;
  return 2*f(x/2)+1;
}
int main(){
  int x,y,z;
  cin>>x>>y>>z;
  x=x-z;
  int ans=0;
  ans+=x/(y+z);
  

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



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int an, bn, m;
    cin >> an >> bn >> m;
    vector<int> a(an), b(bn);
    for(int i=0; i<an; ++i)
        cin >> a[i];
    for(int i=0; i<bn; ++i)
        cin >> b[i];

    int ans = *min_element(a.begin(), a.end()) +
              *min_element(b.begin(), b.end());
    for(int i=0; i<m; ++i){
        int x, y, c;
        cin >> x >> y >> c;
        -- x;
        -- y;
        ans = min(ans, a[x] + b[y] - c);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
n,c,k = map(int,input().split())
T = sorted([int(input()) for _ in range(n)])
#print(T)
cnt = 0
i = 0
while i < n:
    start = i
    m = 1
    cnt += 1
    while i < n:
        if i - start < c and T[i] - T[start] <= k:
            i += 1
        else:
            break
print(cnt)


Measured memory_bytes: 8280
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
    
    int a,b;
    cin>>a>>b;
    
    if(b>=a){
        cout<<a<<endl;
    }else{
        cout<<a-1<<endl;
    }
  
    
    return 0;
   
}






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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskI solver = new TaskI();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskI {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            if (n == 2) {
                out.println(-1);
                return;
            }
            int[][] res = solve(n);
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n - 1; j++) {
                    if (j != 0) out.print(" ");
                    out.print(res[i][j]);
                }
                out.println();
            }
        }

        public static int[][] solve(int size) {
            if (size == 3) {
                return new int[][]{
                        {2, 3},
                        {3, 1},
                        {1, 2},
                };
            }
            int[][] mat = new int[size][size - 1];
            int[][] sub = solve(size - 1);
            for (int i = 0; i < size - 1; i++) {
                System.arraycopy(sub[i], 0, mat[i], 0, sub[i].length);
            }
            for (int i = 0; i < size - 1; i++) {
                mat[size - 1][i] = i + 2;
            }

            for (int i = 0; i < size - 1; i++) {
                mat[i][size - 2] = size;
            }
            mat[size - 1][size - 2] = 1;
            int t = mat[0][size - 2];
            mat[0][size - 2] = mat[0][size - 3];
            mat[0][size - 3] = t;
            return mat;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 10836
a = Array.new(gets.to_i) {|i| i+1}
list = []
gets.to_i.times{ list << gets.split(",").map(&:to_i).map{|i| i-1} }
list.each { |i|
	a[i[0]], a[i[1]] = a[i[1]], a[i[0]]
}
a.each{|n| p n}

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

int main()
{
	int N, W;
	cin >> N >> W;
	vector<int> dp(W + 1, 0);
	for (int i = 0, v, w; i < N; i++) {
		cin >> v >> w;
		for (int j = W; j >= w; j--) {
			if (dp[j] < dp[j - w] + v) {
				dp[j] = dp[j - w] + v;
			}
		}
	}
	cout << dp[W] << endl;
	return 0;
}

Measured memory_bytes: 3136
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
int main()
{
	long long N, M, an = 0;
	cin >> N >> M;
	if (N >= M / 2) {
		an = M / 2;
		M = 0;
	}
	else {
		an = N;
		M -= N * 2;
	}
	an += M / 4;
	cout << an;
}

Measured memory_bytes: 256
if __name__ == '__main__':

	while True:
		try:
			n = int(input())

			if n == 0:
				break

			A = []

			for _ in range(n):
				cmd = input().split()
				A.append((cmd.count("0"),cmd.count("1"),cmd.count("2"),cmd[0]))

			B = sorted(A,key=lambda x:(-x[0],x[1],x[2]))

			for y in B:
				print(y[3])

		except EOFError:
			break



Measured memory_bytes: 5604
#ABC131-D

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=[LI() for _ in range(n)]

  l=sorted(l,key=lambda x:x[1])

  t=0
  for x in l:
    a,b=x
    t+=a
    if t>b:
      return 'No'

  return 'Yes'

print(main())


Measured memory_bytes: 57652
import java.util.*;
 
class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int x = sc.nextInt();
    int[] m = new int[n];
    int min = Integer.MAX_VALUE;
    for(int i=0; i<n; i++){
      m[i] = sc.nextInt();
      x -= m[i];
      if(min > m[i]){
        min = m[i];
      }
    }
    int count = m.length;
    while(x >= 0){
      x -= min;
      count++;
    }
    System.out.println(count-1);

    sc.close();
  }
}


Measured memory_bytes: 21972
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	string sa,sb;
	cin>>sa>>sb;
	n=sa.size();
	b=0;
	for(i=0;i<n;i++){
		if(sa[i]==sb[i])b++;
	}
	cout<<b<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n;
int main(){
    double m; 
    cin >> n;
    cin >> m;
    vector<double> a(n,0.0);
    double border=0.0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        border += double(a[i]);
    }
    sort(a.begin(), a.end(), greater<double>());
    border = border/(4.0*m);
    bool flag=true;
    for(int i=0; i<int(m); i++){
        if(a[i] < border){
            flag = false;
            break;
        }
    }
    cout << (flag ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n, k;
  cin >> n >> k;

  ll ans = 1;
  while (n > pow(k, ans)) ans++;
  if (pow(k, ans) == n) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
t_vote = 1
a_vote = 1
count = 0
while count < n:
  t, a = map(int, input().split(" "))
  if t_vote % t > 0:
    magni_t = t_vote // t + 1
  else:
    magni_t = t_vote // t
  if a_vote % a > 0:
    magni_a = a_vote // a + 1
  else:
    magni_a = a_vote // a
  magni = max(magni_t, magni_a)
  t_vote = magni * t
  a_vote = magni * a
  count += 1
print(t_vote + a_vote)

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

#define int long long
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()

#define fast ios::sync_with_stdio(0); cin.tie(0)
#define print(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1> void __f(const char* name, Arg1&& arg1){
    cout << name << ": " << arg1 << '\n';
}

template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

int32_t main(){
    
    // fast;
    string s,t; cin >> s >> t;

    vector<int> index[26];

    for(int i=0;i<s.size();i++){
        index[s[i]-'a'].pb(i+1);
    }

    int prev = 0 ,ans = 0,c=0;

    for(int i=0;i<t.size();i++){
        if(index[t[i]-'a'].size()==0){
            cout << -1;
            return 0;
        }
        auto idx = upper_bound(all(index[t[i]-'a']),prev);
        if(idx==index[t[i]-'a'].end()){
            c++;
            prev = index[t[i]-'a'][0];
            ans=c*s.size()+prev;
        }else{
            prev = *idx;
            ans=c*s.size()+prev;
        }
    }

    cout << ans;
 
 
    return 0;
} 

Measured memory_bytes: 1724
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repi(i, a, b) for (long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

int main()
{
    int a, b, c, ans;
    cin >> a >> b >> c;
    ans = (a - b) % c;
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n, q;
  cin >> n;
  vector<int> a(n + 1);
  a[n] = 1e9 + 1;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  cin >> q;
  int k[q];
  for(int i = 0; i < q; i++){
    cin >> k[i];
  }
  for(int i : k){
    cout << lower_bound(a.begin(), a.end(), i) - a.begin() << endl;
  }
  return 0;
}


Measured memory_bytes: 3888
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - equeue
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 50;

/* typedef */

/* global variables */

int vs[MAX_N];
int lvs[MAX_N + 1][MAX_N], rvs[MAX_N + 1][MAX_N];
int lsums[MAX_N + 1], rsums[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  for (int i = 0; i < n; i++) scanf("%d", vs + i);

  for (int i = 0; i < n; i++) {
    int &lv = vs[i];
    lsums[i + 1] = lsums[i] + lv;
    int lj = lower_bound(lvs[i], lvs[i] + i, lv) - lvs[i];
    copy(lvs[i], lvs[i] + lj, lvs[i + 1]);
    lvs[i + 1][lj] = lv;
    copy(lvs[i] + lj, lvs[i] + i, lvs[i + 1] + lj + 1);

    int &rv = vs[n - 1 - i];
    rsums[i + 1] = rsums[i] + rv;
    int rj = lower_bound(rvs[i], rvs[i] + i, rv) - rvs[i];
    copy(rvs[i], rvs[i] + rj, rvs[i + 1]);
    rvs[i + 1][rj] = rv;
    copy(rvs[i] + rj, rvs[i] + i, rvs[i + 1] + rj + 1);
  }

  int maxsum = 0, maxi = min(n, k);
  for (int i = 1; i <= maxi; i++) {
    for (int li = 0, ri = i; ri >= 0; li++, ri--) {
      int sum = lsums[li] + rsums[ri];
      int lp = 0, rp = 0;
      for (int j = k - i; j > 0; j--) {
	int lv = (lp < li) ? lvs[li][lp] : 0;
	int rv = (rp < ri) ? rvs[ri][rp] : 0;
	if (min(lv, rv) >= 0) break;

	if (lv < rv) sum -= lv, lp++;
	else sum -= rv, rp++;
      }

      if (maxsum < sum) maxsum = sum;
    }
  }

  printf("%d\n", maxsum);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define INF (1<<29)
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=1e5;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int a,b,c,d;
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    
    cin>>a>>b>>c>>d;
    
    if(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d))cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10001
#define NIL -1

typedef struct{
  int parent;
  int left;
  int right;
}node;
node tree[MAX];


void Preorder(int u){
  if(u == NIL)return;
  printf(" %d",u);
  Preorder(tree[u].left);
  Preorder(tree[u].right);
}

void Inorder(int u){
  if(u == NIL)return;
  Inorder(tree[u].left);
  printf(" %d",u);
  Inorder(tree[u].right);
}

void Postorder(int u){
  if(u == NIL)return;
  Postorder(tree[u].left); 
  Postorder(tree[u].right);
  printf(" %d",u);
}

int main(){
  int i,v,left,right,r,root,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    tree[i].parent = NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&left,&right);
    tree[v].left = left;
    tree[v].right = right;
    if(left != NIL)tree[left].parent = v;
    if(right != NIL)tree[right].parent = v;
  }

  for(i = 0;i<n;i++)if(tree[i].parent == NIL)root = i;
  printf("Preorder\n");
  Preorder(root);
  printf("\nInorder\n");
  Inorder(root);
  printf("\nPostorder\n");
  Postorder(root);
  printf("\n");
  return 0;
}



Measured memory_bytes: 2104
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    cin >> N;

    if (N == 0) {
        cout << 0 << endl;
        return 0;
    }

    string ans;

    map<ll, bool> mp;

    while (N != 0) {
        if (N > 0) {
            ll b = 1;
            ll add = 4;
            ll num = 0;
            while (b < N) {
                b += add;
                num += 2;
                add *= 4;
            }
            mp[num] = true;
            N -= pow(-2, num);
        } else {
            ll b = -2;
            ll num = 1;
            ll add = -8;
            while (b > N) {
                b += add;
                num += 2;
                add *= 4;
            }
            mp[num] = true;
            N -= pow(-2, num);
        }
    }

    auto max_digit = max_element(mp.begin(), mp.end());
    for (ll i = max_digit->first; i >= 0; i--) {
        if (mp[i]) {
            cout << "1";
        } else {
            cout << "0";
        }
    }

    cout << endl;
}

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

using namespace std;

int main() {
  int n,a,b,time=0;
  bool flag = true;
  cin >> n;
  vector<pair<int, int> > pairs(n);
  for(int i=0;i<n;i++){
      cin >> a>>b;
      pairs[i] = make_pair(b,a);

  }
  sort(pairs.begin(),pairs.end());
  for(int i=0;i<n;i++){
      time += pairs[i].second;
    //   cout << "first" << pairs[i].first << "," << pairs[i].second<<"time" << time <<endl;
      if(pairs[i].first<time){
          flag = false;
          break;
      }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;

  //cout << pairs << endl;

}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int n, m, q, A[1001][1001], i, j;
	string str1, str2;
	cin >> q;

	while (q--)
	{
		cin >> str1 >> str2;
		n = str1.size();
		m = str2.size();
		int maxv = 0;

		for (i = 1; i <= n; i++)A[i][0] = 0;
		for (i = 1; i <= m; i++)A[0][i] = 0;

		for(i=1;i<=n;i++)
			for (j = 1; j <= m; j++)
			{
				if (str1[i-1] == str2[j-1])
					A[i][j] = A[i - 1][j - 1] + 1;
				else A[i][j] = max(A[i - 1][j], A[i][j - 1]);
			}
		cout << A[n][m] << endl;
	}
	return 0;
}


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

int selectionSort(int A[], int N){
    int i, j, minj;
    int sw = 0;
    for(i = 0; i < N; i++){
        minj = i;
        for(int j = i; j < N; j++){
            if(A[j] < A[minj]) minj = j;
        }
        swap(A[i], A[minj]);
        if(i != minj) sw++;
    }
    return sw;
}
int main(){
    int A[100], N, i, sw;
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    sw = selectionSort(A, N);
    for(int i = 0; i < N; i++){
        if(i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;
}


Measured memory_bytes: 3116
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> pii;

int main()
{
  int m,n;
  char u[300][15]={};
  char t[300][15]={};
  int i,j;

  cin>>n;
  rep(i,n)
    cin>>u[i];
  cin>>m;
  bool ans=false;//close
  rep(i,m){
    cin>>t[i];
    rep(j,n)
      if(strcmp(t[i],u[j])==0){
	if(ans){
	  ans=false;
	  printf("Closed by ");
	}else{
	  ans=true;
	  printf("Opened by ");
	}
	cout<<t[i]<<endl;
	goto END;
      }
    printf("Unknown %s\n",t[i]);
  END:;
  }
}

Measured memory_bytes: 3196
#include <stdio.h>
 
int main(void) {
  int n;
  int ac,wa,tle,re;
  ac = wa = tle = re = 0;
  int i;
  
  scanf("%d", &n);
  for (i=0; i<n; i++) {
    char str[10];
    scanf("%s",str);
    switch(str[0]) {
      case 'A':ac++;break;
      case 'W':wa++;break;
      case 'T':tle++;break;
      case 'R':re++;break;
    }
  }
  printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d",ac,wa,tle,re);
  return 0;
}

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

int main() {
  int64_t h;
  cin >> h;
  
  int count = 0;
  
  while (h / 2 > 0) {
    h /= 2;
    count++;
  }
  
  int64_t sum = 0, pro = 1;
  for (int i = 0; i <= count; i++) {
    sum += pro;
    pro *= 2;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256