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

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;

const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);

#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define ull unsigned long long
#define deb(x )     cerr << #x << " = "<< x << endl;
#define endl    "\n"
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(y))
#define all(x) (x).begin(), (x).end()
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define verify(x) if(x >= MOD) x -= MOD;

inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void print_case(int tn) {cout<<"Case #"<<tn<<": ";}

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;
/*----------------------------------------------------------------------*/

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ll n,m,k; cin>>n>>m>>k;
    vll a(n), b(m);
    FOR(i, 0, n) cin>>a[i];
    FOR(i, 0, m) cin>>b[i];
    ll res = 0;
    ll sm = 0, ai = -1;
    FOR(i, 0, n) {
        if(sm + a[i] <= k) {
            sm += a[i];
            ai = i;
        }
        else break;
    }
    deb(ai);
    res = ai + 1;
    int bi = 0;
    RFOR(i, ai, 0) {
        while(bi < m && sm + b[bi] <= k) {
            sm += b[bi];
            bi++;
        }
        deb(bi);
        res = max(res, i + 1 + bi);

        sm -= a[i];
    }
    while(bi < m && sm + b[bi] <= k) {
        sm += b[bi];
        bi++;
    }
    res = max(res, 1LL * bi);
    cout << res;
    return 0;
}

Measured memory_bytes: 6296
import itertools
N,X,Y = map(int,input().split())

ret = [0]*N
for s,e in list(itertools.combinations(range(1,N+1), 2)):
  d = min(e-s, abs(X-s)+1+abs(Y-e), abs(X-e)+1+abs(Y-s))
  ret[d] += 1

for r in ret[1:]:
  print(r)


Measured memory_bytes: 147772
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)

int const S_MAX = 8000;

string s;
int x, y;

int xs[S_MAX + 1], ys[S_MAX + 1];

bool xx[S_MAX + 1][(S_MAX + 1) * 2];
bool yy[S_MAX + 1][(S_MAX + 1) * 2];

int main() {
  cin >> s;
  scanf("%d %d", &x, &y);

  int idx = 0;
  bool xd = true;
  int base = s.length();
  rep(i, base) {
    char c = s[i];
    if (c == 'T') {
      xd = !xd;
      if (xd) idx++;
    } else {
      if (xd) {
        xs[idx]++;
      } else {
        ys[idx]++;
      }
    }
  }

  xx[0][base + xs[0]] = true;
  FOR(i, 1, idx + 1) {
    FOR(j, -1 * base, base) {
      if (xx[i - 1][base + j]) {
        xx[i][base + j + xs[i]] = true;
        xx[i][base + j - xs[i]] = true;
      }
    }
  }
  yy[0][base + ys[0]] = true;
  yy[0][base - ys[0]] = true;
  FOR(i, 1, idx + 1) {
    FOR(j, -1 * base, base) {
      if (yy[i - 1][base + j]) {
        yy[i][base + j + ys[i]] = true;
        yy[i][base + j - ys[i]] = true;
      }
    }
  }

  if (xx[idx][base + x] && yy[idx][base + y]) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}


Measured memory_bytes: 125696
#include<iostream>
#include<string>
#include <vector>
#include <stack>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main() {
	stack<int> S;
	int a, b, x;
	string s;
	while (cin >> s) {
		if (s.at(0) == '+') {
			a = S.top(); S.pop();
			b = S.top(); S.pop();
			S.push(a + b);
		}
		else if (s.at(0) == '-') {
			b = S.top(); S.pop();
			a = S.top(); S.pop();
			S.push(a - b);
		}
		else if (s.at(0) == '*') {
			a = S.top(); S.pop();
			b = S.top(); S.pop();
			S.push(a*b);
		}
		else {
			S.push(atoi(s.c_str()));
		}
	}
	cout << S.top() << endl;
}


Measured memory_bytes: 3184
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
    ll n, k; cin >> n >> k;
    vector<ll> A(n+10); A.push_back(-1);
    rep(i, n) cin >> A[i+1];

    vector<ll> visited(200200, -1);
    visited[1] = 0;
    vector<ll> pass; pass.push_back(1);

    ll rp = 0, nrp = 0, cur = 1;
    for(ll i=1; i<=k; i++){
        ll next = A[cur];
        if(visited[next] == -1){
            pass.push_back(next);
            visited[next] = i;
            cur = next;
        }else{
            rp = i - visited[next];
            nrp = pass.size() - rp;
            break;
        }
    }
    if(rp == 0) rp = pass.size();
    ll x = (k - nrp) % rp;
    cout << pass[nrp + x] << ln;
}


Measured memory_bytes: 9720
dbflag=""

def debug(*args):
  if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
  if ""!=dbflag:return _INDATA.readline()
  else: return input()


result = 0

N = int(readline())

#リスト型
A = [int(i) for i in readline().split(' ')]


#２次元配列
import numpy as np
ndary=np.array(A,dtype=int)

ndary.sort()
d = ndary[::-1]
for i in range(0,N):
  if i%2==0:
    result += d[i]
  else:
    result -= d[i]

print(result)


Measured memory_bytes: 12464
#include <iostream>
#include <vector>

using namespace std;

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

  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  if (0 < n) {
    cout << a[n - 1];
    for (int i = 1; i < n; ++i) {
      cout << ' ' << a[n - i - 1];
    }
    cout << endl;
  }
  return 0;
} 



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


int main() {
  char in[120];
  pair<pair<string,int>,int> p[110];
  
  int a;
  scanf("%d",&a);
  
  for(int i = 0; i < a; i++){
  int t;
  scanf("%s%d",in,&t);
  string tmp = in;
  p[i] = make_pair(make_pair(in,-t),i);
  }
  
  std::sort(p,p+a);
  for(int i = 0; i < a; i++)printf("%d\n",p[i].second+1);

  return 0;
}




Measured memory_bytes: 3720
L,R=input().split()

mod=2019

for i in range(int(L),int(R)):
    for j in range(int(i)+1,int(R)+1):
        result=(i*j)%2019
        if mod>result :
            mod=result
        if mod == 0:
            break
    if mod == 0:
        break

print(mod)


Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;

int main() {
    int N,M; cin>>N>>M;
    string S; cin>>S;
    vi ans;
    int pos=N;
    while(1){
        int move=M;
        bool over=true;
        for (int i = 0; i < M; i++){
            if(pos-move<=0){
                ans.push_back(pos);
                for (int j = 0; j < ans.size(); j++){
                    cout<<ans[ans.size()-1-j]<<" ";
                }
                cout<<endl;
                return 0;
            }
            if((int)S[pos-move]-(int)'0')move--;
            else{
                ans.push_back(move);
                over=false;
                break;
            }
        }
        if(over){
            cout<<-1<<endl;
            return 0;
        }
        pos-=move;
    }
}


Measured memory_bytes: 3936
#include<iostream>
#include<algorithm>
using namespace std;
long long h[200005];
int main()
{
	int n;
	int i;
	int k;
	cin>>n;
	cin>>k;
	for(i=1;i<=n;i++) cin>>h[i];
	sort(h+1,h+1+n);
	long long ans=0;
	for(i=1;i<=n-k;i++) ans+=h[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 2176
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    int a,b,c;
    cin>>a>>b>>c;
    
    if(a<=c && c<=b){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
    
    
    return 0;
}






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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 5;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const ll N = 1e6+5;
vector<ll> v;
ll n,k,result,c;
string s;
vector<ll> a;

// 最大公約数
template <typename T> T gcd(T a, T b) {
  if(b == 0) return a;
  return gcd(b, a%b);
}

template <typename T> T G_C_D(const vector<T> &list)
{
    if (list.size() < 2) return list[0];

    T a = list[0];
    for (size_t i = 1; i < list.size(); ++i) {
        a = gcd(a, list[i]);
    }
    return a;
}

int main () {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  rep(i,n) {
    cin >> c;
    if(c == k) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
    a.push_back(c);
  }
  ll m = G_C_D(a);
  VSORT(a);
  if(k % m == 0 && k < a.back()) s = "POSSIBLE";
  else s = "IMPOSSIBLE";
  cout << s << endl;
}


Measured memory_bytes: 1400
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main() {
    int a, b;
    cin >> a >> b;    
    cout << a * b << endl;
	return;
}

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


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>
 
using namespace std;
 
const int N=1e6;

int main()
{

	vector<int> t;
	t.push_back(1);
	for(int i=2;t.back()<=N;i++) t.push_back(i*(i+1)*(i+2)/6);

	vector<int> ans(N+1,N),ans2(N+1,N);

	ans[0]=ans2[0]=0;

	for(int i=0;i<N;i++){
//		cout<<i<<endl;
		for(int j=0;j<t.size() && i+t[j]<=N;j++){
			ans[i+t[j]]=min(ans[i+t[j]],ans[i]+1);
			if(t[j]%2) ans2[i+t[j]]=min(ans2[i+t[j]],ans2[i]+1);
		}
	}

//	cout<<"ok"<<endl;

	long long n;
	while(cin>>n,n){

		cout<<ans[n]<<" "<<ans2[n]<<endl;

	}


	return 0;
}

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

using namespace std;

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

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

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
vi g[125252];
pii es[125252];

map<pii,int> col;
void reg(int a, int b, int c){
    col[pii(a,b)] = c;
    col[pii(b,a)] = c;
}
void dfs(int p, int bef){
    // do
    set<int> S;
    for(int to : g[p]){
        pii P(p,to);
        if(col.count(P)){
            S.insert(col[P]);
        }
    }
    int it = 0;
    for(int to : g[p]){
        pii P(p,to);
        if(!col.count(P)){
            while(S.count(it))it++;
            reg(p,to,it++);
        }
    }
    // dfs
    for(int to : g[p])if(to != bef){
        dfs(to, p);
    }
}

int main(){
    scanf("%d",&n);
    REP(i,n-1){
        int a,b;
        scanf("%d%d",&a,&b);
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
        es[i] = pii(a,b);
    }
    int k = 0;
    REP(i,n)CHMAX(k, (int)g[i].size());
    dfs(0, -1);
    printf("%d\n", k);
    REP(i,n-1){
        printf("%d\n",col[es[i]] + 1);
    }
    return 0;
}


Measured memory_bytes: 26496
#include "bits/stdc++.h"
using namespace std;
const int maxn = 55;
char grid[maxn][maxn];
int dx[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy[] = {1,-1, 0, 1,-1, 0, 1, -1};
int M(){
    int h, w;
    if(!(cin >> h >> w)) return 0;
    for(int e = 0; e < h; e++) scanf("%s", grid[e]);
    for(int e = 0; e < h; e++){
        for(int f = 0; f < w; f++){
            if(grid[e][f] == '#') printf("#");
            else{
                int cnt = 0;
                for(int g = 0; g < 9; g++){
                    int nx = e + dx[g];
                    int ny = f + dy[g];
                    if(nx >= 0 && nx < h && ny >= 0 && ny < w){
                        if(grid[nx][ny] == '#') cnt++;
                    }
                }
                printf("%d", cnt);
            }
        }
        printf("\n");
    }
    return 1;
}
int main(){
    while(M());
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main()
{
    long long int i, j, c=0,count=0;
    int n;
    scanf("%d",&n);
    int ar[n];
    for(i=0;i<n;i++)
    {
        scanf("%lld",&ar[i]);
    }
    for(j=0;j<n;j++)
    {

            if(ar[j]==2)
            {
                    c=0;

            }
            else
            {
            for(i=2; i<=sqrt(ar[j]); ++i)
            {

                if (ar[j]%i!=0)
                {
                    c=0;

                }
                else if (ar[j]%i==0)
                {
                    c=1;
                    break;
                }
                else continue;
            }
            }
            if(c==0)
            {
                count++;
            }

    }

    printf("%lld\n",count);

    return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define FT() int t; scanf("%d",&t); while(t--)
#define pb push_back
#define nl printf("\n")
#define fi(i,start,end) for(int i=start; i < (int)end ; ++i)
#define ip(n)   scanf("%d",&n)
#define mz(a)   memset(a,0,sizeof(a))
#define inpArr(A,n) fi(i,0,n)   ip(A[i]);
#define print(a)  for(auto i : a)   cout<<i<<" "; nl;
#define Fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
ll max(ll a,ll b) { return a>b?a:b;}
ll min(ll a,ll b) { return a<b?a:b;}

void solve()
{
    
}
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    //std::cout << std::fixed;
    //std::cout << std::setprecision(6);
    int n;
    cin>>n;
    int a[n+1];
    fi(i,0,n)
      cin>>a[i+1];
    int c=0;
    fi(i,1,n+1)
    {
      if(i%2!=0 && a[i]%2!=0)
        c++;
    }
    cout<<c;

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
    #endif
    
    return 0;
}


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

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

#define rep(i,n) for (ll i = 0; i < (n); i++)
#define ru(a,b) (((a)+((b)-1)) / (b))   //切り上げ(a/b)
#define dump(x)  cout << #x << " = " << (x) << endl;

ll choose(ll n, ll a) {
	ll x = 1;
	ll y = 1;
	for (ll i = 0; i < a; i++)
	{
		x *= n - i;
		y *= i + 1;
	}
	return x / y;
}

int main()
{
	ll n, m;
	cin >> n >> m;

	if ((n == 1) && (m == 1)) {
		cout << 0 << endl;
		return 0;
	}

	ll cn = 0;
	ll cm = 0;
		
	if (n >= 2) cn = choose(n, 2);
	if (m >= 2) cm = choose(m, 2);

	cout << cn+cm << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n + 1); i++)
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<bool> B(N);
    rep(i, N) { cin >> A[i]; }
    int ans = 0;
    int cnt = 1;
    bool P = false;
    rep(i, N) {
        B[cnt - 1] = true;
        cnt = A[cnt - 1];
        ans++;
        if (cnt == 2) {
            cout << ans << endl;
            P = true;
            break;
        } else if (B[cnt - 1] == true) {
            break;
            P = false;
        }
    }
    if (P == false) {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 3756
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}

void main() {
    long N, M;
    readf("%d %d\n", &N, &M);
    writeln(min(N, M/2) + max(0, (M-2*N)/4));
}

// ----------------------------------------------

// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                return reduce!fun(tuple(seed), r);
            }
        }
    }
}

// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
    auto minElement(alias map, Range)(Range r)
    if (isInputRange!Range && !isInfinite!Range)
    {
        alias mapFun = unaryFun!map;
        auto element = r.front;
        auto minimum = mapFun(element);
        r.popFront;
        foreach(a; r) {
            auto b = mapFun(a);
            if (b < minimum) {
                element = a;
                minimum = b;
            }
        }
        return element;
    }
    auto maxElement(alias map, Range)(Range r)
    if (isInputRange!Range && !isInfinite!Range)
    {
        alias mapFun = unaryFun!map;
        auto element = r.front;
        auto maximum = mapFun(element);
        r.popFront;
        foreach(a; r) {
            auto b = mapFun(a);
            if (b > maximum) {
                element = a;
                maximum = b;
            }
        }
        return element;
    }
}


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

int main() {
  int N;
  cin>>N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N-1);
  rep(i,N)cin>>A[i];
  rep(i,N)cin>>B[i];
  rep(i,N-1)cin>>C[i];
  
  int ans=0;
  rep(i,N)ans += B[i];
  rep(i,N-1){
    if(A[i+1]==A[i]+1){
      ans += C[A[i]-1];
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

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

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> v;
    REP(i, N) {
        int tmp; cin >> tmp;
        v.push_back(tmp);
    }
    for(auto x:v){
        if(x % 2 == 0) {
            if (x % 3 == 0 || x % 5 == 0) {
                continue;
            }
            else {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int h, n;
    scanf("%d%d", &h, &n);
    
    for(int i = 0; i < n; i++){
		int A;
		scanf("%d", &A);
		h -= A;
    }
    
    if(h <= 0){
		printf("Yes");
    }
    
    else
    {
		printf("No");
    }
    
     
}


Measured memory_bytes: 128
N = int(input())
v = input().split()
v_list = [int(i) for i in v]
v_list = sorted(v_list, reverse = True)
if len(v_list) > N:
  v_list = v_list[:N+1]
def calc(a, b):
  return (a+b)/2
for i in range(N):
  a = v_list.pop()
  b = v_list.pop()
  v_list.append(calc(a,b))
  if len(v_list) < 2:
    break
print(v_list[0])

Measured memory_bytes: 3064
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(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 debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
template <typename T> inline constexpr void chmin(T &a, T b) { if (a > b) a = b; }

using LL = long long;
using ULL = unsigned long long;
long long dp[51][510][510];
// dp[i 個数][j A の重さ][k B の重さ] := 価格の最小値
const long long INF = (1LL << 60);

int main() {
    int n, ma, mb; cin >> n >> ma >> mb;
    vector<tuple<int, int, int>> drugs(n);
    rep(i, n) {
        int a, b, c;
        cin >> a >> b >> c;
        drugs[i] = {a, b, c};
    }

    rep(i, 51) rep(j, 500) rep(k, 500) {
        dp[i][j][k] = INF;
    }
    dp[0][0][0] = 0;
    rep(i, n) {
        rep(wa, 500) {
            rep(wb, 500) {
                if (dp[i][wa][wb] >= INF) continue;
                int a, b, c;
                tie(a, b, c) = drugs[i];

                chmin(dp[i + 1][wa][wb],
                      dp[i][wa][wb]);

                chmin(dp[i + 1][wa + a][wb + b],
                      dp[i][wa][wb] + c);
            }
        }
    }
    long long ans = INF;
    for (int wa = 1; wa < 500; wa++) {
        for (int wb = 1; wb < 500; wb++) {
            if (wa * mb != wb * ma) continue;

            chmin(ans, dp[n][wa][wb]);
        }
    }
    if (ans < INF) cout << ans << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 104440
x=int(input())
if x>=400 and x<600:
  print(8)
elif x>=600 and x<800:
  print(7)
elif x>=800 and x<1000:
  print(6)
elif x>=1000 and x<1200:
  print(5)
elif x>=1200 and x<1400:
  print(4)
elif x>=1400 and x<1600:
  print(3)
elif x>=1600 and x<1800:
  print(2)
elif x>=1800 and x<2000:
  print(1)

Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf 1e18
#define g(x) cout<<x<<" "<<endl;
#define gg(x,y) cout<<x<<" & "<<y<<" "<<endl
#define jam(t) cout<<"Case #"<<t<<": "
#define ggg(x,y,z) cout<<x<<" & "<<y<<" & "<<z<<" "<<endl
#define all(x) x.begin(),x.end()
#define input_from_file  freopen("input.txt", "r", stdin);
#define mod 1000000007ll
#define sz 400005
#define bitcnt(x) __builtin_popcountll(x)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}



void solve(){
   ll n;
   cin >> n;
   bool ok = false;
   for(ll i=1;i<=n;i++){
    ll x;
    cin >> x;
    if(x % 2 == 0){
        if(!(x % 3 == 0 || x % 5 == 0))
        {
            g("DENIED");
            return;
        }
    }

   }
    g("APPROVED");
}
int main()
{

 
    FASTIO
    cin.tie(NULL);
    fflush(stdout);
    ll t = 1;
  //  cin >> t;
    for(ll tcase = 1;tcase <= t;tcase++){
        solve();
        
    }
return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main()
{
  cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  if (b / a >= c) cout << c << endl;
  else cout << b / a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Jun 21 21:04:48 JST 2020
 **/

signed main() {
    Int n;
    std::cin >> n;
    n--;
    Int acc = 1;
    REP(i, 1, 10000000000) {
        acc *= 26;
        Int nxt = n - acc;
        if (nxt < 0) {
            std::string ans(i, 'a');
            REP(j, i) {
                ans[j] = 'a' + n % 26;
                n /= 26;
            }
            std::reverse(ans.begin(), ans.end());
            std::cout << ans << std::endl;
            return 0;
        }
        n = nxt;
    }
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];

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

    cout << a[n-1] - a[0] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int point[200][3], s[200] = {0}, i, j, k, n, m;
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		for (j = 0; j < 3; j++){
			scanf("%d", &point[i][j]);
		}
	}
	for (i = 0; i < 3; i++){
		for (j = 0; j < n; j++){
			m = point[j][i];
			for (k = 0; k < n; k++){
				if (j != k && point[j][i] == point[k][i])
					m = 0;
			}
			s[j] += m;
		}
	}
	for (i = 0; i < n; i++)
		printf("%d\n", s[i]);
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
long long f(int n,int K,vector<long long>& h,vector<long long>& m){
	if(n>=h.size()){
		return 1000000000;
	}
	if(n==h.size()-1){
	  return 0;	
	}
	if(m[n]!=-1){
		return m[n];
	}
	long long c=INT_MAX;
	for(int i=1;i<=K;i++){
		c=min(c,f(n+i,K,h,m)+abs(h[n]-h[n+i]));
	}
	m[n]=c;
	return m[n];
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
	int n,K;
	cin>>n>>K;
	vector<long long> h(n);
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	vector<long long> m(n);
	for(int i=0;i<n;i++){
		m[i]=-1;
	}
	cout<<f(0,K,h,m);
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
#define vcin(a) for(int i=0;i<(a).size();i++) cin>>(a)[i];

int main()
{
    int N;
    cin >> N;
    vint u(N), v(N), w(N);
    vector<bool> col(N+1);
    vector<set<pair<int, int>>> edge(N+1);
    rep2(i, 1, N)
    {
        cin >> u[i] >> v[i] >> w[i];
        edge[u[i]].insert({v[i],w[i]});
        edge[v[i]].insert({u[i],w[i]});
    }
    queue<int> q;
    q.push(1);
    vector<bool> arrived(N + 1);
    while (!q.empty())
    {
        int color = 0;
        int node = q.front();
        arrived[node] = true;
        q.pop();
        for (auto k : edge[node])
        {
            if(arrived[k.first])
            {
                continue;
            }
            q.push(k.first);
            if(k.second % 2 == 0)
            {
                col[k.first] = col[node];
            }
            else
            {
                col[k.first] = !col[node];
            }
                }

    }
    rep2(i,1,N+1)
    {
        cout << col[i]<<endl;
    }
    return 0;
}

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

int main(){
    int n,a,b;
    cin >> n >> a >> b;

    long sum = 0;
    for(int i=1 ; i<=n; i++){
        int thou_10 = i / 10000;
        int thou = i % 10000 / 1000;
        int hand = i % 1000 / 100;
        int ten = i % 100 / 10;
        int one = i % 10; 
        int n_sum = thou_10 + thou + hand + ten + one;

        
        if(n_sum >= a && n_sum <= b){
            sum += i;
        }
    }
    cout << sum << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int a,b,c ; cin >> a >> b >>c;
    cout << ((a+b >= c) ? "Yes" : "No") << endl; 
    return 0;
}


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

int main(){
	int n, f, f2, k, i, j, f3;
	
	while(1){
		string str[60] = {}, temp = {};
		cin>>n;
		
		if(n == 0) break;
		
		for(i = 1; i <= n; i++){
			cin>>temp;
			
			str[i] += temp[0]; 
			for(j = 1; j < temp.size(); j++){//cout<<j<<" "<<temp[j]<<endl;
				if(temp[j-1] == 'a' || temp[j-1] == 'i' || temp[j-1] == 'u' || temp[j-1] == 'e' || temp[j-1] == 'o')
					str[i] += temp[j];//cout<<j<<" "<<temp[j]<<endl;
			}
			//cout<<str[i]<<" AAAA "<<str[i].size()<<endl;
		}
		sort(str + 1, str + n+1);
		
		f= 0;
		for(k = 0; ; k++){//cout<<k<<" k "<<endl;
			f2 = 0;
			for(i = 2; i <= n; i++){
				f3 = 0;//cout<<k<<" = k "<<endl;
				if(str[i].size()-1 >= k && str[i-1].size()-1 >= k){
					for(int j = 0; j <= k; j++){//cout<<k<<" "<<i<<" "<<j<<" "<<str[i-1][j]<<" "<<str[i][j]<<endl;
						if(str[i-1][j] != str[i][j]){
							f3 = 1;
							break;
						}
					}
				} else f3 = 1;
				//if(str[i-1].size()-1 == k && str[i].size()-1 == k && f3 == 0){ f = 1; break;}
				if(str[i-1] == str[i]){f = 1; break;}
				if(f3 == 1)f2++;
			}
			
			
			if(f == 1) break;
			if(f2 == n-1) break;
		}
		
		if(f) cout<<-1<<endl;
		else cout<<k+1<<endl;
	}
	return 0;
}


Measured memory_bytes: 3180
import sys
input = sys.stdin.readline

sys.setrecursionlimit(10**9)

h, w = map(int, input().split())
s = [input() for _ in range(h)]

memo = [[0] * w for _ in range(h)]

dir = [(0, 1), (0, -1), (1, 0), (-1, 0)]

def dfs(i, j, color):
    if not (0 <= i <= h-1 and 0 <= j <= w-1):
        return 0, 0
    if memo[i][j] == 1:
        return 0, 0
    if s[i][j] == color:
        return 0, 0
    memo[i][j] = 1
    white, black = 0, 0
    if s[i][j] == ".":
        white += 1
    else:
        black += 1
    for dx, dy in dir:
        cur_w, cur_b = dfs(i + dx, j + dy, s[i][j])
        white += cur_w
        black += cur_b
    return white, black

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            white, black = dfs(i, j, "#")
        else:
            white, black = dfs(i, j, ".")

        ans += white * black

print(ans)



Measured memory_bytes: 154404
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N,x;
	cin>>N>>x;
	int ans = x;
	rep(i,N-1){
		ans *= (x-1);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
snack = [False for i in range(N)]
for i in range(K):
    d = int(input())
    snack_k = [int(i) for i in input().split()]
    for j in snack_k:
        snack[j - 1] = True
sum = 0
for i in snack:
    if not i:
        sum += 1
print(sum)

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

int main(){
  string S;
  cin >> S;
  for(int i=0; i<S.size(); ++i){
    if(i%2==0){
      if(S[i]=='L'){
        printf("No");
        return 0;
      }
    }else{
      if(S[i]=='R'){
        printf("No");
        return 0;
      }
    }
  }
  printf("Yes");
  return 0;
}


Measured memory_bytes: 256
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")
MOD = 1000000007


# 処理内容
def main():
    A, V = map(int, input().split())
    B, W = map(int, input().split())
    T = int(input())

    if V == W:
        print("NO")
        return
        
    if A < B:
        t = (B-A)/(V-W)
    else:
        t = (A-B)/(V-W)
    
    if 0 < t and t <= T:
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    main()


Measured memory_bytes: 10244
/* This code is written by Nemlit */
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define rep(i, a, b) for(re int i = (a); i <= (b); ++ i)
#define drep(i, a, b) for(re int i = (b); i >= (a); -- i)
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define maxn 5005
int n, m, ans, dp[maxn][maxn], a[maxn], d[maxn];
long long sum;
il void solve(int l, int r, int *Dp) {
	if(l == r) {
		rep(i, 0, m) dp[l][i] = Dp[i];
		return;
	}
	int DP[m + 5], mid = (l + r) >> 1;
	memcpy(DP, Dp, sizeof(DP));
	rep(i, l, mid) drep(j, a[i], m) DP[j] |= DP[j - a[i]];
	rep(i, mid + 1, r) drep(j, a[i], m) Dp[j] |= Dp[j - a[i]];
	solve(l, mid, Dp), solve(mid + 1, r, DP);
}
signed main() {
	n = read(), m = read(), d[0] = 1;
	rep(i, 1, n) a[i] = read(), sum += a[i], ans += a[i] >= m;
	solve(1, n, d);
	if(sum >= m) rep(i, 1, n) if(a[i] < m) rep(j, m - a[i], m - 1) if(dp[i][j]) { ++ ans; break; }
	printf("%lld", n - ans);
	return 0;
}


Measured memory_bytes: 98304
// -*- coding:utf-8-unix -*-
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::LinkedList;
use std::collections::VecDeque;
use std::fs::File;
use std::io;
use std::io::prelude::*;

const INF: i64 = 1223372036854775807;

macro_rules! input {
    (source = s:expr, $(r:tt)*) => {
        let mut iter = s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $(r)*}
    };
    ($(r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $(r)*}
    };
}

macro_rules! input_inner {
    (next:expr) => {};
    (next:expr, ) => {};

    (next:expr, var:ident : t:tt $(r:tt)*) => {
        let var = read_value!(next, t);
        input_inner!{next $(r)*}
    };
}

macro_rules! read_value {
    (next:expr, ( $(t:tt),* )) => {
        ( $(read_value!(next, t)),* )
    };

    (next:expr, [ t:tt ; len:expr ]) => {
        (0..len).map(|_| read_value!(next, t)).collect::<Vec<_>>()
    };

    (next:expr, chars) => {
        read_value!(next, String).chars().collect::<Vec<char>>()
    };

    (next:expr, usize1) => {
        read_value!(next, usize) - 1
    };

    (next:expr, t:ty) => {
        next().parse::<t>().expect("Parse error")
    };
}

use std::cmp::*;
use std::collections::*;
use std::io::stdin;
use std::io::stdout;
use std::io::Write;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

/// Equivalent to std::lowerbound and std::upperbound in c++

fn solve() {
    let vec:Vec<i64> = read_vec();
    let x = vec[0];
    let y = vec[1];
    let a = vec[2];
    let b = vec[3];
    let c = vec[4];

    let mut p:Vec<i64> = read_vec();
    let mut  q:Vec<i64> = read_vec();
    let mut  r:Vec<i64> = read_vec();
    p.sort();
    q.sort();
    p.reverse();
    q.reverse();
    let mut heap = BinaryHeap::new();
    for i in 0..x {
        heap.push(p[i as usize]);
    }

    for i in 0..y {
        heap.push(q[i as usize]);
    }
    for i in 0..c {
        heap.push(r[i as usize]);
    }
    let mut res:i64 = 0;
    for int in 0..x + y {
        res += heap.pop().unwrap();
    }
    println!("{:?}", res);




    
}
fn main() {
    solve()
}

Measured memory_bytes: 9196
import sys


def main():
    
    def walk(p, c):
        if visited[p]:
            return
        visited[p] = True
        cnt[p] += c
        for n in tree[p]:
            walk(n, cnt[p])

    sys.setrecursionlimit(2000001)
    rl = sys.stdin.readline

    n, q = [int(x) for x in rl().split()]

    tree = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        a, b = [int(x) for x in rl().split()]
        tree[a].append(b)
        tree[b].append(a)

    cnt = [0] * (n + 1)
    for _ in range(q):
        p, x = [int(x) for x in rl().split()]
        cnt[p] += x

    visited = [False] * (n + 1)
    walk(1, 0)

    print(*cnt[1:])


main()


Measured memory_bytes: 269956
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(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 (int i = 0; i < n; ++i)
#define int long long

typedef long long ll;
typedef pair<int, int> Pair;

const int kMaxH = 1000;
const int kMaxW = 1000;
const int kInf = 1000000000;

map<string, int> m;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};

class Field {
public:
  string f = "";
  int z;
  int cnt;

  bool MoveFrom(Field f0, int i) {
    f = f0.f;
    z = f0.z;
    cnt = f0.cnt;

    // 移動先の座標決定
    int nz;
    if (i == 0) { // 右
      if (z == 3 || z == 7) { return false; }
      nz = z+1;
    } else if (i == 1) { // 下
      if (4 <= z && z <= 7) { return false; }
      nz = z+4;
    } else if (i == 2) { // 左
      if (z == 0 || z == 4) { return false; }
      nz = z-1;
    } else if (i == 3) { // 上
      if (0 <= z && z <= 3) { return false; }
      nz = z-4;
    }

    // 入れ替えなど
    char tmp = f[z];
    f[z] = f[nz];
    f[nz] = tmp;
    z = nz;
    ++cnt;
    return true;
  }
};

void Init() {
  queue<Field> que;

  Field f0 = {"01234567", 0, 0};
  m[f0.f] = f0.cnt;
  que.push(f0);
  while (que.size()) {
    Field cf = que.front(); que.pop();

    REP(i, 4) {
      Field nf;
      if (nf.MoveFrom(cf, i)) {
        if (m.find(nf.f) != m.end()) { continue; }
        que.push(nf);
        m[nf.f] = nf.cnt;
      }
    }
  }

  return;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  Init();
  while (true) {
    string s;
    REP(i, 8) {
      char c;
      cin >> c;
      if (cin.fail()) { goto r; }
      s.push_back(c);
    }
    int ans = m[s];
    cout << ans << endl;
  }
r:
  return 0;
}



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

int main(){
  string S;
  cin>>S;
  int temp=0;
  while(1){
    int OS=S.length();
    for(int i=temp;i<S.length()-1;i++){
      if(S.at(i)=='S' && S.at(i+1)=='T'){
        S=S.erase(i,2);
        if(i>10){
          temp=i-2;
        }
        else{
          temp=0;
        }
        break;
      }
    }
    if(S==""){
      cout<<0<<endl;
      return 0;
    }
    if(S.length()==OS){
      cout<<S.length()<<endl;
      return 0;
    }
  }
  return 0;
}

    
    

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
  int i,j,ans=0;

  int m,d;
  scanf("%d%d",&m,&d);

  for(i=4;i<=m;i++){
    for(j=2;j<=9;j++){
      if(i%j==0&&i/j>=2&&i/j<=9){
        if(j*10+i/j<=d){
          ans++;
        }
      }
    }
  }

  printf("%d\n",ans);

  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 300010
#define MOD 1000000007
using namespace std;
typedef long long ll;
int a[MAXN],len;
char s[MAXN];
ll dp[MAXN][3][2][2][2];
int main(){
	SF("%s",s);
	int len=strlen(s);
	s[len]='1';
	dp[0][0][0][0][0]=1;
	for(int i=0;i<=len;i++)
		for(int j=0;j<3;j++)
			for(int las=0;las<2;las++)
				for(int pos=0;pos<2;pos++)
					for(int sz=0;sz<2;sz++)
						for(int tag=0;tag<2;tag++){
							if(s[i]=='0'&&tag==1)
								continue;
							if(s[i]=='1'&&tag==0)
								continue;
							if(tag==1){
								if((las==1||i==0)&&pos==0)
									dp[i+1][max(1,j)][tag][pos^1][0]=(dp[i+1][max(1,j)][tag][pos^1][0]+dp[i][j][las][pos][sz])%MOD;
								if((las==1||i==0)&&pos==1)
									dp[i+1][2*(j>=1)][tag][pos^1][0]=(dp[i+1][2*(j>=1)][tag][pos^1][0]+dp[i][j][las][pos][sz])%MOD;
								if(las==0&&i!=0&&sz==1)
									dp[i+1][j][tag][pos][0]=(dp[i+1][j][tag][pos][0]+dp[i][j][las][pos][sz])%MOD;
								if(las==0&&i!=0&&sz==0)
									dp[i+1][j][tag][pos^1][0]=(dp[i+1][j][tag][pos^1][0]+dp[i][j][las][pos][sz])%MOD;
							}
							if(tag==0){
								dp[i+1][j][tag][pos][sz^1]=(dp[i][j][las][pos][sz]+dp[i+1][j][tag][pos][sz^1])%MOD;
							}
						}
	ll ans=0;
	for(int i=0;i<2;i++)
		for(int j=0;j<2;j++)
			for(int k=0;k<2;k++)
				ans=(ans+dp[len+1][2][i][j][k])%MOD;
	PF("%lld",ans);
} 

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

typedef long long ll;
# define  pii pair<ll,ll> 
# define pb push_back
# define f first 
# define s second 

std::vector<ll> Adj[2000005] ;
vector<ll> Query[2000005];
ll visited[200005]={0};
ll Ans[200005];

ll sum=0;

void dfs(ll u)
{   
    visited[u]=1;
    ll node_sum=0;
    for(auto it:Query[u])
    {
        node_sum+=it;
    }
    
    sum+=node_sum;
    Ans[u]=sum;
    
    for(auto it:Adj[u])
    {
        if(!visited[it])
        dfs(it);
    }
    
    sum -=node_sum;
}


int main() {
	ll n,q;
	cin>>n>>q;
	memset(visited,0,sizeof(visited));
    for(ll i=0;i<n-1;i++)
    {
        ll x,y;
        cin>>x>>y;
        Adj[x].pb(y);
        Adj[y].pb(x);
    }
    
    for(ll i=0;i<q;i++)
    {
        ll x,y;
        cin>>x>>y;
        Query[x].pb(y);
    }
    
    dfs(1);
    for(ll i=1;i<=n;i++)
    cout<<Ans[i]<<" ";
	
	return 0;
}


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

using namespace std; 



int main() {

	string s; 

	cin >> s; 

	if(s.length() == 0) {
		cout << 0 << endl; 
	}

	int len = s.length(); 

	int paintBlack = 0; 
	int paintWhite = 0;
	int minRepaint = 0;  

	for(int i = 1; i < len; i++) {
		paintBlack += (s[i] - '0') != i%2; 
		paintWhite += (s[i] - '0') == i%2; 
	}

	if(s[0] == '1') {
		minRepaint = min(paintWhite, paintBlack + 1); 
	}
	else {
		minRepaint = min(paintBlack, paintWhite + 1); 
	}

	cout << minRepaint << endl; 

	return 0; 
}

Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 200005;

struct BIT{
	int t[MX];
	int read(int x){
		int r = 0;
		while(x)r += t[x], x -= x&-x;
		return r;
	}
	void update(int x, int v){
		while(x < MX) t[x] += v, x += x&-x;
	}
} tree;

ll solve(string A, string B){
	for(int i = 0; i < MX; i++) tree.t[i] = 0;
	vector<int> T[305];
	for(int i = 0; i < A.size(); i++) T[A[i]].push_back(i);
	for(int i = 'a'; i <= 'z'; i++) reverse(T[i].begin(), T[i].end());

	vector<int> P;
	for(char c : B){
		P.push_back(T[c].back());
		T[c].pop_back();
	}
	ll ans = (ll)A.size() * (A.size()-1) / 2;
	for(int c : P){
		ans -= tree.read(c+1);
		tree.update(c+1, 1);
	}
	return ans;
}

int main()
{
	int cnt[300] = {};
	string D;
	cin >> D;
	for(int c : D) cnt[c] += 1;
	int odd = 0, val = -1;
	for(int i = 'a'; i <= 'z'; i++){
		if( cnt[i]%2 ) odd += 1, val = i;
	}
	if( odd >= 2 ) return !printf("-1\n");
	string X, Y;
	int cnt2[300] = {};
	for(char c : D){
		cnt2[c] += 1;
		if( cnt2[c] <= cnt[c] / 2 ) X += c;
		else if( cnt2[c] > (cnt[c]+1) / 2) Y += c;
	}
	string Z = Y; reverse(Z.begin(), Z.end());
	if( val != -1 ) printf("%lld\n", solve(D, X + (char)val + Y) + solve(X, Z));
	else printf("%lld\n", solve(D, X+Y) + solve(X, Z));
}


Measured memory_bytes: 4472
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll x,y;cin>>x>>y;
    ll ans=0;
    while(x<=y){
        ans++;
        x=x*2;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
s=[]
t=[]
for i in range(N):
    x,y=map(str,input().split())
    s.append(x)
    t.append(y)

X=input()
k=0
for i,j in enumerate(s):
    if j==X:
        k=i
        break
d=0
for i in range(k+1,N):
    d+=int(t[i])
print(d)





Measured memory_bytes: 3060
n = int(input())
a = [int(x) for x in input().split()]
sortA = sorted(a, reverse=True)
Alice = 0
Bob = 0
for i in range(len(a)):
    if i % 2 == 0:
        Alice+=sortA[i]
    else:
        Bob+=sortA[i]
    
print(Alice - Bob)

Measured memory_bytes: 3064