akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a)
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;

inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=200005;
//i_am_noob
int n,a[maxn],ans;
set<int> st;
map<int,int> mm;

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n;
    rep(n) cin >> a[i];
    sort(a,a+n);
    ans=n;
    rep(n) mm[a[i]]++;
    rep(n) if(i==n-1||a[i]<a[i+1]) for(int j=2*a[i]; j<=a[n-1]; j+=a[i]) st.insert(j);
    rep(n) if(mm[a[i]]>1) st.insert(a[i]);
    for(auto i: st) if(mm.count(i)) ans-=mm[i];
    print1(ans);
    return 0;
}


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

typedef long long ll;

#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define clr(a, b) memset(a, b, sizeof(a))
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )

const int N = 1e5 + 5;

vector<int> adj[N];
int visit[N];
int res;

map<pair<int, int>, int> mp;

void dfs(int n, int p) {
      if(visit[n])
          return;
      visit[n] = 1;
      int co = 0;
      for(int x: adj[n]) {
          if(visit[x]) continue;
          ++co;
          if(p == co) 
              ++co;
          if(co > res)
              co = 1;
          mp[{n, x}] = co;
          mp[{x, n}] = co;
          dfs(x, co);
      }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
    int n;
    cin >> n;
    vector<pair<int, int>> v;
    forn(i, n-1) {
        int x, y;
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
        v.pb({x, y});
    }
    forab(i, 1, n)
        res = max(res, (int)adj[i].size());
    dfs(1, 0);
    cout << res << "\n";
    for(auto p: v) {
        cout << mp[{p.first, p.second}] << "\n";
    }
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << res << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)

int main() {
	int n;
	cin >> n;
	vector<int> x(n+1);
	FOR(i, 1, n) {
		cin >> x[i];
	}
	ll summin=INF,sum;
	FOR(i, 0, 100) {
		sum = 0;
		FOR(j, 1, n) {
			sum += pow(x[j] - i, 2);
		}
		summin = min(sum, summin);
	}
	pv(summin)
	return(0);
}

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

int main()
{
	int a,b,c,ans=0,xa,xb,xc;
	
	scanf("%d%d%d",&a,&b,&c);
	xa = a; xb = b; xc = c;
		
	while(a%2==0 and b%2==0 and c%2==0)
	{
		ans++;
		int ta = a/2,tb = b/2,tc = c/2;
		a = tb+tc;
		b = ta+tc;
		c = ta+tb;
		if((a==xa and b==xb and c==xc)or(a==xa and b==xc and c==xb)or(a==xb and b==xa and c==xc)or(a==xb and b==xc and c==xa)or(a==xc and b==xb and c==xa)or(a==xc and b==xa and c==xb))
		{	ans = -1; break;}
	}
	printf("%d",ans);
}

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

#define pi 3.14159265358979323846264

#define ll long long
#define fori(n) for(long long i=0;i<n;i++)
#define forj(n) for(long long j=0;j<n;j++)

#define sp(n) setprecision(n)
#define d7 1000000007
#define mkp make_pair
#define mkt make_tuple

using namespace std;

bool isPrime(long long k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    long long i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}

ll binomialCoeff(ll n, ll k){
    ll C[n + 1][k + 1];ll i, j;
    for (i = 0; i <= n; i++){
        for (j = 0; j <= min(i, k); j++){
            if (j == 0 || j == i){C[i][j] = 1;}
            else{C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);}}}
    return C[n][k];
 }

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

ll srihrg(ll n,ll k,ll m){
    ll ans;
    ans=1;
    fori(k){
        ans=(ans*n)%m;
    }
    return ans;
}


int main(int argc, const char * argv[]) {
 //cout<<"Om\n";
 //Praise to Lord
 //make cin/cout faster
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);cout.tie(NULL);
// code now
   
    ll n,k,s;
    cin>>n>>k>>s;
    fori(k){
        cout<<s<<" ";
    }
    if(s!=1e9){
        fori(n-k) cout<<s+1<<" ";
    }else{fori(n-k) cout<<1<<" ";}
    
//code ends
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
vector<int> v;
int main()
{
	int n;
	scanf("%d",&n);
	int i;
	for(i=0; i<n; i++) 
	{
		int x;
		scanf("%d",&x);
		v.push_back(x);
	} 
	v.erase(unique(v.begin(), v.end()), v.end());
	for(i=0; i<v.size(); i++)
	{
		if(i == v.size()-1) printf("%d\n",v[i]);
		else printf("%d ",v[i]);
	}
	return 0;
}


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

const int MAXN = 1e5 + 10;
int n, ans;
pair <int, int> in[MAXN];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> in[i].first;
		in[i].second = i;
	}
	sort(in, in + n);
	for (int i = 0; i < n; i++){
		if(in[i].second % 2 != i % 2)
			ans++;
	}
	cout << ans / 2;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin >>n;
  if (n==22) cout << "Christmas Eve Eve Eve" <<endl;
  if (n==23) cout << "Christmas Eve Eve" <<endl;
if (n==24) cout << "Christmas Eve" <<endl;
if (n==25) cout << "Christmas" <<endl;

}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

ll nCr(int n, int r){
  ll num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
    int N;
    cin >> N;
    vector<int> H(N);
    for(int i = 0; i < N; i++) cin >> H[i];
    int max_n = 0;
    bool ok = true;
    for(int i = 0; i < N; i++){
        max_n = max(max_n, H[i]-1);
        if(H[i] < max_n) ok = false;
    }
    
    if(ok) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 3776
def if_3(t1,ans1,t2,ans2,ans3):print(ans1 if t1 else ans2 if t2 else ans3)
def if_2(t1,ans1,ans2):print(ans1 if t1 else ans2)
def YN(t):print("YES" if t else "NO")
def yn(t):print("yes" if t else "no")
def Yn(t):print("Yes" if t else "No")
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  x=int(pin())
  if_2(x==1,0,1)
  return
main()

Measured memory_bytes: 9020
// luogu-judger-enable-o2
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;template <typename T> inline void read(T &x)
{
	x=0;int f=1;char c=getchar();
	for(;c>'9'||c<'0';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	x*=f;
}
template <typename T> inline void print(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) print(x/10);
	putchar(x%10+48);
}
inline void judge(int x)
{
	if(x<0)
	{
		x=-x;
		printf("-");
	}
	if(x>=10)
		judge(x/10);
	putchar('0' + x % 10);
}
int main()
{
	int n;
	string s,t;
	read(n);
	cin>>s>>t;
	for(register int i=n;i>=1;--i)
		if(s.substr(n-i,i)==t.substr(0,i))
		{
			judge(2*n-i);
			printf("\n");
			return 0;
		}
	judge(2*n);
	printf("\n");
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

    int s[100000],a1[200000],a2[200000];
    char c;
    int i,q,t,f,counter=1,sp1=0,sp2=0;
    int n = 0;

    while((c=getchar())!='\n'){
        s[n++] = (int)c;
    }
    //rewind(stdin);
    scanf("%d",&q);

    for(i=0;i<q;i++){
        scanf("%d",&t);
        if(t==1){
            counter*=-1;
        }else{
            scanf("%d %c",&f,&c);
            if(f==1){
                if(counter == 1){
                    a1[sp1++] = (int)c;
                }else{
                    a2[sp2++] = (int)c;
                }
            }else{
                if(counter == 1){
                    a2[sp2++] = (int)c;
                }else{
                    a1[sp1++] = (int)c;
                }
            }
            //rewind(stdin);
        }
        //rewind(stdin);
    }

    if(counter == 1){

        for(i=sp1-1;i>=0;i--){
            printf("%c",(char)a1[i]);
        }

        for(i=0;i<n;i++){
            printf("%c",(char)s[i]);
        }

        for(i=0;i<sp2;i++){
            printf("%c",(char)a2[i]);
        }

    }else{

        for(i=sp2-1;i>=0;i--){
            printf("%c",(char)a2[i]);
        }

        for(i=n-1;i>=0;i--){
            printf("%c",(char)s[i]);
        }

        for(i=0;i<sp1;i++){
            printf("%c",(char)a1[i]);
        }

    }

    return 0;
}

Measured memory_bytes: 2824
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
	int N;
	cin >> N;
	vector<int> B(N);
	rep(i, N-1) cin >> B[i];

	int cnt = B[0];
	rept(i, 1, N-1) {
		cnt += min(B[i-1], B[i]);
	}
	cnt += B[N-2];
	cout << cnt << endl;


	return 0;
}



Measured memory_bytes: 256
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  $a = array_map('intval', explode(" ", trim(fgets(STDIN))));

  $cnt = 0;
  for($i=0;$i<$n;$i++){
    while($a[$i] % 2 == 0){
      $cnt++;
      $a[$i] = $a[$i] / 2;
    }
  }
  echo $cnt;


Measured memory_bytes: 17432
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

  lli A,B,C,D;
  cin >> A >> B >> C >> D;
  
  COUT((A-C)*(B - D));
  
  
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N, A, B; cin >> N >> A >> B;
    vector<int> X(N);
    REP(i, 0, N) cin >> X[i];

    ll ans = 0;
    REP(i, 0, N - 1) {
        if ((ll)A * (X[i + 1] - X[i]) > B) {
            ans += B;
        } else {
            ans += (ll)A * (X[i + 1] - X[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N, A, B; cin >> N >> A >> B;
  string S; cin >> S;

  int total = 0;
  int total_b = 0;
  vector<string> result(N);
  rep(i,N) {
    if (S[i] == 'a') {
      if (total < A+B) {
        result[i] = "Yes";
        total++;
      } else {
        result[i] = "No";
      }
    } else if (S[i] == 'b') {
      if (total < A+B && total_b < B) {
        result[i] = "Yes";
        total++;
        total_b++;
      } else {
        result[i] = "No";
      }
    } else if (S[i] == 'c') {
      result[i] = "No";
    }
  }
  
  rep(i,N) {
    cout << result[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int i=2;
	while(true){

	if(i%2==0){
	c=c-b;
	}
	else{
	a=a-d;
	}

	if(a<=0 || c<=0) { break; }

	i=i+1;
	}
	if(a>0) cout<<"Yes";
	else if(c>0) cout<<"No";

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

Measured memory_bytes: 3624
//
// Created by kashi on 27-07-2020.
//
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define Endl endl
#define int long long
int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
bool cmps(pair<int,int>p1,pair<int,int>p2) {
    return p1.ss<p2.ss;
}
int lcm(int a, int b){
    return (a*b)/gcd(a, b);
}
int32_t main() {
    int n,k;
    cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    sort(h,h+n);
    int sum=0;
    if(k>=n)
        sum=0;
    else {
        for (int i = 0; i < n - k; i++)
            sum += h[i];
    }
    cout<<sum<<Endl;
    return 0;
}



Measured memory_bytes: 5116
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) xmax = x; return true;
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) xmin = x; return true;
    return false;
}
template<typename Val>
bool bitcheck(Val bit, size_t idx) {
    return bit & (1 << idx);
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    ll n, m, x; cin >> n >> m >> x;
    vector<ll> a(m); FOR(i, 0, m) cin >> a[i];

    a.push_back(x);
    sort(a.begin(), a.end());
    auto it = find(a.begin(), a.end(), x);
    ll ret = min(it - a.begin(), a.end() - 1 - it);
    cout << ret << endl;
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <complex>
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
#define X real()
#define Y imag()
#define EPS 1e-10
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
typedef vector<P> Poly;

double dot(P a, P b){
  return a.X*b.X + a.Y*b.Y;
}

double cross(P a, P b){
  return a.X*b.Y - a.Y*b.X;
}

int ccw(P a, P b, P c){
  if(cross(b-a,c-a) > EPS) return 1;
  if(cross(b-a,c-a) < -EPS) return -1;
  if(dot(b-a,c-a) < -EPS) return 2;
  if(norm(b-a)+EPS < norm(c-a)) return -2;
  return 0;
}

bool is_cross(L a, L b){
  if(ccw(a.first,a.second,b.first)*ccw(a.first,a.second,b.second) <= 0 &&
     ccw(b.first,b.second,a.first)*ccw(b.first,b.second,a.second) <= 0) return true;
  return false;
}

int in_poly(P a, Poly p){
  int n = p.size(), c = 0;
  p.push_back(p[0]);
  for(int i = 0; i < n; ++i){
    P s = p[i]-a, t = p[i+1]-a;
    if(!ccw(s,t,P(0,0))) return 1;//辺上
    if(s.Y > t.Y + EPS) swap(s,t);
    if((s.Y*t.Y < 0 || (s.Y*t.Y < EPS && t.Y > EPS)) && cross(s,t) < EPS) ++c;
  }
  if(c%2) return 2;//内部
  return 0;//外部
}

int main(){
  int g, q;
  cin >> g;
  Poly p(g);
  double x, y, Mx = 0, My = 0;
  for(int i = 0; i < g; ++i){
    cin >> x >> y;
    p[i] = P(x,y);
  }
  cin >> q;
  for(int i = 0; i < q; ++i){
    cin >> x >> y;
    cout << in_poly(P(x,y),p) << endl;
  }
  return 0;
}



Measured memory_bytes: 3296
N = input()

data = [list(raw_input()) for i in range(N)]

alpha = [chr(i) for i in range(97,97+26)]
cnt = [[0 for i in range(26)] for i in range(N)]

for i in range(N):
    for j in range(26):
        cnt[i][j] = data[i].count(alpha[j])


ans = ''
for i in range(26):
    mini = 10000
    for j in range(N):
        mini = min(mini,cnt[j][i]) 
    ans += alpha[i]*mini

print ans

Measured memory_bytes: 2692
#include<iostream>
using namespace std;
int main(void){
     int first=100000;
     int n;
     cin >> n;
     for(int i=0;i<n;i++){
	  first = first*1.05;
	  if(first%1000!=0){
	       first = (first/1000+1)*1000;
	  }
     }
     cout << first << endl;
     
     return 0;
}

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

long f(long a, long b) {
  if (b < a) swap(a, b);
  if (b%a == 0) return 2 * (b/a) * a - a;
  return 2 * (b/a) * a + f(a, b%a);
}

int main() {
  long N, X;
  cin >> N >> X;
  long ans = N;
  long a = N-X, b = X;
  cout << N + f(N-X, X) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>

#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>

#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;

template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

int main() {
  set<string> ym, my;
  REP(y,100) REP(m,12) {
    char buf[32];
    sprintf(buf, "%02d%02d", y, m+1);
    ym.insert(string(buf));
    sprintf(buf, "%02d%02d", m+1, y);
    my.insert(string(buf));
  }

  string s;
  while (cin >> s) {
    if (ym.count(s) && my.count(s)) {
      cout << "AMBIGUOUS" << endl;
    } else if (ym.count(s)) {
      cout << "YYMM" << endl;
    } else if (my.count(s)) {
      cout << "MMYY" << endl;
    } else {
      cout << "NA" << endl;
    }
  }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A, B, sum = 0;
    cin >> A >> B;
    for (int num = A; num < B+1; num++){
        
        int reverse = 0;
        int a = num;
        for (int i = 0; i < 5; i++){
            int remaind = 0;
            remaind = a % 10;
            reverse = reverse * 10 + remaind;
            a /= 10;
        }

        if (num == reverse) sum++;
        
    }
    
    cout << sum << endl;
}

Measured memory_bytes: 3588
n = int(input())
arr = [int(input()) for _ in range(n)]
def ear(n,t):
    if n:
        if t == 1 or t == 3:
            return n%2
        elif t == 2:
            return (n-1)%2
        else:
            return n
    else:
        if t == 1 or t == 3:
            return 2
        elif t == 2:
            return 1
        else:
            return 0
dp = [[0]*5 for _ in range(n)]
for i in range(n):
    for t in range(5):
        if i == 0:
            dp[i][t] = ear(arr[i],t)
        else:
            if t == 0:
                mind = dp[i-1][t]
                dp[i][t] = ear(arr[i],t) + mind
            else:
                if mind > dp[i-1][t]:
                    mind = dp[i-1][t]
                dp[i][t] = ear(arr[i],t) + mind
            dp[i][t] = ear(arr[i],t) + mind
print(min(dp[n-1]))

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine().ToCharArray();

            for (var i = 0; i < N.Length; i++)
            {
                if (N[i] == '9') N[i] = '1';
                else if (N[i] == '1') N[i] = '9';
            }

            Console.WriteLine(new string(N));
        }
    }
}


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int INF = 1e9;

int K;
int d[100010];

int main() {
	cin >> K;
	priority_queue<pii, vector<pii>, greater<pii>> que;

	que.push(mp(1, 1));
	rep(i, 100010) d[i] = INF;
	d[1] = 1;

	while (!que.empty()) {
		pii p = que.top(); que.pop();
		int v = p.se;

		if (d[v] < p.fi) continue;
		int nv = v * 10 % K;

		if (d[nv] > d[v]) {
			d[nv] = d[v];
			que.push(mp(d[nv], nv));
		}

		nv = (v+1) % K;
		if (d[nv] > d[v] + 1) {
			d[nv] = d[v] + 1;
			que.push(mp(d[nv], nv));
		}
	}

	cout << d[0] << endl;

	return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<ll>>;

int main(){
    ll H,N; cin>>H>>N;
    ll MAX_A = 0;
    vector<pair<ll,ll>> M;
    rep(i,N){
        ll a,b; cin>>a>>b;
        MAX_A = max(MAX_A,a);
        M.push_back(make_pair(a,b));
    }
    vector<ll> dp(H+MAX_A+1,INF);
    dp.at(0) = 0;
    rep(i,N){
        rep1(h,H+MAX_A+1){
            dp.at(h) = min(dp.at(h),dp.at(max((ll)0,h-M.at(i).first))+M.at(i).second);
        }
    }
    ll res = dp.at(H);
    for(ll i = H+1; i < H+MAX_A; i++)res = min(res,dp.at(i));
    cout<<res<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int n;
	cin >> n;
	vector<int> X(n);
	vector<int> Y(n);
	rep(i, n) cin >> X[i];
	rep(i, n) cin >> Y[i];
	long double d1 = 0, d2 = 0, d3 = 0;
	long double d4 = -INF;
	rep(i, n)
		d1 += abs(X[i] - Y[i]);
	rep(i, n)
		d2 += pow(X[i] - Y[i], 2);
	rep(i, n)
		d3 += pow(abs(X[i] - Y[i]), 3);
	rep(i, n)
		chmax(d4, (long double)abs(X[i] - Y[i]));
	d2 = sqrt(d2);
	d3 = cbrt(d3);
	printf("%.6Lf\n%.6Lf\n%.6Lf\n%.6Lf\n", d1, d2, d3, d4);
}


Measured memory_bytes: 3556
#include <iostream>
#include <climits>

using namespace std;
#define MOD 1000000007;

int main() {
    int N, M;

    cin >> N >> M;

    bool S[N + 1];
    int a, D[N + 1];
    for(int i = 0; i < N + 1; i++) S[i] = true;
    for(int i = 0; i < M; i++) {
        cin >> a;
        S[a] = false;
    }

    D[0] = 1;
    if(S[1]) D[1] = 1;
    else D[1] = 0;

    for(int i = 2; i < N + 1; i++) {
        if(S[i]) {
            D[i] = (D[i - 1] + D[i - 2]) % MOD;
        }
        else D[i] = 0;
    }

    cout << D[N] << endl;

    return 0;
}

Measured memory_bytes: 768
let main = (input) => {
    let usrInput = parseInt(input)
    let value = usrInput % 1000
    if (value === 0) {
        console.log(0)
    }
    else {
        console.log(1000 - value)
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 29684
#include <stdio.h>
#define BUFMAX 15

int main(){
    char buf[BUFMAX];
    int a,b,c;

    fgets(buf,BUFMAX,stdin);
    buf[BUFMAX-1] = '\0';
    sscanf(buf,"%d %d %d", &a, &b, &c);

    if(a < b && b < c){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1716
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}
int gcd(int a, int b){
    if(b == 0)
        return a;

    return gcd(b, a%b);
}

int main() {
    ll a, b;
    cin >> a >> b;
    cout << a * b / gcd(a, b) << endl;

    return 0;
}

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

int main(){
    int k,s;
    cin >> k >> s;
    int count = 0;

    for(int i=0; i<=k; i++){
        for(int j=0; j<=k; j++){
            if(s-i-j <= k && s-i-j >= 0){
                count++;
            }
        }
    }

    cout << count << endl;
}

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

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

    int dp[N]={0};
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<N;i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }

    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;


int binary_search_(vector<int> &vec, int l, int r){
    if(l==r-1){
        return r;
    }

    int mid = (l+r)/2;
    long long sum_=vec[mid];
    for(int i=0; i<(int) vec.size(); i++){
        if(i==mid)continue;
        if(vec[i]<=2*sum_){
            sum_+=vec[i];
        }else{
            return binary_search_(vec, mid,r);
        }
    }
    return binary_search_(vec, l,mid);

}

int main(){
    int N;
    cin >> N;
    vector<int> vec(N,0);
    for(int i=0; i<N; i++){
        cin >> vec[i];
    }
    sort(vec.begin(),vec.end());

    cout << N-binary_search_(vec, -1, N-1) << endl;

}

Measured memory_bytes: 640
N, K = map(int, input().split())
xy = [[int(x) for x in input().split()] for _ in range(N)]

xs, ys = tuple(zip(*xy))
cmpx = sorted(xs)
cmpy = sorted(ys)

x2cmp = dict((x, i) for i,x in enumerate(cmpx))
y2cmp = dict((x, i) for i,x in enumerate(cmpy))

sm = [[0] * (N + 1) for _ in range(N + 1)]
for x, y in xy:
    sm[x2cmp[x]][y2cmp[y]] = 1

for i in range(N):
    for j in range(N):
        sm[i][j] += sm[i][j - 1]
for j in range(N):
    for i in range(N):
        sm[i][j] += sm[i - 1][j]

ans = float('inf')
for x1 in range(N):
    for y1 in range(N):
        for x2 in range(x1 + 1, N):
            for y2 in range(y1 + 1, N):
                k = sm[x2][y2] - sm[x2][y1 - 1] - sm[x1 - 1][y2] + sm[x1 - 1][y1 - 1]
                if k == K:
                    area = (cmpx[x2] - cmpx[x1]) * (cmpy[y2] - cmpy[y1])
                    ans = min(ans, area)

print(ans)

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
cnt = [0]*n
for i in range(n):
    cnt[a[i]-1] += 1

tmp = [0]*n
for i in range(n):
    tmp[i] = (cnt[i]*(cnt[i]-1))//2
s = sum(tmp)
for i in range(n):
    print(s - cnt[a[i]-1]+1)



Measured memory_bytes: 79692
from math import isinf

N, M = map(int, input().split())

a = [0 for _ in range(M + 1)]
k = [0 for _ in range(M + 1)]
for i in range(M):
    a_i, _ = map(int, input().split())
    a[i + 1] = a_i
    k_i = 0
    for c in map(int, input().split()):
        k_i = k_i | 2 ** (c - 1)
    k[i + 1] = k_i

dp = [[float('inf') for _ in range(2 ** N)] for _ in range(M + 1)]
dp[0][0] = 0

for i in range(1, M + 1):
    for s in range(2 ** N):
        # i番目の鍵を使わない場合
        dp[i][s] = min(dp[i][s], dp[i - 1][s])
        # i番目の鍵を使う場合
        dp[i][s | k[i]] = min(dp[i][s | k[i]], dp[i - 1][s] + a[i])

ans = dp[M - 1][2 ** N - 1]
if isinf(ans):
    ans = -1
print(ans)

Measured memory_bytes: 139864
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    typedef pair<int,int> P;
    int H,W;
    cin>>H>>W;
    vector<string> S(H);
    int h,w;
    REP(i,H){
        cin>>S[i];
        REP(j,W) if(S[i][j]=='.'){
            h=i;w=j;
        }
    }
    int ans=0;
    int dx[4]={-1,1,0,0},dy[4]={0,0,1,-1};
    vector<vector<bool>> used(H,vector<bool>(W,false));
    REP(hoge,7){
        vector<vector<int>> d(H,vector<int> (W,-1));
        queue<P> que;
        que.push(P(h,w));
        d[h][w]=0;
        used[h][w]=true;
        while(!que.empty()){
            P p=que.front();que.pop();
            int x=p.first,y=p.second;
            REP(j,4){
                int nx=x+dx[j],ny=y+dy[j];
                if(0<=nx&&nx<H&&0<=ny&&ny<W&&S[nx][ny]=='.'&&d[nx][ny]==-1){
                    que.push(P(nx,ny)); d[nx][ny]=d[x][y]+1;
                    ans=max(ans,d[nx][ny]);
                    if(!used[nx][ny]){
                        h=nx;w=ny;
                    }
                }
            }
            
        }
    }
    std::cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

typedef long long int ll;

int main() {
    int n;
    ll w;
    cin >> n >> w;
    vector<pair<int, int>> goods(n);
    for(int i = 0; i < n; i++)
    {
        int vi, wi;
        cin >> wi >> vi;
        goods[i] = {vi, wi};
    }
    int wf = goods.front().second;
    sort(goods.begin(), goods.end());
    reverse(goods.begin(), goods.end());
    vector<vector<pair<ll, ll>>> groups(4);
    groups[0].push_back({0, 0});
    groups[1].push_back({0, 0});
    groups[2].push_back({0, 0});
    groups[3].push_back({0, 0});
    for(int i = 0; i < n; i++)
    {
        if(goods[i].second == wf)
        {
            groups[0].push_back(goods[i]);
        }else if(goods[i].second == wf + 1){
            groups[1].push_back(goods[i]);
        }else if(goods[i].second == wf + 2){
            groups[2].push_back(goods[i]);
        }else{
            groups[3].push_back(goods[i]);
        }
    }
    for(int i = 0; i < 4; i++)
    {
        for(int j = 1; j < groups[i].size(); j++)
        {
            groups[i][j] = {groups[i][j - 1].first + groups[i][j].first,
                                groups[i][j - 1].second + groups[i][j].second};
        }
    }
    ll maxv = 0;
    for(int i = 0; i < groups[0].size(); i++)
    {
        for(int j = 0; j < groups[1].size(); j++)
        {
            for(int k = 0; k < groups[2].size(); k++)
            {
                for(int l = 0; l < groups[3].size(); l++)
                {
                    ll totalv = groups[0][i].first +
                                       groups[1][j].first +
                                       groups[2][k].first +
                                       groups[3][l].first;
                    ll totalw = groups[0][i].second +
                                       groups[1][j].second +
                                       groups[2][k].second +
                                       groups[3][l].second;
                    if(totalw > w) continue;
                    if(maxv < totalv){
                        maxv = totalv;
                    }
                }
            }
        }
    }
    cout << maxv << endl;
    return 0;
}


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


int main(){
    int num;
    cin>>num;
    int a[num];
    for(int i=0;i<num;i++)
        cin>>a[i];
    int counter=0;
    int checker=0;
    for(unsigned i=0;i<num;i++){
        if(a[i]%2==0){
            counter++;
            if(a[i]%3==0){
                checker++;
            }else if(a[i]%5==0){
                checker++;
            }
        }

    }
    if(checker==counter){
        cout<<"APPROVED"<<endl;
    }else{
        cout<<"DENIED"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
cards = list(map(int, input().split()))
a = 0
b = 0

while True:
    if len(cards) == 0:
        break
    a += max(cards)
    cards.remove(max(cards))

    if len(cards) == 0:
        break
    b += max(cards)
    cards.remove(max(cards))

print(a - b)


Measured memory_bytes: 38256
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let[a,b]=nrin(2)
  out(a==b||
    (a==4||a==6||a==9||a==11)&&(b==4||b==6||b==9||b==11)||
    (a==1||a==3||a==5||a==7||a==8||a==10||a==12)&&(b==1||b==3||b==5||b==7||b==8||b==10||b==12)?'Yes':'No')
}
main()


Measured memory_bytes: 7372
n, m = map(int, input().split())
li = []
count = 0

def check_dfs(node_list):
    traveled = []
    return dfs(node_list, traveled, 0)


def dfs(node_list, t_list, position):
    t_list.append(position)
    if len(t_list) == n:
        return 0
    for i in node_list[position]:
        if i not in t_list:
            dfs(node_list, t_list, i)
    if len(t_list) == n:
        return 0
    else:
        return 1

for i in range(m):
    array = list(map(int, input().split()))
    li.append(array)

for i in range(m):
    nodes = [[] for k in range(n)]
    for j in range(m):
        if j == i:
            continue
        else:
            nodes[li[j][0]-1].append(li[j][1]-1)
            nodes[li[j][1]-1].append(li[j][0]-1)
    count += check_dfs(nodes)

print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	string s;
	cin>>s;
	string out="CODEFESTIVAL2016";
	int co=0;
	rep(i,s.size())if(s[i]!=out[i])co++;
	cout<<co<<endl;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if (n == 0) {
        ll t;
        cin >> t;
        if (t == 1) {
            cout << 1 << '\n';
        } else {
            cout << -1 << '\n';
        }
        return 0;
    }
    vector<ll> a(n + 1), b(n + 1);
    ll ans = 1;
    bool ng = false;
    for (int i = 0; i < n + 1; i++) {
        cin >> a[i];
        ans += a[i] * i;
        b[i] = a[i];
    }
    for (int i = n - 1; i >= 0; i--) {
        b[i] += b[i + 1];
    }
    if (a[0] != 0) {
        cout << -1 << '\n';
        return 0;
    }
    debug(ans);
    ll cap = 2;
    ll inf = 1e18;
    for (int i = 1; i <= n; i++) {
        if (a[i] > cap) {
            ng = true;
            break;
        }
        ans -= max(0LL, b[i] - cap);
        cap -= a[i];
        cap *= 2;
        cap = min(cap, inf);
    }
    if (ng) {
        cout << -1 << '\n';
    } else {
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 4780
#include <stdio.h>

int main(void) {
  /* code */
  int i,n;
  int ans = 0;
  scanf("%d", &n);
  char s[n+1];
  scanf("%s\n",s);
  for (i = 0; i < n-2; i++) {
    if(s[i] == 'A'){
      if(s[i+1] == 'B' && s[i+2] =='C'){
        ans++;
      }
    }
    /* code */
  }

    printf("%d\n",ans );
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int maxn=100005;
int a[maxn];
int dp[maxn];
int mincost(int n)
{
    if(n==1)
        return 0;
    else if(n==2)
        return abs(a[n]-a[1]);
    else if(dp[n]!=-1)
        return dp[n];
    else
        return dp[n]=min(mincost(n-1)+abs(a[n]-a[n-1]),mincost(n-2)+abs(a[n]-a[n-2]));
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    memset(dp,-1,sizeof(dp));
        cout<<mincost(n)<<endl;
    return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

int main(){
    ll N, M;
    cin >> N >> M;

    ll ans = 0;

    if(2*N <= M){
        ans += N;
        M -= 2*N;
        ans += M / 4;
    }else{
        ans += M / 2;
    }
    

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	long long k;
	cin >> k;
	cout << 50 << endl;
	if(k <= -1)
	{
		for(int i = 1; i <= k; i ++)
		{
			cout << 50 << " ";
		}
		for(int i = k + 1; i <= 50; i ++)
		{
			cout << 0 << " ";
		}
	}
	else
	{
		long long a = k % 50, b = k / 50;
		for(int i = 1; i <= a; i ++)
		{
			cout << 50 + b << " ";
		}
		for(int i = a + 1; i <= 50; i ++)
		{
			cout << 50 + b - a - 1 << " ";
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>

#define MAX_N 100
#define MAX_L 100

using namespace std;

struct Edge {
  int src, dest, dist, damage;
  Edge(int src, int dest, int dist, int damage): src(src), dest(dest), dist(dist), damage(damage) {;}
};

struct State {
  int pos;
  int rest;
  int damage;
  State(int pos, int rest, int damage): pos(pos), rest(rest), damage(damage) {;}
  bool operator<(const State &rhs) const {
    if (damage == rhs.damage) {
      return rest > rhs.rest;
    } else {
      return damage > rhs.damage;
    }
  }
};

int N, M, L;
vector<vector<Edge> > es;

void Solve()
{
  bool visit[N + 1][L + 1];
  memset(visit, false, sizeof(visit));

  priority_queue<State> que;

  que.push(State(1, L, 0));
  
  int ans = 1000001;
  while (!que.empty()) {
    State s = que.top(); que.pop();
    int from = s.pos, l = s.rest;

    if (visit[from][l])
      continue;

    visit[from][l] = true;
    if (from == N)  {
      ans = s.damage;
      break;
    }

    for (int i = 0; i < es[from].size(); i++) {
      int to = es[from][i].dest;

      que.push(State(to, s.rest, s.damage + es[from][i].damage));

      if (es[from][i].dist <= s.rest) {
        que.push(State(to, s.rest - es[from][i].dist, s.damage));
      }
    }
  }

  cout << ans << endl;
}

int main()
{
  int a, b, d, e;
  while (cin >> N >> M >> L && !(N == 0 && M == 0 && L == 0 )) {
    es.resize(0);
    es.resize(N + 1);
    for (int i = 0; i < M; i++) {
      cin >> a >> b >> d >> e;
      es[a].push_back(Edge(a, b, d, e));
      es[b].push_back(Edge(b, a, d, e));
    }

    Solve();
  }
}

Measured memory_bytes: 1532
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    string s;
    cin>>s;
    int n=s.length();
    vector<int> vec(n,0);
    int mae,kazu;
    for(int i=0;i<n;){
        mae=i;
        while(i<n&&s[i]=='R'){
            i++;
        }
        kazu=i-mae;
        vec[i-1]+=kazu/2;
        vec[i]+=kazu/2;
        if(kazu%2==1)vec[i-1]++;
        mae=i;
        while(i<n&&s[i]=='L'){
            i++;
        }
        kazu=i-mae;
        vec[mae-1]+=kazu/2;
        vec[mae]+=kazu/2;
        if(kazu%2==1)vec[mae]++;
    }
    out(vec);
}

Measured memory_bytes: 3868
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 2e5 + 20 ;
int n , q , a[N] , cnt[N] , num[N] , bads ; 	

inline void add (int x , int val) {
	if (val == -1) {
		if (x - cnt[x] >= 0) {
			num[x - cnt[x]] -- ;
			if (!num[x - cnt[x]]) bads ++ ;
		}

		cnt[x] -- ;
	}
	else {
		cnt[x] ++ ;
		
		if (x - cnt[x] >= 0) {
			if (!num[x - cnt[x]]) bads -- ;
			num[x - cnt[x]] ++ ;
		}
	}
}

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

	cin >> n >> q ;

	bads = n ;

	for (int i = 0 ; i < n ; i ++) cin >> a[i] , add(a[i] , +1) ;

	while (q --) {
		int x , y ;
		cin >> x >> y ;
		x -- ;

		add(a[x] , -1) ;
		a[x] = y ;
		add(a[x] , +1) ;
	
		cout << bads << '\n' ;
	}
}


Measured memory_bytes: 3840