akhauriyash/Code-Regression huggingface dataset:
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

use std::cmp;

fn main() {
    input!(n: usize, s: chars);
    let mut ok = vec![false; n];
    let mut left = vec![0; n];
    let mut right = vec![0; n];
    for i in 1..(n - 1) {
        if s[i - 1] == '1' && s[i] == '0' && s[i + 1] == '1' {
            ok[i] = true;

            let mut cur = i - 1;
            while cur > 0 && s[cur - 1] == '1' {
                left[i] += 1;
                cur -= 1;
            }

            let mut cur = i + 1;
            while cur + 1 < n && s[cur + 1] == '1' {
                right[i] += 1;
                cur += 1;
            }
        }
    }

    let mut dp = vec![0; n + 1];
    for i in 0..n {
        dp[i + 1] = cmp::max(dp[i + 1], dp[i]);
        if !ok[i] {
            continue;
        }
        dp[i + 2] = cmp::max(dp[i + 2], dp[i - 1] + 1);
        dp[i + 2] = cmp::max(dp[i + 2], dp[i - 1 - left[i]] + 1 + left[i]);
        dp[i + 2 + right[i]] = cmp::max(dp[i + 2 + right[i]], dp[i - 1] + 1 + right[i]);
        if left[i] > 0 {
            dp[i + 2] = cmp::max(dp[i + 2], dp[i - 1 - (left[i] - 1)] + 1 + (left[i] - 1));
        }
        if right[i] > 0 {
            dp[i + 2 + (right[i] - 1)] =
                cmp::max(dp[i + 2 + (right[i] - 1)], dp[i - 1] + 1 + (right[i] - 1));
        }
    }
    println!("{}", dp[n]);
}


Measured memory_bytes: 19704
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>

int main() {

    char c1[4];
    char c2[4];
    
    scanf("%s %s", c1,c2);
    
    
    if(c1[0]==c2[2] && c1[2]==c2[0] && c1[1]==c2[1]){
        puts("YES");
    }else {
        puts("NO");
    }


    return 0;

}


Measured memory_bytes: 128
H, W, K = map(int,input().split())
c = []
for i in range(H):
    c.append(list(input()))
ans = 0
for maskR in range(1<<H):
    for maskC in range(1<<W):
        black = 0
        for i in range(H):
            for j in range(W):
                if ((maskR >> i) & 1) == 1 and ((maskC >> j) & 1) == 1 and c[i][j] == '#': black+=1
        if black == K: ans+=1
print(ans)

Measured memory_bytes: 9116
// AOJ Volume 1 Problem 0100

#include <stdio.h>
#include <string.h>

typedef struct {
	int no;
	long long sales;
} DATA;


int main(void)
{
	DATA sale[4000];
	int i, j;
	int n;
	int no, price, quantity;
	int data_no;
	int flag;

	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		
		memset(sale, 0, sizeof(sale));
		data_no = 0;

		for (i = 0; i < n; i++){
			scanf("%d%d%d", &no, &price, &quantity);
			
			for (j = 0; j < data_no; j++){
				if (sale[j].no == no){
					break;
				}
			}
			if (j == data_no){
				sale[j].no = no;
				sale[j].sales = 0;
				data_no++;
			}
			
			if (sale[j].sales < 1000000){
				sale[j].sales += ((long long)price * quantity);
			}
//			printf("<%d-%d %d>",j,sale[j].no,sale[j].sales);
		}
		
		flag = 0;
		for (i = 0; i < data_no; i++){
			if (sale[i].sales >= 1000000){
				printf("%d\n", sale[i].no);
				flag = 1;
			}
		}
		if (flag == 0){
			printf("NA\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first > b.first;
        
    }else{
        return a.second < b.second;
    }
}

bool compareg(Pi a, Pi b) {
    if(a.second != b.second){
        return a.second > b.second;
        
    }else{
        return a.first > b.first;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};



int main() {
    char b;
  	char ans;
	cin>>b;
 	if(b == 'A'){
		ans = 'T';
    }else if(b == 'C'){
		ans = 'G';
    }else if(b == 'G'){
		ans = 'C';
    }else {
		ans = 'A';
    }
  
  
  	cout<<ans<<endl;
    



    return 0;
    

}


Measured memory_bytes: 3588
s = list(input())
t = list(input())
ns=len(s)
nt=len(t)
dp=[[0]*(nt+1) for _ in range(ns+1)]
for i in range(ns):
    for j in range(nt):
        if s[i]==t[j]:
            dp[i+1][j+1]=max(dp[i+1][j+1], dp[i][j]+1)
        else:
            dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j])
ans=[]
i,j=ns,nt
while i!=0 and j!=0:
    if dp[i][j]==dp[i-1][j]:
        i-=1
    elif dp[i][j]==dp[i][j-1]:
        j-=1
    elif dp[i][j]==dp[i-1][j-1]+1:
        ans=[s[i-1]]+ans
        i-=1
        j-=1
print(''.join(ans))

Measured memory_bytes: 112732
import java.util.*;
public class Main  {
   public static void main(String[] args)  {
      Scanner sc = new Scanner(System.in);
      
      long x = sc.nextLong();
      
      long a = 100;
      long count = 0;
      
      while (a < x) {
         a = a + a * 1 / 100;
         count++;
      }
      
      System.out.println(count);
   }
}

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

#define MAX 100000

int N, x = -1 * INT_MAX, ans = 0;
struct bridge{
    int a, b;
    bridge(){}
    bridge(int a, int b): a(a), b(b){}
    bool operator < (const bridge &B) const{
        return b < B.b;
    }
};
bridge E[MAX];

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        int a, b;
        cin >> a >> b;
        E[i] = bridge(a - b, a + b);
    }
    sort(E, E + N);
    for(int i = 0; i < N; i++){
        if(E[i].a <= x) continue;
        ans++;
        x = E[i].b - 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	ll x;
	ll ans = 0;

	cin >> x;

	ans += (x / 11) * 2;

	x %= 11;

	if (x >= 7) ans += 2;
	else if (x >= 1) ans++;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
int n, m;
ll a[maxx];
ll ans;

struct PP {
	int b;
	ll c;
} p[maxx];

bool cmp(PP x, PP y) { return x.c > y.c; }

int main() {
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);
	for(int i = 1; i <= m; i++) scanf("%d %lld", &p[i].b, &p[i].c);
	sort(a + 1, a + n + 1);
	sort(p + 1, p + m + 1, cmp);
	int t = 1;
	for(int i = 1; i <= n; i++) {
		if(!p[t].b) t++;
		if(a[i] < p[t].c && p[t].b) {
			p[t].b--;
			ans += p[t].c;
		}
		else ans += a[i];
	}
	printf("%lld\n", ans);
	return 0;
}

/*
10 3
1 8 5 7 100 4 52 33 13 5
3 10
4 30
1 4

1 4 5 5 7 8 13 33 52 100
30 30 30 30 10 10 13 33 52 100 = 338
*/

Measured memory_bytes: 2560
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b){return b ? gcd(b, a%b) : a;}


int main(){
   int n;
   string s;
   cin >> n >> s;
   vector<int> a(n);
   for(int i = 0; i < n; i++){
      if(s[i] == 'R') a[i] = 0;
      if(s[i] == 'G') a[i] = 1;
      if(s[i] == 'B') a[i] = 2;
   }
   vector<ll> cnt(3);
   for(int i = 0; i < n; i++) cnt[a[i]]++;
   ll ans = 1;
   for(int i = 0; i < 3; i++) ans *= cnt[i]; //(r,g,b)のパターン数

   for(int i = 0; i < n; i++){
      for(int j = i+1; j < n; j++){
         int k = j+(j-i);
         if(k < n){
            if(a[i] == a[j]) continue; //1つ目の条件は満たしているので考えない
            if(a[i] == a[k]) continue;
            if(a[j] == a[k]) continue;
            ans--;
         }
      }
   }
   cout << ans << endl;
   return 0;
}
 

Measured memory_bytes: 3632
t=gets.chomp.chars
q_cnt=t.count('?')
#pts=['P','D'].repeated_permutation(q_cnt-1).to_a
ans=0
res = ""
tmp = t.map do |j|
        if j=='?'
          'D'
        else
          j
        end
end
cmp = tmp.count('D')+tmp.count('PD')
if ans < cmp
  ans = cmp
  res = tmp.join
end

=begin
pts.each do |i|
  tmp = t.map do |j|
          if j=='?'
            i.shift
          else
            j
          end
  end
  cmp = tmp.count('D')+tmp.count('PD')
  if ans < cmp
    ans = cmp
    res = tmp.join
  end
end
=end
puts res

Measured memory_bytes: 38380
#include <bits/stdc++.h>
using namespace std;
#define rep(i,k,n) for(int i = k; i < n; i++)  
#define repp(i,k,n) for(int i = k; i <= n; i++) 
#define per(i,k,n) for(int i = k; i >= n; i--)

#define int long long
#define all(a) a.begin(),a.end()       

#define pb push_back
typedef long long ll; 
typedef pair<int, int> ii;
typedef pair<int,ii > iii; 
typedef vector<ii> vii;
typedef vector<char> vchar;
typedef vector<int> vi;
#define ff first
#define ss second

#define mem(a, b) memset(a, b, sizeof(a));
#define mem0(a) memset(a, 0, sizeof(a));

#define INF 1000000000
//#define mod 998244353
#define mod 1000000007
#define endl "\n"


   //=\/=\/=\/=\/=\/=\/=\/=\/=\/=\        Jai Hind Dosto        /=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\\
  //=\/=\/=\/=\                    ̿̿ ̿̿ ̿̿ ̿'̿'\̵͇̿̿\з= ( ▀ ͜͞ʖ▀) =ε/̵͇̿̿/’̿’̿ ̿ ̿̿ ̿̿ ̿̿                             /=\/=\/=\/=\\
 //=\/=\/=\/=\                                                                               /=\/=\/=\/=\\
//=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\\



int modPow(int a, int b);      

                
void solve(){
    int n;
    cin >> n;
    int a[n];
    rep(i,0,n)cin >> a[i];
    sort(a,a+n);
   
   set<int> x;
   int maxo = 0;
   set <int> y;
    rep(i,0,n){
        y.insert(a[i]);
        if(i<n-1){
            if(a[i]==a[i+1])continue;
        }
        if(i>0){
            if(a[i]==a[i-1])continue;
        }
        maxo = max(maxo, a[i]);
        x.insert(a[i]);
    }

    
    int cnt=0;

    bool hehe[maxo+1]={0};

    for(auto i : y){
    
        int temp =2*i;
        while(temp <=maxo && hehe[i]==0){
            hehe[temp]=1;
            temp += i;
        }
    }
    cnt =0;
    for(auto i : x){
        if(hehe[i]==0)cnt++;
    }
    cout << cnt;
}






signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed;
    //cout <<setprecision(6);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
   // int test=1; cin >> test; while(test--)
    solve();
}

int modPow(int a, int b){
    if(b==0)return 1;
    if(b%2==0){
        int x = a*a;
        x%=mod;
        return modPow(x,b/2);
    }
    return (a*modPow(a,b-1))%mod;
}


 

Measured memory_bytes: 24916
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int ans = 0;
        for (int i = 0; i < n; i++) {
            long a = sc.nextLong();
            if (a % 2 == 0) {
                while (a % 2 == 0 && a >= 2) {
                    a /= 2;
                    ans++;
                }
            }
        }

        System.out.println(ans);        
    }
}


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

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

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

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

int main(){
	LL n,a[201010]={},s[201010]={};
	LL c=0;

	map<LL,LL> mp;
	cin>>n;
	FOR(i,0,n)cin>>a[i];
	if(n==1){
	}
	s[0]=a[0];
	FOR(i,1,n)s[i]+=s[i-1]+a[i];
	FORD(i,n,0)mp[s[i]]++;
	mp[0]++;
	for(auto x:mp){
		//cout<<x.ST<<endl;
		LL t=x.ND*1LL;
		c+=t*(t-1)/2;
	}
	cout<<c<<endl;

    return 0;
}


Measured memory_bytes: 15872
h,w=map(int,input().split())
s=[list(input())for i in range(h)]
dx=[1,-1,0,0]
dy=[0,0,1,-1]
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            judge=False
            for k in range(4):
                x=i+dx[k]
                y=j+dy[k]
                if 0<=x and x<h and 0<=y and y<w and s[x][y]=="#":
                    judge=True
            if judge==False:
                print("No")
                exit()
print("Yes")
                    
        


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
llo mm[19][19];
llo mm2[19][19];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	llo n;
	cin>>n;
	llo ans=0;
	for(llo i=0;i<n;i++){
		string s;
		cin>>s;
		string t="";
		string tt="";
		llo cot=0;
		llo st=0;
		for(llo j=0;j<s.size();j++){
			if(s[j]=='.'){
				st=1;
				continue;
			}

			if(st){
				cot+=1;
				tt+=s[j];
			}
			else{
				t+=s[j];
			}
		}
		
		for(llo j=cot;j<9;j++){
			tt+="0";
		}
		llo x=stoi(t);
		llo y=stoi(tt);
		x=x*((llo)1e9)+y;
	//	cout<<x<<endl;
		llo cur=x;
		cot=0;
		while(cur%2==0){
			cur/=2;
			cot+=1;
		}
		cur=x;
		llo cot2=0;
		while(cur%5==0){
			cur/=5;
			cot2+=1;
		}
		cot2=min(cot2,(llo)18);
		cot=min(cot,(llo)18);
		mm[cot][cot2]++;
		if(cot>=9 and cot2>=9){
			ans-=1;
		}
	//	cout<<cot<<":"<<cot2<<endl;
	}
	
	/*for(llo j=9;j<=18;j++){
		for(llo k=9;k<=18;k++){
			if(mm[j][k]>1){
				ans+=(mm[j][k]*(mm[j][k]-1))/2;
			}
		}
	}*/
	for(llo j=0;j<=18;j++){
		for(llo i=0;i<=18;i++){
			for(llo k=0;k<=j;k++){
				for(llo l=0;l<=i;l++){
					mm2[k][l]+=mm[j][i];
				}
			}
		}
	}
	for(llo j=0;j<=18;j++){
		for(llo i=0;i<=18;i++){
			llo k=18-j;
			llo l=18-i;
			ans+=mm[j][i]*mm2[k][l];
		/*	if(k<=j and i<=l){
				ans-=mm[j][i]*mm[j][i];
				ans+=(mm[j][i]*(mm[j][i]-1));
			}*/
			/*if(mm[j][i]>0){
				cout<<ans<<endl;
				cout<<j<<",,,"<<i<<endl;
			}*/
		}
	}
	cout<<ans/2<<endl;







	return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
	#ifndef DavidLaptop
		#ifdef FILIN
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s;
	for(int i=0;i<s.size();i++)
		if(s[i]!='?') cout<<s[i];
		else cout<<"D";
	cout<<endl;
	return 0;
}



Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(x,y) for(ll i=x;i<y;i++)
#define vll vector<ll>
#define sll set<ll>
#define pb push_back
#define in insert
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define tc ll t;cin>>t;while(t--)
#define rev(x) reverse(all(x))
#define low_str(x) transform(all(x),x.begin(),::tolower)
#define up_str(x) transform(all(x),x.begin(),::toupper)
int main()
{
ll n;
cin>>n;
ll x=1;
ll ans=0;
rep(0,n)
{
    ll y;
    cin>>y;
    if(y==x)
        x++;
    else
        ans++;
}
if(x==1)
    cout<<-1;
else
cout<<ans;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
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; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b;
	cin >> a >> b;
	cout << 6 - a - b << endl;
}




Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n >> s;
  rep(i, n - 2) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 256
import math

def nCr(n,r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r) )


N,P = map(int,input().split())

A = list(map(int,input().split()))

E = 0
O = 0

for i in A:

    if i % 2 == 0:
        E += 1
    else:
        O += 1

ans = 1

ans *= 2**E


if P == 0:

    ans2 = 1

    for i in range(O // 2):

        i += 1
        i *= 2

        ans2 += nCr(O,i)

else:

    ans2 = 0

    for i in range((O+1) // 2):

        i *= 2
        i += 1

        ans2 += nCr(O,i)

print (ans * ans2)


Measured memory_bytes: 38384
#include <iostream>

using namespace std;

int main() {
    int n;
    int r[200000];
    int max;
    int min;

    cin>>n;
    cin>>min;
    for(int i = 0; i < n-1; i++){
        cin>>r[i];
    }
    for(int i = 0; i < n-1; i++){
        int tmp=r[i]-min;
        if(i == 0 || max<tmp){
            max=tmp;
        }
        if(r[i]<min){
            min=r[i];
        }
    }
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 1940
import java.util.Arrays;

public class Main {

  private static void solve() {
    int n = ni();
    int[] a = na(n);

    long[][][] dp = new long[n + 1][4][2];
    for (long[][] v : dp)
      for (long[] u : v)
        Arrays.fill(u, Long.MIN_VALUE / 100);
    dp[0][0][0] = 0;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 3; j++) {
        // take
        dp[i + 1][j][1] = Math.max(dp[i + 1][j][1], dp[i][j][0] + a[i]);
        // after skip
        dp[i + 1][j + 1][0] = Math.max(dp[i + 1][j][0], dp[i][j][0]);
        // first skip
        dp[i + 1][j][0] = Math.max(dp[i + 1][j][0], dp[i][j][1]);
      }
    }

    int m = n % 2 == 0 ? 1 : 2;
    long ret = Long.MIN_VALUE;
    ret = Math.max(ret, dp[n][m][1]);
    ret = Math.max(ret, dp[n][m - 1][0]);
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 89040
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int a;
  string s;
  cin >> a >> s;
  if(a>=3200) cout << s << endl;
  else cout << "red" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    int n;
    int ans=0;
    cin >>n;
    set<int>a;
    set<int>black;
    black.insert(0);
    int bef;
    rep(i,n){
        cin>>bef;
        if(a.find(bef)==a.end()){
            a.insert(bef);
        }else{
            black.insert(bef);
        }
    }
    int now=1;
    vector<bool>dis(3+(1e6),true);
    repi(itr,a){
        if(dis[*itr]){
            now=(*itr)*2;
            while(now <=1e6){
                dis[now]=false;
                now+=*itr;
            }
        }
    }
    repi(itr,black){
        dis[*itr]=false;
    }
    repi(itr,a){
        if(dis[*itr]){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 13092
#include<iostream>
#include<algorithm>
#define MAX 100
#define INF (1 << 30)
using namespace std;

int n, p[103], m[102][102];

int matrixChainMultiplication(void);

int main() {
	int i;

	cin >> n;
	for (i = 1; i <= n; i++) {
		cin >> p[i - 1] >> p[i];
	}

	cout << matrixChainMultiplication() << endl;

	return 0;
}

int matrixChainMultiplication(void) {
	int i, j, k;
	for (i = 1; i <= n; i++)m[i][i] = 0;
	for (j = 2; j <= n; j++) {
		for (i = j - 1; i >= 1; i--) {
			m[i][j] = INF;
			for (k = i; k <= j - 1; k++) {
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	return m[1][n];
}

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

using namespace std;

int main(){
	int N, X, T;
	cin >> N >> X >> T;
	int time = 0;
	while(N > X) {
		N -= X;
		time += T;
	}
	cout << time + T<< "\n";
	return 0;
}

Measured memory_bytes: 3632
#include <vector>
#include <sstream>
#include <algorithm>
#include <fstream>
#include <list>
#include <map>
#include <istream>
#include <bitset>
#include <sstream>
#include <unordered_map>
#include <stack>
#include <set>
#include <cmath>
#include <random>
#include <iostream>
#include <bitset>
#include <iomanip>
#include <queue>
#include <string>

#define int long
#define endl "\n"
#define all(x) x.begin(),x.end()
#define rr return 0
#define xx first
#define yy second
#define pii pair<int,int>

using namespace std;

typedef long long ll;
typedef long double ld;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s, t;
    cin >> s >> t;
    int p = 0;
    for(int i = 0; i < s.size();i++){
        if(s[i] == t[i]){
            p++;
        }
    }
    cout << p;
    rr;
}


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

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type, n,m,d)vector<vector<Type>> vv(n, vector<Type>(m, d));

using namespace std;
using ll = long long;

const ll mod = 1e9 + 7;




int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);

	string s; cin >> s;
	int S = s.length();
	rep(i, S) {
		cout << "x" << flush;
	}
	cout << endl;


	return 0;
}


Measured memory_bytes: 3600
n, m = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]

cumsum = [0] * n
for i in range(n):
  if i == 0:
    cumsum[i] = a[i] % m
  else:
    cumsum[i] = (cumsum[i-1] + a[i]) % m

cumsum = sorted(cumsum)
variation = {}

for i in cumsum:
  if i in variation:
    variation[i] += 1
  else:
    variation[i] = 1

ans = 0
for key in variation:
  if key == 0:
    ans += variation[key]
  ans += variation[key] * (variation[key]-1) // 2
  
print(ans)

Measured memory_bytes: 15564
# -*- coding: utf-8 -*-
N = int(input())
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'

ans = ""
while(N > 0):
    N, mod = divmod(N, 26)
    if mod == 0:
        N -= 1
        ans = "z" + ans
    else:
        ans = ascii_lowercase[mod - 1] + ans

print(ans)

Measured memory_bytes: 9124
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
  int n;
  cin >> n;
  vector<pi> p(n);
  rep(i, 0, n) cin >> p[i].first >> p[i].second;
  sort(rall(p));
  cout << p[0].first + p[0].second << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    int A,B,X;
    cin >> A >> B >> X;
    if(A<=X&&X<=A+B){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 3684
# C - Energy Drink Collector
import numpy as np
N, M = map(int, input().split())
AB = np.zeros((N, 2))
for i in range(N):
    AB[i, :] = np.array(list(map(int, input().split())))

AB_sorted = AB[np.argsort(AB[:, 0]), :]

total_drink = 0
total_cash  = 0
for i in range(N):
    if(total_drink + AB_sorted[i, 1] >= M):
        total_cash += (M-total_drink) * AB_sorted[i, 0]
        break
    else:
        total_cash += AB_sorted[i, 1] * AB_sorted[i, 0]
        total_drink += AB_sorted[i, 1]

print(int(total_cash))

Measured memory_bytes: 18396
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int 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();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=105;
int a[maxn],n;
int main(){
	read(n);rep(i,1,n<<1)read(a[i]);sort(a+1,a+1+n*2);
	int res=0;
	for(int i=1;i<=n*2;i+=2)res+=a[i];
	cout<<res;
	return 0;
}


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

namespace ABC149D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NK = Console.ReadLine().Split(' ');
            string[] RSP = Console.ReadLine().Split(' ');
            string T = Console.ReadLine();
            int N = int.Parse(NK[0]);
            int K = int.Parse(NK[1]);
            int R = int.Parse(RSP[0]);
            int S = int.Parse(RSP[1]);
            int P = int.Parse(RSP[2]);
            string[] group = new string[K];
            for(int i = 0; i < N; i++)
            {
                int g = i % K;
                group[g] += T[i];
            }
            //Console.WriteLine(group[0]);
            long ans = 0;
            for(int i = 0; i < K; i++)
            {
                int l = group[i].Length;
                long[,] dp = new long[l + 1, 3];
                for(int j = 1; j < l + 1; j++)
                {
                    int[] tokuten = kati(group[i][j-1].ToString(), R, S, P);
                    //Console.WriteLine(tokuten[1]);
                    dp[j, 0] = Math.Max(dp[j - 1, 1], dp[j - 1, 2]) + tokuten[0];
                    dp[j, 1] = Math.Max(dp[j - 1, 0], dp[j - 1, 2]) + tokuten[1];
                    dp[j, 2] = Math.Max(dp[j - 1, 0], dp[j - 1, 1]) + tokuten[2];
                }
                ans += Math.Max(Math.Max(dp[l, 0], dp[l, 1]), dp[l, 2]);
            }
            Console.WriteLine(ans);
        }




        static int[] kati(string a, int R, int S, int P)
        {
            int[] rsp = new int[3];
            if (a == "r")
            {
                rsp[2] = P;
                return (rsp);
            }
            else if (a == "s")
            {
                rsp[0] = R;
                return (rsp);
            }
            else
            {
                rsp[1] = S;
                return (rsp);
            }
        }
    }
}


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

int main(){
  int n,corrent_judge=0,max=0;
  cin >> n;
  vector<vector<int>> judge(n,vector<int>(2));
  for(int i=0;i<n;i++){
	for(int j=0;j<2;j++){
      cin >> judge.at(i).at(j);
    }
  }
  for(int i=0;i<n;i++){
    if(judge.at(i).at(0)==judge.at(i).at(1))
      corrent_judge++;
    else
      corrent_judge=0;
    if(corrent_judge==3)
      max=3;
  }
  if(max==3)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 998244353;
const long double EPS = 1e-8;

namespace mod {
    long long pow(long long a, long long x, long long p) {
        long long res = 1;
        while(x > 0) {
            if( x % 2 != 0) {
                res = (res * a) % p;
            }
            a = (a * a) % p;
            x /= 2;
        }
        return res;
    }

    long long inverse(long long a, long long p) {
        //calculates the modular multiplicative of a mod m.
        //(assuming p is prime).
        return pow(a, p-2, p);
    }

    long long factorial(long long a, long long p) {
        long long fact = 1;
        for (long long i=2; i<=a; i++) {
            fact *= i;
            fact %= p;
        }
        return fact;
    }
}

namespace mod {
    struct combination {
        combination(long long max_n, long long p) : _mod(p) {
            factorials_ = std::vector<long long>(max_n+1, 1);
            inverse_factorials_ = std::vector<long long>(max_n+1, 1);
            for (long long i=1; i<max_n+1; i++) {
                factorials_[i] = factorials_[i-1] * i;
                factorials_[i] %= p;
            }
            inverse_factorials_[max_n] = mod::pow(factorials_[max_n],  p-2, p);
            for (long long i=max_n-1; i>=1; i--) {
                inverse_factorials_[i] = inverse_factorials_[i+1] * (i+1);
                inverse_factorials_[i] %= p;
            }
        }

        long long operator()(long long n, long long k) {
            long long result = factorials_[n];
            result *= inverse_factorials_[k];
            result %= _mod;
            result *= inverse_factorials_[n-k];
            result %= _mod;
            return result;
        }

    private:
        std::vector<long long> factorials_, inverse_factorials_;
        long long _mod;
    };
}

void solve(long long N, long long M, long long K){
    if (M == 1) {
        if (N-1 <= K) cout << 1 << endl;
        else cout << 0 << endl;
        return;
    }
    mod::combination comb(N+1, MOD);

    ll answer = 0;
    rrep(i,0,N) {
        if (N - i - 1 > K) break;
        ll cnt = 1;
        cnt *= comb(N-1, i);
        cnt *= M;
        cnt %= MOD;
        cnt *= mod::pow(M-1, i, MOD);
        cnt %= MOD;
        answer += cnt;
        answer %= MOD;
    }
    cout << answer << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long K;
    scanf("%lld",&K);
    solve(N, M, K);
    return 0;
}


Measured memory_bytes: 6452
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 109;
ll n,a,b,i;
ll w[3],c[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>a>>b;
    rep(i,1,n + 1) cin>>c[i];
    sort(c + 1,c + n + 1);
    i = 1;
    while(i <= n && c[i] <= a){
        w[0] += 1;
        i += 1;
    }
    while(i <= n && c[i] <= b){
        w[1] += 1;
        i += 1;
    }
    while(i <= n){
        w[2] += 1;
        i += 1;
    }
    cout<<min(w[0],min(w[1],w[2]));
    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

const int INF = 1010101010;

inline LL conv(LL x){ return x & 1 ? 1LL : min(x, 2LL); }

void mainmain(){
	int n;
	scanf("%d", &n);
	vector<LL> as(n + 2);
	for(int i = 1; i <= n; ++i){
		scanf("%lld", &as[i]);
	}
	vector<LL> acc(n + 2);
	partial_sum(ALL(as), acc.begin());
	vector<LL> dp1(n + 2), dp2(n + 2), dp3(n + 2);
	LL t = 0;
	for(int i = 1; i <= n; ++i){
		t += 2 - conv(as[i]);
		chmin(t, acc[i]);
		dp1[i] = t;
	}
	t = 0;
	for(int i = n; i > 0; --i){
		t += 2 - conv(as[i]);
		chmin(t, acc[n] - acc[i - 1]);
		dp2[i] = t;
	}
	t = 0;
	for(int i = n; i > 0; --i){
		t += abs(1 - conv(as[i]));
		chmin(t, dp2[i]);
		dp3[i] = t;
	}

	LL ans = 1LL << 60;
	t = 0;
	for(int i = 0; i <= n; ++i){
		chmin(ans, dp1[i] + dp3[i + 1]);
	}
	printf("%lld\n", ans);
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 8064
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int main(void){
  int i,j;
  int ii[200001];
  int len,flg;
  scanf("%d",&len);
  for(i=0;i<len;i++){
    scanf("%d",&ii[i]);
  }
qsort(ii, len, sizeof(int), compare_int);
//  for(i=0;i<len;i++){
//		printf("i%d\n",ii[i]);
//  }
  flg =0;
  for(i=0;i<len;i++){
      if(ii[i] == ii[i+1]){
		flg = 1;
      }

  }
	if(flg == 1){
		printf("NO");
    }
  	else{
		printf("YES");
    }
  return 0;
}

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

struct Node {
  int key;
  struct Node *rig, *lef, *parent;
};

struct Node *root,*NIL;

void insert(int);
void inorder(struct Node *);
void preorder(struct Node *);

int main(){
  int n,i,x;
  char c[10];
  char in[10]="insert";
  char pri[10]="print";

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",c);

    if(strcmp(c,in) == 0) {
      scanf("%d",&x);
      insert(x);
    } else if(strcmp(c,pri) == 0) {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}

void insert(int k){
  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;

  z = (struct Node *)malloc(sizeof(struct Node));
  z->key = k;
  z->lef = NIL;
  z->rig = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->lef;
    }else {
      x = x->rig;
    }
  }

  z->parent = y;
  if(y == NIL){
    root = z;
  }else {
    if(z->key < y->key){
      y->lef = z;
    }else{
      y->rig = z;
    }
  }
}

void inorder(struct Node *u){
  if(u == NIL) return;
  inorder(u->lef);
  printf(" %d",u->key);
  inorder(u->rig);
}

void preorder(struct Node *u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->lef);
  preorder(u->rig);
}



Measured memory_bytes: 25296
// AOJ 1541: Yu-kun Likes an Integer
// 2019.2.21 bal4u

#include <stdio.h>
#include <stdlib.h>

int n, m;
int c[10];

int check(int k)
{
	int cnt = n, sum = 0;
	while (k) {
		cnt--;
		sum += c[k % 10];
		if (sum > m) return 0;
		k /= 10;
	}
	if (cnt) {
		sum += c[0] * cnt;
		if (sum > m) return 0;
	}
	return 1;
}

int main()
{
	int i, max;
	char fmt[] = "%0xd\n";

	scanf("%d%d", &n, &m);
	for (i = 0; i < 10; i++) scanf("%d", c + i);
	max = 1; for (i = 0; i < n; i++) max *= 10;
	for (i = 0; i < max; i++) {
		if (check(i)) {
			fmt[2] = n + '0';
			printf(fmt, i);
			break;
		}
	}
	if (i == max) puts("NA");
	return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

int main(){
    ll a, b, c; cin >> a >> b >> c;

    ll tmp1 = c - a - b;
    ll tmp2 = (c - a - b) * (c - a - b) - 4 * a * b;

    if(tmp1 >= 0 && tmp2 > 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int main(){
string a;
cin >> a;
int fre[26];
memset(fre, 0, sizeof(fre));
for(int i = 0; i < a.length(); i++){
fre[a[i] - 'a']++;
}
bool ok = true;
for(int i= 0; i < 26; i++){
if(fre[i] % 2 != 0){
ok = false;
break;
}
}
if(ok){
 cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

struct elem{
    int i;
    int v;
};

int partition(
        struct elem* ary,
        int p, int r)
{
    int i =0;
    int j = 0;
    struct elem x, buf;
    x = ary[r];
    i = p;
    for (j = p; j < r; j++) {
        if (ary[j].v <= x.v) {
            buf = ary[j];
            ary[j] = ary[i];
            ary[i] = buf;
            i++;
        }
    }
    buf = x;
    ary[r] = ary[i];
    ary[i] = buf;
    return i;
}

void quick_arg_sort_impl(
        struct elem *ary,
        const int p,
        const int r
        )
{
    int q = 0;
    if (p < r) {
        q = partition(ary, p, r);
        quick_arg_sort_impl(ary, p, q -1);
        quick_arg_sort_impl(ary, q + 1, r);
    }
}

void quick_arg_sort(
        const int *ary,
        const  int ary_size,
        struct elem *sorted
        )
{
    int i = 0;
    for (i = 0; i < ary_size; i++) {
        sorted[i].i = i;
        sorted[i].v = ary[i];
    }
    /* TODO: ゼロ埋め処理*/
    quick_arg_sort_impl(sorted, 0, ary_size - 1);
}

int Y[100100];
struct elem A[100100];
char K[100100];
int main() {
    int i, n, k;
    int flag = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%s %d", K+i, Y+i);
    }
    quick_arg_sort(Y, n, A);
    for (i = 0; i < n; i++) {
        if ((A[i].v == A[i-1].v) && (A[i].i<A[i-1].i)) {
            flag = 1;
        }
    }

    if (flag) {
        printf("Not stable\n");
    }else{
        printf("Stable\n");
    }
    for (i = 0; i < n; i++) {
        printf("%c %d\n", K[A[i].i], A[i].v);
    }
    return 0;
}


Measured memory_bytes: 3008
#include<stdio.h>
int main(){
  int a,b,sum=0,flag=0;
  
  scanf("%d %d",&a,&b);
  
  while(flag<2){
  if(a>b){
    sum+=a;
    a--;
  }
  else if(a<b){
    sum+=b;
    b--;
  }
  else{
    sum+=a;
    a--;
  }
    
  flag++;
  }
  
  printf("%d",sum);
  
  return 0;
}

Measured memory_bytes: 128