akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

/*
    let's try computer shogi!!!
    a-zが含まれるパケットを取り出し続ければOK
 */

// とても雑な二分探索
enum bscheck{
  BS_OK,
  BS_LARGE,
  BS_SMALL,
  BS_ERR
};

bscheck check(vector<int> &vec, int key, int id){
  if(id==0){
    if(vec[id]>=key){
      return BS_OK;
    }else{
      return BS_SMALL;
    }
  }else{
    if(vec[id] < key){
      return BS_SMALL;
    }else if(vec[id-1]<key){
      return BS_OK;
    }else{
      return BS_LARGE;
    }
  }
  return BS_ERR;
}

// key以上の値を持つ最初のvecのidを返す。vecはソートされているとする
int searchv(vector<int> &vec, int key, int id, int step){
  if(vec.size()==0){
    return -1;
  }
  bscheck bsc = check(vec, key, id);
  const int nstep = max(1,step/2);
  if(bsc == BS_OK){
    return id;
  }else if(bsc == BS_LARGE){
    return searchv(vec, key, id-nstep, nstep);
  }else if(bsc == BS_SMALL){
    if(id == vec.size()-1){
      return -1;
    }
    return searchv(vec, key, id+nstep, nstep);
  }
  return -1; //unreachable
}

int main(){

  string moji;
  cin >> moji;
  int N;
  N = moji.length();
  int azpacket[N];
  bool done[26];
  vector< vector<int> > locs;
  locs.resize(26);
  string outstr = "";
  string az = "abcdefghijklmnopqrstuvwxyz";
  
  for(int j=0;j<26;++j){
    done[j] = false;
  }

  int pid = 0;
  
  for(int i=0; i<N;++i){
    bool packet = true;
    for(int j=0;j<26;++j){
      if(moji[N-i-1] == az[j]){
	locs[j].push_back(N-i-1);
	done[j] = true;
      }
      if(!done[j]){
	packet = false;
      }
    }
    azpacket[N-i-1] = pid;
    if(packet){
      pid++;
      for(int j=0;j<26;++j){
	  done[j] = false;
      }
    }
  }

  /*
  for(int i=0; i<N;++i){
    cout<<azpacket[i]<<",";
  }
  cout<<endl;
  */
  
  for(int j=0;j<26;++j){
    sort(locs[j].begin(), locs[j].end());
  }

  
  // 文字は必ずans文字になる
  const int ans = pid+1;
  //cout<<"ans"<<ans<<endl;
  int point = 0;
  // 以下greedyに
  for(int i=0;i<ans;++i){
    for(int j=0;j<26;++j){
      /*
      for(int l = 0; l<locs[j].size();++l){
	cout<<locs[j][l]<<",";
      }
      cout<<endl;
      */
      const int id = searchv(locs[j], point, locs[j].size()/2, locs[j].size()/2);
      //cout<<j<<","<<point<<","<<id<<","<<locs[j][id]<<","<<endl;
      if(id == -1){
	outstr += az.substr(j,1);
	break;
      }else{
	if(azpacket[locs[j][id]] == ans -2 -i){
	  outstr += az.substr(j,1);
	  point = locs[j][id]+1;
	  break;
	}
      }
    }
  }
  cout<<outstr<<endl;
  
  return 0;
}

Measured memory_bytes: 2180
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define co(n) cout<<n<<endl
using namespace std;
typedef long long ll;
typedef vector<long> vl;
typedef vector<string> vs;

int main(){
  double e,n,m;
  long a,b;
  c(a>>b);
  long x[a],c=0,d=0,y=0;
  rep(i,0,a){
    cin>>x[i];
  }
  rep(i,0,b) y+=x[i];
  c=y;
  rep(i,1,a-b+1){
    y-=x[i-1]; y+=x[i+b-1];
    c=max(c,y);
  }
  c+=b;
  e=c;
  e/=2;
  cout << fixed << setprecision(10);
  cout << e << endl;
 
  return 0;
}

Measured memory_bytes: 1792
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

struct edge {
    int to;
    int cost;
};

const int MAX_N = 100000;
bool visited[MAX_N];
int positions[MAX_N];
vector<edge> table[MAX_N];
int N, M;

bool dfs(int node, int pos) {
    positions[node] = pos;
    visited[node] = true;
    bool valid = true;

    for (edge e : table[node]) {
        if (visited[e.to]) {
            if (pos + e.cost != positions[e.to]) return false;
        } else {
            valid &= dfs(e.to, pos + e.cost);
        }
    }

    return valid;
}

signed main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int L, R, D;
        cin >> L >> R >> D;
        L--; R--;
        table[L].push_back({R, D});
        table[R].push_back({L, -D});
    }

    bool valid = true;
    for (int i = 0; i < N; i++) {
        if (!visited[i]) {
            valid &= dfs(i, 0);
        }
    }

    cout << (valid ? "Yes" : "No") << endl;

    return 0;
}

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

int main(){

int a,b,c,d;
std::cin >>a>>b>>c>>d;

if(abs(a-c)<=d){
std::cout<<"Yes";
}
else{
if(a<=b&&b<=c&&b-a<=d&&c-b<=d){
std::cout<<"Yes";
}
else if(c<=b&&b<=a&&b-c<=d&&a-b<=d){
std::cout<<"Yes";
}
else{
std::cout<<"No";
}
}

}


Measured memory_bytes: 256
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0

for i in range(N):
  try:
      han = int(V[i]) - int(C[i])
      if han > 0:
        ans += han
  except TypeError:
    pass
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 103;
int weith[N],value[N];
long long dp[N][100004];
int n,w;

long long solve(int i,int w){
	if(i==n)
		return 0;
	if(dp[i][w]!=-1)
		return dp[i][w];

	if( w-weith[i]<0 )
		return dp[i][w] = solve(i+1,w);
	return dp[i][w] = max(solve(i+1,w) , solve(i+1,w-weith[i]) + value[i]);
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    
    memset(dp,-1,sizeof(dp));

    cin>>n>>w;

    for(int i=0;i<n;i++)
    	cin>>weith[i]>>value[i];

    cout<<solve(0,w);

    return 0;
}

Measured memory_bytes: 80768
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      // cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  while (1) {
    C -= B;
    if (C <= 0) {
      cout << "Yes" << endl;
      return 0;
    }
    A -= D;
    if (A <= 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 3624
h,w=map(int,input().split());f=lambda x:max(x)-min(x);g=lambda h,w:min([min(f([i*w,((h-i)//2)*w,((h-i)-(h-i)//2)*w]),f([i*w,(h-i)*(w//2),(h-i)*(w-w//2)]))for i in range(1,h)]);print(min(g(h,w),g(w,h)))

Measured memory_bytes: 7096
function main(input){
  input = input.split('\n');

  const N = Number(input[0]);
  const A = input[1].split(' ').map(Number);
  let sum = 0
  for(let i=1; i<N; i++){
    if(A[i-1] > A[i]){
      sum+= A[i-1] - A[i];
      A[i] = A[i-1];
    }
  }

  console.log(sum);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim());


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

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

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    string a, b, c;
    cin >> a >> b >> c;
    if (a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(void) {
	int sheets = 0;
	int N;

	cin >> N;

	if (N % 2 == 0) {
		sheets = (int)N / 2;
	}
	else {
		sheets = N / 2 + 1;
	}
	
	cout << sheets;
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

typedef vector<vector<ll> > Matrix;

Matrix d;
void warshall_floyd(int n) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++)
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

void dfs(vector<vector<ll> >& D,
         vector<int>& RR,
         vector<bool>& vis,
         int N, int tmp, int par,
         ll cost, int cnt, ll& ans) {
  // cout << string(cnt, ' ') << RR[tmp] << endl;
  cost = par == -1 ? 0 : cost + D[RR[par]][RR[tmp]];
  if(cnt == N) ans = min(ans, cost);
  vis[tmp] = true;
  rep(i, N) {
    if(!vis[i])
      dfs(D, RR, vis, N, i, tmp, cost, cnt+1, ans);
  }
  vis[tmp] = false;
}

int main() {
  int N, M, R;
  cin >> N >> M >> R;
  vector<int> RR(R);
  rep(i, R) {
    cin >> RR[i];
    RR[i]--;
  }

  d = Matrix(N, vector<ll>(N, longinf));
  rep(i, N) d[i][i] = 0;
  rep(i, M) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--; b--;
    d[a][b] = c;
    d[b][a] = c;
  }

  warshall_floyd(N);

  vector<bool> vis(N);
  ll ans = longinf;
  rep(i, R)
    dfs(d, RR, vis, R, i, -1, 0, 1, ans);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define nmax_def 110
using namespace std;
typedef long long ll;


int main() {
	int i, j, k;
	int N;
	pair<pair<string, int>, int > SP_i[nmax_def];
	cin >> N;
	for (i = 0; i < N; i++)
	{
		cin >> SP_i[i].first.first >> SP_i[i].first.second;
		SP_i[i].first.second = 100 - SP_i[i].first.second;
		SP_i[i].second = i;
	}
	sort(SP_i, SP_i + N, less <pair<pair<string, int>, int >>());
	for (i = 0; i < N; i++)
	{
		SP_i[i].second++;
		cout << SP_i[i].second << endl;
	}
	return 0;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

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

  int cnt = 0;
  rep(i, H){
    string s;
    cin >> s;
    rep(j, W){
      if(s[j]=='#'){
        cnt++;
      }
    }
  }

  if(cnt == H + W -1){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }



  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", v)
#define PRIY PRI("Yes")
#define PRIN PRI("No")
#define MINS(a,b) a = min(a,(decltype(a))(b))
#define MAXS(a,b) a = max(a,(decltype(a))(b))



//拡張ユークリッドの互除法。戻り値は最大公約数、x,yはax+by=gcd(a,b)を満たす組の一つ
long long gcdext(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long g = gcdext(b, a % b, y, x);
	y -= a / b * x;
	return g;
}

//モジュラ逆数
long long modinv(long long a, long long mod) {
	long long x, y;
	gcdext(a, mod, x, y);
	x = ((x % mod) + mod) % mod;
	return x;
}


//コンビネーション
class com_table {
public:
	vector<long long> frac;
	vector<long long> finv;
	long long mod;
	com_table() = default;
	void init(long long size, long long mod) {
		this->mod = mod;
		frac.resize(size + 1);
		finv.resize(size + 1);
		frac[0] = 1;
		finv[0] = 1;
		for (int i = 1; i <= size; ++i) frac[i] = frac[i - 1] * i % mod;
		finv[size] = modinv(frac[size], mod);
		for (int i = size; i >= 2; --i) finv[i - 1] = finv[i] * i % mod;
	}
	long long operator()(int a, int b) {
		if (a < b)return 0;
		return ((frac[a] * finv[b] % mod) * finv[a - b]) % mod;
	}
};



ll mod = 1e9 + 7;


int main() {
	ll S;
	cin >> S;
	com_table tbl;
	tbl.init(5000,mod);
	ll ans = 0;
	REP(n, 1, S / 3 + 1)ans = (ans + tbl(S - 2 * n - 1, n - 1)) % mod;
	PRI(ans);
	return 0;
}

Measured memory_bytes: 3708
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n,m=map(int,input().split())
num=[1 for _ in range(n)]
red=[False for _ in range(n)]
red[0]=True
for i in range(m):
    x,y=map(int,input().split())
    num[x-1]-=1
    num[y-1]+=1
    if red[x-1]:
        red[y-1]=True
    if num[x-1]==0:
        red[x-1]=False
ans=0
for i in range(n):
    if red[i]:
        ans+=1
print(ans)

Measured memory_bytes: 4772
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n1,n2) for(int (i)=(int)(n1);(i)<(int)(n2);++(i))
#define lpr(i,n1,n2) for(int (i) =(int)(n1); (i) >= (int)(n2);--(i))
#define scan(a) scanf("%d",&a)
#define scan2(a,b) scanf("%d %d",&a,&b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define PI 3.14159265
#define F first
#define S second
typedef map<int,int> mii;
typedef map<string,string> mss;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef long long ll;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;

    int A[1000001];
    int main()
    {
        int n,c,k;
        scan3(n,c,k);
        int wait = -1,cont = 0,ans = 0;
        lp(i,0,n)
            scan(A[i]);
        sort(A,A+n);
        lp(i,0,n)
        {
            int a;
            a = A[i];
            if( wait == -1)
                wait = a;

            //printf("%d\n",wait);
            if( a-wait > k)
            {
                ans++;
                wait = a;
                cont = 1;
            }
            else if( cont+1 == c)
            {
                ans++;
                cont = 0;
                wait = -1;
            }
            else
                cont++;


        }
        if( cont > 0)
        {
            ans++;
        }
        cout<<ans;


        return 0;
    }




Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <string.h>
#include <vector>
#include <unordered_map>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i > 0; i--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

typedef int64_t int64;
typedef int64_t ll;

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

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; }

using namespace std;

class D {
	int n, m;
	vector<int> a;
	unordered_map<int, int> um;

public:
	D()
	{
		cin >> n >> m;
		a.resize(n);
		REP(i, n)
			cin >> a[i];
	}

	inline int64_t comb2(const int n)
	{
		if (n < 2)
			return 0;

		return (int64_t)n * ((int64_t)n - 1) / 2;
	}

	void solve()
	{
		vector<int> cum(n + 1, 0);
		int zeros{ 0 };

		REP(i, n)
		{
			cum[i + 1] = (cum[i] + a[i]) % m;

			auto it{ um.find(cum[i + 1]) };
			if (it != um.end())
				(it->second)++;
			else
				um.insert(MP(cum[i + 1], 1));
		}

		int64_t ans{ 0 };

		for (auto it{ um.begin() }; it != um.end(); it++)
		{
			ans += comb2(it->second);
		}

		auto it{ um.find(0) };
		if (it != um.end())
			ans += it->second;

		cout << ans << endl;

	}
};


int main()
{
	D solution;
	solution.solve();

	return 0;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1'000'000'000'000'007ll;
const llong mod = 1e9+7;

int main() {
#define int int_fast32_t
	int N;
	vector<vector<int>> A;
	cin >> N;

	A.resize(N+1, vector<int>(N-1));
	for (int &&i = 1; i <= N; ++i) {
		for (auto &x : A[i])
			cin >> x;
	}

	vector<int> day(N+1, 0);
	vector<int> next(N+1, 0);
	int cnt = 0, ans = 0;
	for (int &&i = 1;; ++i) {
		bool check = false;
		for (int &&j = 1; j <= N; ++j) {
			if (day[j] >= i) continue;
			if (next[j] == N-1) continue;
			const int &rival = A[j][next[j]];
			if (day[rival] >= i) continue;
			if (next[rival] == N-1) continue;
			if (A[rival][next[rival]] != j) continue;

			cnt++;
			day[j] = day[rival] = i;
			ans = i;
			++next[j];
			++next[rival];
			check = true;
		}
		if (check == false) break;
	}

	if (cnt == N*(N-1)/2)
		cout << ans << endl;
	else
		cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 10112
# AGC024C - Sequence Growing Easy
def main():
    N, *A = map(int, open(0))
    if A[0]:  # can't increment A_0
        print(-1)
        return
    A.append(0)
    ans, B = 0, A[::-1]
    for i, j in zip(B, B[1:]):  # check from the last
        if i > j + 1:  # increment from left one must be 0 or 1
            print(-1)
            return
        if j >= i:  # left one is an end of subsequence
            ans += j
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14100
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()
import copy
n=I()
p=IL()
cnt=0
for i in range(n-1):
    if p[i]==i+1:
        p[i]=p[i+1]
        p[i+1]=i+1
        cnt+=1
if p[n-1]==n:
    p[n-1]=p[n-2]
    p[n-2]=n
    cnt+=1
print(cnt)

Measured memory_bytes: 14324
import sys
input = sys.stdin.readline
from operator import itemgetter
INF = 10**30
sys.setrecursionlimit(10000000)
from collections import deque
G = []
into = [] # 入次数


def topological_sort(n):
    global into
    ans = []
    unvisited = [True] * n
    for i in range(n):
        if into[i] == 0 and unvisited[i]:
            q = deque()
            q.append(i)
            while len(q) > 0:
                node = q.popleft()
                ans.append(node)
                unvisited[node] = False
                for v in G[node]:
                    into[v] -= 1
                    if into[v] == 0:
                        q.append(v)
    return ans

visited = []
answer = deque()
def rec(v):
    global visited
    visited[v] = True

    for node in G[v]:
        if not visited[node]:
            rec(node)
    answer.appendleft(v)

def dfs_topolo(n):
    for i in range(n):
        if not visited[i]:
            rec(i)

def main():
    global G, into, visited
    v, e = list(map(int, input().strip().split()))
    G = [[] for _ in range(v)]
    visited = [False] * v
    into = [0] * v
    for i in range(e):
        s, t = list(map(int, input().strip().split()))
        G[s].append(t)
        into[t] += 1
    # ans = topological_sort(v)
    # for p in ans:
    #     print(p)
    dfs_topolo(v)
    for p in answer:
        print(p)

if __name__ == '__main__':
    main()



Measured memory_bytes: 9268
/* ファイル名：ITP1_8_D.c	*/
/* 内容：リング状の文字列 s の任意の位置から、時計回りに連続した文字をいくつか選んで、	*/
/*		 文字列 p が作れるかを判定する													*/
/* include	*/
#include <stdio.h>
#include <string.h>

/* 外部変数宣言	*/

/* プロトタイプ宣言	*/

/* 関数名:main	*/
/* 処理内容:リング状の文字列 s の任意の位置から文字列 p が作れるかを判定する	*/
int main( void )
{
	/* 内部変数定義	*/
	/* 入力	*/
	char s[100];	/* リング状の文字列の元となる文字列	*/
	char p[100];	/* 作れるか確かめる文字列			*/
	
	/* 処理	*/
	char ring[201];	/* リング状の文字列					*/
	
	/* 入力処理	*/
	scanf("%s",s);	/* sの取得	*/
	scanf("%s",p);	/* pの取得	*/
	
	/* sを加工しリング状の文字列にする	*/
	strcpy(ring,s);	/* sをringにコピー	*/
	
	strcat(ring,s);	/* sをringに連結(これでリング状になる)	*/
	
	/* pが作れるかの判定及び出力	*/
	/* pが作れた場合		*/
	if(strstr(ring,p) != NULL){
		printf("Yes\n");	/* Yesを出力	*/
	}
	/* pが作れなかった場合	*/
	else{
		printf("No\n");		/* Noを出力		*/
	}
	
	return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#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; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    sort(a.begin(),a.end());
    cout<<a[n-1]-a[0]<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char s[100002];
int n,sg,sp,ans;
int main()
{
	scanf("%s",s);
	n=strlen(s);
	sg=sp=0;
	for(int i=0;i<n;i++)
		if(i%2==1&&s[i]=='g')ans++;
		else	if(i%2==0&&s[i]=='p')ans--;
	printf("%d",ans);
	//return 0;
}

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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  string s;
  int k;
  cin >> s >> k;
  for (char& c : s) {
    if (c != 'a' && 'z' + 1 - c <= k) {
      k -= 'z' + 1 - c;
      c = 'a';
    }
  }
  s.back() += k % 26;
  cout << s << endl;
}


Measured memory_bytes: 592
#include<stdio.h>
int main(void){
   int a,b;
   int sum = 0;
  
   scanf("%d %d", &a, &b);
   
  if(a > b){
     sum = a;
     a = a-1;
     if(a > b) sum = sum + a;
     else sum = sum + b;
  }
  else if(a < b){
     sum = b;
     b = b-1;
     if(a < b) sum = sum + b;
     else sum = sum + a;
  }
  else sum = (a + b);

  printf("%d", sum);
  
  return 0;
}

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

int main() {
    int n, ans = 0;
    const int MOD = 1e9 + 7;
    cin >> n;
    vector<int> a(n), b(n, 0);
    rep(i, n) cin >> a.at(i);
    rep(i, n / 2) b.at(i) = b.at(n - i - 1) = n - 2 * i - 1;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    bool flag = true;
    rep(i, n) if(a.at(i) != b.at(i)) flag = false;
    if(flag) {
        ans = 1;
        rep(i, n / 2) ans = ans * 2 % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#define rep(i,s,t) for (int i=s;i<=t;++i)
using namespace std;
double ans=0;
void dfs(int n,double d,double x){
    if (n==0) return;
    ans+=double(2*n*d+x*n*(2*n+1))/(2*n);
    d=d+d/n+3*x/(2*n);
    x=x+2*x/n;
    dfs(n-1,d,x);
}
int main()
{
    int n;
    double d,x;scanf("%d%lf%lf",&n,&d,&x);
    d-=x;
    dfs(n,d,x);
    printf("%.15f\n",ans);
    return 0;
}


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

int main()
{
	int n;
	cin>>n;
	double p[n];
	for (int i = 0; i < n; ++i)
	{
		/* code */
		cin>>p[i];
	}
	double dp[n+1][n+1];
	memset(dp,0,sizeof dp);
	dp[0][0] = 1;
	for (int i = 1; i <= n; ++i)
	{
		dp[i][0] = (1-p[i-1])*dp[i-1][0];
	}

	for (int i = 1; i <= n; ++i)
	{
		for(int j = 1; j<=i; j++)
		{
			dp[i][j] = dp[i-1][j-1]*p[i-1]+dp[i-1][j]*(1-p[i-1]);
		}
	}
	double ans = 0;
	for (int i = (n+1)/2; i <= n; ++i)
	{
		ans += dp[n][i];
	}
	cout<<fixed<<setprecision(9)<<ans<<endl;
}

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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define INF LLONG_MAX

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  
  int n;
  cin >> n;
  
  vector<int> a(n);
  int maxA = 0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    maxA = max(maxA,a[i]);
  }
  
  int closestVal = 0;
  double halfMax = maxA/2.0;
  double minDist = (double)maxA;
  for(int i=0;i<n;i++){
    if(a[i]==maxA) continue;
    if(abs(halfMax-(double)a[i])<minDist){
      minDist = abs(halfMax-(double)a[i]);
      closestVal = a[i];
    }
  }

  cout << maxA << " " << closestVal << endl;
  return 0;
}



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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second

struct monotonic_queue
{
	deque<pair<int, int>> deq;

	void add(int k, int v)
	{
		while (!deq.empty() && deq.back().second >= v)
			deq.pop_back();
		deq.push_back({k, v});
	}

	void remove(int k)
	{
		while (!deq.empty() && deq.front().first <= k)
			deq.pop_front();
	}

	int min()
	{
		return deq.front().S;
	}
};

int main()
{
	#ifdef DGC
		freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

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

	int n, m;
	string s;
	cin >> n >> m >> s;

	++n;
	vector<int> dp(n, -1);
	dp[0] = 0;
	monotonic_queue mq;
	mq.add(0, 0);

	reverse(s.begin(), s.end());
	for (int i = 1; i < n; ++i)
		if (s[i] == '0')
		{
			mq.remove(i-m-1);
			if (!mq.deq.empty())
			{
				dp[i] = mq.min() + 1;
				mq.add(i, dp[i]);
			}
		}

	reverse(dp.begin(), dp.end());

	if (dp[0] == -1)
	{
		cout << "-1\n";
		return 0;
	}

	int x = dp[0], p = 0;

	while (x > 0)
	{
		int last = p;
		while (dp[p] != x-1) ++p;
		--x;
		cout << p-last << " \n"[!x];
	}

	return 0;
}


Measured memory_bytes: 1104
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int N;
vector<i64> A;

int main(){
    cin >> N;
    A.resize(N);
    rep(i,0,N - 1) cin >> A[i];
    map<i64,int> st;
    st[0] = 1;

    i64 sum = 0;
    i64 ans = 0;

    rep(i,0,N - 1){
        sum += A[i];
        ans += st[-sum];
        st[-sum]++;
    }

    cout << ans << endl;
}


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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }

// DEGUG
template <class T>
void dump_(const char *s, T&& x) {
    clog << '{';
    while(*s != '\0') clog << *(s++);
    clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void dump_(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  dump_(s, forward<Tail>(tail)...);
}
// }}} End

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

  VAR(int, H, W);

  vector<bool> side_all(H + 1, false);
  vector<bool> ver_all(W + 1, true);
  vector<string> s(H);

  rep(i, H) {
    IN(s[i]);
    side_all[i] = all_of(all(s[i]), [](char c) { return c == '.'; });
  }

  rep(x, W) {
    rep(y, H) {
      if (s[y][x] == '#') ver_all[x] = false;
    }
  }

  rep(y, H) {
    rep(x, W) {
      if (side_all[y]) break;
      if (ver_all[x]) continue;
      OUTN(s[y][x]);
    }

    if (!side_all[y]) OUTL("");
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int i, j;
    int array[5] = {0};
    for (i = 0; i < 5; i++)scanf("%d", array + i);
    for (i = 0; i < 4; i++)for (j = 0; j < 4 - i; j++)if (array[j] < array[j + 1])array[j] ^= array[j + 1] ^= array[j] ^= array[j + 1];
    for (i = 0; i < 5; i++)printf("%d%c", array[i], 10 + 22 * (i < 4));
    return 0;
}

Measured memory_bytes: 596
n, m = map(int, input().split())
p = [0]*m
s = [0]*m
for i in range(m):
    p[i], s[i] = input().split()
    p[i] = int(p[i])

ac = 0
wa = [0 for _ in range(n)]
notAC = [True for _ in range(n)]

for i in range(m):
    if s[i] == "AC" and notAC[p[i]-1]:
        notAC[p[i]-1] = False
        ac += 1
    elif s[i] == "WA" and notAC[p[i]-1]:
        wa[p[i]-1] += 1

ans_wa = 0
for i in range(n):
    if not notAC[i]:
        ans_wa += wa[i]
print(ac, ans_wa)

Measured memory_bytes: 15024
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long int lli;
int main()
{
  lli i,j,n,t,cnt = 0;
  cin >> n;
  for(i=0;i<n;i++)
  {
    cin >> j;
    if(i % 2 == 0 && j % 2 == 1)
      cnt++;
  }
  cout << cnt;
  
  
  return 0;
}


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

#define	PI	acos(-1)
#define	mp	make_pair
#define f	first
#define s	second
#define mset(arr, val)	memset(arr, val, sizeof(arr))
#define	srt(arr)	sort(arr.begin(), arr.end())

using namespace std;

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

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

	int a, b, c;
	cin >> a >> b >> c;

	if(a==b){
		cout << c << '\n';
	} else {
		if(a == c){
		cout << b << '\n';

		} else {
		cout << a << '\n';
		}
	}
	return 0;
}


Measured memory_bytes: 256
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;

// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}


void solve(istream &in, ostream &out) {
  auto n = next<int>(in);
  if (n == 22) {
    out << "Christmas Eve Eve Eve\n";
  } else if (n == 23) {
    out << "Christmas Eve Eve\n";
  } else if (n == 24) {
    out << "Christmas Eve\n";
  } else {
    out << "Christmas\n";
  }

}



int main() {
    solve(cin, cout);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=2005;
int x[N],a[N][N],b[N][N],f[N],p[N],r,n,m,ans;
char c[N][N];
int main() {
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++) {
        scanf("%s",c[i]+1);
        for (int j=1;j<=m;j++) {
            b[i][j] = c[i][j]=='#'?1:0;
        }
    }
    for (int i=1;i<n;i++) 
        for (int j=1;j<m;j++) 
            if ((b[i][j]+b[i+1][j]+b[i][j+1]+b[i+1][j+1])%2==0) 
                a[i][j]=1;
    for (int i=1;i<m;i++) x[i]=0;
    for (int i=1;i<n;i++) {
        for (int j=1;j<m;j++) 
            if (a[i][j]) x[j]++;else x[j]=0;
        memset(f,0,sizeof f);
        memset(p,0,sizeof p);
        r=0;
        for (int j=1;j<=m;j++) {
            while (r && f[r]>=x[j]) {
                ans=max(ans,(j-p[r-1])*(f[r]+1));
                --r;
            }
            f[++r]=x[j];
            p[r]=j;
        }
  
    }
    printf("%d\n",max(ans,max(m,n)));
    return 0;
}

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

int main()
{
    int n;
    cin>>n;
    int p=(n%10)%10;
    if(p==3)
        cout<<"bon";
    else if(p==0||p==1||p==6||p==8)
        cout<<"pon";
    else
        cout<<"hon";
    return 0;
}


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

using namespace std;
const int N = 1e5 + 3, MOD = 1e9 + 7;
char s[N];
int mem[N][2], n;
int go(int i, bool less) {
	if (i == n)
		return 1;
	int &ret = mem[i][less];
	if (~ret)
		return ret;
	ret = 0;
	if (less || s[i] == '1')
		ret = (go(i + 1, less) * 2) % MOD;
	ret = (ret + go(i + 1, less || s[i] == '1')) % MOD;
	return ret;
}
int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
#endif
	scanf("%s", s);
	n = strlen(s);
	memset(mem, -1, sizeof mem);
	printf("%d\n", go(0, false));
	return 0;
}


Measured memory_bytes: 5760
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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;
}


int n;
VI a;
unordered_map<int, int> twoPow{{1, 0}, {2, 1}, {4, 2}, {8, 3}, {16, 4}, {32, 5}, {64, 6}, {128, 7}, {256, 8}, {512, 9}, {1024, 10}, {2048, 11}, {4096, 12}, {8192, 13}, {16384, 14}, {32768, 15}, {65536, 16}, {131072, 17}, {262144, 18}, {524288, 19}};
unordered_set<int> Sum;

inline int grayCode(int i){
    return i ^ (i >> 1);
}

void bitSearch(){
    int sum = 0, prvj = 0;
    FOR(i, 1, (1 << n)){
        int j = grayCode(i);
        int changebit = j ^ prvj;
        if(j & changebit){
            sum += a[twoPow[changebit]];
        }else{
            sum -= a[twoPow[changebit]];
        }
        Sum.insert(sum);
        prvj = j;
    }
}

int main(){
    cin >> n;
    a.resize(n);
    REP(i, n) cin >> a[i];
    bitSearch();
    int q; cin >> q;
    REP(i, q){
        int m; cin >> m;
        cout << ((Sum.find(m) != Sum.end()) ? "yes" : "no") << "\n";
    }
    return 0;
}




Measured memory_bytes: 3132
n = int(input())
listA = list(map(int,input().split()))
res = []
for i in listA:
    if i % 2 == 0:
        if i % 3 ==0 or i % 5==0:
            res.append('OK')
        else:
            res.append('NO')
    else:
        res.append('OK')
if 'NO' in res:
    print('DENIED')
else:
    print('APPROVED')

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


int n;
int arr[100005];


int f(){

	int dp[n+1]={0};
	dp[0]=0;
	dp[1] = abs(arr[1]-arr[0]);

	for(int i=2;i<n;i++){
		int op1 = abs(arr[i-1]-arr[i])+dp[i-1];
		int op2 = abs(arr[i-2]-arr[i])+dp[i-2];

		dp[i] = min(op1,op2);
	}

	return dp[n-1];
}


int main(){

	//#ifndef ONLINE_JUDGE
	   // // for getting input from input.txt
	   // freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	   // freopen("output.txt", "w", stdout);
	//#endif
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>arr[i];


	cout<<f()<<endl;
}




Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
  int i,j;
  for(i=1;i<=9;i++)
  {
    for(j=1;j<=9;j++)
    {
      printf("%dx%d=%d\n",i,j,i*j);
    }
  }
  return 0;
}

Measured memory_bytes: 0
///not today

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

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair< int, pair<int, int> >
#define plpll pair< ll, pair<ll, ll> >

const int maxn = 2005;
int ans[maxn], a[maxn];

int32_t main(){
    int n, x, sum = 0;
    cin >>n >>x;
    for(int i = 0; i < n; i ++)
        cin >>a[i];
    for(int i = 0; i < n; i ++){
        ans[i] = a[i];
        sum += a[i];
    }
    for(int i = 1; i < n; i ++){
        int s = i* x;
        for(int j = 0; j < n; j ++){
            xmin(ans[j], a[(j + n - i)% n]);
            s += ans[j];
        }
        xmin(sum, s);
    }
    cout <<sum <<endl;
    return false;
}


Measured memory_bytes: 256
import java.util.Scanner;




public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);
    	int X=sc.nextInt();
    	int Y=sc.nextInt();
    	int Z=sc.nextInt();

    	int ninzu=0;
    	while(true) {

    		int next=ninzu+1;
    		if(X>=next*Y+Z*(next+1)) {
    			ninzu=next;
    		}else {
    			break;
    		}


    	}

    	System.out.println(ninzu);

    }


}



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

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

    int n, k;
    cin >> n >> k;

    double ans = 0.0;
    REP(i, n) {
        int cnt = 0;
        while (k > (i + 1) * pow(2, cnt))
            cnt++;
        ans += (1.0 / n) * pow(0.5, cnt);
    }

    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define N 100005
constexpr ll inf = 100000000000000;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

bool check(int mid){

  return false;
}

ll serch(ll ok,ll ng) {
	while (abs(ok-ng) > 1) {
		ll mid = (ok + ng) / 2;
		if (check(mid))ok = mid;
		else ng = mid;
	}
	return ok;
}

int main(){
  int n,p;
  string s;
  cin>>n>>p>>s;
  ll ans=0;
  if(p==2||p==5){
    rep(i,n){
      if((s[i]-'0')%p==0){
        ans+=i+1;
      }
    }
  }
  else{
    map<int,int> m;
    m[0]++;
    int rem=0,dig=1;
    repr(i,n){
      rem=(rem+(s[i]-'0')*dig)%p;
      ans+=m[rem];
      m[rem]++;
      dig*=10;
      dig%=p;
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 900
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    int a[n], left[n], right[n];
    long long ans = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    for(int i = 0; i <= min(n, k); i++)
    {
        for(int j = 0; j <= min(n, k) - i; j++)
        {
            int sub[n];
            long long total = 0;
            for(int l = 0; l < i; l++)
            {
                sub[l] = a[l];
                total += a[l];
            }
            for(int l = 0; l < j; l++)
            {
                sub[l + i] = a[n - l - 1];
                total += a[n - l - 1];
            }
            sort(sub, sub + i + j);
            for(int l = 0; l < min(i + j, k - i - j); l++)
            {
                if(sub[l] < 0)
                {
                    total -= sub[l];
                }
            }
            ans = max(ans, total);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define MN 300001
#define S 0
#define INF 2000000000
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,a[MN+5],b[MN+5],num,id[MN+5],ID[MN+5],T;
int d[MN+5],c[MN+5],q[MN+5],top,head[MN+5],cnt=1,ans;
struct edge{int to,next,w;}e[MN*6+5];
inline void ins(int f,int t,int w)
{
    e[++cnt]=(edge){t,head[f],w};head[f]=cnt;
    e[++cnt]=(edge){f,head[t],0};head[t]=cnt;
}
int dfs(int x,int f)
{
    if(x==T) return f;int used=0;
    for(int&i=c[x];i;i=e[i].next) if(e[i].w&&d[e[i].to]==d[x]+1)
    {
        int w=dfs(e[i].to,min(e[i].w,f-used));
        used+=w;e[i].w-=w;e[i^1].w+=w;
        if(used==f) return f;
    }
    return used;
}
bool bfs()
{
    memset(d,0,sizeof(int)*(T+2));d[q[top=1]=S]=1;
    for(int i=1;i<=top;++i) 
        for(int j=c[q[i]]=head[q[i]];j;j=e[j].next)
            if(!d[e[j].to]&&e[j].w) d[q[++top]=e[j].to]=d[q[i]]+1;
    return d[T];
}
int main()
{
    n=read();
    for(int i=1;i<=n;++i) a[i]=read()+1;
    for(int i=1;i<=n;++i) b[i]=read()+1;
    for(int i=1;i<=n;++i) if(!id[i])
    {
        ++num;int V=0;
        for(int j=i;!id[j];j=a[j])
        {
            id[j]=num;
            if(a[j]!=j) ++V;
        }
        ins(S,num,V);ans+=V;
    }
    for(int i=1;i<=n;++i) if(!ID[i])
    {
        ++num;
        for(int j=i;!ID[j];j=b[j])
        {
            ID[j]=num;
            if(b[j]!=j) ++c[num];
        }
    }
    T=num+1;
    for(int i=1;i<=num;++i) if(c[i]) ins(i,T,c[i]),ans+=c[i];
    for(int i=1;i<=n;++i) 
    {
        int t=(a[i]!=i)+(b[i]!=i);
        int T=(a[i]!=b[i]);
        if(t!=T) ins(id[i],ID[i],t-T);
    }
    while(bfs()) ans-=dfs(S,INF);
    cout<<ans;
    return 0;
}

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

typedef long long lint;

int main(){
  int n;
  cin >> n;
  vector<lint> cnt(5);
  map<char, int> mp;
  string tmp = "MARCH";
  for(int i = 0 ; i < 5 ; i++){
    mp[tmp[i]] = i + 1;
  }
  for(int i = 0 ; i < n ; i++){
    string s;
    cin >> s;
    if(mp[s[0]] > 0){
      cnt[mp[s[0]]-1]++;
    }
  }
  lint ans = 0;
  for(int i = 0 ; i < 5 ; i++){
    for(int j = i + 1 ; j < 5 ; j++){
      for(int k = j + 1 ; k < 5 ; k++){
        ans += cnt[i] * cnt[j] * cnt[k];
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int N;
	int A[1000];
	int v;
	int j;
	int i;
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%d", &A[i]);
	for (i = 0; i < N; i++) {
		v = A[i];
		j = i - 1;
		while (j>=0) {
			if (A[j] <= v) break;
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		int k;
		for (k = 0; k < N-1; k++) printf("%d ", A[k]);
		printf("%d\n", A[N-1]);
	}
	
	return 0;
}

Measured memory_bytes: 604