akhauriyash/Code-Regression huggingface dataset:
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int p[60];
int ans[11000];
int sz=0;
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);
	}
	int pr=-1;
	while(b>=0){
		int m=0;
		int v=mod;
		for(int i=0;i<a;i++){
			if(pr==i)continue;
			if(v>p[i]){
				m=i;
				v=p[i];
			}
		}
		if(v==0){
			printf("-1\n");return 0;
		}
		for(int i=0;i<a;i++){
			if(pr!=i){
				p[i]--;
				if(i!=m)ans[sz++]=i;
			}
		}
		ans[sz++]=m;
		pr=m;
		b--;
	}
	printf("%d\n",sz);
	for(int i=0;i<sz;i++){
		if(i)printf(" ");
		printf("%d",ans[i]+1);
	}
	printf("\n");
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int n;
	int player[200][4] = {0};
	int hanbetu;

	cin >> n;
	
	for (int i = 0; i < n; i++) {
		cin >> player[i][0] >> player[i][1] >> player[i][2];
	}
	for (int k = 0; k < 3; k++) {
		for (int i = 0; i < n; i++) {
			if (player[i][k] == -1 ) {
				continue;
			}
			hanbetu = 0;
			for (int j = 0; j < n; j++) {
				if (j == i) {
					continue;
				}
				if (player[j][k] == player[i][k]) {
					hanbetu = 1;
					player[j][k] = -1;
				}
			}
			if (hanbetu == 0) {
				player[i][3] += player[i][k];
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << player[i][3] << endl;
	}

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;

int main() {
	// your code goes here
	int n,m;
	cin>>m>>n;
	
	vector<vector<char> >v(m);
	for(int i=0;i<m;i++)
	for(int j=0;j<n;j++){
		char a;
	 cin>>a;
	 v[i].push_back(a);}
	
	bool flag=false;
	int dp[m][n];
	for(int i=0;i<m;i++)
	{
		if(v[i][0]=='#'){
			v[i][0]=0;
			flag=true;
		}
		if(v[i][0]=='.' &&!flag )
		dp[i][0]=1;
		else
		dp[i][0]=0;
	}
	flag=false;
	for(int i=0;i<n;i++)
	{
		if(v[0][i]=='#'){
			v[0][i]=0;
			flag=true;
		}
		if(v[0][i]=='.' &&!flag )
		dp[0][i]=1;
		else
		dp[0][i]=0;
	}
	
	for(int i=1;i<m;i++)
	{
		for(int j=1;j<n;j++)
		{
			if(v[i][j]=='#')
			dp[i][j]=0;
			else
			dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
		}
	}
	
	cout<<dp[m-1][n-1];
	return 0;
}

Measured memory_bytes: 5248
/*
  In the name of ALLAH
  Author : Raashid Anwar
*/

#include <bits/stdc++.h>
using namespace std;
 
#define int int64_t
const int M1 =  998244353;
const int M2 =  1000000007;
mt19937 rng((uint64_t)chrono::steady_clock::now().time_since_epoch().count());


void solve() {
  int n;
  cin >> n;
  int x, y = 0, ans = 0;
  while(n--) {
    cin >> x;
    y = max(y, x);
    ans += y - x;
  }
  cout << ans << "\n";
}
 
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int n,i,j,a,b,c,d;
string w[100];
int main()
{
  for(cin>>n>>w[0],i=1;i<n;i++){
    cin>>w[i];
    if(w[i-1][w[i-1].size()-1]!=w[i][0])return cout<<"No",0;
    for(j=0;j<i;j++)if(w[j].compare(w[i])==0)return cout<<"No",0;
  }
  cout<<"Yes";
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 10000
int main(){
  int a,b,i,j,x,y,S[N],T[N],count=0;
  scanf("%d",&x);
  for(i=0;i<x;i++){
    scanf("%d",&a);
    S[i]=a;
  }
  scanf("%d",&y);
  for(j=0;j<y;j++){
    scanf("%d",&b);
    T[j]=b;
  }
  for(j=0;j<y;j++){
    for(i=0;i<x;i++){
      if(S[i]==T[j]){
	count++;
	break;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}



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

int main() {
	int n,i,j,k,y,cur;
	cin >> n >> y;
	
	y/=1000;
	for(i=0; i<=n; i++){
		for(j=0; j<=n-i; j++){
			if(10*i+5*j+(n-i-j)==y){
				printf("%d %d %d\n",i,j,n-i-j); return 0;
			}
		}
	}
	printf("-1 -1 -1\n");
}

Measured memory_bytes: 384
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)
def fix(x):
    q = []
    while root[x]!=x:
        q.append(x)
        x = root[x]
    rt = x
    while  len(q)>0:
        x = q.pop()
        dist[x] += dist[root[x]]
        root[x] = rt
    return rt

n,m = inm()
root = list(range(n))
dist = [0]*n
for i in range(m):
    l,r,d = inm()
    l -= 1
    r -= 1
    rtl = fix(l)
    rtr = fix(r)
    if rtl != rtr:
        #ddprint(f'rtl {rtl} rtr {rtr} dl {dist[l]} dr {dist[r]}')
        if dist[l]+d > dist[r]:
            dist[rtr] = dist[l]+d-dist[r]
            dist[r] = dist[l]+d
            root[r] = root[rtr] = rtl
        else:
            dist[rtl] = dist[r]-dist[l]-d
            #dist[l] += dist[rtl]
            dist[l] = dist[r]-d
            root[l] = root[rtl] = rtr
    else:
        if dist[l]+d != dist[r]:
            print('No')
            exit()
    #ddprint(f'l {l} r {r} d {d}')
    #ddprint(root)
    #ddprint(dist)
print('Yes')


Measured memory_bytes: 55000
def main():
    n, c, k, *t = map(int, open(0).read().split())
    t.sort()
    u = tuple(t)

    cnt = 1
    p, l = 0, u[0] + k
    for v in t:
        if v <= l and p < c:
            p += 1
        else:
            cnt += 1
            p = 1
            l = v + k
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14052
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <string>
#include <iomanip>
using namespace std;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	bool ans = true;
	vector<int>test(3);
	test[0] = a;
	test[1] = b;
	test[2] = c;
	sort(test.begin(), test.end());
	if (test[0] == test[1] && test[1] != test[2]) {
		ans = false;
	}
	else if (test[1] == test[2] && test[0] != test[1]) {
		ans = false;
	}
	else {
		ans = true;
	}
	if (!ans) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef vector< pii > vii;

#define ll          long long
#define ff          first
#define ss          second
#define pb          push_back
#define mkp         make_pair
#define sz          size()

#define forf(a,b,c)    for(int i=a;i<=b;i+=c)
#define forr(a,b,c)    for(int i=a;i>=b;i-=c)
#define all(a)      a.begin(),a.end()
#define mem(a,b)    memset(a,b,sizeof(a))
#define pi          2*acos(0.0)
#define End         return 0;
#define nl endl

#define scan1(a)    scanf("%d",&a)
#define scan2(a,b)  scanf("%d %d",&a,&b)
#define scan3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define scanl(a)    scanf("%lld",&a)
#define scanll(a,b) scanf("%lld %lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define print1(a)    printf("%d",a)
#define print2(a,b)  printf("%d %d",a,b)
#define print3(a,b,c)  printf("%d %d %d",a,b,c)
#define printl(a)    printf("%lld",a)
#define printll(a,b) printf("%lld %lld",a,b)
#define printlll(a,b,c) printf("%lld %lld %lld",a,b,c)

#define MAXN        100000007
#define INF 0x3f3f3f3f
int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   int n;
   cin>>n;
   vll v(n+3),vv(n+3);
   for(int i=1;i<=n;i++) cin>>v[i];

   vv[1]=0;vv[2]=abs(v[2]-v[1]);
   for(int i=3;i<=n;i++){
    vv[i]=min(vv[i-1]+abs(v[i]-v[i-1]), vv[i-2]+abs(v[i]-v[i-2]));
   }
   cout<<vv[n]<<endl;
   return 0;
}


Measured memory_bytes: 1792
fun main(args:Array<String>?): Unit {
    while(true) {
        val n = readLine()!!.trim().toInt()
        if (n == 0) return
        val state = Array(n){ readLine()!!.trim().toCharArray()}
        val depth = state.map{it.takeWhile{c -> c == '.'}.size - 1}
        for (i in state.indices.drop(1)){
            state[i][depth[i]] = '+'
            for (j in 0 until depth[i])
                if (state[i][j] == '.') state[i][j] = ' '
            for (j in (0 until i).reversed().takeWhile{depth[it] > depth[i]})
                state[j][depth[i]] = '|'
        }
        println(
                state.joinToString("\n"){it.joinToString("")}
        )

    }
}


Measured memory_bytes: 101332
package main

import "fmt"

func main() {
	var W, H, x, y, r int

	fmt.Scan(&W, &H, &x, &y, &r)

	flag := true
	if x-r < 0 || x+r > W {
		flag = false
	}
	if y-r < 0 || y+r > H {
		flag = false
	}

	if flag {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}



Measured memory_bytes: 1140
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	lint N;
	cin >> N;

	map<int,int> tobit{ {3,1},{5,2},{7,4} };
	auto dfs = [&](auto &&f, lint n, int bit) -> int {
		if (bit == 7)DMP(n);
		int res = (bit == 7);
		for (const auto &e : vector<int>{ 3,5,7 }) {
			lint tmp = 1.0 * n * 10 + e;
			if (tmp <= N) res += f(f, tmp, bit | tobit[e]);
		}
		DMP(res);
		return res;
	};

	int ans = 0;
	for (const auto &e : vector<int>{ 3,5,7 }) ans += dfs(dfs, e, tobit[e]);
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;


int gcd(int a, int b, int c) {
  int ans = 1;
  for (int i = 1; i <= min(min(a,b), c); ++i) {
    if (a % i == 0) {
      if (b % i == 0) {
        if (c % i == 0){
          ans = i;
        }
      }
    }
  }
  return ans;
}

int main() {
  int K;
  cin >> K;
  int ans = 0;
  for (int a = 1; a <= K; a++) {
    for (int b = 1; b <= K; b++) {
      for (int c = 1; c <= K; c++) {
        ans += gcd(a, b, c);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3164
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<vector>

using namespace std;

int main(){

  int N,M;
  int T[100],P[100],X[100],S[100];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >>  T[i];
  }
  cin >> M;
  for(int i=0; i<M; i++){
    cin >> P[i] >> X[i];
    //cout << P[i] <<  X[i]<< endl;
  }

  for(int i=0; i<M; i++){
    int c = 0;
    for(int j=0; j<N; j++){
      //cout << S[i] << T[j]<<P[i] << endl;
      if(j+1 == P[i])
        c += X[i];
      else
        c += T[j];
    }
    cout << c << endl;
  }
  return 0;
}


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

int main()
{
    string a, b;
    cin >> a;
    cin >> b;
    if (int(a.size()) > int(b.size()))
    {
        cout << "GREATER" << endl;
        return 0;
    }
    else if (int(a.size()) < int(b.size()))
    {
        cout << "LESS" << endl;
        return 0;
    }
    else if (int(a.size()) == int(b.size()))
    {
        for (int i = 0; i < int(a.size()); i++)
        {
            if (int(a.at(i)) > int(b.at(i)))
            {
                cout << "GREATER" << endl;
                return 0;
            }
            else if (int(a.at(i)) < int(b.at(i)))
            {
                cout << "LESS" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
        return 0;
    }
}

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

using namespace std;

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

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

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int k;
    cin >> k;
    if(k <= 10) {
        cout << k << endl;
        return 0;
    }
    
    vector<vector<int>> dp(12, vector<int>(10, 0));
    vector<vector<int>> cnt(12, vector<int>(10, 0));
    // 下の桁から決めていく
    dp[0] = vector<int>(10, 1);
    dp[0][0] = 1;
    for(int j=1;j<=9;++j) cnt[0][j] = j;
    int kk = 9, n_digit = 0;
    for(int i=1;i<12&&n_digit==0;++i) {
        for(int j=0;j<=9;++j) {
            dp[i][j] += dp[i-1][j];
            if(j) dp[i][j] += dp[i-1][j-1];
            if(j != 9) dp[i][j] += dp[i-1][j+1];
        }
        cnt[i][0] = cnt[i-1][9];
        for(int j=1;j<=9;++j) {
            kk += dp[i][j];
            cnt[i][j] = ((j==1)?cnt[i-1][9]:cnt[i][j-1]) + dp[i][j];
        }
        if(kk >= k) {
            n_digit = i;
        }
    }

    int digit = 1;
    while(cnt[n_digit][digit] < k) {
        ++digit; 
    }
    cout << digit;
    k -= cnt[n_digit][digit-1];
    --n_digit;
    int prev_digit = digit;
    while(n_digit >= 0) {
        digit = prev_digit - 1;
        int s = dp[n_digit][digit];
        // cerr << s << "<" << k << endl;
        while(s < k) {
            // cerr << dp[n_digit][digit] << " " << cnt[n_digit][digit] << endl;
            ++digit; 
            s += dp[n_digit][digit];
            if(digit == 9) break;
        }
        s -= dp[n_digit][digit];
        cout << digit;
        --n_digit;
        k -= s;
        prev_digit = digit;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n"
#define DEBUG3(x, y, z)                                                        \
  cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z  \
       << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair< int, int >
#define ld long double
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
#define SIGN(X) ((X) > 0) - ((X) < 0)
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  int prev;
  cin >> prev;
  int ans = 0;
  int up = 0, dn = 0;
  REP(i, N - 1) {
    int p;
    cin >> p;
    if (prev < p) {
      up = 1;
    }
    if (prev > p) {
      dn = 1;
    }
    if (up && dn) {
      up = dn = 0;
      ans++;
    }
    prev = p;
  }
  print(ans + 1);
}

Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int N, K;
    cin >> N >> K;

    vector<vector<vector<ll>>> dp(N+1,vector<vector<ll>>(N+1,vector<ll>(N*N+1,0LL)));
    dp[0][0][0] = 1LL;
    for (int i=1;i<=N;i++) for (int j=0;j<=N;j++) for (int k=2*j;k<=N*N;k++) {
        if (j>0) dp[i][j][k] += dp[i-1][j-1][k-2*j];
        dp[i][j][k] %= MOD;
        dp[i][j][k] += (2*j+1)*dp[i-1][j][k-2*j];
        dp[i][j][k] %= MOD;
        if (j<N) dp[i][j][k] += (j+1)*(j+1)*dp[i-1][j+1][k-2*j];
        dp[i][j][k] %= MOD;
    }
    cout << dp[N][0][K] << endl;

    return 0;
}


Measured memory_bytes: 52224
#include<cstdio>
#include<algorithm>
bool cmp(int a,int b)
{
	return a<b;
}
int a[200005],n,tmp,tot,k,ans;
int main()
{
	scanf("%d%d",&n,&k);
	while(n--)
	{
		scanf("%d",&tmp);
		if(!a[tmp])
			++tot;
		++a[tmp];
	}
	std::sort(a,a+200005);
	for(int i=200005-tot;i<200005;++i)
	{
		if(tot<=k)
			break;
		ans+=a[i];
		tot--;
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); 
	
	int h, w, d;
	cin >> h >> w >> d;
	vector<int> x(h * w + 1), y(h * w + 1);
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			int a;
			cin >> a;
			x[a] = i;
			y[a] = j;
		}
	}
	vector<int> a(h * w + 1);
	for(int i = 1; i <= h * w; i++) {
		if(i <= d) continue;
		a[i] = a[i - d] + abs(x[i] - x[i - d]) + abs(y[i] - y[i - d]);
	}
	int q;
	cin >> q;
	while(q--) {
		int l, r;
		cin >> l >> r;
		cout << a[r] - a[l] << '\n';
	}
	return 0;
}


Measured memory_bytes: 2176
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


############ ---- Input Functions ---- ############
def in_int():
    return (int(input()))


def in_list():
    return (list(map(int, input().split())))


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


def in_ints():
    return (map(int, input().split()))


n, x, y = in_ints()


dis = [0]*(n)
for i in range(1,n+1):
    for j in range(i+1, n+1):
        l = min(abs(j-i), abs(i - x) + abs(y-j) + 1)
        dis[l] +=1


for xx in dis[1:]:
    print(xx)

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


using namespace std;

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


int main() {
	ll n;
	cin >> n;
	vector<double> s(n);
	REP(i, n) cin >> s[i];
	sort(ALL(s));
	REP(i, n - 1) {
		s[i + 1] = (s[i] + s[i + 1]) / 2;
	}
	cout << setprecision(10) << fixed << s[n - 1] << endl;
}
	

Measured memory_bytes: 256
#include <iostream>       // std::cout
#include <string>  
// std::string
using namespace std;
int main ()
{
  
  std::string date;
  cin >>  date ;
  bool mmyy = false;
  bool yydd = false;
  string result;
 
  int first = stoi(date.substr(0,2));
  int second = stoi(date.substr(2,4));
  
  if( first > 0 && first <=12 && second >=00 )
      mmyy = true;
  if( second > 0 && second <=12 && first >=00 )
      yydd = true;
  
  if( mmyy && yydd )
      result = "AMBIGUOUS";
  else if( mmyy ) {
      result = "MMYY";
  }
  else if( yydd ) {
     result =  "YYMM";
  }
  else{
    result = "NA";
  }
 
  cout << result << endl;
  return 0;
}


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



int main()
{
    for(;;){
        string a;
        cin >> a;
        int sum=0;
        if(a[0]==48) break;
        else{
            for(int i=0;i<(int)a.size();i++){
                sum+=a[i];
            }
            cout << sum-(48*(int)a.size()) << endl;
        }
    }

    return 0;
}



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

typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    char prev = 'u';
    int border = 0;
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            prev = s[i];
        } else {
            if (s[i] != prev) {
                border++;
            }
            prev = s[i];
        }
    }
    while (border > 0 && k > 0) {
        border = max(border-2, 0);
        k--;
    }
    int max = n-1;
    cout << max - border << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
int Alice,Bob;
cin >> Alice >> Bob;
if(Alice == Bob){
    cout<<"Draw"<<endl;
}
else if(Alice == 1){
    cout<<"Alice"<<endl;
}
else if(Bob == 1){
    cout<<"Bob"<<endl;
}



else if(Alice > Bob){
    cout<<"Alice"<<endl;
}
else{
    cout<<"Bob"<<endl;
}
return 0;
}


Measured memory_bytes: 384
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>

using namespace std;


int main(int argc, const char * argv[]) {
    

    long long h, ans = 0, cut = 0;
    
    cin >> h;
    
    while(1)
    {
        if (h == 1) break;

        h = h / 2;
        cut++;
        
    }
    
    for(long long i=cut; i>=0; i--)
    {
        ans += pow(2, i);
    }
    
    cout << ans << endl;
    
    return 0;
}


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

int main() {
	
	int a,b,c,d;

	cin >> a >> b >> c >> d;

	if (abs(a - c) <= d || abs(a - b) <= d && abs(b - c) <= d) {
		puts("Yes");
	}

	else {
		puts("No");
	}

}

Measured memory_bytes: 256
#if defined(__GNUC__)
#include <bits/stdc++.h>
#define __int32 __int32_t
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) std::sort(ALL(x))
#define RSORT(x) std::sort(ALL(x), greater<decltype(x)::value_type>())
#define RSORT2(x, T) std::sort(ALL(x), greater<T>())
#define REVERCE(x) std::reverce(ALL(x))
#define ACM(x, y) std::accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)
#define FCT(x) [](int a) -> int {int r = 1; REP(i, a){r *= i;} return r;}(x)

// デバッグ用
#define PUT_LIST(x, y) std::copy(ALL(x), std::ostream_iterator<decltype(x)::value_type>(std::cout, y))

itn main() {
	std::ios::sync_with_stdio(false);

	int n, r;

	cin >> n >> r;

	if (n >= 10) {
		cout << r;

		return 0;
	}
	else {
		cout << r + (100 * (10 - n));

		return 0;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define TOP 0
#define FRONT 1
#define RIGHT 2
#define LEFT 3
#define BACK 4
#define BOTTOM 5
using namespace std;

int dice[6] = {1,2,3,4,5,6};

void rotN(){
  swap(dice[TOP], dice[BACK]);
  swap(dice[TOP], dice[BOTTOM]);
  swap(dice[TOP], dice[FRONT]);
}

void rotE(){
  swap(dice[TOP], dice[RIGHT]);
  swap(dice[TOP], dice[BOTTOM]);
  swap(dice[TOP], dice[LEFT]);
}

void rotS(){
  rotN(), rotN(), rotN();
}

void rotW(){
  rotE(), rotE(), rotE();
}

int main(){
cin >> dice[TOP]>> dice[FRONT]>> dice[RIGHT]>> dice[LEFT]>> dice[BACK]>> dice[BOTTOM];
string str;
cin >> str;
for(int i = 0; i < str.size(); i++){
  if(str[i] == 'N') rotN();
  if(str[i] == 'S') rotS();
  if(str[i] == 'W') rotW();
  if(str[i] == 'E') rotE();
}
cout << dice[TOP] << endl;
}


Measured memory_bytes: 3200
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

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

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

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

void deleteNode(NodePointer t){
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer t = listSearch(key);
  if( t == nil) return;
  deleteNode(t);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	    if ( com[6] == 'F' ) deleteFirst();
	    else if ( com[6] == 'L' ) deleteLast();
      } else {
	    delete(key); 
	    nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}


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

using namespace std;

int main()
{
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    int A, B, C;
    cin >> A >> B >> C;
    swap(A, B);
    swap(A, C);
    cout << A << " " << B << " " << C << "\n";
    return 0;
}


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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

VL nums;

int main() {
    REP(i, 3) nums.emplace_back(IN());
    ll M = *max_element(All(nums)), sum = accumulate(All(nums), 0);
    if(3*M%2==sum%2) {
        cout << (3 * M - sum) / 2 << "\n";
    } else {
        cout << (3 * (M + 1) - sum) / 2 << "\n";
    }
}


Measured memory_bytes: 256
#include <iostream>
const int MAXN = 200000, MAXA = 1000000, lnMAXA = 10, MOD = 998244353;
int Prime[MAXA/lnMAXA + 5], size;
bool not_prime[MAXA + 5];
int mu[MAXA + 5];
int f[MAXA + 5], h[MAXA + 5], sum, m;
int n;

inline int minus_to_mod(int n)
{ return n >= MOD ? n - MOD : n; }

inline int plus_to_mod(int n)
{ return n < 0 ? n + MOD : n; }

inline int change(int n) {
	int t = plus_to_mod(n);
	return (t & 1) ? t + MOD : t;
}

void input() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0), std::cout.tie(0);
	std::cin >> n;
	for(int i = 1; i <= n; ++i) {
		int a;
		std::cin >> a;
		++h[a];
		sum = minus_to_mod(sum + a);
		if(m < a) m = a;
	}
}

void sieve() {
	not_prime[1] = true;
	mu[1] = 1;
	for(int i = 2; i <= m; ++i) {
		if(not_prime[i] == false) {
			Prime[size++] = i;
			mu[i] = MOD - 1;
		}
		for(int j = 0; j < size && i*Prime[j] <= m; ++j) {
			not_prime[i*Prime[j]] = true;
			if(i%Prime[j] == 0) break;
			mu[i*Prime[j]] = MOD - mu[i];
		}
	}
	for(int i = 1; i <= m; ++i)
		for(int j = 1; i*j <= m; ++j)
			f[i] = (1LL*f[i] + 1LL*h[i*j]*j)%MOD;
}

long long solve() {
	int res = 0;
	for(int i = 1; i <= m; ++i)
		for(int j = 1, k = i; k <= m; ++j, k += i)
			res = minus_to_mod(res + 1LL*mu[j]*f[k]%MOD*f[k]%MOD*k%MOD*j%MOD);
	return minus_to_mod(change(res - sum) >> 1);
}

int main() {
	input();
	sieve();
	std::cout << solve() << "\n";
	return 0;
}

Measured memory_bytes: 13312
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < n; i++)
#define CloseIO std::ios::sync_with_stdio(false)
const ll N = 8e6+1000;
const ll Mod = 100;
const ll INF = 0x3f3f3f3f3f;
vector<pair<ll,ll> > mp(N);
int main(){
  ll n;
  cin>>n;
  vector<pair<int,int> > a(n);
  rep(i,n){
    int x,y;
    cin>>x>>y;
    a[i] = {y,x};
  }
  sort(a.begin(),a.end());
  ll sum = 0;
  int flag = 0;
  rep(i,n){
    sum += a[i].second;
    if(sum > a[i].first){
      flag = 1;
      break;
    }
  }
  if(flag)cout<<"No";
  else cout<<"Yes";
    return 0;
}


Measured memory_bytes: 126848
/* ex3_4
        fmuacshai */

#include<stdio.h>

int main(void){
    //整数n、割る数m、商l
    int n,m,l;
    //nの入力
    scanf("%d",&n);
    //mの初期設定
    m=9;
    //余りが出ないまで計算
    while(n%m>0){
        m=m-1;
    }
    //商の計算
    l=n/m;
    //商が10未満ならYes、10以上ならNoと出力
    if(l<10){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
using namespace std;
int main(){
	string s;
	cin>>s;
	int i,c1=0,c2=0;
	for(i=0;i<s.length();i++){
		if(s[i]=='1') c1++;
		else if(s[i]=='0') c2++;
	}
	if(c1<=c2) cout<<c1*2;
	else  cout<<c2*2;
	
}

Measured memory_bytes: 512
fun main(args: Array<String>) {
    var (x, y) = readLine()!!.split(" ").map { it.toInt() }
    var l = (0 until x).map{ readLine()!!.split(" ").map { it.toInt()}.toMutableList()}.sortedBy{it[0]}.toMutableList()
    var sum = 0L
    var store = 0
    while (y != 0){
        if (l[store][1] != 0){
            y -= 1
            sum += l[store][0]
            l[store][1] -= 1
        }
        else store += 1
    }
    println(sum)
}

Measured memory_bytes: 82228
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int A[100000];
char kotae[800000], * it = kotae;
const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	}
	return tmp;
}

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


	int N, K, kari;
	N = getint();
	K = getint();

	int k = N - K;

	if (k <= K) {
		rep(i, k) A[i] = getint();
		rep(i, K - k) {
			if (ci - owa > 0) {
				memcpy(cn, owa, CL);
				ci -= CM;
				fread(cn + CL, 1, CM, stdin);
			}
			ll tmp = *(ll*)ci;
			if ((tmp & ma0) ^ ma0) {
				ci += (__builtin_ctzll((tmp & ma0) ^ ma0) + 4 >> 3);
			}
			else {
				ci += 8;
				while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
			}
		}
		rep(i, k) {
			kari = getint();
			if (kari > A[i]) {
				*it++ = 'Y';
				*it++ = 'e';
				*it++ = 's';
				*it++ = '\n';
			}
			else {
				*it++ = 'N';
				*it++ = 'o';
				*it++ = '\n';
			}
		}
	}
	else if (K == 1) {
		int mae = getint();
		rep(i, k) {
			kari = getint();
			if (kari > mae) {
				*it++ = 'Y';
				*it++ = 'e';
				*it++ = 's';
				*it++ = '\n';
			}
			else {
				*it++ = 'N';
				*it++ = 'o';
				*it++ = '\n';
			}
			mae = kari;
		}
	}
	else {
		rep(i, K) A[i] = getint();
		int kazu = k / K;
		int amari = k % K;
		rep(j, kazu) rep(i, K) {
			kari = getint();
			if (kari > A[i]) {
				*it++ = 'Y';
				*it++ = 'e';
				*it++ = 's';
				*it++ = '\n';
			}
			else {
				*it++ = 'N';
				*it++ = 'o';
				*it++ = '\n';
			}
			A[i] = kari;
		}
		rep(i, amari) {
			kari = getint();
			if (kari > A[i]) {
				*it++ = 'Y';
				*it++ = 'e';
				*it++ = 's';
				*it++ = '\n';
			}
			else {
				*it++ = 'N';
				*it++ = 'o';
				*it++ = '\n';
			}
		}
	}

	fwrite(kotae, 1, it - kotae, stdout);


	Would you please return 0;
}

Measured memory_bytes: 4460
#include <bits/stdc++.h>
using namespace std;
const int MX=300010, inf=2e9;
int n, a, b, X[MX];
int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>n>>a>>b;
	if(1LL*a*b<n || a+b-1>n){
		cout<<-1;
		return 0;
	}
	iota(X, X+n+1, 0);
	int cnt=0, pos=1;
	while(cnt+n-pos+1>a){
		int s=pos, e=pos+b-1, bck=a-cnt-1;
		e=min(e, n-bck);
		reverse(X+s, X+e+1);
		cnt++, pos+=b;
	}
	for(int i=1; i<=n; i++) cout<<X[i]<<' ';
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	int x;
	cin>>x;
	cout<<!x; 
	re 0;
}

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


int main()
{
    int a,b,k;cin>>a>>b>>k;
    int i = 0;
    while(true){
        a /= 2;
        b += a;
        i++;
        if(i == k) break;
        b /= 2;
        a += b;
        i++;
        if(i == k) break;
    
    }
    cout << a << " " << b << endl;
}

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

string S;
int main (){
    cin >> S;
    string T = "CODEFESTIVAL2016";
    int cnt = 0;
    for(int i=0; i<S.length(); i++) if( T[i] != S[i] ) cnt++;

    cout << cnt << endl;
    return 0;
}


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

int N, a, maks = 0, mins = 1100;
int main() {
    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        cin >> a;
        if (a > maks)
        {
            maks = a;
        }
        if (a < mins)
        {
            mins = a;
        }
        
    }
    cout << maks - mins << endl;
    cin.get();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using longlong=long long;

int main(){
    std::cin.tie(nullptr);std::cin.sync_with_stdio(false);
    std::string s,t;std::cin>>s>>t;
    int x=std::stoi(s+t);
    for(int i=0;i<=x;i++){
        if(i*i==x){
            std::cout<<"Yes"<<std::endl;
            return 0;
        }
    }
    std::cout<<"No"<<std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<double, double>P;
typedef tuple<ll, int, int>T;
#define PI 3.14159265358979


int main(){
  int N, A[303], C[4];
double dp[303][303][303];
  cin >> N;
    rep(i, N) cin >> A[i];
    rep(i, N) C[A[i]]++;
 
    rep(c3, N + 1) rep(c2, N + 1) rep(c1, N + 1) {
        int sm = c1 + c2 + c3;
        if (sm == 0) continue;
 
        dp[c1][c2][c3] = 1.0 * N / sm;
        if (c1) dp[c1][c2][c3] += dp[c1 - 1][c2][c3] * c1 / sm;
        if (c2) dp[c1][c2][c3] += dp[c1 + 1][c2 - 1][c3] * c2 / sm;
        if (c3) dp[c1][c2][c3] += dp[c1][c2 + 1][c3 - 1] * c3 / sm;
    }
 
    printf("%.10f\n", dp[C[1]][C[2]][C[3]]);
}


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

using namespace std;

#define sp(x) cout<<setprecision(x);
#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 inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl

typedef pair<int, int> P;
typedef long long ll;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin>>s;
    string reals = s;
    int n = s.length()-1;
    bool flag = false;
    REP(i,8){
        if((s.substr(0,i)+s.substr(n+i-6,7-i))=="keyence"){
            flag=true; 
            break; 
        }
    }
    if(flag == true) print("YES");
    else if(flag == false) print("NO");
    return 0;
}



Measured memory_bytes: 256
class in{struct It{int it;const bool rev;explicit constexpr It(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(It& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const It i,n;public:explicit constexpr in(int n):i(0),n(n<0?0:n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const It& begin(){return i;}const It& end(){return n;}};

#include <bits/stdc++.h>
using namespace std;

vector<int> scc(const vector<vector<int>>& adj) {
    const int n = adj.size();
    vector<int> num(n, 0), low(n, 0), color(n, 0);
    vector<int> sta;
    vector<char> inS(n, 0);
    int t = 0, colnum = 0;
    function<void(int)> visit = [&](int cur) {
        low[cur] = num[cur] = ++t;
        sta.emplace_back(cur); inS[cur] = 1;
        for(int nxt : adj[cur]) {
            if(num[nxt] == 0) {
                visit(nxt);
                low[cur] = min(low[cur], low[nxt]);
            } else if(inS[nxt])
              low[cur] = min(low[cur], num[nxt]);
        }
        if(low[cur] == num[cur]) {
            while(true) {
                int nxt = sta.back(); sta.pop_back(); inS[nxt] = false;
                color[nxt] = colnum;
                if(cur == nxt) break;
            }
            ++colnum;
        }
    };
    for(int v : in(n))
      if(num[v] == 0)
        visit(v);
    return color;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> adj(n);
    for(int _ : in(m)) {
        int u, v;
        cin >> u >> v;
        adj[u].emplace_back(v);
    }
    auto color = scc(adj);
    int q;
    cin >> q;
    for(int _ : in(q)) {
        int u, v;
        cin >> u >> v;
        if(color[u] == color[v])
          cout << 1 << '\n';
        else
          cout << 0 << '\n';
    }
    return 0;
}

Measured memory_bytes: 4356
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String N = in.next();
        int i = 0, j = N.length() - 1;
        double sum = 0;
        while(i < j){
            sum += (N.charAt(i++) - 48) + (N.charAt(j--) - 48);
        }
        if(N.length() % 2 == 1){
            sum += (N.charAt(i) - 48);
        }
        if(sum % 9 == 0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 40684
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{

    static void Main(string[] args)
    {
        int N = GetInputInt();
        int[] A = GetInputsInt();
        int[] B = GetInputsInt();

        long count = 0;

        for (int i = N-1; i>=0; i--)
        {
            int d = Math.Min(A[i + 1], B[i]);
            count += d;
            B[i] -= d;

            if (B[i] == 0) continue;

            d = Math.Min(A[i], B[i]);
            count += d;
            A[i] -= d;
        }


        Console.WriteLine(count);

    }

    

    public static int GetInputInt()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] GetInputsInt()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }
    public static List<int> GetInputsIntList()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
    }
    public static long GetInputLong()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] GetInputsLong()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }

}


Measured memory_bytes: 34140
#include <bits/stdc++.h>
using namespace std;
int main() {
    vector<int>n(999);
    n[0]=1;
    for (int i=1;i<999;i++) {
        n[i]=n[i-1]+i+1;
    }

    int a,b;
    cin>>a>>b;
    int answer;

    for (int i=0;i<998;i++) {
        if(n[i+1]-n[i]==b-a){
            answer=n[i]-a;
            break;
        }
    }
    cout<<answer<<endl;
}


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

int Heap[MAX];
int ppp;

void heapify2(int i){
    if(i/2>0&&Heap[i]>Heap[i/2]){
        swap(Heap[i],Heap[i/2]);
        heapify2(i/2);
    }
    return;
}

void insertkey(int key){
    ppp++;
    Heap[ppp]=key;
    heapify2(ppp);
    return;
}

void heapify(int i){
    int largest=i;
    if(2*i<=ppp&&Heap[largest]<Heap[2*i])largest=2*i;
    if(2*i+1<=ppp&&Heap[largest]<Heap[2*i+1])largest=2*i+1;
    if(i!=largest){
        swap(Heap[largest],Heap[i]);
        heapify(largest);
    }
    return;
}

int extract(){
    int maxi=Heap[1];
    Heap[1]=Heap[ppp];
    heapify(1);
    ppp--;
    return maxi;
}

int main(){
    ppp=0;
    char s[10];
    while(1){
    scanf("%s",s);
    if(s[0]=='i'){int key;scanf("%d",&key);insertkey(key);}
    else if(s[1]=='x'){printf("%d\n",extract());}
    else if(s[1]=='n')return 0;
    }
    return 0;
}


Measured memory_bytes: 7120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long X = scan.nextLong();
		long Y = scan.nextLong();
		long ans = 0;
		while (X <= Y) {
			X *= 2;
			ans++;
		}
		System.out.println(ans);
	}
}


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

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

    static class DRainFlowsIntoDams {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = 2 * in.nextInt(); // MULTIPLIED BY TWO!
            }

            long sum = 0;
            int mult = 1;
            for (long x : a) {
                sum += x * mult;
                mult *= -1;
            }

            long[] answer = new long[n];
            answer[0] = sum / 2;
            for (int i = 1; i < n; i++) {
                answer[i] = a[i - 1] - answer[i - 1];
            }

            StringBuilder sb = new StringBuilder();
            for (long x : answer) {
                sb.append(x + " ");
            }
            sb.deleteCharAt(sb.length() - 1);
            out.println(sb);
        }

    }

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

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

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

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

    }
}



Measured memory_bytes: 48752