akhauriyash/Code-Regression huggingface dataset:
// MADE BY QT666
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=1000050;
ll q,h,s,d,n,v[5],dp[N],w[N],g[N];
int main(){
  scanf("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n);
  v[1]=q*8,v[2]=h*4,v[3]=s*2,v[4]=d;ll cost=2147483647;
  w[1]=q,w[2]=h,w[3]=s,w[4]=d;
  g[1]=1,g[2]=2,g[3]=4,g[4]=8;
  for(int i=1;i<=4;i++) cost=min(cost,v[i]);
  ll x=n/2;ll val=cost*x;ll res=n-x*2;
  if(res==0) printf("%lld\n",val);
  else{
    memset(dp,127,sizeof(dp));dp[0]=0;
    res*=4;
    for(int i=1;i<=4;i++){
      for(int j=g[i];j<=res;j++){
	dp[j]=min(dp[j],dp[j-g[i]]+w[i]);
      }
    }
    printf("%lld\n",val+dp[res]);
  }
  return 0;
}

Measured memory_bytes: 11392
#include<bits/stdc++.h>
#define maxn 2000050
using namespace std;

int main()
{
   int k,x;
   cin >> k >> x;
   int l = 2 * k - 1;
   int a[l];
   for(int i=0;i<l;i++)
   {
   		a[i] = x - k + 1 + i;
   }
   sort(a, a+l);
   for(int i=0;i<l;i++)
   {
   	cout << a[i] << " ";
   }
   return 0;  
}



Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

int main(void) {
	int i, j;
	string s;
	cin >> s;
	for (i = 0; i < s.size(); i++) {
		if (s[i] == 'B') {
			for (j = i - 1; j >= 0; j--) {
				if (s[j] != 'x') {
					s[j] = 'x';
					break;
				}
			}
			s[i] = 'x';
		}
	}
	for (i = 0; i < s.size(); i++) {
		if (s[i] != 'x')
			cout << s[i];
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n")
using P = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;
using ll = long long;
const int dx4[4] = {1,0,-1,0};
const int dy4[4] = {0,1,0,-1};
const int dx8[8] = {-1,0,1,1,1,0,-1,-1};
const int dy8[8] = {1,1,1,0,-1,-1,-1,0};


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

  int n;
  cin >> n;
  int cnt = 0;
  REP(i,n+1){
    if(i%2 == 0) continue;
    int tmp = 0;
    REP(j, i+1){
      if(i%j == 0) tmp++;
    }
    if(tmp == 8) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n;
  double count = 0.0;
  scanf("%d",&n);
  double x[n];
  char  v[3*n];
  for(int i=0; i < n; ++i){
    scanf("%lf %c%c%c",&x[i],&v[3*i],&v[3*i+1],&v[3*i+2]);
    if(v[3*i] == 'J') count += x[i];
    else count += 380000*x[i];
   // printf("%lf,%c",x[i],v[3*i]);
  }
  printf("%lf",count);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>

using namespace std;

struct UnionFind {
  vector<int64_t> data;
  UnionFind(int64_t size) : data(size, -1) { }
  bool unionSet(int64_t x, int64_t y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int64_t x, int64_t y) {
    return root(x) == root(y);
  }
  int64_t root(int64_t x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int64_t size(int64_t x) {
    return -data[root(x)];
  }
};

int main() {
  int64_t N, M;
  cin >> N >> M;
  vector<int64_t> A(M);
  vector<int64_t> B(M);
  for (int64_t i = 0; i < M; i++)
    cin >> A[i] >> B[i];
  int64_t result = N*(N-1) / 2;  // nC2
  UnionFind uf(N+1);
  vector<int64_t> results(M);
  for (int64_t i = M-1; i >= 0; i--) {
    results[i] = result;
    if (!uf.findSet(A[i], B[i])) {
      result -= uf.size(A[i]) * uf.size(B[i]);
      uf.unionSet(A[i], B[i]);
    }
  }
  for (int64_t i = 0; i < M; i++)
    cout << results[i] << endl;
  return 0;
}


Measured memory_bytes: 4480
N,X=map(int,input().split())
A=N

X,N = sorted((X,N-X))
while N != X and X != 0:
    if N%X == 0:
        A += 2*(N//X-1)*X
        X,N=X,X
    else:
        A += 2*(N//X)*X
        X,N=sorted((X,N%X))
print(A+X)

Measured memory_bytes: 7524
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int K = sc.nextInt();
		int N = sc.nextInt();
		int[] A = new int[N];
		for( int i=0; i<N; i++ ){
			A[i] = sc.nextInt();
		}
		int[] dis = new int[N];
		int maxium = 0;
		for( int i=0; i<N; i++ ){
			if( i<N-1 ){
				int a = A[i+1]-A[i];
				maxium = Math.max(maxium,a);
			}else{
				int a = A[0]+(K-A[N-1]);
				maxium = Math.max(maxium,a);
			}
		}
		System.out.println(K-maxium);
	}
}

Measured memory_bytes: 66964
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	private StringTokenizer st;
	private BufferedReader bf;
	private int n;
	private int m;
	
	Main() {
		readData();
		
		if (n > m)
			System.out.println("a > b");
		else if (n < m)
			System.out.println("a < b");
		else
			System.out.println("a == b");
	}
	
	private void readData() {
		try {
			bf = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(bf.readLine());
			n = nextInt();
			m = nextInt();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	
	private String next() throws IOException {
		if (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(bf.readLine());
		return st.nextToken();
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Main m = new Main();
	}

}

Measured memory_bytes: 16872
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int N = 5e5 + 6;
const int M = (1 << 20);
const int MOD = 1e9 + 7;

int mul(int a, int b) {
	return 1LL * a * b % MOD;
}

int add(int a, int b) {
	return (a + b) % MOD;
}

int sub(int a, int b) {
	return (a - b + MOD) % MOD;
}

int x[N];
int a[N];
int p[N];
int dp[N];

int sum_dp[M];
int sum_ml[M];

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

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		x[i] = a[i];
	}
	for (int i = 1; i < n; i++) {
		a[i] ^= a[i - 1];
	}
	for (int i = 0; i < n; i++) {
		if (i > 0) p[i] += p[i - 1];
		p[i] += (a[i] == 0);
	}
	for (int i = 0; i < n; i++) {
		// for (int j = 0; j < i; j++) {
		// 	if (a[i] == a[j]) {
		// 		dp[i] = add(dp[i], mul(dp[j], sub(p[i - 1], p[j])));
		// 	}
		// }
		if (i > 0) {
			dp[i] = mul(p[i - 1], sum_dp[a[i]]);
			dp[i] = sub(dp[i], sum_ml[a[i]]);
		}
		dp[i] = add(dp[i], 1);
		sum_dp[a[i]] = add(sum_dp[a[i]], dp[i]);
		sum_ml[a[i]] = add(sum_ml[a[i]], mul(dp[i], p[i]));
	}
	int ans = 0;
	int allx = a[n - 1];
	for (int i = 0; i < n; i++) {
		if (a[i] == (allx ^ a[i]) || i + 1 == n) {
			ans = add(ans, dp[i]);
		}
	}
	cout << ans << '\n';
}



Measured memory_bytes: 19100
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    string weather[3] = {"Sunny","Cloudy","Rainy"};
    Cins(S);
    auto p = find(weather,weather+3,S) - weather;
    cout << weather[ (p+1)%3] << nn;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
#define MAX 100000

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

    vector<ll> v(n), m(MAX * 10 + MAX + 1, 0);
    //map<P, int> m;
    for (int i = 0; i < n; i++) {
        cin >> v.at(i);
        m.at(i % 2 * 10 * MAX + v.at(i))++;
        //auto itr = m.find(make_pair(i%2, v.at(i)));
        //if (itr != m.end()) m[make_pair(i%2, v.at(i))]++;
        //else m[make_pair(i%2, v.at(i))] = 1;
    }

    vector<P> p;
    for (int i = 0; i < MAX * 10 + MAX + 1; i++) p.push_back(make_pair(m.at(i), i));
    sort(p.begin(), p.end(), greater<P>());

    ll ans, max_v = 0;
    if ( (p.at(0).second + MAX * 10) != p.at(1).second && p.at(0).second != (p.at(1).second + MAX * 10) ) ans = accumulate(m.begin(), m.end(), 0LL) - p.at(0).first - p.at(1).first;
    else {
        ans = accumulate(m.begin(), m.end(), 0LL);
        for (int i = 0; i < 100; i++) {
            for (int j = i + 1; j < 100; j++) {
                if ( (p.at(i).second + MAX * 10) != p.at(j).second && p.at(i).second != (p.at(j).second + MAX * 10) ) {
                    max_v = max(max_v, p.at(i).first + p.at(j).first);
                }
            }
        }
        ans -= max_v;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 45652
def main():
    xy = []
    n = int(input())
    for _ in range(n):
        a = int(input())
        xy.append([list(map(int, input().split())) for _ in range(a)])
    ans = 0
    
    for a in range(2**n):
        c = []
        for b in range(n):
            c.append(a >> b & 1)
       
        flag = True
        for i in range(n):
            if c[i] == 1:
                for x, y in xy[i]:
                    if c[x - 1] != y:
                        flag = False
                        
        if flag:
            ans = max(ans, sum(c))
    
    print(ans)
        
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;

typedef long long LL;
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define OUT(a) cout<<(a)<<endl;

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

    string s,a,b,ans;
    cin >>s;
    a=s.substr(0,4);
    b=s.substr(4,8);
    ans=a+' ' + b;


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


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

const int N = 1e3;

int n;
int B[N+5];
int A[N+5];

int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++) scanf("%d",&B[i]);
	for(int i=1;i<=n;i++) A[i] = 1e5;
	for(int i=1;i<n;i++){
		A[i] = min(A[i],B[i]);
		A[i+1] = min(A[i+1],B[i]);
	}
	int ans = 0;
	for(int i=1;i<=n;i++) ans+=A[i];
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    unsigned long long money = 1000;
    int a, b;
    cin >> b; 
    for (int i = 2; i <= n; i++) {
        cin >> a;
        if (b < a) {
            long long kabu = money / b;
            money -= kabu * b;
            money += kabu * a;
        }
        b = a;
    }
    cout << money << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    cout << b / x - max(a - a, a - 1) / x + (a == 0 ? 1 : 0) << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t  ll;
typedef uint64_t ull;

#define rep(i,n)   for (int i = 0; i < (n); i++)
#define rrep(i,n)  for (int i = (n)-1; i >= 0; i--)
#define rep1(i,n)  for (int i = 1; i <= (n); i++)
#define rrep1(i,n) for (int i = (n); i > 0; i--)

int main(void) {
    int x, nope, nmod, sum=0, cnt=0, num=5;
    cin >> x;
    nope = x/100;
    nmod = x%100;
    while ((cnt < nope) && sum < nmod && num > 0) {
        if ((sum + num) <= nmod) {
            sum += num;
            cnt++;
        } else {
            num--;
        }
    }
    if (sum == nmod) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}


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

#define fo(i,s,t) for(int i = s;  i<= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
const int maxn = 10005;

bool f[maxn];
int n, s[maxn], all, ans;

int main()
{
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&s[i]), all += s[i];
	f[0] = true;
	fo(i,1,n) fd(j,all,s[i]) f[j] |= f[j-s[i]];
	fd(j,all,0) if(j%10&&f[j]) return 0*printf("%d\n",j);
	printf("0");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
//----
const int N=5010;
const int MOD=1e9+7;
int n;
char s[N];
int dp[N][N];
int main(){
	scanf("%d%s", &n, s);
	dp[0][0]=1;
	int m=strlen(s);
	rep(i, 1, n+1){
		dp[i][0]=(dp[i-1][0]+dp[i-1][1]*2%MOD)%MOD;
		rep(j, 1, i+1)dp[i][j]=(dp[i-1][j-1]+dp[i-1][j+1]*2%MOD)%MOD;
	}
	printf("%d\n", dp[n][m]);
	return 0;
}
/*
3
0
5

300
1100100
519054663

5000
01000001011101000100001101101111011001000110010101110010000
500886057
*/

Measured memory_bytes: 96512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)
#define cap first
#define to second.first
#define rev second.second

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

void mul_mod(ll &a, ll b){
	a *= b;
	a %= MOD;
}

vector<E> g[222];

void make_edge(int u, int v){
	g[u].push_back(E(1,P(v,g[v].l_ength())));
	g[v].push_back(E(0,P(u,g[u].l_ength()-1)));
}

bool used[222];

int dfs(int s, int t, int f){
	int i,ret;
	if(s == t){
		return f;
	}
	used[s] = true;
	for(i=(g[s].l_ength()-1); i>=0; --i){
		if(!used[g[s][i].to] && g[s][i].cap){
			ret = dfs(g[s][i].to,t,min(g[s][i].cap,f));
			if(ret){
				g[s][i].cap -= ret;
				g[g[s][i].to][g[s][i].rev].cap += ret;
				return ret;
			}
		}
	}
	return 0;
}

int main(void){
	int a[123],b[123],c,d,n,m,i,j,ans=0,f;
	cin >> n; m = n*2;
	for(i=0; i<n; ++i){
		make_edge(m,i);
		cin >> a[i] >> b[i];
	}
	for(i=n; i<m; ++i){
		cin >> c >> d;
		make_edge(i,m+1);
		for(j=0; j<n; ++j){
			if(c > a[j] && d > b[j]){
				make_edge(j,i);
			}
		}
	}
	while(true){
		fill(used,used+222,false);
		f = dfs(m,m+1,INF);
		if(!f){
			break;
		}
		ans += f;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a;
  cin >> a;
  if(a.at(5) == '0' && (a.at(6) == '1' || a.at(6) == '2' || a.at(5) == '3' || a.at(6) == '4')){
    cout << "Heisei" << endl;
  }
  else{
    cout << "TBD" << endl;
  }
}

Measured memory_bytes: 256
def solve():
    n = int(input())
    s = list(input())
    k = int(input())
    tar = s[k-1]
    for i in range(n):
        if s[i] != tar:
            s[i] = "*"
    print("".join(s))
    return 0

if __name__ == "__main__":
    solve()


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

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch&15);ch=getchar();}
	return x*f;
}

int a,b;

int main()
{
	a=read(),b=read();
	if(a>0) {printf("Positive\n");return 0;}
	if(!a || a<0&&b>=0) {printf("Zero\n");return 0;}
	if((b-a)%2) printf("Positive\n");
	else printf("Negative\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
const ll MOD = 1000000007;


int main() {
    int n;
    cin >> n;
    int h[n];
    rep(i,n) {
        cin >> h[i];
    }
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2;i < n;i++) {
        dp[i] = min(abs(h[i]-h[i-1]) + dp[i-1],abs(h[i]-h[i-2]) + dp[i-2]);
    }
    cout << dp[n-1];

}

Measured memory_bytes: 1024
/*
मनस्वी म्रियते कामं कार्पण्यं न तु गच्छति ।
अपि निर्वाणमायाति नानलो याति शीतताम् ॥
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
#define test3(x,y,z) cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define test4(w,x,y,z) cout << #w " = " << w << " " << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
    ll n,k;
    cin>>n>>k;

    ll sum = 0;
    vl v(k);
    forn(i,0,k)
    {
        cin>>v[i];
        sum += v[i];
    }
        

    if(sum > n)
    {
        cout<<-1;
        return 0;
    }
    else
    {
        cout<<n-sum;
        return 0;
    }

        












    return 0;
}   

Measured memory_bytes: 3692
n = int(input())
a = []
b = []
for i in range(n):
    c, d = map(int, input().split())
    a.append(c)
    b.append(d)
a.sort()
b.sort()
if n % 2 == 0:
    min_a = a[n // 2 - 1] + a[n // 2]
    min_b = b[n // 2 - 1] + b[n // 2]
    print(min_b - min_a + 1)
else:
    min_a = a[n // 2]
    min_b = b[n // 2]
    print(min_b - min_a + 1)

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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef unsigned long long int lli;
typedef pair<int, string> pi;


int main()
{
    int n;
    cin >> n;
    vector<lli> a(n+1), b(n);
    for(auto &x: a){
        cin >> x;
    }
    for(auto &x: b) cin >> x;

    lli ans = 0;
    for(int i=0; i<n; i++){
        int x = min(a[i], b[i]);
        ans += x;
        a[i] -= x;
        b[i] -= x;
        x = min(a[i+1], b[i]);
        ans += x;
        a[i+1] -= x;
        b[i] -= x;
    }
    cout << ans << "\n";


    return 0;
}


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

#define int long long
#define double long double

using namespace std;

#define REP(i, a, b) for (int(i) = (a); i < (b); (i)++)
#define rep(i, n) REP(i, 0, n)
#define PER(i, a, b) for (int(i) = (a - 1); i >= (b); (i)--)
#define per(i, n) PER(i, n, 0)
#define each(i, n) for (auto &i : n)
#define clr(a) memset((a), 0, sizeof(a))
#define mclr(a) memset((a), -1, sizeof(a))
#define all(a) (a).begin(), (a).end()
#define dum(val) cerr << #val " = " << val << " ";
#define dump(val) cerr << #val " = " << val << endl;
#define FILL(a, v) fill(a, a + sizeof(a) / sizeof(*a), v)

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const int mod = 1e9 + 7;
const int INF = 1e9;

int x, y;

deque<int> vx;
deque<int> vy;

unordered_map<int, int> dp[8001];

int x_solve(int i, int tx) {
	if (dp[i].count(tx)) {
		return dp[i][tx];
	}
	if (vx.size() == i) {
		if (x == tx) {
			return 1;
		} else {
			return 0;
		}
	}

	return dp[i][tx] = min(1ll, x_solve(i + 1, tx + vx[i]) + x_solve(i + 1, tx - vx[i]));
}

int y_solve(int i, int ty) {
	if (dp[i].count(ty)) {
		return dp[i][ty];
	}
	if (vy.size() == i) {
		if (y == ty) {
			return 1;
		} else {
			return 0;
		}
	}

	return dp[i][ty] = min(1ll, y_solve(i + 1, ty + vy[i]) + y_solve(i + 1, ty - vy[i]));
}

signed main() {
	string s;
	cin >> s;
	cin >> x >> y;
	bool xf = true;
	int count = 0;

	s += 'T';

	each(c, s) {
		if (c == 'F') {
			count++;
		} else {
			if (xf) {
				vx.push_back(count);
			} else {
				vy.push_back(count);
			}
			xf = !xf;
			count = 0;
		}
	}

	int ix = vx[0];
	vx.pop_front();

	int ok = 0;
	ok += x_solve(0, ix);
	rep(i, 8001) {
		dp[i].clear();
	}
	ok += y_solve(0, 0);

	if (ok == 2) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 168576
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	int x, a, b;
	cin >> x >> a >> b;
	if (a >= b) {
		cout << "delicious" << endl;
	}
	else if (x >= (b - a)) {
		cout << "safe" << endl;
	}
	else {
		cout << "dangerous" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 200005
#define oo 2000000007
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, q, a[maxN], cnt[maxN], fre[maxN], ans;

void add(int x) {
    ++fre[x];
    if (x-fre[x]+1 >= 1) {
        if (cnt[x-fre[x]+1] == 0) --ans;
        ++cnt[x-fre[x]+1];
    }
}

void del(int x) {
    if (x-fre[x]+1 >= 1) {
        --cnt[x-fre[x]+1];
        if (cnt[x-fre[x]+1] == 0) ++ans;
    }
    --fre[x];
}

int main () {
    scanf("%d%d", &n, &q);
    ans = n;
    fto(i, 1, n) {
        scanf("%d", &a[i]);
        add(a[i]);
    }

    fto(i, 1, q) {
        int x, y; scanf("%d%d", &x, &y);
        del(a[x]);
        a[x] = y;
        add(a[x]);
        printf("%d\n", ans);
    }

    return 0;
}


Measured memory_bytes: 3840
#include<iostream>
#include<math.h>

using namespace std;

int main()
{
  int N,M;
  double p0,p1;
  double X;
  cin >> N >> M;

  p0 = pow(2,M);
  p1 = (p0 - 1)/p0;
  X = 0;

  for(int i=1;i<=2000;i++){
    X = X + ((N-M)*100 + 1900 *M )* i * pow(p1,i-1) / p0;
  }


  cout << X << endl;
}











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

ans=0
for i in range(N):
    if x>=a[i]:
        ans+=1
        x-=a[i]
    else:
        break
if ans==N:
    if x==0:
        pass
    else:
        ans-=1
print(ans)

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

typedef long long ll;
typedef pair <int , int> pii;
typedef long double ld;

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n;
   cin >> n;
   bool mark[n];
   memset(mark , 0 , sizeof(mark));
   int cur = 7 % n , id = 1;
   while(!mark[cur]){
      if(cur == 0)
         return cout << id , 0;
      mark[cur] = true;
      id++;
      cur = (10 * cur + 7) % n;
   }
   cout << -1;
   return 0;
}


Measured memory_bytes: 4584
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
   	//freopen("output.txt","w",stdout);
    //freopen("input.txt","r",stdin);
    ll N,M;
    cin>>N>>M;
    ll arr[N];
    for(auto &it:arr)
    	cin>>it;
    ll sum=0;
    for(auto it:arr){
    	sum+=it;
    }
    long double req=sum/(double)(4*M);
    ll count=0;
    for(auto it:arr)
    {
    	if(it>=req)
    	{
    		count++;
    	}
    }
    if(count<M)
    {
    	cout<<"No";
    }
    else
    {
    	cout<<"Yes";
    }
}

Measured memory_bytes: 256
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n = readline() |> parseInt
	red = Array{Int}(2,n)
	blu = Array{Int}(2,n)
	for i in 1:n
		red[1:2,i] = readline() |> split |> parseMap
	end
	for i in 1:n
		blu[1:2,i] = readline() |> split |> parseMap
	end
	red = sortcols(red, by=x->x[2], rev=true)
	blu = sortcols(blu, by=x->x[1])
	r = zeros(Int,n)
	for i in 1:n
		for j in 1:n
			if red[1,j] < blu[1,i] && red[2,j] < blu[2,i] && r[j] == 0
				r[j] = 1
				break
			end
		end
	end
	println(sum(r))
end

main()

Measured memory_bytes: 128712
#n=int(input())
n,q=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
s=list(input())

cuml=[0]
count=0
for i in range(1,n):
    if s[i]=="C" and s[i-1]=="A":
        count+=1    
    cuml.append(count)

ansl=[]
for i in range(q):
    l,r=map(int,input().split())
    if l==1:
        ansl.append(cuml[r-1])
    else:
        ansl.append(cuml[r-1]-cuml[l-1])

for i in range(q):
    print(ansl[i])

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

int H, W;
vector<vector<int> > S;

int main()
{
    cin >> H >> W;

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            unsigned char hoge;
            cin >> hoge;
            S.resize(H);
            S[i].push_back((unsigned int)hoge);
        }
    }


    int rowPattern = 1;
    for (int i = H; i > 0;)
    {
        if (i == 1)
        {
            break;
        }
        else if (i % 2)
        {
            rowPattern *= i;
            i--;
        }
        else
        {
            rowPattern *= (i - 1);
            i = i - 2;
        }
    }

    for (int pp = 0; pp < rowPattern; pp++)
    {
        int p = pp;
        int center = -1;
        vector<vector<int> > Scopy = S;
        vector<vector<int> > Snew(H);

        if (H%2)
        {
            center = p % H;
            p = p / H;
            Snew[(int)(H / 2)] = Scopy[center];
            Scopy.erase(Scopy.begin() + center);
        }

        int pairNum = H / 2;
        for (int i = 0; i < pairNum; i++)
        {
            int tmp = p % (2 * (pairNum - i) - 1);
            p /= (2 * (pairNum - i) - 1);

            Snew[i] = Scopy[0];
            Scopy.erase(Scopy.begin());
            Snew[H - 1 - i] = Scopy[tmp];
            Scopy.erase(Scopy.begin() + tmp);
        }

        vector<vector<int> > columns(W);
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                columns[j].push_back(Snew[i][j]);
            }
        }

        while (!columns.empty())
        {
            int matchedColumn = -1;
            for (int i = 1; i < columns.size(); i++) // 0列目とi列目を比較
            {
                bool matchedFlag = true;
                for (int j = 0; j<H; j++)
                {
                    if (columns[0][j] != columns[i][H-1-j])
                    {
                        matchedFlag = false;
                        break;
                    }
                }

                if (matchedFlag)
                {
                    matchedColumn = i;
                    break;
                }
            }

            if (columns.size() %2 && matchedColumn < 0)
            {
                columns.erase(columns.begin());
                continue;
            }

            if (!(columns.size()%2) && matchedColumn < 0)
                break;

            columns.erase(columns.begin() + matchedColumn);
            columns.erase(columns.begin());
        }
        if (columns.empty())
        {
            cout << "YES\n";
            return 0;
        }
    }

    cout << "NO\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#define REP(i, n) for(int i = 0;i < n;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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

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

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long power_mod(long long x, long long n, long long m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return power_mod(x * x % m, n / 2, m);
	else
		return x * power_mod(x, n - 1, m) % m;
}
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}

signed main() {
	/*cin.tie(0);
	ios::sync_with_stdio(false);*/
	int N, A, B, C; cin>>N >> A >> B >> C;
	ll ans = 0;
	COMinit();
	int a = A * inv[A+B]%MOD, b = B * inv[A+B]%MOD;
	//pe(a)print(b);
	REP(i, N) {
		int res = mult(bin_pow(a, N), bin_pow(b, i));
		res = mult(res, N + i);
		res = mult(res, COM(N + i - 1, i));
		int res2 = mult(bin_pow(a, i), bin_pow(b, N));
		res2 = mult(res2, N + i);
		res2 = mult(res2, COM(N + i - 1, i));
		//pe(N)pe(i)print(res);
		ans = add(ans, res); ans = add(ans, res2);
	}
	ans *= 100*inv[A + B] % MOD;
	print(ans%MOD);
	//print(100 * inv[100] % MOD);
}


Measured memory_bytes: 4992
#include<stdio.h>

#define INF 10000
#define WHITE 0
#define BLACK 1
#define NIL -1

int n,d[100],pi[100],w[100][100],mincost,cost;

void prim(void)
{
  int u,v,i,color[100];
  for(u=0;u<n;u++)
    {
      d[u]=INF;
      pi[u]=NIL;
      color[u]=WHITE;
    }
  d[1]=0;
  
  while(1)
    {
      mincost=INF;
      for(i=0;i<n;i++)
	{
	  if((color[i]!=BLACK)&&(d[i]<mincost))
	    {
	      mincost=d[i];
	      u=i;
	    }
	}
      if(mincost==INF)
	{
	  break;
	}

      color[u]=BLACK;

      for(v=0;v<n;v++)
	{
	  if((color[v]!=BLACK)&&(w[u][v]<d[v]))
	    {
	      pi[v]=u;
	      d[v]=w[u][v];
	    }
	}
    }
  for(i=0;i<n;i++)
    {
      cost+=d[i];
    }
}

int main()
{
  int i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
	{
	  scanf("%d",&w[i][j]);
	  if(w[i][j]==-1) w[i][j]=INF;
	}
    }
  prim();
  
  printf("%d\n",cost);
    

  return 0;
}

Measured memory_bytes: 640
left = ['q','a','z','w','s','x','e','d','c','r','f','v','t','g','b']
right= ['y','h','n','u','j','m','i','k','o','l','p']

while True:
	hand = 0
	count = 0
	string = str(raw_input())
	if string == "#":
		break
	
	for var in range(0, len(string)):
		if string[var:var+1] in left:
			if hand != 1:
				hand = 1
				count += 1
		elif string[var:var+1] in right:
			if hand != 2:
				hand = 2
				count += 1
				
	print count - 1

Measured memory_bytes: 6448
#include<stdio.h>
    int main(void){
      int H,W,i,j,cou,cou2;
      char A[1000];
      scanf("%d %d",&H,&W);
      W-=1;
      scanf("%s",A);
      if(A[W]=='A'){
        A[W]='a';
      }else if(A[W]=='B'){
        A[W]='b';
      }else if(A[W]=='C'){
        A[W]='c';
      }
      printf("%s",A);


     }
      

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int ans; string S,cur,lst;
int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin>>S; cur = lst = "";
    for (int i = 0;i < S.size();i++) {cur += S[i]; if (cur != lst) ans++,lst = cur,cur = "";}
    cout<<ans<<"\n";
}


Measured memory_bytes: 720
#include<stdio.h>
int main(void) {
	int a, b, d = 1;
	while (scanf("%d %d", &a, &b) != EOF) {
		for (size_t i = 10; ; i *= 10)
		{
			if ((a + b) / i == 0)break;
			d++;
		}
		printf("%d\n", d);
		a = 0; b = 0; d = 1;
	}
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

void solve()
{
    int n;
    cin>>n;
    vl a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    ll M=a[0],ans=0;
    for(int i=1;i<n;i++) {
        if(a[i]<M) {
            ans+=M-a[i];
        }
        else {
            M=max(M,a[i]);
        }
    }

    cout<<ans;
}

int main()
{
    fastio;
    int t;
    t = 1;
    //cin >> t;
    //int test=t;
    
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

Measured memory_bytes: 4760
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cctype>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <set>
#include <deque>
#include <map>
#include <bitset>
#include <functional>
#include <cmath>

#define INF 1000000000
using namespace std;

const long long MOD = 998244353;

int main() {
	long long n, s;
	cin >> n >> s;
	vector<long long> a(n);
	long long i, j;
	for(i = 0; i < n; i++){
		cin >> a[i];
	}

	long long dp1[3010] = {0};
	dp1[0] = 1;
	for(i = 0; i < n; i++){
		long long dp2[3010] = {0};
		for(j = 0; j <= s; j++){
			dp2[j] = (2*dp1[j])%MOD;
		}
		for(j = 0; j <= s; j++){
			if(j-a[i] >= 0){
				dp2[j] += dp1[j-a[i]];
				dp2[j] %= MOD;
			}
		}
		for(j = 0; j < 3010; j++){
			dp1[j] = dp2[j];
		}
	}

	cout << dp1[s] << endl;
}


Measured memory_bytes: 3692
#!/usr/bin/env python3

N, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
    diff = a[i] + a[i + 1] - x
    if diff > 0:
        ans += diff
        a[i + 1] = max(0, a[i + 1] - diff)
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define pb pop_back
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define Sim template<class n
Sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
Sim> auto operator << (ostream &p, n y) -> 
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
Sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
Sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
Sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "
const int M = 1024 * 1024;

int n;

void rob(int a, int b)
{
	int mid = a ^ b;
	printf("%d %d\n%d %d\n", a, b, b, mid);
	printf("%d %d\n%d %d\n", mid, a + n, a + n, b + n);
}

int main()
{
	//ios_base::sync_with_stdio(0);
	//cin.tie(NULL);
	scanf("%d", &n);
	if (n < 3)
	{
		printf("No\n");
		return 0;
	}
	
	if (n % 2 == 1)
	{
		printf("Yes\n");
		printf("1 2\n2 3\n3 %d\n%d %d\n%d %d\n", n + 1, n + 1, n + 2, n + 2, n + 3);
		for (int i = 4; i < n; i += 2)
		{
			printf("%d %d\n%d %d\n", i, i + 1, i + 1, 1);
			printf("%d %d\n%d %d\n", 1, n + i, n + i, n + i + 1);
		}
	}
	else
	{
		int nn = n;
		while (nn % 2 == 0)
		{
			nn /= 2;
		}
		if (nn == 1)
		{
			printf("No\n");
			return 0;
		}
		printf("Yes\n");
		int tmp = 1;
		while (tmp * 2 <= n)
		{
			tmp *= 2;
		}
		FOR(i, 2, tmp - 1)
		{
			printf("%d %d\n", i - 1, i);
		}
		printf("%d %d\n", tmp - 1, n + 1);
		FOR(i, 2, tmp - 1)
		{
			printf("%d %d\n", n + i - 1, n + i);
		}
		rob(tmp, tmp + 2);
		for (int i = tmp + 3; i < n; i += 2)
		{
			rob(i, i + 1);
		}
		printf("%d %d\n%d %d\n", tmp + 1, tmp + 2, tmp + 1 + n, 1);
	}
	return 0;
}





Measured memory_bytes: 2560
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

LL a, n, m;

int main(){
	cin >> a >> n >> m;
	int ans = 0;

	for(int i = 1;i <= 72;i++){
		LL x = 1;
		REP(j, n) x *= (i + a);
		if(d_sum(x) == i && x <= m){
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3136
try:
    while True:
        str = str(input())
        str_replace_period = str.replace(".",",")
        str_replace_space = str_replace_period.replace(" ",",")
        word = str_replace_space.split(",")
        i = 0
        word_list = ""
        while i < len(word) :
            if len(word[i]) >= 3 and len(word[i]) <= 6 :
                word_list = word_list + word[i] + " "
            i += 1
except EOFError:
    pass

if(word_list[-1:]==" "):
    print(word_list[:-1])
else:
    print(word_list)


Measured memory_bytes: 5556
N, M = gets.chomp.split.map(&:to_i)

paths = Hash.new { |h, k| h[k] = [] }
while line = gets
  a, b = line.chomp.split.map(&:to_i)
  paths[a] << b
  paths[b] << a
end

roots = []
first_islands = paths[1]
first_islands.each do |i1|
  paths[i1].each do |i2|
    roots << [i1, i2]
  end
end

root = roots.detect { |r| r[1] == N }
puts(root ? 'POSSIBLE' : 'IMPOSSIBLE')

Measured memory_bytes: 30844
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int N = sc.nextInt();
			final int K = sc.nextInt();
			
			if(N == 0 && K == 0){
				break;
			}
			
			int[] drinks = new int[K];
			for(int i = 0; i < K; i++){
				drinks[i] = sc.nextInt();
			}
			
			boolean flag = true;
			for(int i = 0; i < N; i++){
				for(int j = 0; j < K; j++){
					drinks[j] -= sc.nextInt();
					if(drinks[j] < 0){
						flag = false;
					}
				}
			}
			
			System.out.println(flag ? "Yes" : "No");
		}

	}

}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,n,temp;
    cin>>n>>a>>b;
    if((b-a)%2==0)
    {
        cout<<(b-a)/2;
    }
    else if((b-a)%2==1)
    {
        temp=min(n-b,a-1);
        cout<<temp+1+(b-a-1)/2;
    }
}


Measured memory_bytes: 256
from collections import deque

# input
N, D, A = map(int, input().split())
XH = [tuple(map(int, input().split())) for _ in range(N)]

# process
XH.sort()
#print(XH)

ans = 0
dq = deque()
dam = 0
for x, h in XH:
    while dq:
        x2, h2 = dq[0]
        if x > x2:
            dam -= h2
            dq.popleft()
        else:
            break

    h -= dam
    if h <= 0:
#        print("x,h,dam: {},{},{}".format(x,h,dam))
        continue

    c = -(-h//A)
    ans += c
    d = A*c
    dam += d
    dq.append((x+D*2, d))
#    print("x,h,dam,ans,dq: {},{},{},{},{}".format(x,h,dam,ans,dq))
    
# output
print(ans)


Measured memory_bytes: 44608
// Dont hack this or I hack ur mama
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#define ll long long 
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define EPS (1e-9)
using namespace std;

////////////// END OF TEMPLATE
const int nmax = 0;
int n;
int a[200100];
void read()
{
	cin >> n;
	for(int i = 0 ; i < n; ++i)
		cin >> a[i];

}
void solve()
{
	int i = n-1;
	while( i >= 0)
	{
		cout << a[i] << ' ';
		i-=2;
	}
	if( i == -1)
		i = 0;
	else if(i == -2)
		i = 1;
	while( i < n)
	{	cout << a[i] << ' ';
		i+=2;
	}
	cout << endl;
}
int main()
{
	std::ios::sync_with_stdio(false);
	read();
	solve();
	return 0;
}


Measured memory_bytes: 2944