akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
    ifstream t("/proc/self/status");
    cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum = 0, fg = 1;
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MAXN = 18;

int n;

char s[MAXN * 2 + 5];

inline void input()
{
	n = read<int>();
	scanf("%s", s + 1);
}

LL ans = 0;

bool col[MAXN + 5];

inline int DP()
{
	static char red[MAXN + 5], blue[MAXN + 5];
	int N, M;
	memset(red, 0, sizeof red), N = 0;
	memset(blue, 0, sizeof blue), M = 0;

	for(int i = 1; i <= n; ++i)
		if(col[i] == 0) red[++N] = s[i];
		else blue[++M] = s[i];

	static int f[MAXN + 5][MAXN + 5];
	memset(f, 0, sizeof f);

	f[0][0] = 1;
	for(int i = 0; i < n; ++i)
		for(int j = 0; j <= N; ++j) if(f[i][j])
		{
			if(j < N && s[n + i + 1] == red[j + 1]) f[i + 1][j + 1] += f[i][j];
			if(i - j < M && s[n + i + 1] == blue[i - j + 1]) f[i + 1][j] += f[i][j];
		}

	return f[n][N];
}

inline void dfs(int dep)
{
	if(dep > n)
	{
		ans += DP();
		return;
	}

	col[dep] = 0, dfs(dep + 1);
	col[dep] = 1, dfs(dep + 1);
}

inline void solve()
{
	reverse(s + n + 1, s + 2 * n + 1);
	dfs(1);
	printf("%lld\n", ans);
}

int main()
{
	input();
	solve();

	return 0;
}



Measured memory_bytes: 384
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion


void Main();
void solve(std::string S, std::string T);

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

void Main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
}

void solve(std::string S, std::string T){
    int cnt = 0;
    REP(i, S.length()){
        if(S[i] != T[i]){
            cnt++;
        }
    }
    cout << cnt << el;
}



Measured memory_bytes: 4124
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,ans;
int p[MAXN],dep[MAXN],pw[MAXN];
vector<int> lay[MAXN];
int vis[MAXN],tims,cnt[MAXN],dp[MAXN][2];
vector<int> son[MAXN];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
int fpow(int x,int c) {
    int res = 1,t = x;
    while(c) {
	if(c & 1) res = mul(res,t);
	t = mul(t,t);
	c >>= 1;
    }
    return res;
}
void Init() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) read(p[i]);
    for(int i = 1 ; i <= N ; ++i) dep[i] = dep[p[i]] + 1;
    for(int i = 1 ; i <= N ; ++i) {
	lay[dep[i]].pb(i);
    }
    pw[0] = 1;
    for(int i = 1 ; i <= N + 1 ; ++i) pw[i] = mul(pw[i - 1],2);
}
auto cmp = [](int a,int b){return dep[a] < dep[b];};
priority_queue<int, vector<int>, decltype(cmp)> Q(cmp);
void BFS() {
    while(!Q.empty()) {
	int u = Q.top();Q.pop();
	if(vis[p[u]] != tims) {
	    Q.push(p[u]);
	    vis[p[u]] = tims;
	    son[p[u]].clear();
	    dp[p[u]][0] = dp[p[u]][1] = 0;
	}
	if(son[u].size() == 1){
	    if(u != 0) {
		p[son[u][0]] = p[u];
		son[p[u]].pb(son[u][0]);
	    }
	}
	else if(u != 0) son[p[u]].pb(u);
	if(son[u].size() > 1 || u == 0) {
	    int s1 = 1,s2 = 1;
	    for(auto v : son[u]) {
		s1 = mul(s1,dp[v][0]);
		s2 = mul(s2,inc(dp[v][0],dp[v][1]));
	    }
	    for(auto v : son[u]) {
		update(dp[u][1],mul(s1, mul(fpow(dp[v][0], MOD - 2), dp[v][1])));
	    }
	    dp[u][0] = inc(s2, MOD - dp[u][1]);
	}
    }
}
void Solve() {
    update(ans,pw[N]);
    for(int i = 1 ; i <= N ; ++i) {
	if(!lay[i].size()) break;
	++tims;
	for(auto k : lay[i]) {
	    Q.push(k);vis[k] = tims;
	    dp[k][0] = 1;dp[k][1] = 1;
	}
	BFS();
	update(ans,mul(dp[0][1], pw[N + 1 - lay[i].size()]));
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Init();
    Solve();
    return 0;
}


Measured memory_bytes: 27648
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> v;
int main(){
	for(int i=2;i<50000;i++){
		bool ok=true;
		for(int j=0;j<v.size();j++){
			if(i%v[j]==0)ok=false;
		}
		if(ok)v.push_back(i);
	}
	int m,a,b;
	while(cin>>m>>a>>b&&m){
		int p=-1,q=0;
		for(int i=0;i<v.size();i++){
			for(int j=i;j<v.size();j++){
				if(v[i]*v[j]>m)break;
				if(v[j]<=b*v[i]/a){
					if(p*q<v[i]*v[j])p=v[i],q=v[j];
				}
			}
		}
		cout<<p<<" "<<q<<endl;
	}
	return 0;
}

Measured memory_bytes: 3144
#include<bits/stdc++.h>
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define pb push_back
using namespace std;

const int lim=100005;
const int mod=1000000007;
int n;

vector<int>g[lim];

int a,b;

ll t[lim][2];//ile sposobow jesli czarny i ile jesli bialy

void dfs(int x, int par){
	t[x][0]=1; t[x][1]=1;
	
	for(int i=0;i<g[x].size();i++){
		if(g[x][i]!=par){
			dfs(g[x][i],x);
			t[x][0]*=t[g[x][i]][1];
			t[x][1]*=(t[g[x][i]][1]+t[g[x][i]][0]);
			t[x][0]%=mod;
			if(t[x][1]>=mod) t[x][1]%=mod;
		}
	}
}

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;	

	for(int i=1;i<n;i++){
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}
	
	dfs(1,0);
	
	cout<<(t[1][0]+t[1][1])%mod;
	return 0;
}

Measured memory_bytes: 14208
N = int(input())
red = [list(map(int, input().split())) for _ in range(N)]
blue = [list(map(int, input().split())) for _ in range(N)]
red.sort(key=lambda x: x[1], reverse=True)
blue.sort(key=lambda x: x[1])
blue.sort(key=lambda x: x[0])
ans = 0
for b in blue:
    for r in red:
        if r[0] <= b[0] and r[1] <= b[1]:
            ans += 1
            red.remove(r)
            break
print(ans)


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

int main(){
  int N; cin >> N;
  vector<int> P;
  for(int i=0; i<N; i++){
    int tmp; cin >> tmp;
    P.push_back(tmp);
  }
  int countP=0;
  do{
    countP++;
  }while(prev_permutation(P.begin(),P.end()));
  vector<int> Q;
  for(int i=0; i<N; i++){
    int tmp; cin >> tmp;
    Q.push_back(tmp);
  }
  int countQ=0;
  do{
    countQ++;
  }while(prev_permutation(Q.begin(),Q.end()));
  cout << abs(countP-countQ) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,i; cin>>n;
    vector<int> h(n), dp(n);
    for(i=0;i<n;i++) cin>>h[i];
    dp[0]=0, dp[1]=abs(h[1]-h[0]);
    for(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;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  while (true) {
    C -= B;
    if (C <= 0) {
      cout << "Yes" << endl;
      break;
    }

    A -= D;
    if (A <= 0) {
      cout << "No" << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pb push_back
#define ii pair<int,int>
#define ppb pop_back
#define orta ((bas+son)>>1)
#define st first
#define nd second
#define ll long long
#define N 200005
#define inf 1000000005
#define MOD 1000000007
#define LOG 29
#define EPS 0.000000001
#define M 305
using namespace std;

struct shop {
	int a,b;
} s[N];

int n,t;
int dp[34][N];

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);	

	cin>>n>>t;
	for(int i=1;i<=n;i++) { 
		cin>>s[i].a>>s[i].b;
	}
	sort(s+1,s+1+n,[](shop i,shop j) {
		return (ll)(j.a)*(i.b+1)<(ll)(i.a)*(j.b+1);
	});
	int b=n;
	for(int i=n;i>=1;i--) {
		if(s[i].a!=0) 
			break ;
		--b;
	}
	int magic=32;
	for(int tot=1;tot<=magic;tot++) {
		fill(dp[tot],dp[tot]+b+1,inf);
		for(int i=1;i<=b;i++) {
			dp[tot][i]=dp[tot][i-1];
			ll prv=dp[tot-1][i-1];
			ll nt=(prv+1)*(s[i].a+1)+s[i].b;
			if(nt>t) 
				nt=inf;
			dp[tot][i]=min((ll)dp[tot][i],nt);
		}
	}
	sort(s+b+1,s+1+n,[](shop i,shop j) {
		return i.b<j.b;
	});
	int res=0;
	for(int tot=0;tot<=magic;tot++) {
		int ct=dp[tot][b];
		if(ct>t) continue ;
		int ans=tot;
		for(int i=b+1;i<=n;i++) {
			if((ct+=s[i].b+1)>t) 
				break ;
			ans++; 
		}
		res=max(res,ans);
	}
	cout<<res;

}

Measured memory_bytes: 27648
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
function PriorityQueue(){
  this.heap = [];
}
PriorityQueue.prototype = {
  push : function(x){
    var h = this.heap, i = h.length++, j;
    while(i){
      j = i-1 >> 1;
      if(h[j] <= x)break;
      h[i] = h[j];
      i = j;
    }
    h[i] = x;
  },
  pop : function(){
    var h = this.heap, r = h[0], x = h.pop();
    var i = 0, k = h.length >> 1, j;
    while (i < k) {
      j = (i << 1) + 1;
      if(h[j+1] < h[j])++j;
      if(x <= h[j])break;
      h[i] = h[j];
      i = j;
    }
    if(h.length)h[i] = x;
    return r;
  },
  size : function(){return this.heap.length;},
  top : function(){return this.heap[0];},
};

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var a = o.m(n);
  a.push([1e9,0]);
  a.sort((a,b)=>a[0]-b[0]);
  var ans = 0, j = 0;
  var pq = new PriorityQueue();
  for(var i = 1; i <= m; i++){
    while(a[j][0] <= i){
      pq.push(-a[j][1]);
      j++;
    }
    if(pq.size())ans += pq.pop();
  }
  return 0-ans;
}

Measured memory_bytes: 66156
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int):
    print(min( B // A , C))


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 314159
#define  vi vector<int>
#define  v  vector

signed main() 
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    stack<int>s;
    string in;
    cin>>in;
    
    int ans=0;
    //cout<<s.top();
    //return 0;
    forn(i,0,in.size()-1)
    {
        if(s.size()==0)
        {
            s.push(in[i]-'0');continue;
        }
        int b=s.top();
        int a=in[i]-'0';
        if(a+b==1)
        {
            s.pop();
            ans+=2;
        }
        else
        {
            s.push(a);
        }
        
    }
    cout<<ans;


}

//       g++ -g c.cpp ; ./a.exe

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

using namespace std;


struct Bipartite_Matching
{
  vector< vector< int > > graph;
  vector< int > dist, match;
  vector< bool > used, vv;

  Bipartite_Matching(int n, int m)
  {
    graph.resize(n);
    match.assign(m, -1);
    used.assign(n, false);
  }

  void add_edge(int u, int v)
  {
    graph[u].push_back(v);
  }

  void bfs()
  {
    dist.assign(graph.size(), -1);
    queue< int > que;
    for(int i = 0; i < graph.size(); i++) {
      if(!used[i]) {
        que.emplace(i);
        dist[i] = 0;
      }
    }

    while(!que.empty()) {
      int a = que.front();
      que.pop();
      for(auto &b : graph[a]) {
        int c = match[b];
        if(c >= 0 && dist[c] == -1) {
          dist[c] = dist[a] + 1;
          que.emplace(c);
        }
      }
    }
  }

  bool dfs(int a)
  {
    vv[a] = true;
    for(auto &b : graph[a]) {
      int c = match[b];
      if(c < 0 || (!vv[c] && dist[c] == dist[a] + 1 && dfs(c))) {
        match[b] = a;
        used[a] = true;
        return (true);
      }
    }
    return (false);
  }

  int bipartite_matching()
  {
    int ret = 0;
    while(true) {
      bfs();
      vv.assign(graph.size(), false);
      int flow = 0;
      for(int i = 0; i < graph.size(); i++) {
        if(!used[i] && dfs(i)) ++flow;
      }
      if(flow == 0) return (ret);
      ret += flow;
    }
  }
};

int dp[1000][1000];

int gcd(int x, int y)
{
  if(x < 1000) {
    if(~dp[x][y]) return (dp[x][y]);
    int r = x % y;
    if(r == 0) return dp[x][y] = y;
    return dp[x][y] = gcd(y, r);
  } else {
    int r = x % y;
    if(r == 0) return y;
    return gcd(y, r);
  }
}

int main()
{
  memset(dp, -1, sizeof(dp));

  int M, N, B[500], R[500];
  while(scanf("%d %d", &M, &N), M) {
    Bipartite_Matching flow(M, N);
    for(int i = 0; i < M; i++) scanf("%d", &B[i]);
    for(int i = 0; i < N; i++) scanf("%d", &R[i]);
    for(int i = 0; i < M; i++) {
      for(int j = 0; j < N; j++) {
        if(gcd(max(B[i], R[j]), min(B[i], R[j])) > 1) flow.add_edge(i, j);
      }
    }
    printf("%d\n", flow.bipartite_matching());
  }
}

Measured memory_bytes: 7476
#include<bits/stdc++.h>
#define int long long
using namespace std;


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

    int L[n+2] = {0};
    int D[n+2] = {0};

    D[1] = 0;

    for(int x=1;x<=n;x++){
          cin >> L[x];
    }

    for(int x=2;x<=n+1;x++){
          D[x] = D[x-1] + L[x-1];
    }

    int ans = 0 ;
    for(int x=1;x<=n+1;x++){
          if(D[x] <= last){
                ans++;
          }
    }

    cout << ans << endl;

     return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define endl '\n'
const int mod=1e9+7;
const int inf=1e17+10;
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(),x.end()
#define si(a) a.size()
#define pii pair<int,int>
using namespace std;
//#if !defined(ONLINE_JUDGE)
//#include "debugging.h"
//#endif



int32_t main() {
   std::ios::sync_with_stdio(false);cin.tie(NULL);
   int n,p;string s;
   cin>>n>>p;
   cin>>s;
   int a[n+1]={0};
   int pw=1;
   for(int i=n;i>=1;i--)
   {
       a[i]=(s[i-1]-'0');
       a[i]*=pw;
       a[i]%=p;
       pw*=10LL;
       pw%=p;
   }
   //a[1]%=p;
   for(int i=n-1;i>=1;i--)
   {
       a[i]+=a[i+1];
       a[i]%=p;
   }
   map<int,int>mp;
   int ans=0;
   if(p==2 || p==5)
   {
       for(int i=1;i<=n;i++)
       {
           int num=(s[i-1]-'0');
           if(num%p == 0)
           {
               ans+=i;
           }
       }
   }
   else
   {
       mp[0]=1;
       for(int i=n;i>=1;i--)
       {
           ans+=mp[a[i]];
           //if(mp.count(a[i]))
           mp[a[i]]++;
           //else mp[a[i]]=1;
           //cout<<ans<<endl;
       }
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 2580
import numpy as np
k,n = [int(i) for i in input().split()]

A = [int(i) for i in input().split()]

A.sort()

ans_p = A[0] + k - A[-1]

for i in range(n-1):
    cand = A[i+1] - A[i]
    if cand > ans_p:
        ans_p = cand
        
ans = k - ans_p

print(ans)

Measured memory_bytes: 41284
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>

#define all(v) v.begin(), v.end()
typedef long long ll;
#define rep(i, z, n) for(int i = z; i < n; i++)
//const int INF = 1<<29;
//const ll MOD = 1000000007;
using namespace std;

int main(){
    ll N;
    cin >> N;
    ll hi = 0, left = 0;
    ll sum = 0;
    rep(i, 0, N){
        ll A;
        cin >> A;
        int x;
        if(left > A){
            x = left - A;
            sum += x;
        }
        else{
            left = A;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3612
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder(br.readLine());
		StringBuilder sb2 = new StringBuilder();
		int q = Integer.parseInt(br.readLine());
		boolean rev = false;
		for (int i = 0; i < q; i++) {
			String[] sa = br.readLine().split(" ");
			if ("1".equals(sa[0])) {
				rev = !rev;
			} else {
				if ("1".equals(sa[1]) ^ rev) {
					sb2.append(sa[2]);
				} else {
					sb.append(sa[2]);
				}
			}
		}
		br.close();

		sb2.reverse();
		sb2.append(sb);
		if (rev) {
			sb2.reverse();
		}
		System.out.println(sb2.toString());
	}
}


Measured memory_bytes: 49824
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>  //setprecision(桁)
using namespace std;
#define pb push_back
#define ll long long int
#define rep(i,n) for(int i = 0;i < (n);i++)
ll INF = 1000000010; 
const ll MOD = 1000000007;


int main(){ 
    int n, a, b; cin >> n >> a >> b;
    string s; cin >> s;
    int koku = 0, kai = 0, all = 0;

    rep(i,n){
        if(s[i] == 'c') cout << "No" << endl;
        else if(s[i] == 'a'){
            if(all < a + b) {
                cout << "Yes" << endl;
                all++;
            }
            else cout << "No" << endl;
        }else{
            if(all < a + b && kai < b) {
                cout << "Yes" << endl;
                kai++;
                all++;
            }
            else cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 896
/*
 * 2019年  2月 25日 月曜日 12:20:59 JST
 */

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

using P = pair<int, int>;

const int N_MAX = 8;
const int INF = 1000*8     * 100;

int N, A[3];
int l[N_MAX];
int dp[3+1][(1<<N_MAX)];

int dfs(int idx, int A1len, int A2len, int A3len, const int target){
  if(idx == target){
    if(A1len == 0 || A2len == 0 || A3len == 0) return INF;
    return abs(A[0] - A1len) + abs(A[1] - A2len) + abs(A[2] - A3len);
  }
  int res = INF;
  res = min(res, dfs(idx+1, A1len+l[idx], A2len, A3len, N) + 10);
  res = min(res, dfs(idx+1, A1len, A2len + l[idx], A3len, N) + 10);
  res = min(res, dfs(idx+1, A1len, A2len, A3len + l[idx], N) + 10);
  res = min(res, dfs(idx+1, A1len, A2len, A3len, N));
  return res;
}

int main(void){
  cin >> N >> A[0] >> A[1] >> A[2];
  for(int i = 0; i < N; i++){
    cin >> l[i];
  }

  cout << dfs(0, 0, 0, 0, N) - 30 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define INF 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;
typedef pair<int, int> P;

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

	int N;
	cin >> N;

	vector<int> d(N);
	rep(i,N) cin >> d[i];

	sort(d.begin(),d.end());

	cout << d[N / 2] - d[N / 2 - 1] << endl;

	return 0;
}

Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))
m = 1000
s = 0
flag = "e"
idx = 0
for i in range(N-1):
  if A[i]<A[i+1] and (flag == "d" or flag == "e"):
    s += m//A[i]
    m = m%A[i]
    flag = "u"
  elif A[i]>A[i+1] and (flag == "u" or flag == "e"):
    m += s*A[i]
    s = 0
    idx = i
    flag = "d"
  elif A[i]==A[i+1]:
    flag = "e"
    
m += s*A[N-1]

print(int(m))


Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	ll int a[100][100];
	ll int b[100];
	int n,m;
	cin >> n >> m;
	REP(i,n) REP(j,m) cin >> a[i][j];
	REP(i,m) cin >> b[i];
	REP(i,n){
		ll int sum = 0;
		REP(j,m){
			sum += a[i][j]*b[j];
		}
		cout << sum << endl;
	}	
}

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

int main() {
  string s;
  cin>>s;
  int n = s.length();
  int odd=0, even=0;
  int i = 0;
  while (i < n) {
    even += (s[i]=='0');
    i++;
    if(i<n) odd += (s[i]=='1');
    i++;
  }
  
  cout<<min(even+odd,n-(even+odd))<<endl;
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	static final long MOD=1000000007;
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		String s=sc.next();
		int len=s.length();
		long[][] dp=new long[len+1][4];
		for(int i=0; i<=len; i++) {
			for(int j=0; j<4; j++) {
				dp[i][j]=0;
			}
		}
		dp[0][0]=1;dp[0][1]=0;dp[0][2]=0;dp[0][3]=0;
		for(int i=1; i<=len; i++) {
			if(s.charAt(i-1)=='A') {
				dp[i][0]=dp[i-1][0];
				dp[i][1]=(dp[i-1][1]+dp[i-1][0])%MOD;
				dp[i][2]=dp[i-1][2];
				dp[i][3]=dp[i-1][3];
			}
			else if(s.charAt(i-1)=='B') {
				dp[i][0]=dp[i-1][0];
				dp[i][1]=dp[i-1][1];
				dp[i][2]=(dp[i-1][2]+dp[i-1][1])%MOD;
				dp[i][3]=dp[i-1][3];
			}
			else if(s.charAt(i-1)=='C') {
				dp[i][0]=dp[i-1][0];
				dp[i][1]=dp[i-1][1];
				dp[i][2]=dp[i-1][2];
				dp[i][3]=(dp[i-1][3]+dp[i-1][2])%MOD;
			}
			else{
				dp[i][3]=(dp[i-1][3]*3+dp[i-1][2])%MOD;
				dp[i][2]=(dp[i-1][2]*3+dp[i-1][1])%MOD;
				dp[i][1]=(dp[i-1][1]*3+dp[i-1][0])%MOD;
				dp[i][0]=(dp[i-1][0]*3)%MOD;
			}
		}
		pl(dp[len][3]);
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}

Measured memory_bytes: 29524
fn read() -> (i32, i32, i32) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let vec: Vec<i32> = s
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    (vec[0], vec[1], vec[2])
}

fn main() {
    let (a, b, c) = read();
    if b - a == c - b {
        println!("YES");
    } else {
        println!("NO")
    }
}


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

int main() {
    int n, a, b;
    cin >> n;
    a = n / 100;
    b = n % 100;
    if(0 < a && a < 13){
        if(0 < b && b < 13){
            cout << "AMBIGUOUS" << endl;
        }else{
            cout << "MMYY" << endl;
        }
    }else{
        if(0 < b && b < 13){
            cout << "YYMM" << endl;
        }else{
            cout << "NA" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX_S 100001
 
int main(){
  int i, j;
  int word, head;                                             
  char s[MAX_S];
  const char* words[6]
    = {"dreameraser","dreamerase","dreamer", "dream", "eraser", "erase"};
  const int words_length[6] = {11,10,7,5,6,5};
  scanf("%s", s); 
  head = 0;
  do{ 
    for(i = 0; i < 6; i++){
      word = i;
      for(j = 0; j < words_length[i]; j++){
        if(s[head+j] != words[i][j]){
          word = -1; 
          break; 
        }   
      }   
      if(word != -1){
        head+=words_length[word];
        break;
      }   
    }   
    if(word == -1){
      printf("NO\n");
      return 0;
    }   
  }while(s[head]!='\0');
  printf("YES\n");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll h,w,a,b;
	cin>>h>>w>>a>>b;
	for(ll i=0;i<h;i++){
		ll ch;
		if(i<b){
			ch=0;
		}
		else{
			ch=1;
		}
		for(ll j=0;j<w;j++){
			if(j<a){
				cout<<ch;
			}
			else{
				cout << abs(ch-1);
			}
		}
		cout <<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 1280
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,k;
    cin >> a >> b >> k;
    if(a<b)swap(a,b);
    int cnt=0;
    REPR(i,b+1){
        if(a%i==0&&b%i==0)cnt++;
        //if(i)cout << i << ":" << cnt << endl;
        if(cnt==k){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

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

int main()
{
    string S;
    cin >> S;

    int size = static_cast<int>(S.size());

    int count = 0;
    int maxCount = 0;

    rep(i, size)
    {
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T')
        {
            count++;
        }
        else
        {
            maxCount = max(maxCount, count);
            count = 0;
        }

        maxCount = max(maxCount, count);
    }

    std::cout << maxCount << endl;
    return 0;
}


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

int n;
double a[500011],b[500011],c[500011];

double ans;
double eps=1e-12;

bool eq(double xx,double yy)
{
    double p,q;
    p=fabs(xx-yy);
    q=fabs(xx)+fabs(yy);
    if((p<q*eps) || p<eps)
    {
        return 1;
    }
    return 0;
}

struct node
{
    double y;
    double d;
    int id;
};

node p[500011];

bool cmp(node xx,node yy)
{
    if(fabs(xx.y-yy.y)>1e-12)
    {
        return xx.y<yy.y;
    }
    return xx.d<yy.d;
}
bool cmp2(node xx,node yy)
{
    return xx.d<yy.d;
}





int r[500011];
int tree[500011];

int lb(int x)
{
    return x&(-x);
}

void ins(int k)
{
    int i;
    for(i=k;i<=n;i+=lb(i))
    {
        tree[i]++;
    }
}
int calc(int k)
{
    int i,ans=0;
    for(i=k;i>0;i-=lb(i))
    {
        ans+=tree[i];
    }
    return ans;
}


long long check(double x)
{
    //cout<<x<<"  kkk"<<endl;
    int i;
    for(i=1;i<=n;i++)
    {
         //cout<<a[i]<<' '<<b[i]<<' '<<c[i]<<"  III"<<endl;
         p[i].y=(c[i]-a[i]*x)/b[i];
         p[i].d=-a[i]/b[i];
         p[i].id=i;
         
         
         //cout<<p[i].y<<' '<<p[i].d<<' '<<p[i].id<<endl;
    }
    //cout<<"!!!!"<<endl;
    //system("pause");
    sort(p+1,p+n+1,cmp);
    
    for(i=1;i<=n;i++)
    {
        r[p[i].id]=i;
    }
    sort(p+1,p+n+1,cmp2);
    memset(tree,0,sizeof(tree));
    
    
    long long ans=0;
    for(i=1;i<=n;i++)
    {
        ans+=calc(r[p[i].id]);
        ins(r[p[i].id]);
    }
    return ans;
}


void gao()
{
    double from=-1e14,to=1e14;
    double mid;
    long long k=(long long)n*(n-1)/2;
    k=(k+1)/2;
    
    while(!eq(from,to))
    {
        //cout<<from<<' '<<to<<endl;
        mid=(from+to)/2.0;
        if(check(mid)>=k)
        {
            to=mid;
        }
        else
        {
            from=mid;
        }
    }
    
    ans=(from+to)/2.0;
    return ;
}


int main()
{
    int i,j;
    int xx,yy,zz;
    
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d %d %d",&xx,&yy,&zz);
        a[i]=xx;b[i]=yy;c[i]=zz;
        //cout<<a[i]<<' '<<b[i]<<' '<<c[i]<<"^^^"<<endl;
    }
    
    double x,y;
    
    gao();
    x=ans;
    for(i=1;i<=n;i++)
    {
        swap(a[i],b[i]);
    }
    gao();
    y=ans;
    
    
    cout.precision(15);
    cout.setf(ios::fixed);
    cout<<x<<' '<<y<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 12672
#include <bits/stdc++.h>
#define rep(i, N) for (int i=0; i<(int)N; i++)
#define rep1(i, N) for (int i=1; i<(int)N; i++)

using namespace std;

string S;

int main() {
  cin >> S;
  rep(i, S.size()) {
    cout << "x";
  }
}


Measured memory_bytes: 256
s = int(input())
f = s/100
l = s%100
if 1 <= f and f <= 12:
    if 1 <= l and l <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 1 <= l and l <= 12:
        print('YYMM')
    else:
        print('NA')

Measured memory_bytes: 8992
#include<stdio.h>



int cmp( int a ,int b )
{
	if( a == b )
	{
		return -1 ;
	}


	return a > b ;
}



int Iwanna( int h1 ,int fish1 ,int kale1 )
{
	return ( h1 * fish1 ) + ( ( h1 / 10 ) * kale1 ) ;
}


int MtEye( int h1 ,int fish1 ,int kale1 )
{
	return ( h1 * fish1 ) + ( ( h1 / 20 ) * kale1 ) ;
}


int main()
{
	int h1 ,h2 ;
	int k1 ,k2 ;

	scanf( "%d %d" ,&h1 ,&h2 ) ;
	scanf( "%d %d" ,&k1 ,&k2 ) ;


	int fish1 ,fish2 ;
	int kale1 ,kale2 ;

	scanf( "%d %d %d %d" ,&fish1 ,&fish2 ,&kale1 ,&kale2 ) ;


	h1 = Iwanna( h1 ,fish1 ,kale1 ) + MtEye( h2 ,fish2 ,kale2 ) ;
	k1 = Iwanna( k1 ,fish1 ,kale1 ) + MtEye( k2 ,fish2 ,kale2 ) ;



	switch( cmp( h1 ,k1 ) )
	{
		case 0 :
			puts( "kenjiro" ) ;
			break ;

		case 1 :
			puts( "hiroshi" ) ;
			break ;

		default :
			puts( "even" ) ;
	}


	return 0 ;
}

Measured memory_bytes: 584
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
    char a, b;
	cin >> a >> b;
	if (a == b) {
		cout << "H" << endl;
	}
	else {
		cout << "D" << endl;
	}
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string.h>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <math.h>
#include <assert.h>
#define ff first
#define ss second
#define ll long long
#define mod 998244353
using namespace std;
int s, w;
int main () {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>s>>w;
    if(w >= s)
        cout<<"unsafe";
    else
        cout<<"safe";
}
/*
 4
 -2 2 3 5
 3 10 21 5
 */


Measured memory_bytes: 3584
#include<iostream>
using namespace std;
const int BUF = 6;


int row, col, nRemain;
string b[BUF];

void read() {
    cin >> row >> col >> nRemain;
    for (int i = 0; i < row; ++i) {
        cin >> b[i];
    }
}


void work() {
    int ans = 0;
    for (int rMask = 0; rMask < (1 << row); ++rMask) {
        for (int cMask = 0; cMask < (1 << col); ++cMask) {
            int cnt = 0;
            for (int r = 0; r < row; ++r) {
                if (rMask & (1 << r)) continue;
                for (int c = 0; c < col; ++c) {
                    if (cMask & (1 << c)) continue;
                    if (b[r][c] == '.') continue;
                    ++cnt;
                }
            }
            ans += cnt == nRemain;
        }
    }
    cout << ans << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;
bool compare(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){
    return a.second < b.second;
}
int main(){
    int n,m;cin >> n >> m;
    int a[n];rep{a[i] = 0;}
    for(int i = 0;i<m;i++){
        int x,y;cin>> x >> y;
        a[x-1] += 1; a[y-1] += 1;
    }
    rep{
        cout << a[i] << endl;
    }
}

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

int primes[10000001] = {0};

long long maxdiv(long long n, long long p) {
    if (n == 1)
        return p;

    long long a = 2;
    while(p >= a * a) {
        if (p % a == 0)
        {
            p /= a;
            primes[a]++;
        }
        else {
            a++;
        }
    }

    if (p < 10000001)
        primes[p]++;

    long long max = 1;

    for (long long i = 0; i < 10000001; i++) {
        // if (1 <= primes[i]) {
        //     cout << i << " : " << primes[i] << endl;
        // }

        if (n <= primes[i]) {
            max *= pow(i, primes[i] / n);
        }
    }

    return max;
}

int main(void) 
{
    long long n, p;
    cin >> n >> p;

    cout << maxdiv(n, p) << endl;

    return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <iomanip>
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
using namespace std;
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;

int main() { 
    int N; cin >> N;
    int A[N], B[N], C[N];
    REP(i, N) {
        cin >> A[i]; A[i]--;
    }
    REP(i, N) {
        cin >> B[i];
    }
    REP(i, N-1) {
        cin >> C[i];
    }

    int v = 0;
    REP(i, N) {
        v += B[A[i]];
        if (i>0) {
            if(A[i]-A[i-1] == 1) {
                v += C[A[i-1]];
            }
        }
    }
    cout << v << endl;
    
    return 0;
}

Measured memory_bytes: 888
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<u32> = procon_read();
	let x = v[0]; let y = v[1];
	let mut flag = false;
	if y%2 == 1{
	    println!("No");
	}else{
	    for i in 0..(x+1) {
	        if 2*i+4*(x-i) == y {
	            flag = true;
	            break;
	        }
	    }
	    if flag {
	        println!("Yes");
	    }else{
	        println!("No");
	    }
	}
}


Measured memory_bytes: 2156
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);i <= (e);(i)++)

int N;

int solve(vector<int> a){
  int res = 0;

  rep(i,0,N - 2){
    res += a[i] * 2;
    a[i + 1] -= a[i];
    a[i + 1] = max(0,a[i + 1]);
  }

  res += a[N - 1];

  return res;
}

int main(){
  cin >> N;

  vector<int> a(N);

  rep(i,0,N - 1) cin >> a[i];

  int MAX = a[0];

  int res = 1e9;

  rep(i,0,MAX){
    int t = MAX - i;
    a[0] = i;
    t += solve(a);

    res = min(res, t);
  }

  cout << res << endl;

}



Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

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

	map<int, int> mp;
	for (int i = 1; i <= N; i++) {
		int a; cin >> a;
		mp.insert(make_pair(a, i));
	}

	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		cout << itr->second << " ";
	}

	return 0;
}

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

int main() {
  char s[5];
scanf ("%s", &s );
if ( s[0] == s[1] && s[1] == s[2]) puts("Yes");
else if ( s[1] == s[2] && s[2] == s[3]) puts("Yes");
else puts("No");
    
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long k = Long.parseLong(sc.next());
        int q = Integer.parseInt(sc.next());
        int[] ary = new int[n];
        for (int i = 0; i < q; i++) {
            ary[Integer.parseInt(sc.next()) - 1]++;
        }
        for (int num : ary) {
            if (k - (q - num) > 0) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }
}

Measured memory_bytes: 48356
s= raw_input()
arr=[]
for i in range(4):
    if s[i] not in arr:
        arr.append(s[i])
if len(arr)!=2:
    print "No"
else:
    a=0
    b=0
    for i in range(4):
        if s[i]== arr[0]:
            a = a+1
        elif s[i]==arr[1]:
            b=b+1
    if a == 2 and b==2:
        print "Yes"
    else:
        print "No"

Measured memory_bytes: 2568
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int x, a, b;
	cin >> x >> a >> b;
	if (abs(x - a) < abs(x - b))
		cout << 'A' << endl;
	else
		cout << 'B' << endl;

} 

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

int main() {
  int a[5];

  for (int i = 0; i < 5; i++) {
    std::cin >> a[i];
  }

  int count = 0;

  std::sort(std::begin(a), std::end(a));

  for (int i = 0; i < 5; i++) {
    if (a[i] % 10 == 0) {
      count += a[i];
    } else {
      count += (a[i] / 10 + 1) * 10;
    }
  }

  int p = 0;
  for (int i = 0; i < 5; i++) {
    if (a[i] % 10 == 0) {
    } else {
      p = std::max(p, 10 - (a[i] % 10));
    }
  }

  std::cout << count - p << std::endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
 static int[] hai;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int i;
   Scanner sca=new Scanner(System.in);
      hai=new int[sca.nextInt()+1];
      for(i=0;i<hai.length;i++)hai[i]=-1;
      System.out.println(fib(hai.length-1));
	}
	public static int fib(int n){
		if(n==0||n==1)return 1;
		if(hai[n]!=-1)return hai[n];
		hai[n]=fib(n-1)+fib(n-2);
		return hai[n];
	}

}



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

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

    std::string N;
    std::cin>>N;

    int NtoI=std::stoi(N);
    int sum=0;

    for(int i=0;i<N.length();i++){
        sum+=(N[i]-'0');
    }

    if(NtoI%sum==0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  char l;
  int b;
  scanf("%c",&l);
  if((l>='a') && (l<='z')){
    printf("a\n");
  }else if((l>='A')&&(l<='Z')){
    printf("A\n");
  }
    return 0;
}


Measured memory_bytes: 1996
n = int(input())
a = list(map(int, input().split()))

l = 60

ones = [0] * l
for i in range(n):
    b = bin(a[i])[2:].zfill(l)
    for j in range(l):
        if b[j] == '1':
            ones[j] += 1


ans = 0
for i in range(l):
    ans += ones[i] * (n - ones[i]) * 2 ** (l - i - 1)
    ans = ans % (10 ** 9 + 7)
print(ans)


Measured memory_bytes: 122936
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)9e18;
int node1[2 * 100000 + 1] = {};
int node2[2 * 100000 + 1] = {};


int root1(int n) {
	if (node1[n] == n) return n;
	else return node1[n] = root1(node1[n]);
}

int root2(int n) {
	if (node2[n] == n) return n;
	else return node2[n] = root2(node2[n]);
}

void unite1(int n, int m) {
	if (n > m) swap(n, m);
	n = root1(n);
	m = root1(m);
	if (n == m) return;
	else node1[m] = n;
}

void unite2(int n, int m) {
	if (n > m) swap(n, m);

	n = root2(n);
	m = root2(m);
	if (n == m) return;
	else node2[m] = n;
}

int main() {
	int N, K, L;
	cin >> N >> K >> L;
	FOR(i, 1, N + 1) node1[i] = node2[i] = i;

	REP(i, K) {
		int p, q;
		cin >> p >> q;
		unite1(p, q);
	}
	REP(i, L) {
		int r, s;
		cin >> r >> s;
		unite2(r, s);
	}

	map<pair<int, int>,int> mp;
	FOR(i, 1, N + 1) mp[{root1(i), root2(i)}]++;
	FOR(i, 1, N + 1) cout << mp[{root1(i), root2(i)}] << " ";
	cout << endl;
	//cin >> N >> K >> L;



	return 0;
}


Measured memory_bytes: 13568
#include <stdio.h>

int main(void){
  int N,cnt,cnt8 = 0;
  scanf("%d",&N);
  
  int i,j;
  for(i = 1;i <= N; i += 2){
    cnt = 0;
    for(j = 1;j <= i; j += 2){
      if(!(i % j))	cnt++;
    }
    if(cnt == 8) ++cnt8;
  }
  printf("%d\n",cnt8);
  return 0;
}


Measured memory_bytes: 128