akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin>>n;
    vector<int> a(n);
    cin>>a;
    vector<int> bl;
    a.push_back(0);
    int cnt=0;
    REP(i,n+1) {
        if(a[i]==0) {
            bl.push_back(cnt);
            cnt=0;
        }
        else {
            cnt+=a[i];
        }
    }
    int ans=0;
    REP(i,SZ(bl)) {
        ans+=bl[i]/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2800
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  int m=s.length(),n=t.length(),i,ans;
  ans=n;
  for(i=0;i<=m-n;i++){
    int c=0;
    for(int j=0;j<n;j++) if(t.at(j)==s.at(i+j)) c++;
    ans=min(ans,n-c);
  }
  cout<<ans<<endl;
}

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

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

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

const int MOD = 1000'000'007;
const double EPS = 0.000'000'001;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

const int N = 100010;
vi g[N];
int dp[N];

int solve(int v)
{
	if(dp[v] != -1) return dp[v];

	int ans = 0;
	for(int& u : g[v])
		ans = max(1 + solve(u), ans);

	return dp[v] = ans;
}


int main()
{
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);
	cout.precision(10);
	
	int n, m; cin >> n >> m;

	while(m--)
	{
		int a, b; cin >> a >> b;
		g[a].emplace_back(b);
	}

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

	int ans = 0;
	for(int i = 1; i <= n; i++)
		ans = max(ans, solve(i));

	cout << ans << endl;

	//cerr << "Tempo de execucao: " << (double)clock() / CLOCKS_PER_SEC << endl;
	return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <utility>
#include <map>

using namespace std;

typedef pair<int, int> P;

int main() {
	int m, n;
	
	while (cin >> m && m != 0) {
		P p[200], s[1000];
		map<P, bool> mp;

		for (int i = 0; i < m; ++i) {
			cin >> p[i].first >> p[i].second;
		}
		cin >> n;
		for (int i = 0; i < n; ++i) {
			cin >> s[i].first >> s[i].second;
			mp[s[i]] = true;
		}

		//O(nmlogn)
		for (int j = 0; j < n; ++j) { //j???????????????
			int dx = s[j].first - p[0].first;
			int dy = s[j].second - p[0].second;
			bool success = true;
			for (int k = 0; k < m; ++k) { //??????k????????¨?????????
				if (mp[make_pair(p[k].first + dx, p[k].second + dy)] != true) {
					success = false;
					break;
				}
			}
			if (success) {
				cout << dx << " " << dy << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3200
is = gets.chomp!.split(" ")
is.map!(&:to_i)

w = is[0]
h = is[1]
x = is[2]
y = is[3]
r = is[4]

if ((x+r) > w)||((x-r) < 0)||((y+r) > h)||((y-r)<0) then
	puts "No"
else
	puts "Yes"
end

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

int main()
{
  ll n, k, q;
  cin >> n >> k >> q;
  vector<ll> member(n, 0);
  for (ll i = 0; i < q; i++)
  {
    ll a;
    cin >> a;
    member[a - 1]++;
  }
  for (ll i = 0; i < n; i++)
  {
    if (member[i] + k - q > 0)
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 4048
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  int n, pPre,pPost;
  int[] pre,in,post;

  public static void main(String[] args) {
    
    new Main().run();
  }

  public void run() {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      n = Integer.parseInt(br.readLine());
      String[] linesPre =  br.readLine().split(" ");
      String[] linesIn  =  br.readLine().split(" ");

      pre  = new int[n];
      in   = new int[n];
      post = new int[n];
  
      for(int i=0; i<n; i++){
        pre[i] = Integer.parseInt(linesPre[i]);
        in[i]  = Integer.parseInt(linesIn[i] );
      }

      solve();

    } catch ( IOException e ) {
      System.out.println("IOException!");
    }
  }
  
  void solve() {
    pPre = pPost = 0;
    StringBuilder buf = new StringBuilder();

    rec(0,pre.length);

    for (int var : post) {
      buf.append(var).append(" ");
    }
    buf.setLength(buf.length()-1);
    System.out.println(buf);
  }

  void rec(int l, int r) {
    if( l < r ) {
      int root = pre[pPre++];
      int m = arrayDistance(0, in.length, root);

      rec(l,m);
      rec(m+1,r);
  
      post[pPost++] = root;
    }
  }

  int arrayDistance(int start, int end, int find) {
    int d=start;

    for( ; d<end; d++)
      if( in[d] == find ) break;

    return d;
  }
}


Measured memory_bytes: 24476
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m,X = inpl()
c = []
a = []
for _ in range(n):
    tmp = inpl()
    c.append(tmp[0])
    a.append(tmp[1:])

res = INF
for fl in itertools.product(range(2), repeat=n):
    ri = [0] * m
    cost = 0
    for i,x in enumerate(fl):
        if x:
            cost += c[i]
            for j,y in enumerate(a[i]):
                ri[j] += y
    if min(ri) >= X:
        res = min(res, cost)
print(res if res != INF else -1)

Measured memory_bytes: 91500
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()
	// a b c
	// (b+c)/2, (a+c)/2, (a+b)/2
	// (2a+b+c)/4, (a+2b+c)/4, (a+b+2c)/4,
	// (2a+3b+3c)/8, (3a+2b+3c)/8, (3a+3b+2c)/8
	a := readInt()
	b := readInt()
	c := readInt()
	if a%2 == 1 || b%2 == 1 || c%2 == 1 {
		println(0)
		return
	}
	if a == b && b == c {
		println(-1)
		return
	}
	xa := calc(a)
	xb := calc(b)
	xc := calc(c)
	//eprintln(xa, xb, xc)
	ans := min(xa, min(xb, xc))
	if xa == xb && xb == xc {
		ans++
	}
	println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func calc(n int) int {
	count := 0
	for n%2 == 0 {
		n /= 2
		count++
	}
	return count
}

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,k,ans = 0;
	cin >> n >> k;
	if(!k){
		cout << n * n << endl;
		return 0;
	}
	for(int i = k + 1;i <= n;i++){
		ans += (int)((n + 1) / i) * (i - k) + max(0ll,(n + 1) % i - k);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = 1000000007;
#define op(x) (x&(-x))
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define si(n) scanf("%d",&n)
#define s2i(x,y) scanf("%d %d",&x,&y);
#define s3i(x,y,z) scanf("%d %d %d",&x,&y,&z);
#define s4i(x,y,z,w) scanf("%d %d %d %d",&x,&y,&z,&w);
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define print2d(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}

//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);

char a[10][10];
int h,w;

int main()
{
	cin>>h>>w;
	for(int i=0;i<h;i++) cin>>a[i];
	if(a[0][0]!='#') {cout<<"Impossible"<<endl; return 0;}
	if(a[h-1][w-1]!='#') {cout<<"Impossible"<<endl; return 0; }
	a[0][0]='X';
	int i = 0, j = 0;
	while(1)
	{
		if(i==h-1&&j==w-1) {a[i][j]='X'; break;}
		if(i+1<=h-1&&j+1<=w-1)
		{
			if(a[i+1][j]=='#'&&a[i][j+1]=='#') {cout<<"Impossible"<<endl; return 0;}
			else if(a[i+1][j]=='#') a[i+1][j]='X', i++;
			else if(a[i][j+1]=='#') a[i][j+1]='X', j++;
			else {cout<<"Impossible"<<endl; return 0;}
		}
		else if(i+1<=h-1)
		{
			if(a[i+1][j]=='#') a[i+1][j]='X', i++;
			else {cout<<"Impossible"<<endl; return 0;}
		}
		else 
		{
			if(a[i][j+1]=='#') a[i][j+1]='X', j++;
			else {cout<<"Impossible"<<endl; return 0;}
		}
	}
	bool flag = false;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(a[i][j]=='#')
			{
				flag = true;
				break;
			}
		}
	}
	if(flag)
		cout<<"Impossible"<<endl;
	else
		cout<<"Possible"<<endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long sum=1;
    for(int i=1; i<=n; i++) {
      sum*=i;
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 25716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int cnt[200010];
 
int main(){
    int n,k;
    cin>>n>>k;
    set<int> s;
    rep(i,n){
        int a;
        cin>>a;
        s.insert(a);
        cnt[a]++;
    }

    if(s.size()<=k){
        cout<<0<<endl;
        return 0;
    }

    vector<int> v;
    rep(i,200010){
        if(cnt[i]>0) v.push_back(cnt[i]);
    }

    sort(all(v));
    int c=s.size()-k;
    int ans=0;
    rep(i,c){
        //cout<<v[i]<<endl;
        ans+=v[i];
    }

    cout<<ans<<endl;
}

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

int main(){
  string S;
  cin >> S;
  int N=S.size();
  bool a=false;
  for(int i=0;i<N-1;i++){
    string T=S.substr(i,2);
    if(T.at(0)==T.at(1)){
      a=true;
      cout << i+1 << " " << i+2 << endl;
      break;
    }
    if(i!=N-2){
      string U=S.substr(i,3);
      if(U.at(0)==U.at(2)){
        a=true;
        cout << i+1 << " " << i+3 << endl;
        break;
      }
    }
  }
  if(!a){
    cout << -1 << " " << -1 << endl;
  }
}   

Measured memory_bytes: 3704
from itertools import combinations as cb
import sys

N = int(input())

k = (1 + int((1 + 8 * N) ** 0.5)) // 2

if k * (k - 1) // 2 != N:
    print('No')
    sys.exit()

print('Yes')
print(k)

x = list(cb(range(k), 2))
dp = [[] for i in range(k)]
for i,(a,b) in enumerate(x):
    dp[a].append(i+1)
    dp[b].append(i+1)
for r in dp:
    print(len(r), *r)

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


#define M 1000000007
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define mod 998244353
#define sz(v) (int)(v).size()

#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

ll add(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a+b)%M;
	return (p+M)%M;
}

ll mul(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a*b)%M;
	return (p+M)%M;
}


int main()
{
	fastio;
	ll x;
	cin>>x;
	cout<<(x/500)*1000+((x%500)/5)*5<<endl;
    return 0;
}





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

int main(){
	int tim , hour, minut, sec;
	cin >> tim;
	hour = tim / 3600;
	minut = tim % 3600 / 60;
	sec = tim % 3600 % 60;
	
	cout << hour << ":" << minut << ":" << sec << endl;
	
	return 0;
}

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

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

typedef bitset<200010> B;

#define fr first
#define sc second

int main(){
	static int n,m;
	static int l[200010],r[200010];
	scanf("%d%d",&n,&m);
	for(int i = 0 ; i < n ; i ++){
		scanf("%d%d",&l[i],&r[i]);
	}
	
	vector<P> vec;
	for(int i = 0 ; i < n ; i ++){
		vec.push_back(P(l[i],r[i]));
	}
	sort(vec.begin(),vec.end());
	
	int ret = 0;
	vector<int> L;
	B R; R.set();
	for(P p: vec){
		int x = R._Find_next(p.sc-1);
		if(x <= m){
			ret ++;
			R[x] = false;
		}
		else {
			L.push_back(p.fr);
		}
	}
	sort(L.begin(),L.end());
	
	int cnt = 0;
	for(int i = 0 ; i < L.size() ; i ++){
		if(cnt < L[i]){
			cnt ++;
		}
	}
	ret += cnt; ret = min( ret , m );
	cout << n-ret << endl;
}
	

Measured memory_bytes: 5232
def main():
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10 ** 9 + 7
    ans = 0
    L = 100
    for l in range(L):
        one = 0
        zero = 0
        for a in A:
            if (a & (1<<(L - l - 1))):
                one += 1
            else:
                zero += 1
        ans += (one * zero) * 2 ** (L - l - 1)
        ans %= MOD

    print(ans)
    


if __name__ == "__main__":
    main()

Measured memory_bytes: 124648
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] h = new long[n];
        for(int i = 0;i < n;i++) h[i] = sc.nextLong();
        boolean[] isGoodTower = new boolean[n];
        for(int i = 0;i < n;i++) isGoodTower[i] = true;
        int[] a = new int[m];
        int[] b = new int[m];
        for(int i = 0;i < m;i++) {
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
        }

        for(int i = 0;i < m;i++) {
            long aH = h[a[i]];
            long bH = h[b[i]];
            
            if(aH < bH) {
                isGoodTower[a[i]] = false;
            }
            else if(aH == bH) {
                isGoodTower[a[i]] = false;
                isGoodTower[b[i]] = false;
            }
            else {
                isGoodTower[b[i]] = false;
            }
        }

        int count = 0;
        for(int i = 0;i < isGoodTower.length;i++) {
            if(isGoodTower[i]) count++;
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 62116
Q = int(input())
qs = [tuple(map(int,input().split())) for i in range(Q)]

import heapq
class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        return heapq.heappop(self.hq) * self.sign

    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)

    def top(self):
        return self.hq[0] * self.sign

lq = Heapq([],True)
rq = Heapq([])
ans = 0

for q in qs:
    if q[0] == 2:
        print(lq.top(), ans)
        continue
    _,a,b = q
    ans += b
    lq.push(a)
    rq.push(a)
    if lq.top() > rq.top():
        l = lq.pop()
        r = rq.pop()
        ans += abs(l-r)
        lq.push(r)
        rq.push(l)

Measured memory_bytes: 47600
def fizzbuzz_length(n):
  f3 = 0
  f5 = 0
  f15 = 0
  folen = 0
  keta = 1
  while True:
    ub = 10**keta - 1
    lim = min(n, ub)
    folen += keta * (lim-10**(keta-1)+1 - (lim // 3 - f3) - (lim // 5 - f5) + (lim//15 - f15))
    f3 = lim // 3
    f5 = lim // 5
    f15 = lim // 15
    if n <= ub:
      break
    keta += 1
  return folen + 4 * (f3 + f5)
  
def fizzbuzz(i):
  if i % 15 == 0:
    return "FizzBuzz"
  elif i % 3 == 0:
    return "Fizz"
  elif i % 5 == 0:
    return "Buzz"
  else:
    return str(i)
  
s = int(input())
  
lb = 0
ub = s

while ub - lb > 1:
  m = (ub + lb) // 2
  if s <= fizzbuzz_length(m):
    ub = m
  else:
    lb = m

ans = ""
for i in range(ub, ub + 20):
  ans += fizzbuzz(i)

pos  = s - fizzbuzz_length(ub-1) - 1
print(ans[pos:pos+20])

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

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n+1,0);
    int tmpa, tmpb;
    for(int i = 0; i < m; i++){
        cin >> tmpa >> tmpb;
        a[tmpa]++;
        a[tmpb]++;
    }
    for(int i = 0; i < n+1; i++){
        if(a[i]%2!=0){
            cout << "NO" <<endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (int i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++)
	{
		for (int j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
bool is_not_out_of_range(size_t now, size_t max_num)
{
	return !(now < 0 || max_num <= now);
}
ll repeat_squaring(ll n, ll p, ll m)
{
	if (p == 0)
		return 1;
	if (p % 2 == 0)
	{
		ll t = repeat_squaring(n, p / 2, m);
		return t * t % m;
	}
	return n * repeat_squaring(n, p - 1, m);
}

int main()
{
	str s;
	cin >> s;
	str ans = "";
	rep(i, s.size())
	{
		if (s[i] == 'B')
		{
			if (!ans.empty())
				ans.pop_back();
		}
		else
		{
			ans.push_back(s[i]);
		}
	}
	cout << ans << endl;
	return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var n = int.Parse(Console.ReadLine());

            for (var i = 0; i < n; i++)
            {
                var line = Console.ReadLine().Split();
                var cmd = line[0];
                int one = int.Parse(line[1]), two = int.Parse(line[2]);
                var subs = two - one + 1;
                var bef = s.Substring(0, one);
                var af = s.Substring(one+subs);

                if (cmd == "print")
                {
                    Console.WriteLine(s.Substring(one, subs));
                }
                else if (cmd == "reverse")
                {
                    var tmp = string.Join("", s.Substring(one, subs).Reverse());
                    s = s.Replace(s.Substring(one, subs), tmp);
                }
                else
                {
                    var tmp2 = s.Substring(one, subs);
                    tmp2 = tmp2.Replace(tmp2, line[3]);

                    s = bef + tmp2 + af;
                }

            }
        }
    }
}


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

int main()
{
	int N,M;
	cin >> N >> M;
	int sum = 0;
	rep(i,N)
	{
		cin >> A[i];
		sum += A[i];
	}
	int cnt = 0;
	rep(i,N)
	{
		if (4 * M * A[i] >= sum) cnt++;
	}
	if (cnt >= M) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int32 n,k;
vector<vector<int32>> to;
vector<int32> dist;
int32 ans = 0;

void dfs(int32 v, int32 d = 0){
  if(to[v].size() == 0){
    dist[v] = 0;
  }
  for(auto u : to[v]){
    dfs(u,d+1);
    dist[v] = max(dist[v], dist[u] + 1);
  }
  if(dist[v]== k-1 && d >= 2){
    ++ans;
    dist[v] = -1;
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  to.resize(n);
  REP(i,n){
    int32 a;
    cin >> a;
    a--;
    if(i == 0){
      if(a != 0)++ans;
    }else{
      to[a].push_back(i);
    }
  }
  dist.resize(n,-1);
  dist[0] = 0;
  dfs(0);
  // REP(i,n)ANS(dist[i]);
  ANS(ans);
  return 0;
}

Measured memory_bytes: 12800
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
using namespace std;
using ll = long long;

int main(void) {
    ll N, M;
    cin >> N >> M;
    
    ll total = 0;
    for (int i = 0; i < M; i++) {
        ll a;
        cin >> a;
        total += a;
    }
    if (N - total >= 0)
        cout << N - total << endl;
    else
        cout << -1 << endl;
}

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

#define MAX 500010

int A[MAX +1];
int H;

// ここからプロトタイプ宣言
void maxHeapify(int i);
// ここまでプロトタイプ宣言

int main(){
	cin>>H;
	for(int i=1;i<=H;i++)cin>>A[i];

	for(int i=H/2;i>0;i--)maxHeapify(i);

	for(int i=1;i<=H;i++)cout<<" "<<A[i];
	cout<<endl;

	return 0;
}


//---------------------
// 関数
void maxHeapify(int i){
	int largest;

	int l = i*2;
	int r = i*2 +1 ;

	if(l<=H && A[l]>A[i]){
		largest = l;
	}else{
		largest=i;
	}

	if(r<=H && A[r]>A[largest]){
		largest=r;
	}

	if(largest != i){
		swap(A[i],A[largest]);

		maxHeapify(largest);
	}
}



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

    int main(void){
        set<int> s;
        int n;
        cin >> n;
        for (int i = 0; i < n;i++){
            int d;
            cin >> d;
            s.insert(d);
        }
        cout << s.size() << endl;
        return 0;
    }


Measured memory_bytes: 256
#include <algorithm>
#include <sstream>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string>
#include <queue>
#include <vector>
using namespace std;

int main()
{
	int w, n, a, b;
	vector<int> A;

	cin >> w >> n;

	for (int i = 1; i <= w; i++) A.push_back(i);

	for (int i = 0; i < n; i++) {
		scanf("%d,%d", &a, &b);
		swap(A[a - 1], A[b - 1]);
	}

	for (int i = 0; i < w; i++) cout << A[i] << endl;
}



Measured memory_bytes: 3204
N = int(input())
arr = [[0]*3 for _ in range(N)]
"""
a = [0]*N
b = [0]*N
c = [0]*N
"""
for i in range(N):
    arr[i]=list(map(int,input().split()))
    #a[i],b[i],c[i] = map(int,input().split())

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

dp[0] = arr[0]

for i in range(1,N):
    for j in range(3):
        k = (j+1)%3
        l = (j+2)%3
        dp[i][j] = max(dp[i-1][k]+arr[i][j],dp[i-1][l]+arr[i][j])

ans = max(dp[-1])
print(ans)

Measured memory_bytes: 77932
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string[] input = Console.ReadLine().Split(' ');
        int guusuu = 0;
        int syurui = 0;

        int[] A = new int[100010];

        for(int i = 0; i < 100010; i++)
        {
            A[i] = 0;
        }

        for(int i = 0; i < N; i++)
        {
            A[int.Parse(input[i])]++;
        }

        for(int i = 0; i < 100010; i++)
        {
            if (A[i] != 0) syurui++;
            if (A[i] % 2 == 0 && A[i] != 0) guusuu++;
        }

        if (guusuu % 2 == 0) Console.WriteLine(syurui);
        else Console.WriteLine(syurui - 1);


        
    }

}

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

int N;
int n[200010];

int main()
{
    cin >> N;
    memset(n, 0, sizeof(n));
    for(int i = 2; i <= N; i++)
    {
        int a;
        cin >> a;
        n[a]++;
    }

    for(int i = 1; i <= N; i++) cout << n[i] << endl;

}

Measured memory_bytes: 4424
N = int(input())
S = input()
ans = [S[1: ].count('E')] * N
for i in range(1, N):
  ans[i] = ans[i - 1]
  if S[i - 1] == 'W':
    ans[i] += 1
  if S[i] == 'E':
    ans[i] -= 1
print(min(ans))

Measured memory_bytes: 15436
#include<bits/stdc++.h>
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;

int main(){
    int A[3][3];
    rep(i, 3){
        rep(j, 3){
            cin >> A[i][j];
        }
    }

    bool B[3][3];
    rep(i, 3){
        rep(j, 3){
            B[i][j] = false;
        }
    }

    int N;
    cin >> N;
    int c;
    rep(k, N){
        cin >> c;
        rep(i, 3){
            rep(j, 3){
                if (A[i][j] == c) {
                    B[i][j] = true;
                }
            }
        }
    }

    rep(i, 3){
        bool flag = true;
        rep(j, 3){
            if (!B[i][j]) {
                flag = false;
            }
        }
        if (flag) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    rep(i, 3){
        bool flag = true;
        rep(j, 3){
            if (!B[j][i]) {
                flag = false;
            }
        }
        if (flag) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    bool flag = true;
    rep(i, 3) {
        if (!B[i][i]) {
            flag = false;
        }

    }
    if (flag) {
        cout << "Yes" << endl;
        return 0;
    }

    flag = true;
    rep(i, 3) {
        if (!B[i][3-i-1]) {
            flag = false;
        }
    }
    if (flag) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;


}


Measured memory_bytes: 256
"use strict";
const main = arg => {
    var lines = arg.split('\n');
    var input = lines.shift().split(' ').map(function(n){return +n;});

    var maxV = 0;

    if(input[0] >= input[3]){
        console.log(input[3]);
        return;
    }

    maxV = input[0];
    input[3] -= input[0];
    
    if(input[1] >= input[3]){
        console.log(maxV);
        return;
    }

    input[3] -= input[1];

    maxV -= input[3];
    console.log(maxV);
    return;

}
 
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}

int main()
{
    int H, W;
    char c;
    cin >> H >> W;
    map<char, int> cnt;
    //   auto ans=make_v<char>(H,W);
    bool ok = true;
    rep(i, H) rep(j, W)
    {
        cin >> c;
        cnt[c]++;
    }
    int per4[4] = {0};

    int res1, res2, res0;
    if (H % 2 == 1 and W % 2 == 1)
    {
        res1 = 1;
        res2 = H / 2 + W / 2;
        res0 = (H * W - 1 * res1 - 2 * res2) / 4;
    }
    else if (H % 2 == 1 or W % 2 == 1)
    {
        if (H % 2 == 0)
            swap(H, W); //Hが奇数のときだけ考える
        res1 = 0;
        res2 = W / 2;
        res0 = (H * W - 1 * res1 - 2 * res2) / 4;
    }
    else
    {
        res1 = 0;
        res2 = 0;
        res0 = (H * W - 1 * res1 - 2 * res2) / 4;
    }
    for (auto i : cnt)
    {
        int n = i.second;
        do
        {
            if (n % 2 == 1)
            {
                res1--;
                n--;
            }
            else if (n % 4 == 2)
            {
                res2--;
                n -= 2;
            }
            else if (n % 4 == 0)
            {
                if (res0 > 0)
                {
                    res0--;
                    n -= 4;
                }

                else
                {
                    res2 -= 2;
                    n -= 4;
                }
            }
        } while (n > 0);
    }
    ok = (res1 == 0 and res2 == 0 and res0 == 0);
    cout << (ok ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main()
{	 
	int a, b, c, k, x;
	
	scanf("%d%d%d%d", &a, &b, &c, &k);
	if(a > k) x = k;
	else{
		x = a, k -= a;
		if(k > b) x -= k - b;
	}
	printf("%d\n", x);
		
	return 0;
}

Measured memory_bytes: 1684
#include <bits/stdc++.h>
using namespace std;
int main(){
    string x;
    cin >> x;
    int a = 0, b = 0;
    for(int i = 0;i < 3;i++){
        if(x[i] == 'A'){
            a++;
        }
        else{
            b++;
        }
    }
    if(a && b){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define pb push_back
#define ll long long

vec<vec<int>> solve(vec<int> a, vec<int> b)
{
  if (a.size() == 1) {
    vec<vec<int>> c(0);
    c.pb(a);
    c.pb(b);
    return c;
  }

  int bit = - 1;
  vec<int> a_(a.size() - 1), b_(b.size() - 1);
  rep(i, a.size()) {
    a_[i] = a[i];
    b_[i] = b[i];
    if (a[i] != b[i]) {
      bit = i;
      break;
    }
  }
  for (int i = bit; i < a.size() - 1; i++) {
    a_[i] = a[i + 1];
    b_[i] = b[i + 1];
  }
  vec<int> m_(a.size() - 1);
  rep(i, a.size() - 1) m_[i] = a_[i];
  m_[0] = 1 - a_[0];
  auto l = solve(a_, m_);
  auto r = solve(m_, b_);
  vec<vec<int>> c(l.size() + r.size(), vec<int>(l[0].size() + 1));
  rep(i, l.size()) {
    for (int j = 0; j < bit; j++) c[i][j] = l[i][j];
    c[i][bit] = a[bit];
    for (int j = bit; j < l[i].size(); j++) c[i][j + 1] = l[i][j];
  }
  rep(i, r.size()) {
    for (int j = 0; j < bit; j++) c[l.size() + i][j] = r[i][j];
    c[l.size() + i][bit] = b[bit];
    for (int j = bit; j < r[i].size(); j++) c[l.size() + i][j + 1] = r[i][j];
  }
  return c;
}

int main(void)
{
  int n;
  cin >> n;
  ll A, B;
  cin >> A >> B;
  vec<int> a(n), b(n);
  int counta = 0, countb = 0;
  rep(i, n) {
    a[i] = (A >> i) % 2;
    b[i] = (B >> i) % 2;
    counta += a[i];
    countb += b[i];
  }
  if (counta % 2 == countb % 2) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  vec<vec<int>> ans = solve(a, b);
  rep(i, ans.size()) {
    ll ret = 0;
    rep(j, n) ret += ans[i][j] ? ((ll)1 << (ll)j) : 0;
    cout << ret;
    if (i == ans.size() - 1) cout << endl;
    else cout << " ";
  }
  return 0;
}



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

#define lli long long
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define rep(i,n) for (lli i=0;i<(n);i++)

#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>

int main(){
  lli x,y;
  
  while(1){
    cin>>x>>y;
    if(x==0 and y==0)break;
    cout<<min(x,y)<<" "<<max(x,y)<<endl;
  }  
  
  return 0;
}

Measured memory_bytes: 2948
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, z, w;
  cin >> n >> z >> w;
  vector<int> in(n);
  for (int i = 0; i < n; i++) {
    cin >> in[i];
  }
  if (n == 1) {
    cout << abs(in[0] - w) << endl;
  } else {
    cout << max(abs(in[n - 1] - w), abs(in[n - 1] - in[n - 2])) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,j,k,a;
  char str[100];

  while(scanf("%s",str)!=EOF){
  for(i=0;str[i]!='\0';i++);
  
  for(j=0;j<i;j++){
    if(str[j]=='@'){
      switch(str[j+1]){
      case'1':a=1;break;
      case'2':a=2;break;
      case'3':a=3;break;
      case'4':a=4;break;
      case'5':a=5;break;
      case'6':a=6;break;
      case'7':a=7;break;
      case'8':a=8;break;
      case'9':a=9;break;
      }

      for(k=0;k<a;k++){
	printf("%c",str[j+2]);
      }
      j+=2;
    }else{
      printf("%c",str[j]);
    }
  }
  printf("\n");
  }
  return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<unordered_set>
#include<map>
#include<utility>
#include<string>
#include<iomanip>
#include<unordered_map>
using namespace std;
#define int   long long
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define LM LONG_MAX
#define LS LONG_MIN
#define cfM 998244353
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define inf 10000000000000000
#define sp setprecision(9)
int max(int b,int a)
{if(b>a)return b;else return a;}
int min(int b,int a)
{if(b<a)return b;else return a;}
int ab(int b)
{if(b<0) return (-1*b);else return(b);}
int32_t main()
{
	//CHECK IF NEGATIVE INPUT UNSIGNED->SIGNED
	int n;
    cin>>n;
    vector<int> a(n),dp(n);
    for (int i=0; i<n ;i++)
    {
        cin>>a[i];
    }
    if(n<=1)cout<<0<<endl;
    
    dp[0]=0;
    dp[1]=ab(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(ab(a[i]-a[i-1])+dp[i-1],ab(a[i]-a[i-2])+dp[i-2]);
        //cout<<i<<dp[i]<<endl;
    }
    cout<<dp[n-1]<<endl;
    return 0;


}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	for (int h = 0; h < 550; h++) {
		int n, a, b, ans = 0;
		cin >> n;
		int test[101] = { 0 };
		for (int h = 0; h <= n; h++) {
			cin >> a;
			test[h] = a;
		}
		for (int h = 0; h <= n; h++) {
			int uiop[101] = { 0 }; int b = 0;
			for (int i = 0; i <= n; i++) {
				if (h != i) {
					uiop[b] = test[i]; b++;
				}
			}
			for (int i = 1; i < n - 1; i++) {
				if (uiop[i] - uiop[i - 1] == uiop[i + 1] - uiop[i]) {
					ans++;
				}
			}
			if (ans == n - 2) {
				cout << test[h] << endl;
				h = n;
			}
			ans = 0;
		}
	}
}


Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//-------------------------------------------------------
long A[200000]; 
long Left[200001];
long Right[200001];
int R[200001];
int restL[200000];
int restR[200000];
void Calc(){
	int N = rei();
	for(int i=0;i<N;i++){
		A[i] = rel();
	}
	restL[0] = 100000000;
	stack<int> sp;
	sp.push(0);
	for(int i=1;i<N;i++){
		Left[i] = Left[i-1];
		if(A[i] > A[i-1]){
			long x = A[i-1];
			int c = 0;
			while(A[i] > x){
				c++;
				x *= 4;
			}
			while(c--){
				while(restL[sp.top()] == 0){
					sp.pop();
				}
				int p = sp.top();
				Left[i] += i-sp.top();
				restL[sp.top()]--;
			}
		}
		else{
			long x = A[i];
			int c = 0;
			while(x*4 <= A[i-1]){
				c++;
				x *= 4;
			}
			restL[i] = c;
			sp.push(i);
		}
	}
	restR[N-1] = 100000000;
	while(!sp.empty()){
		sp.pop();
	}
	sp.push(N-1);
	for(int i=N-2;i>=0;i--){
		Right[i] = Right[i+1];
		if(A[i] > A[i+1]){
			long x = A[i+1];
			int c = 0;
			while(A[i] > x){
				c++;
				x *= 4;
			}
			Right[i] = Right[i+1];
			while(c--){
				while(restR[sp.top()] == 0){
					sp.pop();
				}
				int p = sp.top();
				Right[i] += sp.top()-i;
				restR[sp.top()]--;
			}
		}
		else{
			long x = A[i];
			int c = 0;
			while(x*4 <= A[i+1]){
				c++;
				x *= 4;
			}
			restR[i] = c;
			sp.push(i);
		}
	}
	long ans = min(Left[N-1]*2+N,Right[0]*2);
	for(int i=1;i<N;i++){
		ans = min(Left[i-1]*2+i+Right[i]*2,ans);
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
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;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    int X[N];
    double s;s=0;
    REP(i,N){
        cin>>X[i];
        s+=X[i];
    }
    int c;
    c=(int)(s/N+0.5);
    int ans;ans=0;
    REP(i,N){
        ans+=pow(X[i]-c,2);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    int H[N + 1], A[M + 1], B[M + 1];
    vector<int> R[N + 1];

    for (int i = 1; i <= N; i++) {
        cin >> H[i];
    }

    for (int i = 1; i <= M; i++) {
        cin >> A[i] >> B[i];
    }

    for (int i = 1; i <= M; i++) {
        R[A[i]].push_back(B[i]);
        R[B[i]].push_back(A[i]);
    }

    int G = 0;
    for (int i = 1; i <= N; i++) {
        G += 1;
        for (int j = 0; j < R[i].size(); j++) {
            if (H[i] <= H[R[i][j]]) {
                G -= 1;
                break;
            }
        }
    }

    cout << G;
    return 0;
}

Measured memory_bytes: 9904
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef unsigned long long  ull;
typedef vector<int> vi;

struct pp{ll x,y;};

const int base = 1000*1000*1000;
const int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
const int inf = (int)1e9;
const int mod = 1e9+7;
ll gcd (ll a, ll b) {
        while (b) {
            a %= b;
            swap (a, b);
        }
        return a;
}

/*
void quickSort(int left, int right) {
      int i = left, j = right;
      pp tmp;
      int pivot = a[(left + right) / 2].x;
      while (i <= j) {
            while (a[i].x < pivot)
                  i++;
            while (a[j].x > pivot)
                  j--;
            if (i <= j) {
                 swap(a[i],a[j]);
                  i++,j--;
            }
      };
    if (left < j)
            quickSort(left, j);
      if (i < right)
            quickSort(i, right);
}*/
ll binpow (ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a,res %= mod;
		a *= a,a %= mod;
		n >>= 1;
	}
	return res;
}
const int MaxN = 1e5 + 17;
ll a[111111],n,sum;
int main(){
    cin>>n;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    if(sum%(n*(n+1)/2)){
        cout<<"NO";
        return 0;
    }
    ll x=sum/(n*(n+1)/2),cnt=0;
    for(ll i=0;i<n;i++)if(a[i]<x){
        cout<<"NO";
        return 0;
    }
    for(ll i=1;i<=n;i++){
        ll b=a[i%n]-a[i-1];
        if(abs(b+(n-1)*x)%n||b+(n-1)*x<0){
            cout<<"NO";
            return 0;
        }
        else cnt+=x-(b+(n-1)*x)/n;
    }
    cout<<"YES";

    return 0;
}


Measured memory_bytes: 1024
// Problem : E - Colorful Blocks
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

const int MOD = 998244353;

int mul(int a, int b) {
    return (long long) a * b % MOD;
}

int inv(int a) {
    int b = MOD - 2, ret = 1;
    for (; b>0; b/=2) {
        if (b % 2) ret = mul(ret, a);
        a = mul(a, a);
    }
    return ret;
}

int fact[200001], facti[200001], power[200001];

int choose(int n, int k) {
    return mul(fact[n], mul(facti[k], facti[n-k]));
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    int n, m, k;
    cin >> n >> m >> k;
    
    fact[0] = facti[0] = power[0] = 1;
    for (int i=1; i<=n; i++) {
        fact[i] = mul(fact[i-1], i);
        facti[i] = inv(fact[i]);
        power[i] = mul(power[i-1], m-1);
    }
    
    int ret = 0;
    for (int i=0; i<=k; i++) {
        ret += mul(mul(choose(n-1, i), m), power[n-i-1]);
        if (ret >= MOD)
            ret -= MOD;
    }
    
    cout << ret << "\n";

    return 0;
}


Measured memory_bytes: 5944
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

n = inn()
p = inl()
sum = 0
for i in range(n-2):
    a = p[i]
    b = p[i+1]
    c = p[i+2]
    if a<b and c>=b or c<b and a>=b:
        sum += 1
print(sum)


Measured memory_bytes: 38256