akhauriyash/Code-Regression huggingface dataset:
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)*}
    };
}

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

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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

fn main() {
    input!{
        a: u64,
        b: u64,
    }
    println!("{}", if a <= b { a } else { a - 1 });
}


Measured memory_bytes: 4352
N = int(input())
used_words = []

pre_word = input()
used_words.append(pre_word)
state = "Yes"


for i in range(N-1):
    W = input()

    if pre_word[-1] != W[0]:
        state = "No"
        break

    for uw in used_words:
        if uw == W:
            state = "No"
            break
    if state == "No":
        break

    used_words.append(W)
    pre_word = W

print(state)


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

int main() {
  ll n,count=0;
  cin>>n;
  vector<ll> a,b;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    a.push_back(x);
    b.push_back(x);
  }
  sort(b.begin(),b.end());
  for(int i=0;i<n;i++){
    if(a[i]!=b[i]) count++;
  }
  if(count>2) cout<<"NO";
  else cout<<"YES";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;

int main() {

    double N, T;
    cin >> N >> T;

    vector<int > costs;
    for (int i = 0; i < N; ++i) {
        int c, t;
        cin >> c >> t;
        if (t <= T) {
            costs.push_back(c);
        }
    }

    if (costs.size() == 0) {
        cout << "TLE" << endl;
        return 0;
    }

    int min = *std::min_element(costs.begin(), costs.end());
    cout << min << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct iofix
{
   ios_base::Init i;
   iofix() {
      cin.sync_with_stdio(0);
      cin.tie(0);
      cout.sync_with_stdio(0);
      cout.tie(0);
   }
} iofix;

void solve(){
    int N; cin >> N;
    cout << ((N % 1000 == 0)? 0 : 1000 - (N % 1000)); 
}

int main(){
// #ifndef Judge
//     freopen("in.txt","r",stdin);
//     freopen("out.txt","w",stdout);
// #endif 

   	solve();

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

Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
#include <chrono>
#include <fstream>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

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

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


int main() {
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> refs(a), mics(b);
    cin >> refs >> mics;

    int ans = 1000000000;
    rep(i, m) {
        int x, y, c;
        cin >> x >> y >> c;
        x--; y--;
        chmin(ans, refs[x] + mics[y] - c);
    }
    sort(refs.begin(), refs.end());
    sort(mics.begin(), mics.end());
    chmin(ans, refs[0] + mics[0]);
    cout << ans << endl;
}

Measured memory_bytes: 4016
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.Bifunctor (first)
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS

main = do
  n <- readLn
  as <- U.unfoldrN n (readInt64 . BS.dropWhile isSpace) <$> BS.getLine
  let x0 = (U.sum as - 2 * sum [as U.! i | i <- [1,3..n-1]]) `quot` 2
  let xs = U.scanl' subtract x0 as
  putStrLn $ unwords $ map show $ U.toList $ U.map (* 2) $ U.init xs

readInt64 :: BS.ByteString -> Maybe (Int64, BS.ByteString)
readInt64 s = first fromIntegral <$> BS.readInt s


Measured memory_bytes: 12668
#include<stdio.h>

typedef struct CAKE{
	int w;
	int d;
}cake;



int main(void){
	int n,p,s;
	int i,j;
	cake piece[102];
	cake hoge;

	while(1){
		scanf("%d %d %d",&n,&piece[1].w,&piece[1].d);
		if(n==0&&piece[1].w==0&&piece[1].d==0){break;}

		for(i=1;i<n+1;i++){
			scanf("%d %d",&p,&s);
				
			if(s%(piece[p].w+piece[p].d)<piece[p].w){
				piece[i+1].w=(piece[p].w-(s%(piece[p].w+piece[p].d)));
				piece[i+1].d=piece[p].d;
	
				hoge.w=piece[p].w-piece[i+1].w;
				hoge.d=piece[p].d;
			}
	
			else{
				piece[i+1].w=piece[p].w;
				piece[i+1].d=(piece[p].d+piece[p].w-(s%(piece[p].w+piece[p].d)));
	
				hoge.w=piece[p].w;
				hoge.d=piece[p].d-piece[i+1].d;
			}
			
			for(j=p;j<=i-1;j++){
				piece[j]=piece[j+1];
			}
	
			if((hoge.w*hoge.d)>(piece[i+1].d*piece[i+1].w)){
				piece[i]=piece[i+1];
				piece[i+1]=hoge;
			}
			
			else{piece[i]=hoge;}

		}
	
		for(i=1;i<n+1;i++){
			for(j=1;j<n+1;j++){
				if((piece[j].w*piece[j].d)>(piece[j+1].d*piece[j+1].w)){
					hoge=piece[j];
					piece[j]=piece[j+1];
					piece[j+1]=hoge;
				}
			}
		}
	
		for(i=1;i<=n+1;i++){
			if(i==n+1){printf("%d\n",piece[i].d*piece[i].w);}
			else{printf("%d ",piece[i].d*piece[i].w);}
		}

	}
	return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <algorithm>
#define rep(i,j,k) for (i=j;i<=k;i++)
using namespace std;
const int N=1e5+5;
int n,i,u,v,flag;
int En,fst[N],a[N],b[N],up[N],nxt[N*2],to[N*2];
void add(int u,int v) {
	En++; nxt[En]=fst[u]; fst[u]=En; to[En]=v;
}
void dfs(int x,int fa)
{
	int i,j,cnt=0,son=0,rest,sum=0,SUM,t1,t2;
	for (j=fst[x];j;j=nxt[j])
		if (to[j]!=fa) {
			son++;
			dfs(to[j],x);
			if (!flag) return ;
		}
	if (!son) {up[x]=a[x]; return ;}
	for (j=fst[x];j;j=nxt[j])
		if (to[j]!=fa) if (up[to[j]]) b[++cnt]=up[to[j]];
	sort(b+1,b+1+cnt);
	rep(i,1,cnt-1) sum+=b[i];
	SUM=sum+b[cnt];
	if (!cnt) rest=0;
	else if (sum<=b[cnt]) rest=b[cnt]-sum;
	else rest=SUM%2;
	t1=2*(SUM-a[x]); t2=SUM-t1;
	if (t1<0 || t2%2 != rest%2 || t2<rest) { flag=0; return ; }
	up[x]=t2; if (x==1 && son==1) up[x]=0;
}
int main()
{
	//freopen("clean.in","r",stdin);
	//freopen("clean.out","w",stdout);
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]);
	rep(i,1,n-1)
	{
		scanf("%d%d",&u,&v);
		add(u,v); add(v,u);
	}
	flag=1;
	dfs(1,1);
	if (up[1]) flag=0;
	if (flag) printf("YES\n");
	else printf("NO\n");
	return 0;
}

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

#define M 1046527
#define NIL (-1)
#define L 14
#define rep(i, n) for( int (i) = 0; (i) < (n); ++(i))


char H[M][L];

// 文字から数値に変換
int getChar(char ch) {
    if(ch == 'A') return 1;
    else if(ch == 'B') return 2;
    else if(ch == 'C') return 3;
    else if(ch == 'D') return 4;
    else return 0;
}
// 文字列から数値へ変換して key を生成する
int getKey(char str[]) {
    int sum = 0;
    int p = 1;
    rep(i,strlen(str)) {
        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[]) {
    int key,h;
    key = getKey(str);
    for(int 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[]) {
    int 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];
    rep(i,M) {
        H[i][0] = '\0';
    }
    scanf("%d",&n);
    rep(i,n) {
        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: 16980
#include<bits/stdc++.h>
using namespace std;
int main(){
  	int a,b;
  	cin >> a >> b;
  	if((a+b)%2 == 0){
    	cout << (a+b)/2 << endl;
    }
  	else{
    	cout << "IMPOSSIBLE" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
abc = 'abcdefghijklmnopqrstuvwxyz'
arrabc = []
for s in abc:
	arrabc.append(s)

line = ''
while True:
	try:
		sinput = input()
		if sinput == '':
			break
		line = line + sinput
	except EOFError:
		break

arrinput = []
for s in line:
	arrinput.append(s.lower())

for s in arrabc:
	print('{0} : {1}'.format(s,arrinput.count(s)))


Measured memory_bytes: 5560
#include <iostream>
#include <vector>
using namespace std;
int cal(int f,int l){
  int ans = 0;
  for(int i = f;i <= l;i++){
    ans += i;
  }
  return ans;
}
int main(){
  int n;
  
  while(cin >> n,n != 0){
    int cnt = 0;
    for(int i = 1;i < n;i++){
      int tmp = 0;
      for(int j = i;j < n;j++){
	if(cal(i,j) == n){
	  cnt++;
	}
	else if(cal(i,j) > n){
	  break;
	}
      }

    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 1160
// D - XOR World
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

// n%2==0 -> n^(n+1)=1
//ex. f(0,4) = (0^1) ^ (2^3) ^ 4 = 1^1^4 = 4
ll f0(ll n){//f(0,n)
	ll eo_pair = (n+1)/2;//⌈n/2⌉=(n+2-1)/2 number of even-odd pair
	ll c = eo_pair%2;//pair: even->0, odd->1
	if(n%2==0) c ^= n;//n: even -> {0,1} xor last number
	return c;
}

ll f(ll A, ll B){
	return f0(B) ^ f0(A-1);
}

int main(){
	ll A,B; cin>>A>>B;
	cout<<  f(A,B) <<endl;
}

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

class Program {
    static string ReadLine() { return Console.ReadLine().Trim(); }
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return ReadLine().Split(); }

    // OK
    static void Display1(int[] xs) {
        string[] ss = xs.Select(e => e.ToString()).ToArray();
        Console.WriteLine(string.Join(" ", ss));
    }

    // NG: ?????????????????¨??????
    // error CS1502: The best overloaded method match for `string.Join(string, string[])' has some invalid arguments
//    static void Display2(int[] xs) {
//        Console.WriteLine(string.Join(" ", xs));
//    }

    // OK: string[] ????????£??????????????¨?????????????????§??????
    static void Display3(int[] xs) {
        Console.WriteLine(string.Join(" ", (string[])xs.Select(e => e.ToString()).ToArray()));
    }

    static void Main() {
        int n = ReadInt();
        int[] xs = ReadInts();
        if (n != xs.Length) throw new Exception();

        Display1(xs);
        for (int i = 1; i < xs.Length; i++) {
            int key = xs[i];
            // insert xs[i] into the sorted sequence xs[0..j-1]
            int j = i - 1;
            while (j >= 0 && xs[j] > key) {
                xs[j+1] = xs[j];
                j--;
            }
            xs[j+1] = key;

            // output
            Display1(xs);
        }
    }
}

Measured memory_bytes: 6120
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<pair<pair<int,int>,int>>yp;
pair<int,int> ans[100010];
int cnt[100010];
int main() {
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	
	{
		int a,b;
		cin>>a>>b;
		yp.push_back({{b,a},i+1});
	}
	sort(yp.begin(),yp.end());
	for(int i=0; i<m; ++i)
		ans[yp[i].second] = {yp[i].first.second, ++cnt[yp[i].first.second]};
	for(int i=1; i<=m; ++i){
		cout << setfill('0') << setw(6) << right << ans[i].first;
		cout << setfill('0') << setw(6) << right << ans[i].second;
		cout << "\n";
	}	
	return 0;
}

Measured memory_bytes: 3956
// AOJ 1068: School of Killifish
// 2017.12.14 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define INF 0x7fffffff

int pool[9000000];
int **seg;
int h, w;
int r1, c1, r2, c2, g;

void update(int r, int c, int x)
{
	int c2, t, a;

	r += h - 1;
	c += w - 1;
	seg[r][c] = x;

	while (r >= 0) {
		c2 = c;
		while (c2) {
			if (!(c2 & 1)) c2--;
			t = c2, c2 >>= 1;
			a = seg[r][t++]; if (a > seg[r][t]) a = seg[r][t];
			seg[r][c2] = a;
		}
		if (r == 0) break;

		if (!(r & 1)) r--;
		t = r, r >>= 1;
		a = seg[t++][c]; if (a > seg[t][c]) a = seg[t][c];
		seg[r][c] = a;
	}
}
 
int query2(int l, int r, int k)
{
	int m, lmin, rmin;

	if (c2 <= l || r <= c1) return INF;
    if (c1 <= l && r <= c2) return seg[g][k];
     
	k <<= 1, m = (l + r) >> 1;
    lmin = query2(l, m, ++k);
    rmin = query2(m, r, ++k);
    if (lmin > rmin) lmin = rmin; 
    return lmin;
}
 
int query(int l, int r, int k)
{
	int m, lmin, rmin;

    if (r2 <= l || r <= r1) return INF;
    if (r1 <= l && r <= r2) { g = k; return query2(0, w, 0); }
    
	k <<= 1, m = (l + r) >> 1;
    lmin = query(l, m, ++k);
    rmin = query(m, r, ++k);
    if (lmin > rmin) lmin = rmin;
    return lmin;
}
 
int main()
{
	int R, C, Q, h2, w2, r, c, v, i;

    while (scanf("%d%d%d", &R, &C, &Q) && R > 0) {

		h = w = 1;
		while (h < R) h <<= 1;
		while (w < C) w <<= 1;

		h2 = (h << 1) - 1, w2 = (w << 1) - 1;

		memset(pool, 0, sizeof(pool));
		seg = malloc(h2 * sizeof(int *));
		for (r = 0; r < h2; r++) seg[r] = pool + r*w2;

        for (r = 0; r < R; r++) for (c = 0; c < C; c++)
			scanf("%d", &v), update(r, c, v);

        for (i = 0; i < Q; i++) {
			scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
			r2++, c2++;
            printf("%d\n", query(0, h, 0));
        }

		free(seg);
    }
    return 0;
}

Measured memory_bytes: 52968
N, M = map(int, input().split())
digits = [-1] * N
for _ in range(M):
    s, c = map(int, input().split())
    s -= 1
    if (N > 1 and s == 0 and c == 0) or (digits[s] != -1 and digits[s] != c):
        print(-1)
        exit()
    digits[s] = c
ans = ''
if digits[0] == -1:
    if N == 1:
        ans += '0'
    else:
        ans += '1'
else:
    ans += str(digits[0])
for i in range(1, N):
    if digits[i] == -1:
        ans += '0'
    else:
        ans += str(digits[i])
print(ans)


Measured memory_bytes: 39108
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int h,a;
    cin >> h >> a;
    int cnt=0;
    while(h>0){
        h -= a;
        cnt++;
    }
    cout << cnt << endl;
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n;
double p[3003],dp[3003][3003],ans;
void solve(){
    cin>>n;
    rep(i,1,n+1) cin>>p[i];
    rep(i,1,n+1) dp[0][i]=0;
    dp[0][0]=1;
    rep(i,1,n+1){
        rep(j,0,n+1){
            dp[i][j]=(j?dp[i-1][j-1]*p[i]:0)+dp[i-1][j]*(1-p[i]);
        }
    }
    rep(j,1,n+1){
        if(2*j>n) ans+=dp[n][j];
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 70656
while True:
    H,W = map(int,input().split())
    if W == 0 and H == 0:
        break
    for i in range(H):
        for j in range(W):
            if i == 0 or i == H - 1 or j == 0 or j == W - 1:
                print("#", end = "")
            else :
                print(".", end = "")
        print()
    print()


Measured memory_bytes: 7004
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,c=0;
    string s,t;
    cin>>s;
    cin>>t;
    for(i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
        {
            c=1;
            break;
        }
    }
    if(t.size()-1 !=s.size())
        c=1;
    if(c==1)
    cout<<"No"<<"\n";
    else
    cout<<"Yes"<<"\n";
    return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>

int main(){
  int K,A,B;
  scanf("%d %d %d",&K,&A,&B);
  
  int L=K;
  int sw=0;
  
  while(L<=B){
    if(A<=L){
      sw=1;
  }
  L=L+K;
  }
    
  if(sw==1){
    printf("OK\n");
  }else{
    printf("NG\n");
  }
  return 0;
}

Measured memory_bytes: 1616
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <cmath>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define ins insert
#define iter ::iterator
#define upb upper_bound
#define lwb lower_bound

#define sz(v) v.size()
#define aloc(i, a, n) i *a = new i[n]

#define for0(i,a) for(ll i = 0; i < a; i++)
#define fori(i,a,b) for(ll i = a; i < b; ++i)
#define rfor0(i,a) for(ll i = a; i >= 0; --i)
#define rfor(i,a,b) for(ll i = a; i >= b; --i)
//##############################################################################

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


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static int n,count;
    public static int[] a;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n=sc.nextInt();
        a=new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        sumDigits();
        for(int i=0;i<n;i++){
            if(i==n-1)System.out.printf("%d",a[i]);
            else System.out.printf("%d ",a[i]);
        }
        System.out.printf("\n%d\n",count);
        sc.close();
    }
    public static void sumDigits() {
            for(int i=0;i<n;i++){
                int minj=i;
                for(int j=i;j<n;j++){
                    if(a[j]<a[minj]){
                        minj=j;
                    }
                }
                if(i!=minj){
                    int b;
                    b=a[i];
                    a[i]=a[minj];
                    a[minj]=b;
                    count++;
                }
            }
    }
}


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

#define nax 100009
#define FOR(i,n,m) for(int i =(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back

typedef vector<int> vi;

vi v[nax];
bool vis[nax];
int dp[nax];

void dfs(int node){
	vis[node] = true;
	dp[node] = 1;
	for(int u:v[node]){
		if(vis[u]){
			dp[node] = max(dp[u]+1,dp[node]);
			continue;
		}
		dfs(u);
		dp[node] = max(dp[u]+1,dp[node]);
	}
}

int main(){
	int n,m; cin>>n>>m;
	REP(i,m){
		int a,b; cin>>a>>b;
		a--; b--;
		v[a].pb(b);
	}

	REP(i,n){
		if(!vis[i]){
			dfs(i);
		}
	}

	int ans =0;
	REP(i,n) ans = max(ans,dp[i]);
	cout<<ans-1;

	return 0;
}

Measured memory_bytes: 8192
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  if(n<r)return 0;
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // int codeforces;cin>>codeforces;while(codeforces--){
  ll N,ans;
  string s;
  cin>>N;
  set<string> se;
  while(N--){
    cin>>s;
    se.insert(s);
  }
  print(se.size());
  return 0;
}

Measured memory_bytes: 19136
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int a,b,c; cin >> a >> b >> c;
    int count = 0;
    int d = a;
    if(a==1){
        cout << "YES" << endl;
    }else{
        REP(i,1,10000000){
            if(a%b==c){
                cout << "YES" << endl;
                count += 1;
                break;
            }
            a+=d;
        }
        if(count==0){
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
N = map(int, input().split())
values = list(map(int, input().split()))
costs = list(map(int, input().split()))
# N = 3
# values = [10, 2, 5]
# costs = [6, 3, 4]
# N = 4
# values = [13, 21, 6, 19]
# costs = [11, 30, 6, 15]
# N = 1
# values = [1,]
# costs = [50,]


def calculate_maximum_gain(values, costs):
    gain = 0
    for value, cost in zip(values, costs):
        if value - cost > 0:
            gain = gain + value - cost
    
    return gain


print(calculate_maximum_gain(values, costs))


Measured memory_bytes: 2940
def check(line):
    n = len(line)
    flag = True
    for i in range(n // 2):
        if line[i] != line[n - i - 1]:
            flag = False

    return flag

s = list(input())
n = len(s)
sf = s[:n//2]
sb = s[n//2 + 1:]
if sf != sb:
    print("No")
else:
    if check(sf):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 9072
#line 1 "Q.cpp"
#include <cstdio>
#include <string>
#include <vector>

#line 1 "~/git/library/utility/make/pre17/vector.cpp"
/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */

#ifndef H_make_vector
#define H_make_vector

#include <cstddef>
#include <type_traits>
#line 12 "~/git/library/utility/make/pre17/vector.cpp"

namespace detail {
  template <typename Tp, size_t N>
  std::vector<Tp> make_vector(
      std::vector<size_t>& sizes,
      typename std::enable_if<(N == 1), Tp const&>::type x
  ) {
    return std::vector<Tp>(sizes[0], x);
  }
  template <typename Tp, size_t N>
  auto make_vector(
      std::vector<size_t>& sizes,
      typename std::enable_if<(N > 1), Tp const&>::type x
  ) {
    size_t size = sizes[N-1];
    sizes.pop_back();
    return std::vector<decltype(make_vector<Tp, N-1>(sizes, x))>(
        size, make_vector<Tp, N-1>(sizes, x)
    );
  }
}  // detail::

template <typename Tp, size_t N>
auto make_vector(size_t const(&sizes)[N], Tp const& x = Tp()) {
  std::vector<size_t> s(N);
  for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
  return detail::make_vector<Tp, N>(s, x);
}

#endif  /* !defined(H_make_vector) */
#line 6 "Q.cpp"

int main() {
  size_t h, w;
  int k;
  scanf("%zu %zu %d", &h, &w, &k);

  auto a = make_vector({h, w}, 0);
  for (size_t i = 0; i < h; ++i) {
    char buf[384];
    scanf("%s", buf);
    std::string s = buf;
    for (size_t j = 0; j < w; ++j) {
      if (s[j] == '#')
        a[i][j] = k--;
    }
  }

  for (size_t i = 0; i < h; ++i)
    for (size_t j = 1; j < w; ++j)
      if (a[i][j] == 0)
        a[i][j] = a[i][j-1];

  for (size_t i = 0; i < h; ++i)
    for (size_t j = w-1; j--;)
      if (a[i][j] == 0)
        a[i][j] = a[i][j+1];

  for (size_t i = 1; i < h; ++i)
    for (size_t j = 0; j < w; ++j)
      if (a[i][j] == 0)
        a[i][j] = a[i-1][j];

  for (size_t i = h-1; i--;)
    for (size_t j = 0; j < w; ++j)
      if (a[i][j] == 0)
        a[i][j] = a[i+1][j];

  for (size_t i = 0; i < h; ++i)
    for (size_t j = 0; j < w; ++j)
      printf("%d%c", a[i][j], j+1<w? ' ': '\n');
}


Measured memory_bytes: 1152
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  ull X=0,t=0;
  cin >> X >> t;
  cout << (X>t?X-t:0) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; cin >> n;
    vector<vector<int>> g(n);
    rep(i,n-1){
        int a,b; cin >> a >> b; a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> df(n, -1), ds(n, -1);
    df[0] = 0; ds[n-1] = 0;
    queue<int> que;
    que.push(0);
    while(!que.empty()){
        int u = que.front(); que.pop();
        for(int v : g[u]){
            if(df[v] != -1) continue;
            df[v] = df[u] + 1;
            que.push(v);
        }
    }
    que.push(n-1);
    while(!que.empty()){
        int u = que.front(); que.pop();
        for(int v : g[u]){
            if(ds[v] != -1) continue;
            ds[v] = ds[u] + 1;
            que.push(v);
        }
    }
    int cf = 0, cs = 0;
    FOR(i,1,n-1){
        if(ds[i] < df[i]) cs++;
        else cf++;
    }
    if(cs < cf) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}

Measured memory_bytes: 6528
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b)
		print(c);
	else if (a == c)
		print(b);
	else if (b == c)
		print(a);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <vector>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
typedef  long long ll;
const int maxn=1e6+50;
const int inf=0x3f3f3f3f;
const int MOD=1e9+7;
const int HASH=131;

int a[maxn];
map<int,int> mp;

bool cmp(int a,int b)
{
    return a>b;
}



int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    sort(a+1,a+1+n,cmp);
    ll ans=a[1];
    int ti=1;
    for(int i=2;i<=n;i++)
    {
        ti+=2;
        if(ti<=n-1)
        {
            ans+=2*a[i];
        }
        else
        {
            if(ti==n) ans+=a[i];
            else break;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 13904
#include <bits/stdc++.h> 
using namespace std; 
typedef long long ll;
ll mod = 1e9+7;

int main() { 
  
	ll n;
	cin>>n;
	ll a=0,b=0,c=0,d=0;
	for(int i=0; i<n; i++) {
		string s;
		cin>>s;
		if(s.compare("AC")==0) a++;
		if(s.compare("WA")==0) b++;
		if(s.compare("TLE")==0) c++;
		if(s.compare("RE")==0) d++;
	}
	cout<<"AC x "<<a<<"\n";
	cout<<"WA x "<<b<<"\n";
	cout<<"TLE x "<<c<<"\n";
	cout<<"RE x "<<d<<"\n";
	return 0;
}

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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;

int gcd(int a, int b) {
  if (a%b==0) return(b);
  else return(gcd(b,a%b));
}

int lcm(int a, int b){
    return a * b / gcd(a, b);
}



int main() {
  vector<int> T(3);
  int A,B,C; cin >> T[0] >> T[1] >> T[2];
  
  int ans=0;
  while(T[0] !=T[1] || T[0] != T[2] || T[1] != T[2]) {
    sort(T.begin(), T.end());
    if(T[0]+2<=T[2]) {
      T[0] +=2;
    } else {
      T[0]++;
      T[1]++;
    }
    ans++;
  }
  dump(ans);

}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC diagnostic error "-std=c++14"
#include "bits/stdc++.h"
//#include "ext/pb_ds/tree_policy.hpp"
//#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ll inf = 1e9+7;
const ld eps = 1e-9;
const db PI = atan(1)*4;
template<typename T>
inline int sign(const T&a) {
    if(a<0)return -1;
    if(a>0)return 1;
    return 0;
}

template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}

template<typename T> inline void in(T &x) {
    x = 0;
    T f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (isdigit(ch))  {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    x *= f;
}

ll twop(int x) {
    return 1LL<<x;
}

template<typename A,typename B > inline void in(A&x,B&y) {
    in(x);
    in(y);
}
template<typename A,typename B,typename C>inline void in(A&x,B&y,C&z) {
    in(x);
    in(y);
    in(z);
}
template<typename A,typename B,typename C,typename D> inline void in(A&x,B&y,C&z,D&d) {
    in(x);
    in(y);
    in(z);
    in(d);
}

int n;
int dp[200010];
int main() {
    
    
    
    
    cin>>n;
    int ans = 0;
    REP(i,1,n+1){
        int c;in(c);
        dp[c] = dp[c-1]+1;
        upmax(ans, dp[c]);
    }
    cout<<n-ans;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
vector<T> create(size_t n) {
	return vector<T>(n);
}
template<typename T, typename ... Args>
auto create(size_t n, Args ... args) {
	return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef EZZAT
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#else
#endif
}

const ll MAX = 1e18;

int main() {
	run();
	int n;
	cin >> n;
	vector<int> v(n + 1);
	for (auto &it : v)
		cin >> it;
	vector<ll> min_number_of_nodes(n + 1);
	min_number_of_nodes[n] = v[n];
	for (int i = n - 1; i >= 0; i--)
		min_number_of_nodes[i] = (min_number_of_nodes[i + 1] + 1 >> 1) + v[i];
	min_number_of_nodes[0] = max(min_number_of_nodes[0], 1LL);
	vector<ll> max_number_of_nodes(n + 1);
	ll number_of_nodes = 1;
	for (int i = 0; i <= n; i++) {
		if (v[i] > number_of_nodes || number_of_nodes < min_number_of_nodes[i])
			return cout << -1, 0;
		max_number_of_nodes[i] = number_of_nodes;
		number_of_nodes = min(number_of_nodes - v[i] << 1, MAX);
	}
	ll sum = number_of_nodes = v[n];
	for (int i = n - 1; i >= 0; i--) {
		number_of_nodes = min(v[i] + number_of_nodes, max_number_of_nodes[i]);
		sum += number_of_nodes;
	}
	cout << sum << endl;
}


Measured memory_bytes: 5308
#include <stdio.h>

int s[100005], n;

int binarySearch(int key) {
  int left = 0;
  int right = n;

  while (left < right) {
    int mid = left + (right-left) / 2;
    if (key == s[mid]) return 1;
    else if (key > s[mid]) { left = mid + 1; }
    else { right = mid; }
  }
  return 0;
}

int main() {
  int q, i;
  int t, ans = 0;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%d", &s[i]);
  }

  scanf("%d", &q);

  for (i = 0; i < q; i++) {
    scanf("%d", &t);
    if (binarySearch(t)) {
      ans++;
    }
  }

  printf("%d\n", ans);

  return 0;
}



Measured memory_bytes: 2160
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <cstdio>
#include <cstdlib>

using namespace std;

int n,p[100001];

int main(int argc,char** argv) {
	cin >> n;
	vector<int > seq;
	int cs = 0;
	for(int i = 1;i <= n;i++) {
		cin >> p[i];
		if(i == p[i]) {
			cs++;
		}
		else if(cs != 0) {
			seq.push_back(cs);
			cs = 0;
		}
	}
	if(cs != 0) {
		seq.push_back(cs);
	}
	int res = 0;
	for(auto e:seq) {
		res += (e / 2) + (e % 2);
	}
	cout << res << endl;
}


Measured memory_bytes: 1020
#include<stdio.h>
typedef struct{
  int inf;
  int math;
  int sci;
  int eng;
  int sum;
  int inf2;
  int math2;
  int sci2;
  int eng2;
  int sum2;
}joi;
int main(){
  joi point;
  scanf("%d %d %d %d",&point.inf,&point.math,&point.sci,&point.eng);
  scanf("%d %d %d %d",&point.inf2,&point.math2,&point.sci2,&point.eng2);
  point.sum=point.inf+point.math+point.sci+point.eng;
  point.sum2=point.inf2+point.math2+point.sci2+point.eng2;
  if(point.sum<point.sum2){
    printf("%d\n",point.sum2);
  }else if(point.sum>point.sum2){
    printf("%d\n",point.sum);
  }else{
    printf("%d\n",point.sum);
  }
  return 0;
}
  

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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;

ll a, b;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> a >> b;

	if(a <= 0 && 0 <= b){
		cout << "Zero\n";
		return 0;
	}
	
	ll cnt = b - a + 1;
	
	if(0 < a){
		cout << "Positive\n";
		return 0;
	}

	if(b < 0){
		if(cnt % 2){
			cout << "Negative\n";
		} else {
			cout << "Positive\n";
		}
	}

	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define INF 1 << 30
#define MAX 1000000000
#define SIZE 1000000000
const ll mod = 1000000007;
ll factorial(ll n) {
	ll r = 1;
	while (n) {
		r *= n;
		r %= mod;
		n--;
	}
	return r;
}
int main() {
	ll N, M, a, b;
	scanf("%lld%lld", &N, &M);
	if (abs(N - M) >= 2) {
		puts("0");
		return 0;
	}
	a = (factorial(N));
	b = (factorial(M));
	printf("%lld\n", (N == M ? 2 : 1) * a * b % mod);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int a,b;
    float avrg,result;
    scanf("%d%d",&a,&b);
    avrg=(float)(a+b)/2;
    printf("%.f\n", ceil(avrg));
    return 0;
}

Measured memory_bytes: 128
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#pragma GCC optimize ("O3")
	#define NDEBUG
#endif
// #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

const array<int, 4> dx = {0, 1, 0, -1};
const array<int, 4> dy = {1, 0, -1, 0};


typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<int> a(n);
		vector<int> b(n);
		vector<int> c(n -1);
		REP(i, n) cin >> a[i];
		REP(i, n) cin >> b[i];
		REP(i, n - 1) cin >> c[i];
		int pre = -100;
		int ans = 0;
		REP(i, n) {
			int x = a[i] - 1;
			if(pre + 1 == x) {
				ans += c[pre];
			}
			ans += b[x];
			pre = x;
		}
		cout << ans << endl;
	}
	return 0;
}


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

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


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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if(A % B == 0){
    cout << A / B * C << endl;
  }
  else{
    cout << A / B * C + C << endl;
  }

 
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;
    vector<int> v(N);
    rep(i, N) cin >> v[i];
    int ans = 0;
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        int x = v[i];
        if(x % 2 == 0) {
            cnt++;
            if(x % 3 == 0 || x % 5 == 0) {
                ans++;
            }
        }
    }

    if(ans == cnt){
        cout << "APPROVED" << endl;
    } else {
        cout << "DENIED" << endl;
    }

}


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

int main()
{
	std::string s;
	std::cin >> s;
	int result_count = 0;
	for (unsigned int i = 0; i < s.size() - 1; i++)
	{
		if (s[i] == s[i + 1])
		{
			if (s[i] == '1')
			{
				s.replace(i + 1, 1, "0");
			}
			else if (s[i] == '0')
			{
				s.replace(i + 1, 1, "1");
			}
			result_count++;
		}
	}
	std::cout << result_count << "\n";
	return 0;
}



Measured memory_bytes: 512