akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>

using namespace std;

int main(void)
{
	int N, K;
	string S;

	cin >> N >> K;
	cin >> S;

	vector<int> switch_index;	// S[i-1]とS[i]とで値が切り替わる場合、switch_indexにiを追加する

	// 1回の指示 → 人の切り替わりを2箇所まで潰せる(1110011 を 11111111)
	// 1回の変換で潰せる切り替わり場所は最大2K
	// 開始地点が0の場合、まずそこを切り替えないとなので、潰せる切り替え場所が1つ減る(どこかで00011..となっているものを11111..にしないとなので)
	
	switch_index.push_back(0);
	for (int i = 1; i < N; i++) {
		if (S[i - 1] != S[i]) {
			switch_index.push_back(i);
		}
	}
	switch_index.push_back(N);
	
	/*
	for (int i = 0; i < switch_index.size(); i++) {
		cout << switch_index[i] << endl;
	}
	*/

	int max_length = 0;
	// 切り替わり箇所の数だけ候補がある
	for (int i = 0; i < switch_index.size(); i++) {
		int first = i;
		int last;
		if (S[switch_index[i]] == '1') {
			last = first + 2 * K + 1;
		}
		else {
			last = first + 2 * K;
		}

		if (last >= switch_index.size()) {
			last = switch_index.size() - 1;
		}

		int length = switch_index[last] - switch_index[first];
		//cout << "length = " << length << endl;
		if (length > max_length) {
			max_length = length;
		}
	}
	cout << max_length << endl;

	return 0;
}

Measured memory_bytes: 1020
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
#define M 1050000
#define L 14
#define NIL (-1)

char H[M][L];
int getChar(char ch){
	switch(ch){
		case 'A':return 1;break;
		case 'C':return 2;break;
		case 'G':return 3;break;
		case 'T':return 4;break;
		default :return 0;
	}
}
long long getKey(char str[]){
	long long sum=0,p=1,i;
	for(i=0;i<strlen(str);i++){
		sum+=p*(getChar(str[i]));
		p*=5;
	}
	return sum;
}
int h1(int key){
	return key%M;
}
int h2(int key){
	return 1+(key%(M-1));
}
int find(char str[]){
	long long key,i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)return 1;
		else if(strlen(H[h])==0)return 0;
	}
	return 0;
}
int insert(char str[]){
	long long key,i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)return 1;
		else if(strlen(H[h])==0){
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}

int main(){
	int i,n,h;
	char str[L],com[9];
	for(i=0;i<M;i++)H[i][0]='\0';
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %s",com,str);
		if(com[0]=='i'){
			insert(str);
		}else{
			if(find(str)){
				printf("yes\n");
			}else{
				printf("no\n");
			}
		}
	}
	return 0;
}


Measured memory_bytes: 17496
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
int main(){
    int A,B,K;
    SCD3(A,B,K);
    int turn = 1;
    REP(i,K){
        if (turn == 1){
            if (A % 2 == 1) A--;
            A = A / 2;
            B = A + B;
        }else{
            if (B % 2 == 1) B--;
            B = B / 2;
            A = A + B;
        }
        turn *= -1;
    }

    printf("%d %d\n",A,B);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>

using namespace std;
#define mod 1000000007
#define ll long long 


ll N, W, w[109], v[109];

ll dp[109][100009];


ll solve(int id, int wt) {
    if(id == N)
        return 0;

    if(dp[id][wt] != -1)
        return dp[id][wt];

    ll ans = solve(id + 1, wt);

    if(w[id] + wt <= W)
        ans = max(ans, solve(id + 1, wt + w[id]) + v[id]);

    return dp[id][wt] = ans;
}
 
 
int main() {
    memset(dp, -1, sizeof(dp));

    cin>>N>>W;

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

    cout<<solve(0, 0)<<endl;
 
}


Measured memory_bytes: 85376
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD = 1000000007
#define INF (1e9)
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;


int main()
{
    ll A, B;
    cin >> A >> B;
    print(max(A+B, max(A-B, A*B)));
    return 0;
}


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

int main() {
  int h, w;
  cin >> h >> w;
  char a[h][w];
  bool h_output[h] = {false}, w_output[w] = {false};
  int i, j;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      cin >> a[i][j];
      if (a[i][j] == '#') {
        h_output[i] = true;
        w_output[j] = true;
      }
    }
  }
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      if (h_output[i] && w_output[j]) {
        cout << a[i][j];
      }
    }
    if (h_output[i]) {
      cout << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         998244353
#define mode        1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323

void solve()
{
       ll x,y;
       cin>>x>>y;
       if(x<0 && y>0)
       {
              if(abs(x)>=abs(y))
                    {
                           cout<<1+abs(x)-abs(y)<<endl;
                           exit(0);
                    }
              else if(abs(x)<abs(y)) { cout<<1+abs(y)-abs(x)<<endl; exit(0); }
       }
       else if(y<0 && x>0  && (abs(y)>=abs(x)))
       {
              cout<<1+abs(y)-abs(x)<<endl;
              exit(0);
       }
       if(y>=x) cout<<y-x<<endl;
       else
       {
             if(x==0 && y==0) cout<<0<<endl;
             else if(x+y==0) cout<<1<<endl;
             else if(x==0)
             {
                    cout<<1+abs(y)<<endl;
             }
             else if(y==0) cout<<1+abs(x)<<endl;
             else if(x>0 && y>0)
             {
                    cout<<2+x-y<<endl;
             }
             else if(x>0 && y<0)
             {
                    if(abs(x)>abs(y))
                    {
                           cout<<1+abs(x)-abs(y)<<endl;
                    }
                    else
                    {
                           cout<<1+abs(y)-abs(x)<<endl;
                    }
             }
             else if(x<0 && y<0)
             {
                    cout<<2+abs(y)-abs(x);
             }
       }
}



int main()
{
    speed_up
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int n,i=0;
    scanf("%d",&n);
    int m[n];
    while(n>i){
        scanf("%d",&m[i]);
        i++;
    }
    i=n-1;
    while(i>=0){
        printf("%d",m[i]);
        if(i>0)printf(" ");
        else if(i==0)printf("\n");
        i--;
    }
    return 0;
}

Measured memory_bytes: 2740
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

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

    vector<ll> sum(n+1, 0);
    for(int i=0; i<n; i++){
        sum[i+1] = sum[i] + a[i];
    }

    ll ans = INF;
    for(int i=1; i<n; i++){
        ll r = sum[n] - sum[i];
        ll l = sum[i];
        // cout << l << " " << r << endl;
        chmin(ans, abs(r - l));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
const int N = 100001;
int n;
string s;
int main(){
    cin>>n;
    cout<<n+n*n+n*n*n;
}



Measured memory_bytes: 3188
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: June 11 2019
 * 
 */

#include <bits/stdc++.h>

#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define ef else if
#define wh while
#define el else
#define ivv(x) int x; cin>>x
#define lv(x) bint x; cin>>x
#define sv(x) string x; cin>>x
#define cv(x) char x; cin>>x
#define fv(x) float x; cin>>x
#define dv(x) double x; cin>>x
#define endl '\n'
using namespace std;




auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 

    ivv(n);
    vi v(n);
    iv(v);
    sort(all(v));
    int sum=0;
    for(int i=0; i<n-1;++i){
        sum+=v[i];
    }
    puts((sum>v.back())?"Yes":"No");


    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("input","r",stdin);
    freopen("output","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
n,k=map(int, input().split())
A=[((int(i)*(int(i)+1))/2)/int(i) for i in input().split()]
al = list(accumulate(A))
ans = al[k-1]
for i in range(k, n):ans=max(ans, al[i]-al[i-k])
print(ans)

Measured memory_bytes: 23616
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: u64,
    }
    fn s(n: u64) -> u64 {
        if n < 10 {
            n
        } else {
            n % 10 + s(n / 10)
        }
    }
    let ans = if n % s(n) == 0 { "Yes" } else { "No" };
    println!("{}", ans);
}


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

int isEmpty(char);
int isFull();
void push(int);
int pop();

int top=0,B[150];
char A[10];

int main(){
  int i,a,b,temp;

  while(scanf("%s",A) != EOF){
    if(A[0] == '+'){
      a = pop();
      b = pop();
      temp = a + b;
      push(temp);
    }else if(A[0] == '-'){
      a = pop();
      b = pop();
      temp = b - a;
      push(temp);
    }else if(A[0] == '*'){
      a = pop();
      b = pop();
      temp = a * b;
      push(temp);
    }else{
      temp = atoi(A);
      push(temp);
    }
  }
  
  printf("%d\n",pop());
  return 0;
}

void push(int x){
  if(top > 149){
    printf("error\n");
    exit(1);
  }
  top++;
  B[top] = x;
}

int pop(void){
  if(top == 0){
    printf("error\n");
    exit(1);
  }
  top--;
  return B[top+1];
}
  



Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int n, m, a[100100] = {0};
    int sa[100100] = {0};
    int ans = 0;

    cin >> n >> m;

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

    sort(a, a+m);

    for (int i = 0; i < m-1; i++) {
        sa[i] = a[i+1]-a[i];
        ans += sa[i];
    }

    sort(sa, sa+(m-1));
    reverse(sa, sa+(m-1));

    for (int i = 0; i < n-1; i++) {
        ans -= sa[i];
    }

    cout << ans << endl;

}


Measured memory_bytes: 1024
N,K=map(int, input().split())
S=list(map(int, input().split()))
s=sum(S[:K])
dp=[0]*(N-K+1)
dp[0]=s
for i in range(1,N-K+1):
    s=s-S[i-1]+S[i+K-1]
    if s>dp[i-1]:
        dp[i]=s
print((max(dp)+K)/2)

Measured memory_bytes: 25060
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAXN = 2e5 + 10;
int a[MAXN];
map<int,int> freq;

void solve(){
    int n; cin>>n;

    int ways = 0;
    FOR(i,1,n) cin>>a[i];

    FOR(i,1,n) freq[a[i]]++;

    for(auto x:freq) ways += x.second*(x.second-1)/2;

    FOR(i,1,n){
        ways -= freq[a[i]]*(freq[a[i]]-1)/2;
        freq[a[i]]--;
        ways += freq[a[i]]*(freq[a[i]]-1)/2;
        cout<<ways<<endl;
        ways -= freq[a[i]]*(freq[a[i]]-1)/2;
        freq[a[i]]++;
        ways += freq[a[i]]*(freq[a[i]]-1)/2;
    }    
}

signed main(){

   FastRead;    


    int t = 1; 
    // cin>>t; 
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl;
#define rep(i,n) for(ll i = 0;i < n;++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0);

const ll INF = 1e9+7;

// 各桁の和
template<typename T>
T digit(T num){
  T sum = 0;
  while(num){
    sum += num % 10;
    num /= 10;
  }
  return sum;
}

template<typename T>T gcd(T a,T b){
  if(b == 0)
    return a;
  return gcd(b,a%b);
}
template<typename T>T lcm(T a, T b){
  T g = gcd(a,b);
  return a/g*b; 
}

int main(){
  int n;cin>>n;
  int even = 0,odd = 0;
  rep(i,n){
    int a;cin>>a;
    even += a % 2 == 0;
    odd += a % 2 != 0;
  }
  
  if(odd % 2 == 0)
    print("YES")
  else
    print("NO")
  return 0;
}


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

int main()
{
  int N;
  cin>>N;
  long long int sum=0;
  for(int i=1; i<=N; i++)
  {
   if(i%3!=0&&i%5!=0)
      sum+=i;
   else
      continue;
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 3624
# frozen_string_literal: true

class Node
  attr_accessor :id, :key, :left, :right, :parent
end

def to_max_heap(heap, i)
  left_i = left(i) - 1
  right_i = right(i) - 1

  p = heap[i - 1]
  l = heap[left_i]
  r = heap[right_i]

  largest = if l && p < l
              left_i
            else
              i - 1
  end

  largest = right_i if r && heap[largest] < r

  if largest != i - 1
    heap[i - 1], heap[largest] = heap[largest], heap[i - 1]
    to_max_heap(heap, largest + 1)
  end
end

def build_max_heap(heap)
  (heap.size / 2).downto(1) do |i|
    to_max_heap(heap, i)
  end
end

_n = gets
heap = gets.split.map(&:to_i)

def left(i)
  i * 2
end

def right(i)
  i * 2 + 1
end

build_max_heap(heap)

heap.each do |n|
  print " #{n}"
end

print "\n"



Measured memory_bytes: 44048
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
const int maxn=2e5+5,inf=1e8;
int i,j,n,num,H,W,S,T,last;
int k[maxn],ne[maxn],g[maxn],f[maxn],d[maxn];
int bz[maxn],bk,ans,now[maxn];
char c[105][105];
void add(int x,int y,int z){
	ne[++num]=k[x],k[x]=num,g[num]=y,f[num]=z;
	ne[++num]=k[y],k[y]=num,g[num]=x;
}
int dfs(int x,int a){
	if (x==T){
		ans+=a;
		return a;
	}
	bz[x]=bk;
	int i;
	for(i=k[x];i;i=ne[i]){
		int y=g[i];
		if (f[i]&&bz[y]!=bk&&d[x]==d[y]+1){
			int j=dfs(y,min(a,f[i]));
			if (j){
				f[i]-=j,f[i^1]+=j,now[x]=i;
				return j;
			}
		}
	}return now[x]=0;
}
bool update(){
	int z=inf,i,x,y;
	fo(x,1,n) if (bz[x]==bk){
		for(i=k[x];i;i=ne[i]){
			y=g[i];
			if (f[i]&&bz[y]!=bk) z=min(z,d[y]+1-d[x]);
		}
	}
	if (z==inf) return 0;
	fo(x,1,n) if (bz[x]==bk) d[x]+=z; 
	return 1;
}
int main(){
	scanf("%d%d",&H,&W);
	fo(i,1,H){
		scanf("%s",c[i]+1);
		fo(j,1,W) if (c[i][j]!='.') n++;
	}n+=H+W;
	num=1;
	fo(i,1,H) last++,add(last,last+n,inf);
	fo(i,1,W) last++,add(last,last+n,inf);
	fo(i,1,H){
		fo(j,1,W) {
			if (c[i][j]!='.') {
				last++,add(last,last+n,c[i][j]=='o'?1:inf);
				add(last+n,i,inf),add(i+n,last,inf);
				add(last+n,j+H,inf),add(j+H+n,last,inf);
				if (c[i][j]=='S') S=last;
				if (c[i][j]=='T') T=last+n; 
			}
		}
	}
	n<<=1;
	for(;;){
		fo(i,1,n) now[i]=k[i];
		bk++;
		for(;dfs(S,inf);bk++);
		if (ans>=inf||!update()) break;
	}
	if (ans>=inf) puts("-1");else printf("%d\n",ans);
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
    int n;
    cin >> n;
    vector<int> v(n);
    rep (i, n) cin >> v[i];

    map<int, int> mp1, mp2;
    

    int use1, use2;

    for (int i = 0; i < n; i += 2) {
        mp1[v[i]]++;
    }

    int _max1 = 0, _max2 = 0;
    for (auto x: mp1) {
        if(chmax(_max1, x.se))use1 = x.fi;
    }

    int ans = 0;
    ans += n / 2 - _max1;

    for (int i = 1; i < n; i += 2) {
        mp2[v[i]]++;
    }

    for (auto x: mp2) {
        if(chmax(_max2, x.se))use2 = x.fi;
    }

    ans += n / 2 - _max2;

    if (use1 != use2) {
        cout << ans << endl;
        return 0;
    }

    int ans1 = n / 2 - _max2;
    int ans2 = n / 2 - _max1;
    _max1 = 0;
    _max2 = 0;
    for (auto x: mp1) {
        if (x.fi == use1) {
            continue;
        }
        chmax(_max1, x.se);
    }

    ans1 += n / 2 - _max1;
    for (auto x: mp2) {
        if (x.fi == use2) continue;
        chmax(_max2, x.se);
    }
    ans2 += n / 2 - _max2;

    cout << min(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

ll n, c[500], s[500], f[500];

int main(int argc, char **argv) {
	cin >> n;
	REP(i, n-1) cin >> c[i] >> s[i] >> f[i];
	REP(i, n-1) {
		ll t = c[i] + s[i];
		FOR(j, i+1, n-1) {
			t = c[j] + max(((t-1)/f[j]+1)*f[j], s[j]);
		}
		cout << t << endl;
	}
	cout << 0 << endl;
	return 0;
}
 

Measured memory_bytes: 256
/*  Author:  Hariom_Pandey
    Created: 2/9/2020 6:06:07 PM
*/
 
#include "bits/stdc++.h"
using namespace std;

#define ll              long long
#define Mset(s, n)      memset(s, n, sizeof(s))
#define Rp0(i, m)       for(int i = 0; i < m; ++i)
#define Rpd(i, m, l)    for(int i = l; i >= m; --i)
#define Rp1(i ,m)       for(int i = 1; i <= m; i++)
#define All(a)          (a).begin(), (a).end()
#define Lwb             lower_bound
#define Upb             upper_bound
#define Sz(a)           int((a).size())
#define u_map           unordered_map
#define Exist(a, b)     (find(All(a), (b)) != (a).end())
#define Sort(x)         sort(All(x))
#define Gsort(x)        sort(All(x), greater<typeof(*((x).begin()))>())
#define Unique(v)       Sort(v); (v).resize(unique(All(v)) - (v).begin())
#define all(a)  (a).begin(),(a).end()
const ll mod=1000000007;


int32_t main() {
  ll num , snum; cin >> num >>snum;
  vector<ll> arr(num);
  for(ll i=0; i<num; i++) cin >> arr[i];
  vector<ll> vsum(num-snum+1);
  ll sum =0;
  for(ll j=0; j<snum; ++j) sum += arr[j];
  vsum[0] = sum;
  for(ll l=1; l<num-snum+1; ++l) vsum[l] = vsum[l-1] - arr[l-1] + arr[snum-1+l];
  sort(all(vsum));
  ll out = vsum[vsum.size()-1];
  cout << fixed << setprecision(10) << (double)(out+snum)/2.0d<< "\n";

  return 0;
}


Measured memory_bytes: 3328
// https://atcoder.jp/contests/abc116/tasks/abc116_b

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))

int main() {
    int s;
    set<int> st;
    cin >> s;
    st.insert(s);

    for (int i = 2; i < 10000000; i++) {
        // 偶数なら2で割って、奇数なら3倍して1を足す
        if (s % 2 == 0) {
            s = s / 2;
        } else {
            s = s * 3 + 1;
        }
        if (st.count(s) > 0) {
            cout << i << endl;
            break;
        }
        st.insert(s);
    }

    return 0;
}


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


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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] A = new int[N];
    int[] B = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
      B[i] = sc.nextInt();
    }
    Main abc122C = new Main();
    System.out.println(abc122C.solve(N, M, A, B));
  }

  public long solve(int N, int M, int[] A, int[] B) {
    long ans = 0;
    Store[] Stores = new Store[N];
    for (int i = 0; i < N; i++) {
      Stores[i] = new Store(A[i], B[i]);
    }
    Arrays.sort(Stores);
    for (int i = 0; i < N; i++) {
      int num = M > Stores[i].num ? Stores[i].num : M;
      ans += (long) num * Stores[i].price;
      M -= num;
      if(M == 0) break;
    }
    return ans;
  }

  class Store implements Comparable<Store> {
    int price;
    int num;
    public Store(int price, int num){
      this.price = price;
      this.num = num;
    }
    @Override
    public int compareTo(Store other) {
      return this.price - other.price;
    }
  }
}


Measured memory_bytes: 66544
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
//#define int long long
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
	int T=1;
	//cin >> T;
	FOR1(tp, T)  
	{
		//cout << "Case #" << i << ": ";
		string s, t; cin >> s >> t;
		if(s == t.substr(0, s.length())) cout << "Yes";
		else cout << "No";
		
		cout<<'\n';
	}
	return 0;
}


Measured memory_bytes: 3656
#include<stdio.h>
#include<math.h>
double distance(double x1,double y1,double x2,double y2)
{
  double dis,X,Y;
  X=(x1-x2)*(x1-x2);
  Y=(y1-y2)*(y1-y2);
  dis=sqrt(X+Y);
  return dis;
}
int main(void)
{
  double x1,y1,x2,y2;
  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
  printf("%f",distance(x1,y1,x2,y2));

  return 0;
}



Measured memory_bytes: 2100
#include <iostream>

using namespace std;

int n, q;
long long sum, frecv[100005], b, c, nr;

int main() {
    cin >> n;

    for (int i = 0; i < n; ++i) {
        cin >> nr;
        sum += nr;
        ++frecv[nr];
    }

    cin >> q;
    while (q--) {
        cin >> b >> c;

        sum -= b*frecv[b];
        sum += c*frecv[b];
        frecv[c] += frecv[b];
        frecv[b] = 0;

        cout << sum << endl;
    }
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

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

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; }

const ll INF=(ll)1e19;
//const int INF=(1<<30);

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

  map<int,int> me,mo;
  REP(i,n){
    int m;
    cin >> m;
    if(i%2==0){
      me[m]++;
    }else{
      mo[m]++;
    }
  }

  vector<P> ev, od;
  for(auto v: me){
    ev.emplace_back(make_pair(v.second, v.first));
  }
  for(auto v: mo){
    od.emplace_back(make_pair(v.second, v.first));
  }
  sort(ev.rbegin(), ev.rend());
  sort(od.rbegin(), od.rend());

  int e1,e2,o1,o2;
  e1 = ev[0].second;
  e2 = (ev.size() > 1 ? ev[1].second : -1);
  o1 = od[0].second;
  o2 = (od.size() > 1 ? od[1].second : -1);

  if(e1!=o1){
    cout << n - me[e1] - mo[o1] << endl;
  }else{
    cout << min(n - me[e1] - mo[o2], n - me[e2] - mo[o1]) << endl;
  }

}



Measured memory_bytes: 6136
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    
    int x = 800 * n;
    int y = (n / 15) * 200;
    
    System.out.println(x - y);
  }
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,k;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin >> n >> k;
      rrep(i,1,n+1){
        pos = i % k;
        if(pos * 2 == k){
          cmp = n + pos;
          cmpp = cmp / k;
          ans += cmpp * cmpp;
        }
        else{
          if(pos % k != 0)continue;
          cmp = n / k;
          ans += cmp * cmp;
        }
      }
      Cout(ans);
      
     

       
return 0;
}


Measured memory_bytes: 256
N = int(input())
V = [int(i) for i in input().split()]
C = [int(k) for k in input().split()]

diff = [V[i] - C[i] for i in range(N)]

for i in range(N):
    if diff[i] < 0:
        diff[i] = 0

print(sum(diff))

Measured memory_bytes: 3060
#include <iostream>

int main() {
    int N;

    std::cin >> N;
    if(N % 1000 == 0) {
        std::cout << 0 << std::endl;
    }
    else {
        int num = N / 1000;
        int money = num + 1;

        std::cout << (money*1000-N) << std::endl;
    }
}

Measured memory_bytes: 3584
#include <iostream>
#define int long long
using namespace std;

signed main(){
	int n,k,pos = 0;
	cin >> n >> k;
	for(int i = 0;i < n - 1;i++){
		pos += 1 + pos / (k - 1);
	}
	cout << pos << endl;
	return 0;
}

Measured memory_bytes: 3096
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cstdlib>
#include <fstream>


using namespace std;

int main(void) {
	int n;
	cin >> n;
	cout << (n * 2) / 60 << " " << (n * 2) % 60 << endl;

	
	
	return 0;
}

Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;

int main(){
  int N;
  cin >> N;
  int tmp;
  int ans[N+1];
  ans[0]=0;
  int a;
  int b;
  int i;
  for (i=1;i<=N;i++){
        a=1;
        b=1;
      while(a<=i){
        a=a*6;
      }
      a=a/6;
      while(b<=i){
        b=b*9;
      }
      b=b/9;
      tmp=ans[i-1];
      if (ans[i-a]<tmp){
        tmp=ans[i-a];
      }
      if (ans[i-b]<tmp){
        tmp=ans[i-b];
      }
      ans[i]=tmp+1;
 }
  cout << ans[N];
  return 0;
}


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

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

    int ans = 0;
    rep(i,n-2){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') ++ans;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,op=0;
    long long x=0LL,ai,t1;
    cin>>n;
    deque<long long> s;
    for(int i=0;i<n;i++){
        cin>>ai;
        s.push_back(ai);
        while(s.size()>2&&(s[s.size()-2]>=s[s.size()-1])&&(s[s.size()-2]>=s[s.size()-3])){
                t1 = s[s.size()-1]+s[s.size()-3]-s[s.size()-2];
                s.pop_back();
                s.pop_back();
                s.pop_back();
                s.push_back(t1);
        }
    }
    int sign = 1;
    while(s.size()){
        if(s.back()>s.front()){
            x = x + sign*s.back();
            s.pop_back();
        }else{
            x = x + sign*s.front();
            s.pop_front();
        }
        sign = -sign;
    }
    cout<<x<<"\n";
    return 0;
}

Measured memory_bytes: 256
n = io.read("*n")
w = {}
sum = 0
for i = 1, n do
  w[i] = io.read("*n")
  sum = sum + w[i]
end
l = 0
ret = sum
for i = 1, n - 1 do
  l = l + w[i]
  ret = math.min(ret, math.abs(sum - l - l))
end
print(ret)


Measured memory_bytes: 2720
#include<bits/stdc++.h>
using namespace std;
int n,x,y,a,b,c,t;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>c>>a>>b;
        if((abs(x-a)+abs(y-b)>c-t)||((abs(x-a)+abs(y-b))%2==0 &&(c-t)%2==1)||((abs(x-a)+abs(y-b))%2==1&&(c-t)%2==0)){
            cout<<"No";
            return 0;
        }
        x=a;
		y=b;
		t=c;
    }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
while True:
    a,op,b = input().split()
    a = int(a)
    b = int(b)
    if op == '+':
        print (a + b)
    elif op == '-':
        print (a - b)
    elif op == '*':
        print (a * b)
    elif op == '/':
        print (a // b)
    else:
        break

Measured memory_bytes: 7664
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int n, q, a[20], m[200];

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

  cin >> q;
  rep(i, q) {
    cin >> m[i];
  }

  bool mb[200];
  rep(i, q) {
    mb[i] = false;
  }

  for(int bit = 0; bit < (1<<n); bit++) {
    int sum = 0;
    for(int i = 0; i < n; i++) {
      if(bit & (1<<i)) {
        sum += a[i];
      }
    }
    for(int i = 0; i < q; i++) {
      if(sum == m[i]) mb[i] = true;
    }
  }

  for(int i = 0; i < q; i++) {
    if(mb[i] == true) cout << "yes" << endl;
    else cout << "no" << endl;
  }

  return 0;
}


Measured memory_bytes: 3096
#include<cstdio>
int main(){
	int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	d = a/b;
	r = a%b;
	f = 1.0000*a/b;
	printf("%d %d %.5lf\n",d,r,f);
	return 0;
}

Measured memory_bytes: 1068
#include <stdio.h>
     
    int main(void)
    {
     
        int A,B,K;
        scanf("%d %d",&A,&B);
        K=(A+B)/2;
        if(abs(A-K)==abs(B-K)){
        printf("%d\n",K);
        }   
        else{
         printf("IMPOSSIBLE\n");
        }   
        return 0;
        }   

Measured memory_bytes: 128
tap = list(map(int, input().split()))

if tap[1] <= 1:
    print(0)
elif tap[0] >= tap[1]:
    print(1)
else:
    num = tap[0]
    inc = tap[0] - 1
    cnt = 1

    while True:
        num += inc
        cnt += 1

        if num >= tap[1]:
            break

    print(cnt)

Measured memory_bytes: 3064
#include<cstdlib>
#include<cstdio>
#include<cstring>

struct Node{
	int key;
	Node *prev, *next;
};

Node* nil;

void init(){
	nil = (Node *)malloc(sizeof(Node));
	(*nil).prev = nil;
	nil->next = nil;
}

void insert(int key){
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	x->next->prev = x;
	x->prev = nil;
	nil->next = x;
}

Node* listSearch(int key){
	Node *cur = nil->next;
	while(cur != nil && cur->key != key){
		cur = cur->next;
	}
	return cur;
}

void deleteNode(Node *t){
	if(t == nil)
		return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	deleteNode(listSearch(key));
}

void printList(){
	Node *cur = nil->next;
	int isf = 0;
	while(true){
		if(cur == nil)
			break;
		if(isf++ > 0)
			printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

int main(){
	int key, n;
	char com[12];
	scanf("%d", &n);
	init();
	for(int i = 0; i < n; i++){
		scanf("%s%d", com, &key);
		if(com[0] == 'i')
			insert(key);
		else if(com[0] == 'd'){
			if(strlen(com) > 6){
				if(com[6] == 'F')
					deleteFirst();
				else if(com[6] == 'L')
					deleteLast();
			}
			else
				deleteKey(key);
		}
	}
	printList();
	return 0;
}


Measured memory_bytes: 33844
A, B, C, K = map(int, input().split())

ans = 0
n = min(A, K)
ans += n
K -= n
if K == 0:
    print(ans)
    exit()
n = min(B, K)
K -= n
if K == 0:
    print(ans)
    exit()
n = min(C, K)
ans -= n
print(ans)

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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

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

int main() {
	int n = nxt(), m = nxt(), v = nxt(), p = nxt();
	vector<int> a(n);
	generate(all(a), nxt);
	sort(all(a));
	reverse(all(a));

	auto check = [&](int score) -> bool {
		auto b = a;
		b.erase(find(all(b), score));
		score += m;
		int cnt = lower_bound(all(b), score, greater<int>()) - b.begin();
		if (cnt > p - 1) {
			return false;
		}
		if (v - 1 <= p - 1) {
			return true;
		}
		long long can = 0;
		for (int i = p - 1; i < (int)b.size(); ++i) {
			assert(b[i] <= score);
			can += score - b[i];
			if (i + (v - p) >= (int)b.size()) {
				if (can < (i - (int)b.size() + v - p + 1) * 1ll * m) {
					return false;
				}
			}
		}
		return true;
	};

	cout << partition_point(all(a), check) - a.begin() << "\n";

	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void) {

	int n;
	int a, b;

	int x[5];
	int sum;

	int total = 0;

	int i,j;

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

	for (i = 1; i <= n; i++)
	{
		x[0] = i / 10000;
		x[1] = (i % 10000) /1000;
		x[2] = (i % 1000) /100;
		x[3] = (i % 100)  / 10;
		x[4] = i % 10;

		sum = 0;

		for ( j = 0; j < 5; j++)
		{
			sum += x[j];
		}

		if (a <= sum && sum <= b)
		{
			total += i;
		}
	}

	printf("%d", total);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>

const int MAXN = 1e6;
const int MOD = 1e9 + 7;

int n, sum;
int dp[MAXN + 2];

int main() {
	scanf("%d", &n);
	dp[n] = n;
	dp[n - 1] = 1LL * n * n % MOD;
	for (int i = n - 2; i >= 1; --i) {
		sum = (sum + dp[i + 3]) % MOD;
		dp[i] = (1LL * dp[i] + dp[i + 1] + sum + i + 1 + (n - 1) * 1LL * (n - 1)) % MOD;
	}
	printf("%d\n", dp[1]);
	return 0;
}


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

const int64_t inf = 1e15 + 3;

void chmin (int64_t &x, int64_t a) {
    x = min(x, a);
}

signed main () {
    int n;
    cin >> n;
    vector < int > a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i] -= i + 1;
    }
    sort(a.begin(), a.end());
    vector < int64_t > pref(n + 1, 0), suff(n + 1, 0);
    for (int i = 0; i < n; ++i)
        pref[i + 1] = pref[i] + a[i];
    for (int i = n - 1; i >= 0; --i)
        suff[i] = suff[i + 1] + a[i];
    int64_t ans = inf;
    for (int i = 0; i < n; ++i) {
        int64_t here = (int64_t(i) * a[i] - pref[i]) + (suff[i + 1] - int64_t(n - 1 - i) * a[i]);
        chmin(ans, here);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 4096
#include <iostream>

using namespace std;

int main()
{
    int n, ac = 0, wa = 0, tle = 0, re = 0;
    char c;

    cin >> n;
    for (size_t i = 0; i < n; i++)
    {
        cin >> c;
        switch (c)
        {
        case 'A':
            ++ac;
            cin.ignore(1);
            break;
        case 'W':
            ++wa;
            cin.ignore(1);
            break;
        case 'T':
            ++tle;
            cin.ignore(2);
            break;
        case 'R':
            ++re;
            cin.ignore(1);
            break;
        }
    }

    cout << "AC" << " x " << ac << '\n';
    cout << "WA" << " x " << wa << '\n';
    cout << "TLE" << " x " << tle << '\n';
    cout << "RE" << " x " << re << '\n';
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vi a(n), b(n), c(m), d(m);
  rep(i, n) cin >> a[i] >> b[i];
  rep(i, m) cin >> c[i] >> d[i];
  rep(i, n) {
    int ans, mn = 1e9;
    rep(j, m) {
      int now = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if(now < mn) {
        ans = j + 1;
        mn = now;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
def sumcal(num):
  sum = 0
  while(num != 0):
    sum += (num % 10)
    num = num // 10
  return sum

N, A, B = map(int, input().split())
count = 0
for i in range(N):
  sum = sumcal(i + 1)
  if sum >= A and sum <= B:
    count += i + 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define INF 1e12
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int t,mx=0,tot=0;
	For(i,1,3)
	{
		cin>>t;
		mx=max(mx,t);
		tot+=t;
	}
	tot+=mx*9;
	cout<<tot<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long l,r,ans=2020;
	cin>>l>>r;
	for(long long i=l;i<=r;i++){
		for(long long j=i+1;j<=r;j++){
			long long s=(i*j)%2019;
			ans=min(ans,s);
			if(ans==0){
				cout<<ans;
				return 0;
			}
		}
		if(ans==0){
			cout<<ans;
			return 0;
		}
	}
	cout<<ans;
	return 0;
}

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

int main(){
  string s,t;
  cin >> s >> t;
  string a = "Yes";
  
  for(int i = 0;i < s.size();i++){
    if(s.at(i) == t.at(i)){
      continue;
      }
   else{
     a = "No";
     break;
     }
   }
   
   if(s.size() + 1 != t.size()){
   a == "No";
   }
   cout << a << endl;
}

Measured memory_bytes: 3604
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/

//var min, min2, count: Int!
//for i in 1...10 {
//    let x = Int(readLine()!)!
//    if i == 1 {
//        min = x
//        count = 1
//    } else if x < min {
//        min2 = min
//        min = x
//        count = 1
//    } else if x == min && count == 1 {
//        min2 = x
//        count = 2
//    }
//}
//print(min2)

/*************** メインプログラム ***************/

let N = readInt()!
let K = readInt()!
var ans = 1
for i in 0..<N {
    ans += min(ans, K)
}
print(ans)


Measured memory_bytes: 1024