akhauriyash/Code-Regression huggingface dataset:
/* This code is written by Nemlit */
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define rep(i, a, b) for(re int i = (a); i <= (b); ++ i)
#define drep(i, a, b) for(re int i = (b); i >= (a); -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define int long long
#define D double
#define inf 1023456789
#define mod 1000000007
#define lb(x) (x)&(-(x))
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
#define ls k * 2
#define rs k * 2 + 1
#define maxn 100005
namespace Graph {
	int head[maxn], cnt;
	struct edge { int v, next; }e[maxn << 1];
	il void add(int u, int v) { e[++ cnt] = (edge){v, head[u]}, head[u] = cnt; }
}
//using namespace Graph;
int n, m, ans, a[maxn];
char c[maxn];
signed main() {
	n = ans = read(), m = read();
	rep(i, 1, m) {
		int x = read();
		rep(j, 1, x) {
			int y = read();
			if(!a[y]) a[y] = 1, -- ans;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    string s; cin >> s;
    cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll A, B, C, D, E, F, G, H, X, Y, Z, P, Q, M, N, T, R, K, W, L, ANS;
string S, S1, S2;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> S1 >> S2;
    N = S1.length();
    if(S1 == S2.substr(0, N))
        cout << "Yes";
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define INF 100100100
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  reverse(a.begin(), a.end());

  int ans = 0;
  int minus = 0;
  for(int i = 1; i < n; ++i){
  	if(a[i-1] <= a[i]) ++minus;
  	else minus = 0;
  	ans = max(ans, minus);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int maxn = 500005;

int parent[maxn], Rank[maxn];
int n,m;
int ans;
void Initialization(int n)
{
    for(int i = 0; i <= n; i++)
        parent[i] = i, Rank[i] = 1;
}

int find_parent(int x)
{
    if(parent[x] == x)
    {
        return x;
    }
    return parent[x] = find_parent(parent[x]);
}

void make_union(int x, int  y)
{
    int p = find_parent(x);
    int q = find_parent(y);
    if(p != q)
    {
        if(Rank[p] < Rank[q])
            swap(p,q);
        parent[q] = p;
        Rank[p] += Rank[q];
        n--;
        // Rank[q] += Rank[p];
    }
}

bool isUnion(int x, int y)
{
    return find_parent(x) == find_parent(y);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    Initialization(n);
    for(int i = 0; i < m; i++)
    {
        int a,b,c;
        cin >> a >> b >> c;
        make_union(a, b);
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
    freopen("gout.txt", "w", stdout);
   
    #endif
}
 

void solve()
{
 
 int a,b;
 cin >> a >> b;
 cout <<  max((int)0,a-2*b);

}


int32_t main()
{
  pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
   // cout << "Time taken by function: "
   //       << duration.count() << " microseconds" << endl; 

 }
      
      

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

int main(void) {
	int N, T, c, t, c_min = 1001;
	
	cin >> N >> T;
	
	for (int i = 0; i < N; i++) {
		cin >> c >> t;
		if (c_min > c && t <= T)
			c_min = c;
	}
	
	if (c_min == 1001)
		cout << "TLE" << endl;
	else
		cout << c_min << endl;
	
	return 0;
}


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

int main(){
	int n, arr[5000];
	std::vector<int> v;
	while(std::cin >> n, n){
		std::fill(arr, arr+5000, 0);
		v.clear();

		for(int i=1;i<=(n-1)/2;i++){
			if(std::find(v.begin(), v.end(), i*i%n) == v.end()){//まだない
				v.push_back(i*i%n);
			}
		}

		for(int i=0;i<v.size();i++){
			for(int j=i+1;j<v.size();j++){
				int value = v[i] - v[j];
				if(value < 0){
					value += n;
				}
				if(value > (n-1)/2){
					value = n - value;
				}
				arr[value]++;
			}
		}

		for(int i=1;i<=(n-1)/2;i++){
			std::cout << arr[i]*2 << std::endl;
		}
	}
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

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

  int n, m; cin>>n>>m;
  int tot = 1900*m + 100*(n-m);
  int d = 1 << m;
  tot *= d;
  cout<<tot<<endl;
  return 0;
}
// don't forget to read in the input :^)


Measured memory_bytes: 256
#include<stdio.h>
#define N 45
 
int Fibonacci[N];
 
int FibonacciNumber(n){
  int i, f0fibonacci, f1fibonacci, fibonacci;
  f0fibonacci = 1;
  f1fibonacci = 1;
  fibonacci = 1;
  for(i = 2;i <= n;i++){
    fibonacci = f0fibonacci + f1fibonacci;
    f0fibonacci = f1fibonacci;
    f1fibonacci = fibonacci;
  }
  return fibonacci; 
 
}
 
int main(){
  int n;
  int fibonacci;
   
  scanf("%d",&n);
   
  printf("%d\n",FibonacciNumber(n));
  return 0;
}

Measured memory_bytes: 596
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    ll N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    ll mn = min(A, min(B, min(C, min(D, E))));
    ll ans = N / mn + 5;
    if(N % mn == 0)ans--;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
const int INF = 2e9 + 1;
int x[4] = {-1, 0, 1, 0};
int y[4] = {0, 1, 0, -1};
int dp[1010][1010];
struct node{
    int d;
    int nx;
    int ny;
};
void Main(){
    int h, w;
    cin >> h >> w;
    h += 2;
    w += 2;
    int sh, sw, gh, gw;
    cin >> sh >> sw >> gh >> gw;
    vector<string> s(h);
    string str = "";
    For(i,0,w) str += '#';
    s[0] = str;
    s[h-1] = str;
    For(i,1,h-1){
        cin >> s[i];
        s[i] = '#' + s[i] + '#';
    }
    For(i,0,h) For(j,0,w) dp[i][j] = INF;
    dp[sh][sw] = 0;
    deque<node> que;
    node init;
    init.d = 0;
    init.nx = sh;
    init.ny = sw;
    que.push_back(init);
    while(!que.empty()){
        auto now = que.front();
        node to;
        que.pop_front();
        if(now.nx == gh && now.ny == gw) break;
        For(i,0,4){
            if(s[now.nx + x[i]][now.ny + y[i]] == '#'){
                continue;
            }
            if(dp[now.nx + x[i]][now.ny + y[i]] > now.d){
                dp[now.nx + x[i]][now.ny + y[i]] = now.d;
                to.d = now.d;
                to.nx =  now.nx + x[i];
                to.ny = now.ny + y[i];
                que.push_front(to);
            }
        }
        For(i, -2, 3){
            if(clamp(now.nx + i, 0, h-1) != now.nx + i) continue;
            For(j, -2, 3){
                if(clamp(now.ny + j, 0, w-1) != now.ny + j) continue;
                if(s[now.nx + i][now.ny + j] == '#') continue;
                if(dp[now.nx + i][now.ny + j] > now.d + 1){
                    dp[now.nx + i][now.ny + j] = now.d + 1;
                    to.d = now.d + 1;
                    to.nx =  now.nx + i;
                    to.ny = now.ny + j;
                    que.push_back(to);
                }               
            }
        }
    }
    /*For(i,0,h){
        For(j,0,w){
            cout << dp[i][j] << " \n"[j==w-1];
        }
    }*/
    if(dp[gh][gw] == INF) cout << -1 << endl;
    else cout << dp[gh][gw] << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 9528
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int a,b;cin >> a >> b;
	cout << a + b/2 << endl;
}

Measured memory_bytes: 3604
N, x = map(int, input().split())
a = sorted(list(map(int, input().split())))

c = 0
i = 0
while x > a[i] and i < N - 1:
    x -= a[i]
    c += 1
    i += 1
if x == a[i]:
    c += 1
print(c)

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

int main(){
    string s, p;
    cin >> s;
    cin >> p;
    s = s + s;  // sを2つ繋げればpが有無が判別できる（pはsより小さい）
    if ( s.find(p) != -1 ) cout << "Yes" << endl;    //findはstringの探索が可能でindexを返す（見つからなければ-1）
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> ll gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> ll lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long x[2], y[2];
  cin >> x[0] >> y[0];
  x[1] = -x[0], y[1] = -y[0];
  long long ans = LLONG_MAX - 100;
  
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < 2; ++j) {
      ll tmp = y[j] - x[i];
      if (i == 1) ++tmp;
      if (j == 1) ++tmp;
      if (x[i] <= y[j]) {
        chmin(ans, tmp);
      }
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 256
import numpy as np
n=int(input())
a=np.array(list(map(int,input().split())))
mod=10**9+7
ans=0
for k in range(60):
  m=np.count_nonzero((a>>k)&1)
  ans+=m*(n-m)*2**k
  ans%=mod
print(ans)


Measured memory_bytes: 48804
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n,m,k; cin >> n >> m >> k;
  vector<ll> a(n+1), b(m+1);
  rep(i, n) cin >> a[i+1];
  rep(i, n) a[i+1] += a[i];
  rep(i,m) cin >> b[i+1];
  rep(i,m) b[i+1] += b[i];
  a.pop_back();
  b.pop_back();
  // rep(i,n+1) printf("%lld%c", a[i], i==n?'\n':' ');
  int ans = 0;
  rep (i,n+1) {
    if (a[i] > k) break;
    int now = i;
    int rest = k-a[i];
    auto it = lower_bound(b.begin(), b.end(), rest);
    now += it - b.begin();
    if (rest < *it) now--;
    chmax(ans, now);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6336
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define REPo(i, n) FORe((i), 1, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  vi a(n);
  REP(i, n) {
    if (s[i]=='R') a[i] = 0;
    if (s[i]=='G') a[i] = 1;
    if (s[i]=='B') a[i] = 2;
  }
  vl cnt(3);
  REP(i, n) cnt[a[i]]++;
  ll ans = 1;
  REP(i, 3) ans *= cnt[i];
  REP(j, n) REP(i, j) {
    int k = j + (j-i);
    if (k < n) {
      if (a[i]==a[j]) continue;
      if (a[i]==a[k]) continue;
      if (a[k]==a[j]) continue;
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

char s[3005],t[3005];
int n,m;
int dp[3005][3005];
bool c[3005][3005];
char r[3005];

int f(int i, int j){
	int& r=dp[i][j];
	if(r>=0)return r;
	if(i==n||j==m)return r=0;
	if(s[i]==t[j])return 1+f(i+1,j+1);
	int r0=f(i+1,j),r1=f(i,j+1);
	if(r0>r1){c[i][j]=false;return r=r0;}
	else {c[i][j]=true;return r=r1;}
}

int main(){
	scanf("%s%s",s,t);n=strlen(s);m=strlen(t);
	mset(dp,-1);
	f(0,0);
	int i=0,j=0,k=0;
	while(i<n&&j<m){
		if(s[i]==t[j]){r[k++]=s[i];i++;j++;}
		else if(!c[i][j])i++;
		else j++;
	}
	puts(r);
	return 0;
}

Measured memory_bytes: 44672
#include <stdio.h>
long long p = 1000000007;
long long x, y, z;
long long rui(long long a,long long b) {
	if (b == 0)return 1;
	if (b == 1)return a;
	if (b == 2)return a * a % p;
	if (b % 2)return rui(rui(a, b / 2), 2) * a % p;
	else return rui(rui(a, b / 2), 2);
}
int main() {
	scanf("%lld%lld", &x, &y);
	if ((x + y) % 3) {
		printf("0\n");
		return 0;
	}
	if (x > 2 * y || y > x * 2) {
		printf("0\n");
		return 0;
	}
	z = (x + y) / 3;
	x -= z;
	y -= z;
	z = 1;
	for (long long i = 1; i <= x + y; i++) {
		z *= i; z %= p;
	}
	for (long long i = 1; i <= x; i++) {
		z *= rui(i, p - 2);
		z %= p;
	}
	for (long long i = 1; i <= y; i++) {
		z *= rui(i, p - 2);
		z %= p;
	}
	printf("%lld\n", z);
}

Measured memory_bytes: 256
#define ll long long
#define lld long double
#define cn(n)  ll n;cin >> n;
#define tes(t) ll t;cin>>t;while(t--) 
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define al(v) v.begin(), v.end()
#define oset(X) tree<X, null_type, less<X>, rb_tree_tag, tree_order_statistics_node_update>
#define roset(X) tree<X, null_type, greater<X>, rb_tree_tag, tree_order_statistics_node_update>
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
const ll MOD2 = 998244353;
const long double PI = 3.141592653589793;
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
ll power(ll x, ll y, ll p){ll res = 1;x %= p;while (y > 0){if (y & 1)res = (res * x) % p;y = y >> 1;x = (x * x) % p;}return res;}
ll po(ll base, ll powerRaised){if (powerRaised != 0)return (base * po(base, powerRaised - 1));else return 1;}
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
ll lcm(ll a, ll b){return (a * b) / gcd(a, b);}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
// #ifndef ONLINE_JUDGE
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
// #endif //*
  // tes(t)
  // {
  // }
  int n;
  cin>>n;
  ll ans=0;
  ll mx;
  cin>>mx;
  rep(i,1,n-1)
  {
    ll x;
    cin>>x;
    ans+=max(mx-x,0ll);
    mx=max(x,mx);
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 3648
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

H,W,A,B=inpl()
ans = 0

MAX = H+W
fac = [1]*(MAX+1)
for i in range(1,MAX+1):
	fac[i] = (fac[i-1]*i)%mod

gyakugen = [1]*(MAX+1)
gyakugen[MAX] = pow(fac[MAX],mod-2,mod)
for i in range(MAX,0,-1):
	gyakugen[i-1] = (gyakugen[i]*i)%mod

def Comb(n,k):#nCk
	return (fac[n]*gyakugen[k]*gyakugen[n-k])%mod

for x1 in range(B+1,W+1):
	y1 = H-A
	x2 = A
	y2 = W-x1+1
	ans += (Comb(x1+y1-2,y1-1)*Comb(x2+y2-2,y2-1))%mod
	ans %= mod

print(ans)


Measured memory_bytes: 20068
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

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

	int length = s.length() - 2;

	cout << s[0];
	cout << length;
	cout << s[s.length() - 1];
}

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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll N, M, V, P; cin >> N >> M >> V >> P;
    vector<ll> vll;
    REP(i, N) {
        ll tmp; cin >> tmp;
        vll.push_back(tmp);
    }
    sort(vll.begin(), vll.end(), greater<ll>());
    ll lb = -1, ub = N;
    while (ub - lb > 1) {//クリアできたらそれより元の配点が大きいものは全部可能性がある <-二分探索
        ll target_idx = (lb + ub) / 2;
        ll boader_value = vll[P-1];
        ll rest = M * V;
        ll target_value = vll[target_idx];
        //targetへは全員投票
        target_value += M; rest -= M;
        if (rest <= 0 && boader_value <= target_value) {
            lb = target_idx;
            continue;
        }
        //あとはboaderを出来るだけ上げないように
        //boaderが上がらない安牌
        rest -= M * ((P-1) + (N-1 - target_idx));
        if (rest <= 0 && boader_value <= target_value) {
            lb = target_idx;
            continue;
        }
        if (boader_value > target_value) {
            ub = target_idx;
            continue;
        }
        //boaderも上がるがターゲットに比べれば薄められる操作
        vector<ll> boader2target_v(target_idx-(P-1));
        copy(vll.begin()+P-1,vll.begin()+target_idx,boader2target_v.begin());
        ll sukima = 0;
        for(auto x: boader2target_v) {
            sukima+=x;
        }
        sukima += rest;
        if (sukima > target_value * (target_idx - (P-1))) ub = target_idx;
        else lb = target_idx;
    }
    
    cout << ub << endl;
    return 0;
}


Measured memory_bytes: 2292
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)

hash = {}

a.each.with_index do |item, i|
  hash[i.to_s] = item-1
end
junban = Array.new(n)

hash.each.with_index do |item, i|
	junban[hash[i.to_s]] = (i+1)
end

puts junban.join(' ')


Measured memory_bytes: 24708
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
int main(){
  ll n,p;
  string s;
  cin >> n >> p >> s;
  if(p == 2 || p == 5){
    ll kotae = 0;
    for(int i = 0;i <= n - 1;i++){
      if((s[i] - '0') % p == 0)kotae += i + 1;
    }
    cout << kotae << endl;
  }
  else{
    ll kotae = 0;
    vector<ll> mod(p);
    for(int i = 1;i <= p - 1;i++)mod[i] = 0;
    mod[0] = 1;
    ll times = 0;
    times = 1;
    reverse(s.begin(),s.end());
    ll syoukei = 0;
    for(int i = 0;i <= n - 1;i++){
      syoukei += (((s[i] - '0') % p) * times) % p;
      mod[syoukei % p]++;
      //cout << "i" << i << " 余り" << (((s[i] - '0') % p) * times) % p << endl;
      //cout << "s[i]" << s[i] - '0' << " s[i]の余り" << (s[i] - '0') % p << " times" << times << endl;
      times = (times * 10) % p;
    }
    /*for(int i = 0;i <= p - 1;i++){
      cout << "amari" << i << " " << mod[i] << "個" << endl;
    }*/
    for(auto i:mod) kotae += i * (i - 1) / 2;
    cout << kotae << endl;
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
struct edge { int to, cost; };
typedef pair<int, int>P;
#define PI 3.14159265359
#define MOD 1000000007
const int MAX =510000;

int main(){
  	ll N;
  	cin >>N;
  	ll a[N];
  	rep(i,N){cin >> a[i];}
  	ll ans=0;
  	ll twof=1;
  	rep(i,60){
    	ll zero=0;ll one=0;
      	ll g=1LL<<i; 
    	rep(j,N){
        	if(a[j]&g)one++;
        	else zero++;
        }
    	ans+=(one*zero)%MOD*(twof)%MOD;
      	ans%=MOD;
      	twof=(twof*2)%MOD;
    }
  	cout<<ans;
}


Measured memory_bytes: 2560
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner (System.in)){
			Queue<String> q = new LinkedList<String>();
			while(true) {
				String s = sc.next();
				if (s.equals("-")) break;
				int times = sc.nextInt();
				int [] moves = new int[times];
				for (int i=0; i<times; i++) {
					moves[i] = sc.nextInt();
				}
				String result = Shuffle(s, times, moves);
				q.add(result);
			}
			int a = q.size();
			for (int i=0; i<a; i++) {
				System.out.println(q.remove());  //結果表示
			}
		}
	}

	static String Shuffle(String s,int times, int[] moves) {
		String s2 = s;
		for (int i=0; i<times; i++) {
			int m = moves[i];
			String s3 = s2.substring(m)+s2.substring(0,m);
			s2 = s3;
		}
		return s2;
	}
}


Measured memory_bytes: 26268
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void main() { // 日本語文字列のテスト
    int w = readint;
    int n = readint;

    auto xs = new int[w + 1];
    for (int i = 0; i < xs.length; i++)
        xs[i] = i;

    for (int i = 0; i < n; i++) {
        auto ab = readln.chomp.split(",").to!(int[]);
        int a = ab[0], b = ab[1];
        swap(xs[a], xs[b]);
    }

    foreach (x; xs[1 .. $])
        writeln(x);
}

Measured memory_bytes: 2296
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    int ans = 100000;
    for (int i = 1; i <= N - 1; i++){
        int A = i;
        int B = N - i;
        int sub_ans = 0;
        sub_ans += A % 10;
        if (A >= 10) sub_ans += (A / 10) % 10;
        if (A >= 100) sub_ans += (A / 100) % 10;
        if (A >= 1000) sub_ans += (A / 1000) % 10;
        if (A >= 10000) sub_ans += (A / 10000) % 10;
        sub_ans += B % 10;
        if (B >= 10) sub_ans += (B / 10) % 10;
        if (B >= 100) sub_ans += (B / 100) % 10;
        if (B >= 1000) sub_ans += (B / 1000) % 10;
        if (B >= 10000) sub_ans += (B / 10000) % 10;
        ans = min(ans,sub_ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type box struct {
	red   bool
	count int
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	boxes := make([]box, N)
	for i := range boxes {
		boxes[i].count = 1
	}
	boxes[0].red = true
	for i := 0; i < M; i++ {
		x := nextInt(sc)
		y := nextInt(sc)
		x-- // 0-indexed
		y-- // 0-indexed
		boxes[x].count--
		boxes[y].count++
		if boxes[x].red {
			if boxes[x].red {
				boxes[y].red = true
			}
			if boxes[x].count == 0 {
				boxes[x].red = false
			}
		}
	}
	ans := 0
	for i := 0; i < len(boxes); i++ {
		if boxes[i].red {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3328
// https://atcoder.jp/contests/abc177/tasks/abc177_e

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "string"
#include "unordered_set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
template <typename T>
using VV = V<V<T>>;
using VVL = VV<ll>;
template <typename T>
using VVV = VV<V<T>>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
using asc_pq = priority_queue<T, V<T>, greater<T>>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();
void solve2();

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

  try {
    solve2();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

string PC = "pairwise coprime";
string SC = "setwise coprime";
string NC = "not coprime";

VPL factorize(ll n) {
  VPL res;

  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;

    auto r = PL(i, 0);

    while (n % i == 0) {
      n /= i;
      r.second++;
    }

    res.push_back(r);
  }

  // sqrt(n) 以上の素因数は高々一つ
  if (n != 1) res.emplace_back(n, 1);

  return res;
}

void solve() {
  ll N;
  cin >> N;

  V<int> as(N);
  rep(i, N) cin >> as[i];

  unordered_set<int> facts;

  auto is_pc = [&]() {
    for (int a : as) {
      VPL fact = factorize(a);

      for (PL pa : fact) {
        auto [fact, _] = pa;

        if (facts.count(fact)) {
          return false;
        }

        facts.insert(fact);
      }
    }

    return true;
  };

  if (is_pc()) drop(PC);

  ll gcd_v = 0;
  rep(i, N) { gcd_v = gcd(gcd_v, as[i]); }

  if (gcd_v == 1) drop(SC);

  drop(NC);
}

void solve2() {
  ll N;
  cin >> N;

  V<int> as(N);
  rep(i, N) cin >> as[i];

  auto is_pc = [&]() {
    int a_max = *max_element(all(as));
    VL cs(a_max + 1);

    rep(i, N) cs[as[i]]++;

    repf(fact, 2, a_max + 1) {
      ll ct = 0;

      for (int num = fact; num <= a_max; num += fact) {
        ct += cs[num];
      }

      if (ct > 1) return false;
    }

    return true;
  };

  if (is_pc()) drop(PC);

  ll gcd_v = 0;
  rep(i, N) { gcd_v = gcd(gcd_v, as[i]); }

  if (gcd_v == 1) drop(SC);

  drop(NC);
}


Measured memory_bytes: 15056
// #Sazaの1日1AC
#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
const long long INF=9e15;
const double PI=3.14159265358979323846;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vP=vector<pair<long long, long long>>;
//ショートカット
#define rep(i,n) for(long long i = 0; i < n; i++)
#define rep2(i,k,n) for(long long i = k; i < n; i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mkp make_pair
//入力
#define vin(v,N) for(long long id=0;id<N;id++) cin>>v.at(id)
#define lin(n) long long n;cin>>n
#define chin(x) char x;cin>>x;
#define sin(s) string s;cin>>s;
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if(n==0) return 1;
  else if(n%2==0){
    long long t=repeat_squaring(x,n/2);
    return t*t%mod;
  }
  else
    return x*repeat_squaring(x,n-1);
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//構造体

/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////


//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  lin(N);sin(S);
  if(S.size() <= N) cout << S << endl;
  else{
    rep(i, N) cout << S[i];
    cout << "..." << endl;
  }
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main()
{
    LL n;cin>>n;
    LL check = 1000000000000000000LL;
    LL result=1;

    VL a(n);
    REP(i,n){
        cin>>a[i];
    }
    SORT_ASC(a);
    REP(i,n){
        if(result == 0){
            cout<<0<<endl;
            return;
        }
        if(a[i] > check/result){
            cout<<-1<<endl;
            return;
        }
        result*=a[i];
    }
    cout<<result<<endl;


	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 3952
#include<iostream>
#include<cmath>
using namespace std;
int x[1000000], y[100000], n, cnt;
int main() {
	for (int i = 2; i < 200000; i++) {
		for (int j = 2; j <= sqrt(i); j++) {
			if (i%j == 0) { goto E; }
		}
		x[i] = 1;
	E:;
	}
	for (int i = 0; i < 200000; i++) {
		if (x[i] == 1) { cnt++; y[cnt] = y[cnt - 1] + i; }
	}
	while (1) {
		cin >> n; if (!n) { break; }
		cout << y[n] << endl;
	}
}

Measured memory_bytes: 2016
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
const int N = 2*1e5, M = 7 + 1e9;
int n, t, a[N], b[N];
ll seg[4*N];
void update(int p, int l, int r, int i, ll v){
	if(l == r){
		seg[p] = v;
		return;
	}
	int md = (l+r)/2;
	if(i <= md)	
		update(p*2, l, md, i, v);
	else
		update(p*2+1, md+1, r, i, v);
	seg[p] = max(seg[p*2], seg[p*2+1]);
}
ll get(int p, int l, int r, int a, int b){
	if(a <= l && r <= b)
		return seg[p];
	if(l > b || r < a)
		return 0;
	int md = (l+r)/2;
	return max(get(p*2, l, md, a, b), get(p*2+1, md+1, r, a, b));
}
int main()
{
	cin >> n;
	ll mx = -1;
	f(i, 0, n)
		cin >> a[i];
	f(i, 0, n)
		cin >> b[i];
	for(ll i=0, h, a, v; i < n; ++i){
		h = ::a[i];
		a = b[i];
		v = get(1, 1, n, 1, h);
		update(1, 1, n, h, a+v);
		mx = max(mx, a+v);
	}
	cout << mx;
}

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

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

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

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

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    vector< int > as(5);
    cin >> as;

    range(i, 0, 5) {
        if (as[i]) continue;
        cout << i + 1 << endl;
    }
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3616
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-30 19:03:40
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int64 n; cin >> n;
  if (n & 1) {
    cout << 0 << endl; return 0;
  }

  n >>= 1;

  int64 ans = 0;

  while (n > 0) {
    ans += n / 5;
    n /= 5;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL A,B,C,D;
inline LL Gcd(LL a,LL b){return b?Gcd(b,a%b):a;}
inline LL LCM(LL a,LL b){return a/Gcd(a,b)*b;}
inline LL F(LL n){
	return n-n/D-n/C+n/LCM(C,D);
}
int main(){
	cin>>A>>B>>C>>D;
	printf("%lld\n",F(B)-F(A-1));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using p = pair<int,int>;
int main(){
    int n, a, x, y;
    cin >> n;
    vector<vector<p>> s(n, vector<p>());
    for(int i = 0; i < n; i++){
        cin >> a;
        for(int j = 0; j < a; j++){
            cin >> x >> y;
            s[i].push_back({--x,y});            
        }
    }
    int ans = 0;
    for(int t = 0; t < pow(2,n); t++){
        vector<int> tr(n);
        int p = 0;
        int sm = 0;
        int tp = t;
        while(tp != 0){
            tr[p] = tp%2;
            sm += tp%2;
            tp /= 2;
            p++;
        }

        bool flag = true;
        for(int i = 0; i < n; i++){
            // i 人目の人の証言
            if(!tr[i]) continue;
            for(int j = 0; j < s[i].size(); j++){
                if(tr[s[i][j].first] != s[i][j].second){
                    flag = false;
                }
            }
        }
        if (flag) ans = max(ans, sm);
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 15 05:49:43 2020

@author: Dell
"""

n = int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=0
for i in range(n):
    
    
   
    
    
    
    if a[i]>0:
        k=min(a[i],b[i])
        s+=k
        b[i]-=k
        a[i]-=k
    if b[i]>0:
        if a[i+1]>0:
            k=min(a[i+1],b[i])
            s+=k
            b[i]-=k
            a[i+1]-=k
print(s)
    

    


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

ll modpow(ll a, ll p)
{
    if (p == 0)
        return 1;
    if (!(p % 2))
    {
        ll halfP = p / 2;
        ll half = modpow(a, halfP);
        return half * half % mod;
    }
    else
    {
        return a * modpow(a, p - 1) % mod;
    }
}

ll ans[200010], ans2[200010], p[200010];

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

    int N; cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll sum = 0, sum2 = 0;

    rep(i, N) {
        p[A[i]]++;
    }

    reps(i, N) {
        ans[i] += (p[i] * (p[i] - 1)) / 2;
        sum += ans[i];
    }
    reps(i, N) {
        ans2[i] += ((p[i] - 1) * (p[i] - 2)) / 2;
        sum2 += ans2[i];
    }

    rep(i, N) {
        ll tmp = sum - ans[A[i]] + ans2[A[i]];
        cout << tmp << endl;
    }

    return 0;

}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1e9+7
ll dp[21][1<<21];
ll set1(ll N)
{
    ll ans=0;
    for(ll i=0;i<23;i++)
    { if(N>>i&1) ans++; }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll N;
    cin>>N;
    ll a[N][N],i,j,k;
    for(i=0;i<N;i++) for(j=0;j<N;j++) cin>>a[i][j];
    for(i=0;i<N;i++)
    {
        if(i==0)
        {
            for(j=0;j<N;j++)
            {
                if(a[i][j]==1)
                dp[i][1<<j]=1;
            }
        }
        else
        {
            for(j=0;j<(1<<21);j++)
            {
                if(set1(j)==i+1)
                {
                    for(k=0;k<21;k++)
                    {
                        if((j>>k&1)&&(a[i][k]==1))
                        {
                            dp[i][j]=dp[i][j]+dp[i-1][j^(1<<k)];
                            if(dp[i][j]>=mod) dp[i][j]-=mod;
                        }
                    }
                }
            }
        }
    }
    cout<<dp[N-1][(1<<N)-1]<<'\n';
    return 0;
}


Measured memory_bytes: 307456
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

vector<int> x[100100];
	
int main(){
	int n, m; cin >> n >> m;
	for( int i = 0; i < n; ++i ){
		int a, b; cin >> a >> b;
		x[a].push_back(b);
	}
	priority_queue<int> pq;
	ll ans = 0;
	for( int i = 1; i <= m; ++i ){
		for( auto k : x[i] ) pq.push(k);
		if( !pq.empty() ){
			ans += pq.top();
			pq.pop();
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 5632
import copy
import bisect
import math

def bit_and(s, ans):
    if s[-1] == 0:  return ans

    n = int(math.log2(s[-1]))
    ind = bisect.bisect_left(s, 2**n)
    if len(s) - ind == K:
        temp = s[-1]
        for i in range(1, K):
            temp &= s[-i-1]
        return ans + temp
    elif len(s) - ind > K:
        ans += 2**n
        return bit_and(sorted([x & (2**n-1) for x in s[ind:]]), ans)
    else:
        return bit_and(sorted([x & (2**n-1) for x in s]), ans)


N, K = map(int, input().split())
a = list(map(int, input().split()))

s = [a[0]]
for i in range(1, N):
    s.append(s[i-1] + a[i])
ps = copy.copy(s)
for i in range(N):
    ps = [ps[j] - ps[0] for j in range(1, N-i)]
    s += ps

print(bit_and(sorted(s), 0))

Measured memory_bytes: 77500