akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
getchar();
string s;
getline(cin,s);
int Count=0;
for(int i=0;i<n;i++){
    if((s[i]=='A')&&(s[i+1]=='B')&&(s[i+2]=='C')){
        ++Count;
    }
}
cout<<Count<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
using namespace std;

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

	int n;
	cin>>n;
	vector<ll> a(n+1);
	a[0]=1;
	a[1]=1;
	rep(i,n-1){
		a[i+2]=a[i+1]+a[i];
	}
	cout<<a[n]<<endl;
}

Measured memory_bytes: 3108
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define aint(x) (x).begin(),(x).end()
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; }

int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  int h, w, k;
  int x1, y1, x2, y2;
  cin >> h >> w >> k >> x1 >> y1 >> x2 >> y2;
  vector<vector<char>> c(h, vector<char>(w));
  rep(i, h) {
    rep(j, w) {
      cin >> c[i][j];
    }
  }
  vector<vector<int>> d(h, vector<int>(w, inf));
  queue<pair<int, int>> Queue;
  d[x1 - 1][y1 - 1] = 0;
  Queue.push(make_pair(x1 - 1, y1 - 1));
  int u, v;
  pair<int, int> uv;
  while (!Queue.empty()) {
    uv = Queue.front();
    Queue.pop();
    u = uv.first;
    v = uv.second;
    int p, q;
    for (int l = 1; l <= k; l++) {
      p = u + l; q = v;
      //cout << p << q << endl;
      //cout << h << endl;
      if (!(0 <= p && p < h && 0 <= q && q < w)) {
        break;
      } 
      //cout << (0 <= p < h) << endl;
      if (c[p][q] == '@') {
        break;
      }
      if (d[u][v] + 1 > d[p][q]) {
        break;
      }
      if (d[p][q] == inf) {
        Queue.push(make_pair(p, q));
      }
      d[p][q] = d[u][v] + 1;
    }
    for (int l = 1; l <= k; l++) {
      p = u - l; q = v;
      if (!(0 <= p && p < h && 0 <= q && q < w)) {
        break;
      } 
      if (c[p][q] == '@') {
        break;
      }
      if (d[u][v] + 1 > d[p][q]) {
        break;
      }
      if (d[p][q] == inf) {
        Queue.push(make_pair(p, q));
      }
      d[p][q] = d[u][v] + 1;
    }
    for (int l = 1; l <= k; l++) {
      p = u; q = v + l;
      //cout << k << endl;
      //cout << l << endl;
      //cout << u << v << p << q << endl;
      if (!(0 <= p && p < h && 0 <= q && q < w)) {
        break;
      } 
      if (c[p][q] == '@') {
        break;
      }
      if (d[u][v] + 1 > d[p][q]) {
        break;
      }
      if (d[p][q] == inf) {
        Queue.push(make_pair(p, q));
      }
      d[p][q] = d[u][v] + 1;
    }
    for (int l = 1; l <= k; l++) {
      p = u; q = v - l;
      if (!(0 <= p && p < h && 0 <= q && q < w)) {
        break;
      } 
      if (c[p][q] == '@') {
        break;
      }
      if (d[u][v] + 1 > d[p][q]) {
        break;
      }
      if (d[p][q] == inf) {
        Queue.push(make_pair(p, q));
      }
      d[p][q] = d[u][v] + 1;
    }
  
  }
  if (d[x2 - 1][y2 - 1] == inf) {
    cout << -1 << endl;
  }
  else {
    cout << d[x2 - 1][y2 - 1] << endl;
  }
}


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

using namespace std;

int main(){
    long long N, T;
    cin >> N >> T;

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

    long long ans = T;
    for (int i = 1; i < N; i++){
        if (t[i] - t[i-1] < T){
            ans += t[i] - t[i - 1];
        }else{
            ans += T;
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
#define N 100'000
struct katana {
    int a, b;
} k[N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, H;
    cin >> n >> H;
    int maxa = 0;
    for(int i = 0; i < n; i++) {
        cin >> k[i].a >> k[i].b;
        maxa = max(maxa, k[i].a);
    }
    int thrown = 0;
    int sumb = 0;
    for(int i = 0; i < n; i++) {
        if(k[i].b > maxa) {
            sumb += k[i].b;
            thrown++;
        }
    }
    if(sumb >= H) {
        sort(k, k + n, [](auto& k1, auto& k2) {
            return k1.b > k2.b;
        });
        int ans = 0;
        for(int i = 0; i < n and k[i].b > maxa and H > 0; i++) {
            H -= k[i].b;
            ans++;
        }
        cout << ans << endl;
    } else {
        cout << thrown + (H - sumb + maxa - 1) / maxa << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
n = gets.to_i

t = 0
h = 0
n.times do |i|
    tt, hh = gets.split(" ")
    
    if tt > hh then
        t += 3
    elsif tt < hh then
        h += 3
    else
        t += 1
        h += 1
    end
end

print t," ", h, "\n"



Measured memory_bytes: 6868
N = int(input())

dp = [[0] * 3 for _ in range(N + 1)]

for i in range(N):
    a, b, c = list(map(int, input().split()))
    dp[i+1][0] = a + max(dp[i][1:])
    dp[i+1][1] = b + max(dp[i][::2])
    dp[i+1][2] = c + max(dp[i][:2])

print(max(dp[N]))


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

int main()
{
    int N;
    cin >> N;
    vector <int> t(N+1),x(N+1),y(N+1);
    bool truth=1;
    t[0]=0;
    x[0]=0;
    y[0]=0;
    int X,Y,T=0;
    for (int i=1;i<N+1;i++)
    {
        cin >> t[i] >> x[i] >> y[i];
        T=t[i]-t[i-1];
        X=abs(x[i]-x[i-1]);
        Y=abs(y[i]-y[i-1]);
        if ((T<X+Y)|((T-X-Y)%2==1))
        {
            truth=0;
        }
    }
    if (truth) cout << "Yes" << endl;
    else
    {
        cout << "No" << endl;
    }
return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
template<class t>
t read_template(){
  t res;
  cin >> res;
  return res;
}
template<class t>
int print_template(t x){
  cout << x;
  return 1;
}
int main(){
  function<long long(long long,long long,long long,long long)> FUNC = [&](long long N,long long MIN,long long MAX,long long SUM)->long long{
                                                                        return ((N==0)?[&]()->long long{
                                                                                         print_template(MIN);
                                                                                         print_template(" ");
                                                                                         print_template(MAX);
                                                                                         print_template(" ");
                                                                                         print_template(SUM);
                                                                                         return print_template("\n");
                                                                                       }()
                                                                          :[&]()->long long{
                                                                             long long X = read_template<long long>();
                                                                             return FUNC ((N - 1),((X<=MIN)?X:MIN),((X>=MAX)?X:MAX),(SUM + X));
                                                                           }()
                                                                          );
                                                                      };
  ;
  FUNC (read_template<long long>(),10000000000,-10000000000,0);
  return 0;
}



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

int main(){
   int w,h,x,y,r;
   cin >> w >> h >> x >> y >> r;
   if((x-r) >= 0 && (y-r) >= 0 && (x+r) <= w && (y+r) <= h ) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

#define int long long

#define fst first
#define scd second
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)

typedef pair<int, int> pii;

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

const int inf = 3e18;

int X[100010];
int Y[100010];
pii pos[100010];
int v[100010];

signed main()
{
	omajinai;

	int W, H; cin >> W >> H;

	int N; cin >> N;

	rep(i, N) {
		cin >> X[i];
		cin >> Y[i];
		pos[i] = pii(X[i], Y[i]);
	}

	sort(X, X + N);
	sort(Y, Y + N);

    int ans = inf;
    int ansx = -1, ansy = -1;

    rep(i, 2) {
        rep(j, 2) {
            int x = X[N / 2 - i], y = Y[N / 2 - j];

            int sum = 0;
            int ma = 0;
            rep(k, N) {
                int a = abs(x - pos[k].fst) + abs(y - pos[k].scd);
                sum += a * 2;
                chmax(ma, a);
            }
            sum -= ma;

            if (ans >= sum) {
                ans = sum;
                ansx = x;
                ansy = y;
            }
        }
    }

    cout << ans << endl;
    cout << ansx << ' ' << ansy << endl;
}

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

using namespace std;

int main()
{
    int N, K;
    cin>>N>>K;
    vector<int> a(N);
    for (int &t: a)
        cin>>t;

    vector<bool> T(K+1);
    for (int k=0; k<=K; k++)
        for (int t: a)
            if (k-t>=0 && !T[k-t])
                T[k] = true;
    cout<<(T[K] ? "First" : "Second")<<endl;
}


Measured memory_bytes: 384
import math

n, a, b = map(int, input().split())
hs = list(map(int, (input() for _ in range(n))))

m = sum(hs) // (a + (n-1)*b) - 1
#M = sum(math.ceil(h/a) for h in hs)
M = max(hs) // b + 1

def killable(p, hs, a, b):
    x = sum(max(0, math.ceil((h-p*b) / (a-b))) for h in hs)
    return x <= p

while(m+1 < M):
    c = (m+M) // 2
    if killable(c, hs, a, b):
        M = c
    else:
        m = c
print(M)

Measured memory_bytes: 7076
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

signed main(){
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(n*a,b) << endl;
    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc133.contest.atcoder.jp/tasks/abc133_b

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a[100];
    for(int i=0;i<=2;i++){
    cin>>a[i];
    }
    if(a[0]==1){
        if(a[1]==0){cout<<"Close"<<endl;}
        else {cout<<"Open"<<endl;}
    }
    else if(a[0]==0){
        if(a[1]==1){cout<<"Close"<<endl;}
        else{
            if(a[2]==1){cout<<"Open"<<endl;}
            else {cout<<"Close"<<endl;}
        }
    }
}


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

using namespace std;

int table[2002][2002]={};

int main() {
    int H, W;
    cin >> H >> W;
    string s[H];
    for(int i=0; i<H; i++) cin >> s[i];

    int k;
    for(int i=0; i<H; i++) {
        k=0;
        for(int j=0; j<W; j++) {
            if(s[i][j]=='#') {
                table[i][j] = 0;
                k = 0;
            } else {
                if(k==0) while(j+k<W && s[i][j+k]=='.') k++;
                table[i][j] = k;
            }
        }
    }

    for(int j=0; j<W; j++) {
        k=0;
        for(int i=0; i<H; i++) {
            if(s[i][j]=='#') k=0;
            else {
                if(k==0) while(i+k<H && s[i+k][j]=='.') k++;
                table[i][j] += k-1;
            }
        }
    }

    int m = 0;
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            m = max(m, table[i][j]);
        }
    }
    cout << m << endl;
    return 0;
}


Measured memory_bytes: 19968
N, M, X = map(int, input().split())
D = [list(map(int, input().split())) for i in range(N)]
money = 12 * 10 ** 5 + 1
for i in range(2**N):
    pattern = str(bin(i))[2:]
    und = [0] * M
    mon = 0
    for j in range(len(pattern)):
        if pattern[(-1)*j - 1] == '1':
            mon += D[j][0]
            for k in range(M):
                und[k] += D[j][k + 1]
    for k in range(M):
        if all([l >= X for l in und]):
            money = min(mon, money)
if money == 12 * 10 ** 5 + 1:
    money = -1
print(money)

Measured memory_bytes: 69264
while 1:
    n = int(input())
    if n == 0:
        break

    visitor = [0] * 7
    for _ in range(n):
        a = int(input())
        category = a // 10
        if category > 6:
            category = 6
        visitor[category] += 1

    for v in visitor:
        print(v)



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

long gcd(long a, long b){
    if(a<b){
        long t=a;
        a=b;
        b=t;
    }
    while(b!=0){
	long r=a%b;
	a=b;
	b=r;
    }
    return a;
}
bool solve(){
    long a, b, c, d;
    cin >> a >> b >> c >> d;
    if(b>d || a<b){
        return false;
    }
    long g=gcd(d-b, b);
    if(g+c<b){
        return false;
    }
    for(long i=0; i<10; i++){
        long q = a/b;
        long r = a%b;
        a=r;
        if(q==0){
            return false;
        }
        if(a<=c){
            a+=d;
        }
    }
    return true;
}

int main(void){
    long t;
    cin >> t;
    for(long i=0; i<t; i++){
        bool b=solve();
        cout << (b ? "Yes" : "No" ) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int k; cin >> k;
    ll num = 0; ll ans = 0;
    rep(i,k){
        ans++;
        num*=10; num+=7;
        if(num % k == 0){
            cout << ans << endl;
            return 0;
        }
        num %= k;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
  ll X1, Y1, X2, Y2, X3, Y3, X4, Y4;
  cin >> X1 >> Y1 >> X2 >> Y2;
  ll dX = X2 - X1, dY = Y2 - Y1;
  
  X3 = X2 - dY;
  Y3 = Y2 + dX;
  X4 = X1 - dY;
  Y4 = Y1 + dX;
  
  cout << X3 << " " << Y3 << " " << X4 << " " << Y4 << endl;
}

Measured memory_bytes: 3636
N,X = map(int, input().split())
ms = []
for _ in range(N):
    ms.append(int(input()))
min = 0
cnt = 0
for i,m in enumerate(ms):
    if i == 0:
        min = m
    elif m < min:
        min = m
    X -= m
    cnt += 1

cnt += (X//min)
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
using namespace std;

int main(){
    
    ll n,cnt = 1;
    cin >> n;
    map<string,ll> map;
    string s;
    rep(i,0,n){
        cin >> s;
        if(map.count(s)){
            map[s]++;
            cnt = max(cnt,map[s]);
        }
        else map[s] = 1;
    }
    
    for(auto i = map.begin();i != map.end();++i){
        if(i->second == cnt) cout << i->first << endl;
    }
    return 0;
}

Measured memory_bytes: 25216
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

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

    var(i64, N, K);

    i64 ans = 0;
    for (i64 p = 1; p <= N; ++p) {
        if (p <= K) continue;
        const i64 n = N / p;
        ans += (p - K) * n;

        ans += max<i64>(0, N - (p * n + K) + 1);

    }
    if (K == 0) ans -= N;

    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef long double ld ;
#define F first
#define S second
#define pb push_back 
#define mp make_pair
#define vi vector <int>
#define vb vector <bool>
#define vc vector <char>
#define vll vector <ll>
#define vs vector <string>
#define pll pair < ll , ll >
#define pld pair < ld , ld >
#define pii pair < int , int >
#define vpld vector < pld >
#define vpii vector < pii >
#define vpll vector < pll >
#define vvi vector < vector < int > >
#define vvll vector < vector < ll > >
#define vvld vector < vector < ld > >
#define vvb vector < vector < bool > >
#define vvpii vector < vector < pii > >
#define all(v) (v).begin() , (v).end()
#define allrev(v) (v).rbegin() , (v).rend()
#define dist(x1 , y1 , x2 , y2) sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1))
const int MOD = 1e9 + 7 ;
const int infi = INT_MAX ;
const ll infll = LLONG_MAX ;
const int dx4[] = {0 , -1 , 0 , 1} ;
const int dy4[] = {-1 , 0 , 1 , 0} ;
const int dx8[] = {-1 , -1 , -1 , 0 , 1 , 1 , 1 , 0} ;
const int dy8[] = {-1 , 0 , 1 , 1 , 1 , 0 , -1 , -1} ;
const ld PI = 3.1415926535897932384626 ;

///////////////////////////////////////////////////////////////////////////////////////

ll pow_mod(ll a , ll b , ll m) {
	ll ans = 1 ;
	while(b)
	{
		if (b&1) {
			ans = (ans*a) % m ;
		}
		b /= 2 ;
		a = (a*a) % m ;
	}
	return ans ;
}

bool isprime(ll num) {
    for (ll i = 2 ; i * i <= num ; ++i)
        if (num % i == 0) {
        	return false ;
		}
    return true;
}

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

ll lcm(ll a, ll b) {
    return ((a / gcd(a , b)) * b) ;
}

ll cel(ll x1, ll y1) {
    if ((x1) <= 0) {
        return (x1) / (y1) ;
    }
    return (((x1) / (y1)) + (((x1) % (y1)) != 0)) ;
}

///////////////////////////////////////////////////////////////////////////////////////

const int N = 1e7 + 1 ;
int d[N] = {} ;
void sieve(int n) {
	for (int i = 1 ; i <= n ; ++i) {
		for (int j = i ; j <= n ; j += i) {
			++d[j] ;
		}
	}
}

void solve (int test_case) {
	int n ;
	cin >> n ;
	sieve(n) ;
	ll ans = 0 ;
	for (int i = 1 ; i <= n ; ++i) {
		ans += 1LL*i*d[i] ;
	}
	cout << ans << "\n" ;
}

int main() {
	ios_base :: sync_with_stdio (false) ;
	cin.tie(0) ;
	cout.tie(0) ;
	int tc = 1 ;
	//cin >> tc ;
	while (tc--) {
		solve (tc) ;
	}
	return 0 ;
}

Measured memory_bytes: 42628
N = int(input())
a = list(map(int, input().split()))

i = 0
num = 1
cnt = 0
while i <= N-1:
    if a[i] == num:
        num += 1
        i += 1
    else:
        cnt += 1
        i += 1

if cnt == N:
    print(-1)
else:
    print(cnt)


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

string s;
int a,b;

int main(){
	getline(cin,s);
	int l=s.length();
	for(int i=0;i!=l;++i){
		if(s[i]=='0')++a;
		else ++b;
	}
	long long ans=a>b?b:a;
	printf("%lld\n",ans*2);
	return 0;
}

Measured memory_bytes: 512
N, H = map(int, input().split())
A, B = [0]*N, [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())
target = max(A)
ans = 0
B.sort(reverse=True)
for i in B:
    if i >= target:
        H -= i
        ans += 1
    if H <= 0:
        print(ans)
        exit()
print(ans-(-H//target))

Measured memory_bytes: 11312
#include <cassert>
#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 <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#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>
#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>

using namespace std;
typedef long long ll;
typedef double ld;
const ld eps = 1e-7;
#define sqr(x) (x)*(x)
#define sz(x) ((x).size())
#define TASK ""
const ll MOD = 2999999989LL;
const ll BASE = 43;
#define hash hrescgwx

int run() {
    string s;
    cin >> s;
    ll ans = 0;
    ll have = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'g' && have != 0) {
            have--;
            ans++;
        } else if (s[i] == 'p' && have == 0) {
            have++;
            ans--;
        } else if (s[i] == 'p' && have != 0) {
            have--;
        } else {
            have++;
        }
    }
    cout << ans;
}

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

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    if(strlen(TASK)!=0)
    {
        freopen(TASK".in", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }
#endif
    run();
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string.h>
#include <cstring>
#include <math.h>
#include <cmath>
#include <iomanip>
#include <set>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <cassert>

using namespace std;
using ll = long long;

#define nl "\n"
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trav(x) for(auto& i: x)

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

	int h, w, n;
	cin >> h >> w >> n;
	cout << (max(h, w) + n - 1) / max(h, w);
}

Measured memory_bytes: 256
#include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.14159265358979323846264;
 const int mod=1000000007;

int main(){
	int n;
	cin>>n;
	int a[101010]={};
	FOR(i,0,n)cin>>a[i];
	sort(a,a+n);
	LL ans=0;
	FOR(t,0,2){
		if(t==1){
			reverse(a,a+n);
		}
		deque<int> d;
		int used[101010]={};
		d.PB(a[0]);
		used[0]=1;
		FOR(i,1,n){
			if(i%2==1){
				int i1=n-i,i2=n-i-1;
				if(used[i1]==1)break;
				if(used[i2]==1){
					if(abs(a[i1]-d.front())>abs(a[i1]-d.back())){
						d.push_front(a[i1]);
					}else{
						d.push_back(a[i1]);

					}
				}else{
					d.push_front(a[i1]);
					d.push_back(a[i2]);

				}
				used[i1]=used[i2]=1;
			}else{
				int i1=i-1,i2=i;
				if(used[i1]==1)break;
				if(used[i2]==1){
					if(abs(a[i1]-d.front())>abs(a[i1]-d.back())){
						d.push_front(a[i1]);
					}else{
						d.push_back(a[i1]);

					}
				}else{
					d.push_front(a[i1]);
					d.push_back(a[i2]);
				}

				used[i1]=used[i2]=1;

			}
		}
		LL tmp=0,bf=d.front();
		d.pop_front();
		//cerr<<d.size()<<endl;
		//cerr<<bf<<" ";
		FOR(i,1,n){
			tmp+=1LL*abs(d.front()-bf);
			bf=d.front();
			d.pop_front();
			//cerr<<bf<<" ";
		}
		//cerr<<" tmp:"<<tmp<<endl;
		ans=max(ans,tmp);

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


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N;
int A[30], B[30], C[30];

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

	cin >> N;
	rep(i, 0, N)
	{
		cin >> A[i];
		A[i]--;
	}
	rep(i, 0, N)
	{
		cin >> B[i];
	}
	rep(i, 0, N-1)
	{
		cin >> C[i];
	}

	int pi = -INF;
	int ans = 0;
	rep(i, 0, N) 
	{
		ans += B[A[i]];
		if (pi + 1 == A[i])
		{
			ans += C[pi];
		}
		pi = A[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int x;
    cin >> x;

    int qnt = x / 100;
    int sobra = x % 100;

    if ( sobra <= 5 * qnt ) cout << 1 << endl;
    else cout << 0 << endl;

    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair<int, int>pi;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef pair<P, P> PPP;

const ll MOD = 1e9 + 7;
const ll INF = 9e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

int a, b, h, m, cnt;
map<int, P>mp;
map<int, bool>mpb;

int main() {
	cin >> a;
	for (int i = 0;i < a;i++) {
		cin >> h >> m;
		mp[h * 60 + m] = P(h, m);
		mpb[h * 60 + m] = 1;
	}
	cin >> b;
	for (int i = 0;i < b;i++) {
		cin >> h >> m;
		if (mpb[h * 60 + m])cnt++;
		mp[h * 60 + m] = P(h, m);
	}
	for (auto u : mp) {
		cnt++;
		string p = to_string(u.sc.sc);
		if (u.sc.sc < 10)p = "0" + p;
		if (cnt != a + b)cout << u.sc.fr << ':' << p << ' ';
		else cout << u.sc.fr << ':' << p << endl;
	}
	return 0;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

/*
0-index
functionの中を書いて使う
宣言の時に単位元を書く
*/
template<typename T>
class segtree{
	int n;vector<T> dat;T ZERO;
public:
	segtree(int n_,T zero):ZERO(zero){
	  n = 1;
	  while(n < n_)n*=2;
	  dat.resize(2*n);
	  for(int i = 0;i < 2*n;i++)dat[i] = ZERO;
	}
	void update(int k, T a){
	  k += n - 1;dat[k] = a;
	  while(k > 0){
		k = (k-1)/2;
		dat[k] = function(dat[k*2+1],dat[k*2+2]);
	  }
	}
	
	T function(T a,T b){
		return max(a,b);
	}
	
	T get(int k){return dat[k+n-1];}
	T que(int a,int b){
		T L = ZERO,R = ZERO;
		int A = a + n - 1;
		int B = b + n - 1;
		while(A < B){
			if((A & 1) == 0)L = function(L,dat[A++]);
            if((B & 1) == 0)R = function(R,dat[--B]);
            A = A >> 1;
            B = B >> 1;
		}
		return function(L,R);
	}
};


int main(){
	
	int n;cin >> n;
	vector<ll> h(n);
	vector<ll> a(n);
	vector<ll> mp(n);
	vector<pair<int,int>> v;
	REP(i,n){
		cin >> h[i];
		v.EB(h[i],i);
	}
	REP(i,n)cin >> a[i];
	
	sort(ALL(v));
	REP(i,n)mp[v[i].SE] = i;
	segtree<ll> seg(n+1,0);
	REP(i,n){
		ll now = mp[i];
		seg.update(now,seg.que(0, now+1) + a[i]);
	}
	
	cout << seg.que(0,n) << endl;
	
	
	return 0;
}


Measured memory_bytes: 10736
ref = [[[10,8],[4,4]],[[10,2],[4,2]]]
r =10000001
p = [1]*r
p[0]= p[1] = 0
for i in range(int(r**0.5)):
	if p[i]:
		p[2*i::i] = [0 for j in range(2*i,r,i)]
		
while 1:
	try:
		n = input()
		if n == 0: break
		n -= 1-n%2
		while any(not p[n-i] for i in [0,2,6,8]):
			n -= ref[p[n-2]][p[n-6]][p[n-8]]
		print n
	except:
		pass

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

int main() {
    string s, name;
    bool bin = false;
    
    getline(cin, s);
    for (int i=0; i<s.length(); i++) {
        if(s[i]>=65 && s[i]<=90 && bin==false){
            name.push_back(s[i]);
            bin = true;
        }else if(s[i] == ' '){
            bin = false;
        }
    }
    for (int i=0; i<name.length(); i++) {
        cout << name[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int f[100009];

int main(){
  int n,ans=0;
  cin>>n;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    f[a]++;
  }
  for(int i=1;i<=100000-1;i++){
    ans=max(ans,f[i-1]+f[i]+f[i+1]);
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string input1;
    string input2;
    cin >> input1;
    cin >> input2;
    
    string bubun_input2 = input2.substr(0, input2.length() - 1);
    
    if (input1 == bubun_input2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3628
Alpha = [chr(i) for i in range(65, 91)]
N = int(input())
S = list(input())
New_S = []
for i in range(len(S)):
    p = Alpha.index(S[i]) + N
    if p >= 26:
        p = p - 26
    New_S.append(Alpha[p])

print(''.join(New_S))

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp71
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] T = new int[N];
            string[] Ts = Console.ReadLine().Split(' ');
            for(int i = 0; i < N; i++)
            {
                T[i] = int.Parse(Ts[i]);
            }
            int M = int.Parse(Console.ReadLine());
            int[] P = new int[M];
            int[] X = new int[M];
            for(int j = 0; j < M; j++)
            {
                string[] PXs = Console.ReadLine().Split(' ');
                P[j] = int.Parse(PXs[0]);
                X[j] = int.Parse(PXs[1]);
            }
            int SumT = 0;
            for(int i = 0; i < N; i++)
            {
                SumT = SumT + T[i];
            }
            for(int j = 0; j < M; j++)
            {
                int AllTime = 0;
                AllTime = SumT - T[P[j] - 1] + X[j];
                    Console.WriteLine(AllTime);
            }

        }
    }
}


Measured memory_bytes: 13140
n, m = map(int, input().split())
stack = [1]*n
p = [False]*n
p[0] = True

for i in range(m):
    x, y = map(int, input().split())
    stack[x-1] -= 1
    stack[y-1] += 1
    p[y-1] = p[x-1] or p[y-1]
    if stack[x-1] == 0:
        p[x-1] = False

ans = 0
for i in p:
    if i:
        ans += 1
print(ans)


Measured memory_bytes: 4596
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/16/20 21:00:53
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  string s; cin>>s;
  int as = 0;
  ll ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
      as++;
    } else {
      if (s[i] == 'B' and i<s.size()-1 and s[i+1] == 'C') {
        ans += as;
        i++;
      } else {
        as = 0;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 720
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt();
  	int m=sc.nextInt();
  	int[] nums = new int[m];
  	int sum=0;
  	for(int i=0;i<m;i++){
  		nums[i]=sc.nextInt();
  		sum+= nums[i];
  	}
  	if(n>=sum){
  		System.out.print(n-sum);
  	}else{
  		System.out.print(-1);
  	}
  }
}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N;
int H[100100];

signed main() {
    cin >> N;
    rep(i, N) {
        cin >> H[i];
    }
    rep(i, N) {
        if (i == 0)H[i]--;
        else {
            if (H[i] > H[i - 1])H[i]--;
            else if (H[i] < H[i - 1]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl

// computes whether s > t or not when s and t are regarded
// as numeric numbers
bool gt(string s, string t) {
  if(s.size() > t.size()) return true;
  if(s.size() < t.size()) return false;
  return s > t;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> A(m);
  rep(i, m) cin >> A[i];
  vector<int> K = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

  // The dp[j] table is the strage of the solutions in the
  // case of being used j matches. The 'X' means there is no
  // solution at that case.
  vector<string> dp(n + 1, "X");

  dp[0] = "";    // when we use 0 matches, we CAN make the
                 // empty sequence.

  for(int j = 1; j <= n; j++) {
    rep(i, m) {
      int k = K[A[i]];
      if(j - k < 0) continue;
      if(dp[j - k] == "X") continue;
      char c = '0' + A[i];
      string s = dp[j - k] + c;
      if(dp[j] == "X" || gt(s, dp[j])) {
        dp[j] = s;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 41472
#include<bits/stdc++.h>
using namespace std;
void close(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
}
string s;
int main(){
	close();
	cin>>s;
	int n=s.length();
	int ans=0;
		for(int i=0;i<n/2;i++){
			if(s[i]!=s[n-1-i]) ans++;
		}
	cout<<ans;
} 

Measured memory_bytes: 256
S = input()
T = input()
L = [chr(i) for i in range(97, 97+26)]
countS = []
countT = []
for x in L:
    countS.append(S.count(x))
    countT.append(T.count(x))
countS.sort()
countT.sort()
if countS == countT:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3632
/**
 *    author        : Sudipta Banik Trisha 
 *    created       : August 30, 2020 1:48 AM
 *    Problem Name  : D - Prediction and Restriction
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc149/tasks/abc149_d
 *    @genarated by : ai-virtual-assistant
**/

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

int main(){
    ios_base::sync_with_stdio(false);
    
    int n,k;
    cin >> n >> k;

    int R,S,P;
    cin >> R >> S >> P;

    string s;
    cin >> s;

    string t = "";
    int sum = 0;
    
    for(int i=0; i<k; i++){
       if(s[i] == 'r'){
          t+='p';
          sum += P;
       }
       else if(s[i] == 's'){
          t+='r';
          sum += R;
       }

       else if(s[i] == 'p'){
          t+='s';
          sum += S;
       }
    }

    for(int i=k; i<n; i++) {
       if(s[i] == 'r' && t[i-k] != 'p') {
          sum += P;
          t += 'p';
       }

       else if(s[i] == 's' && t[i-k] != 'r'){
          t+='r';
          sum += R;
       }

       else if(s[i] == 'p' && t[i-k] != 's'){
          t+='s';
          sum += S;
       }

       else {
          t += 'x';
          sum += 0;
       }
    }

    cout << sum << endl;
    return 0 ;
}


Measured memory_bytes: 3768
N,K=map(int,input().split())
V=list(map(int,input().split()))
SCORE=0

for l in range(min(K,N)+1):
    ANS_l=V[:l]

    for r in range(min(K,N)+1-l):
        ANS=ANS_l+V[N-r:]

        #print(l,r,ANS)

        ANS.sort()

        SUM=sum(ANS)
        SCORE=max(SCORE,SUM)

        #print(SCORE,ANS)

        for u in range(min(len(ANS),K-l-r)):
            SUM-=ANS[u]
            SCORE=max(SCORE,SUM)

            #print(SCORE)
print(SCORE)


Measured memory_bytes: 41840
#include <iostream>
using namespace std;
int n, m, k, c, ans, s[15][15], p[15];
int main() {
	int i, j, t;
	cin>>n>>m;
	for(i=0; i<m; i++) {
		cin>>k;
		while(k--) {
			cin>>t;
			s[i][--t] = 1;
		}
	}
	for(i=0; i<m; i++) cin>>p[i];
	for(k=0; k<1<<n; k++) {
		for(i=0; i<m; i++) {
			c = 0;
			for(j=0; j<n; j++) {
				if(s[i][j] && (k>>j)&1) c++;
			}
			if(c%2 != p[i]) break;
		}
		if(i==m) ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
c = 0
if N == 1:
  print(0)
else:
  for i in range(N-1):
    if a[i+1] < a[i]:
      c += a[i]-a[i+1]
      a[i+1] = a[i]
  print(c)

Measured memory_bytes: 32224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

struct Mo {
    int width;
    int nl, nr, ptr;
    vector<bool> used;
    vector<int> left, right, order;
    using F = function<void(int)>;
    F expandL, expandR, shrinkL, shrinkR;

    // クエリの区間 \subseteq [0,n) 
    Mo(int n, F el, F er, F sl, F sr) : width((int)sqrt(n)), nl(0), nr(0), ptr(0), used(n), expandL(el), expandR(er), shrinkL(sl), shrinkR(sr) {}

    // [l, r)
    void insert(int l, int r) {
        left.push_back(l);
        right.push_back(r);
    }
    void build() {
        order.resize(left.size());
        iota(ALL(order), 0);
        sort(ALL(order), [&](int a, int b) {
            if(left[a] / width != left[b] / width) return left[a] < left[b];
            return right[a] < right[b];
        });
    }
    // クエリを1つ進め、クエリのidを返す
    int process() {
        if(ptr == (ll)order.size()) return -1;
        const auto id = order[ptr];
        while(nl > left[id]) expandL(--nl);
        while(nr < right[id]) expandR(nr++);
        while(nl < left[id]) shrinkL(nl++);
        while(nr > right[id]) shrinkR(--nr);
        return order[ptr++];
    }
};

int main(void) {
    ll n, k, q;
    cin >> n >> k >> q;
    vector<ll> a(k), b(k);
    REP(i, k) cin >> a[i] >> b[i], a[i]--, b[i]--;
    vector<ll> type(q), s(q), t(q), x(q);
    REP(i, q) cin >> type[i] >> s[i] >> t[i] >> x[i], s[i]--, t[i]--, x[i]--;

    vector<ll> c(n), d(n);
    iota(ALL(c), 0); 
    iota(ALL(d), 0);
    auto moveL = [&](ll v) {
        ll p1 = d[a[v]], p2 = d[b[v]];
        swap(c[p1], c[p2]);
        swap(d[c[p1]], d[c[p2]]);
    };
    auto moveR = [&](ll v) {
        ll p1 = a[v], p2 = b[v];
        swap(c[p1], c[p2]);
        swap(d[c[p1]], d[c[p2]]);
    };
    Mo mo(k, moveL, moveR, moveL, moveR);
    REP(i, q) mo.insert(s[i], t[i]+1);
    mo.build();

    vector<ll> ans(q);
    REP(i, q) {
        ll idx = mo.process();
        if(type[idx] == 1) ans[idx] = c[x[idx]];
        else ans[idx] = d[x[idx]];
    }

    REP(i, q) cout << ans[i]+1 << "\n";
    cout << flush;

    return 0;
}


Measured memory_bytes: 11344
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
map<string, vector<int> > memo;
const int MAX_LEN = 50 * 4;
int terminate(const string& s){
  string DNA = "ATGC";
  int S = 0;
  REP(i, DNA.size()){
    FOR(j, 1, s.size() - 1){
      if(s[j] == DNA[i]){
        S |= (1 << i);
        break;
      }
    }
  }
  return S;
}
vector<int> expand(const string& name, map<string, vector<string> >& roles){
  if(memo.count(name)) return memo[name];
  vector<int> res;
  vector<string> role = roles[name];
  REP(i, role.size()){
    if(role[i][0] == '['){
      res.push_back(terminate(role[i]));
    }else{
      vector<int> v;
      v = expand(role[i], roles);
      FORIT(it, v) res.push_back(*it);
    }
    if(res.size() > MAX_LEN) break;
  }
  return memo[name] = res;
}
void update(int& x, int y){
  x = (x + y) % MOD;
}

int main(){
  int NA, NT, NG, NC;
  while(cin >> NA >> NT >> NG >> NC){
    int N = NA + NT + NG + NC;
    map<string, vector<string> > roles;
    int M; cin >> M; cin.ignore();
    string start;
    REP(i, M){
      string line;
      getline(cin, line);
      stringstream ss(line);
      string name;
      ss >> name;
      name = name.substr(0, name.size() - 1);
      if(i == 0) start = name;
      vector<string> rv;
      string s;
      while(ss >> s){ rv.push_back(s); }
      assert(!rv.empty());
      roles[name] = rv;
    }
    vector<int> v = expand(start, roles);
    if(v.size() != N){
      cout << 0 << endl;
      return 0;
    }
    static int dp[202][52][52][52] = {}; // dp[i][j][k][l], 合計:i個, A:j個 T:k個, G:l個 T: i - j - k - l
    dp[0][0][0][0] = 1;
    for(int i = 0; i < N; i++){
      for(int A = 0; A <= i && A <= NA; A++){
        for(int T = 0; A + T <= i && T <= NT; T++){
          for(int G = 0; A + T + G <= i && G <= NG; G++){
            if(v[i] & (1 << 0)) update(dp[i + 1][A + 1][T][G], dp[i][A][T][G]);
            if(v[i] & (1 << 1)) update(dp[i + 1][A][T + 1][G], dp[i][A][T][G]);
            if(v[i] & (1 << 2)) update(dp[i + 1][A][T][G + 1], dp[i][A][T][G]);
            if(v[i] & (1 << 3)) update(dp[i + 1][A][T][G], dp[i][A][T][G]);
          }
        }
      }
    }
    cout << dp[N][NA][NT][NG] << endl;
  }
  return 0;
}

Measured memory_bytes: 107828