akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

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

int d[MAX_N][MAX_N];
int e[MAX_N][MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    vs fd(h);
    int si,sj;
    vp vec;
    rep(i,h){
        cin >> fd[i];
        rep(j,w){
            if(fd[i][j] == '@'){
                si = i,sj = j;
            }else if(fd[i][j] == '$'){
                vec.pb(P(i,j));
            }
        }
    }
    rep(i,h){
        rep(j,w){
            d[i][j] = INF;
        }
    }
    queue<P> que;
    rep(i,len(vec)){
        que.push(P(vec[i]));
        d[vec[i].fi][vec[i].se] = 0;
    }
    while(!que.empty()){
        P p = que.front();
        que.pop();
        rep(i,4){
            int nx = p.fi+dx[i],ny = p.se+dy[i];
            if(0 <= nx && nx < h && 0 <= ny && ny < w && fd[nx][ny] != '#'){
                if(d[nx][ny] > d[p.fi][p.se]+1){
                    d[nx][ny] = d[p.fi][p.se]+1;
                    que.push(P(nx,ny));
                }
            }
        }
    }
    queue<P> q;
    q.push(P(si,sj));
    rep(i,h){
        rep(j,w){
            e[i][j] = INF;
        }
    }
    e[si][sj] = 0;
    while(!q.empty()){
        P p = q.front();
        q.pop();
        rep(i,4){
            int nx = p.fi+dx[i],ny = p.se+dy[i];
            if(0 <= nx && nx < h && 0 <= ny && ny < w && fd[nx][ny] != '#' && d[nx][ny] > e[p.fi][p.se]+1){
                if(e[nx][ny] > e[p.fi][p.se]+1){
                    if(fd[nx][ny] == '%'){
                        cout << "Yes\n";
                        return 0;
                    }
                    e[nx][ny] = e[p.fi][p.se]+1;
                    q.push(P(nx,ny));
                }
            }
        }
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 5516
import java.util.Scanner;

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

        char[] firstLine = scanner.next().toCharArray();
        char[] secondLine = scanner.next().toCharArray();

        if (firstLine[0] == secondLine[2] && firstLine[1] == secondLine[1] && firstLine[2] == secondLine[0]) {
            result = "YES";
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 23892
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int Q =sc.nextInt();
		int A[] = new int[Q];
		for(int i = 0; i < Q; i++) {
			A[i] = sc.nextInt() - 1;
		}
		
		int P[] = new int[N];
		Arrays.fill(P, K - Q);
		for(int i = 0; i < Q; i++) {
			P[A[i]]++;
		}
		for(int i = 0; i < N; i++) {
			if(P[i] > 0) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}


Measured memory_bytes: 73848
# -*- coding: utf-8 -*-

n = int(input())
W = [input() for _ in range(n)]
dic = {}
for word in W:
    if word not in dic:
        dic[word] = True
    else:
        print('No')
        exit()
for i in range(n-1):
    if W[i][-1] != W[i+1][0]:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
##############################

from fractions import gcd
N = int(input())
A = list(map(int, input().split()))

ans = A[0]
for i in range(1, N):
    ans = gcd(ans, A[i])

print(ans)



Measured memory_bytes: 16240
import java.util.Scanner;

public class Main {
  public static final int BIG_NUM = 2000000000;
  public static void main(String[] args) {
    Scanner scanInt = new Scanner(System.in);
    int N = scanInt.nextInt();
    int num, max = -BIG_NUM, min = BIG_NUM;
    for(int i = 0; i < N; i++){
      num = scanInt.nextInt();
      max = Math.max(max, num - min);
      min = Math.min(min, num);
    }

    System.out.println(max);
  }
}



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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }

ll n;
void solve() {
    cin >> n;

    if (n % 2 == 1) { cout << 0 << endn; return; }
    ll ans = 0;
    ll div = 10;
    while (n / div != 0) {
        ans += n / div;
        div *= 5;
    }

    cout << ans << endn;

}

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include<algorithm>
using namespace std;

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int countW[N];
  countW[-1]=0;
  int ans=N;
  for(int i=0;i<N;i++){
    countW[i]=countW[i-1];
    if(S[i]=='W'){
      countW[i]++;
    }
  }
  int iti=-1;
  for(int i=0;i<N;i++){
   if(countW[i-1]+(N-1-i)-(countW[N-1]-countW[i])<ans){
    ans=countW[i-1]+(N-i-1)-(countW[N-1]-countW[i]);
   }
  }
  cout << ans << endl;
  return 0;}

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

int gcd(int x,int y) {return y ? gcd(y,x%y) : x;}

int main()
{
    int n; cin >> n;
    vector<int> a(n); rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    vector<int> l(n), r(n);
    rep(i,n-1) l[i+1] = gcd(l[i],a[i]);
    for (int i = n-1; i >= 1; i--) r[i-1] = gcd(r[i],a[i]);
    int ans = 1;
    rep(i,n) ans = max(ans,gcd(l[i],r[i]));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
use std::str::FromStr;
use std::cmp::max;
use std::cmp::min;

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

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let v : Vec<i32> = get_vec();
    let w : i32 = v[0];
    let h : i32 = v[1];
    let n = v[2] as usize;

    let mut l : i32 = 0;
    let mut r : i32 = w;
    let mut u : i32 = h;
    let mut d : i32 = 0;
    for _i in 0..n {
        let v2 : Vec<i32> = get_vec();
        if v2[2] == 1 {
            l = max(l, v2[0]);
        }
        else if v2[2] == 2 {
            r = min(r, v2[0]);
        }
        else if v2[2] == 3 {
            d = max(d, v2[1]);
        }
        else if v2[2] == 4 {
            u = min(u, v2[1]);
        }
    }

    //println!("{} {} {} {}", u, d, r, l);
    if l >= r || u <= d {
        println!("{}", 0);
    }
    else {
        println!("{}", (u-d) * (r-l))
    }
}


Measured memory_bytes: 4352
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    ans=0
    for i in 1:n
        l,r=parseMap(split(readline()))
        ans+=r-l+1
    end
    println(ans)
end
main()

Measured memory_bytes: 152056
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

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); }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}

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

signed main(void)
{
  string a, b;
  cin >> a >> b;
  int c = stoi(a+b);
  int sq = (int)sqrt(c);
  if(sq*sq == c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define INF 10**9+7
using namespace std;
using Graph = vector<vector<long long> >;//Graph graph(ノードの数)で生成できる

bool check(long long a,long long b,long long c){
    return true;
}

long long dfs(long long n, vector<long long> &dp){
    if(n<0){
        return 0;
    }
    if(n-1==0 || n-2==0){
        return 0;
    }
    if(n-3==0){
        return 1;
    }
    if(dp[n]!=-1){
        return dp[n];
    }
    dp[n] = dfs(n-1, dp)%10007+dfs(n-2, dp)%10007+dfs(n-3, dp)%10007;

    return dp[n];
}

int main(){
    long long N;
    long long ans=0;
    string S;
    cin >> N;
    cin >> S;

    vector<long long> R(N, 0);
    vector<long long> G(N, 0);
    vector<long long> B(N, 0);
    vector<long long> R_num(N+1, 0);
    vector<long long> G_num(N+1, 0);
    vector<long long> B_num(N+1, 0);

    for(int i=0; i<N; i++){
        if(S.at(i)=='R'){
            R.at(i) = 1;
            continue;
        }
        if(S.at(i)=='G'){
            G.at(i) = 1;
            continue;
        }
        if(S.at(i)=='B'){
            B.at(i) = 1;
            continue;
        }
    }
    for(int i=0; i<N; i++){
        R_num.at(i+1) = R_num.at(i) + R.at(i);
        G_num.at(i+1) = G_num.at(i) + G.at(i);
        B_num.at(i+1) = B_num.at(i) + B.at(i);
 
    }
    for(int i=0; i<N-2; i++){
        for(int j=i+1; j<N-1; j++){
            if(S.at(i)==S.at(j)){
                continue;
            }
            if((S.at(i)=='R' && S.at(j)=='G') || (S.at(i)=='G' && S.at(j)=='R')){
                ans = ans + B_num.at(N)-B_num.at(j+1);
                if((j+j-i)<N && B.at(j+j-i)==1){
                    ans = ans - 1;
                }
            }
            if((S.at(i)=='R' && S.at(j)=='B') || (S.at(i)=='B' && S.at(j)=='R')){
                ans = ans + G_num.at(N)-G_num.at(j+1);
                if((j+j-i)<N && G.at(j+j-i)==1){
                    ans = ans - 1;
                }
            }
            if((S.at(i)=='B' && S.at(j)=='G') || (S.at(i)=='G' && S.at(j)=='B')){
                ans = ans + R_num.at(N)-R_num.at(j+1);
                if((j+j-i)<N && R.at(j+j-i)==1){
                    ans = ans - 1;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef vector<int> int_vec;

bool linear_search(const int_vec& v, int n) {
    for (int_vec::const_iterator it = v.begin(); it != v.end(); ++it) {
        if (*it == n) {
            return true;
        }
    }
    return false;
}

bool binary_search(int_vec::iterator begin, int_vec::iterator end, int n) {
    while (begin < end) {
        int_vec::iterator mid = begin + ((end - begin) / 2);
        if (*mid == n)
            return true;
        else if (n < *mid)
            end = mid;
        else
            begin = mid+1;
    }
    return false;
}

int main()
{
    int n;
    cin >> n;
    int_vec S;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        S.push_back(x);
    }

    int q;
    cin >> q;
    int_vec T;
    for (int j = 0; j < q; ++j) {
        int x;
        cin >> x;
        T.push_back(x);
    }

    int c = 0;
    for (int_vec::iterator it = T.begin(); it != T.end(); ++it) {
        if (binary_search(S.begin(), S.end(), *it))
            c++;
    }
    cout << c << endl;
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;
  string s;cin>>s;
  ll ans=0;
  ll L=0,R=0;
  for(int i=0;i<n-1;i++){
    if(s[i]=='R'&&s[i+1]=='R'){
      ans++;
    }else if(s[i]=='R'&&s[i+1]=='L')R++;
  }
  if(s.back()=='R')R++;
  for(int i=n-1;i>0;i--){
    if(s[i]=='L'&&s[i-1]=='L'){
      ans++;
    }else if(s[i]=='L'&&s[i-1]=='R')L++;
  }
  if(s[0]=='L')L++;
  if(R==L){
    if(k>=R)cout<<n-1<<endl;
    else cout<<ans+2*min(k,min(R,L))<<endl;
  }else{
    if(k>=min(R,L))cout<<n-1<<endl;
    else cout<<ans+2*min(k,min(R,L))<<endl;
  }
  //cout<<ans+2*min(k,min(R,L))<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  string s;
  cin >> s;
  char moji = s[s.size() - 1];
  mp[s] = 1;
  int flag = 1;
  for (int i = 1; i < n; i++) {
    cin >> s;
    if (s[0] != moji) flag = 0;
    auto itr = mp.find(s);
    if (itr != mp.end()) flag = 0;
    mp[s] = 1;
    moji = s[s.size() - 1];
  }
  if (flag) Yes;
  else No;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n,mi=1e9;
    cin>>n;
    int a;
    int num=0; 
    for(int i=0;i<n;i++){
        cin>>a;
        if(a<=mi)num++;
        mi=min(mi,a);
    }
    cout << num<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    private static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(final String[] args) throws IOException {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out, true);

        String s = in.nextLine();
        String t = in.nextLine();

        int answer = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != t.charAt(i)) {
                answer++;
            }
        }
        out.println(answer);
    }
}


Measured memory_bytes: 37192
let rec fix f x = f (fix f) x

let _ =
  Scanf.scanf "%d %d %d" @@ fun n u v ->
  let a = Array.init (n+1) (fun _ -> []) in
  for i = 1 to n-1 do
    Scanf.scanf " %d %d" @@ fun x y ->
      a.(x) <- y :: a.(x);
      a.(y) <- x :: a.(y);
  done;
  let rec mark arr u d =
    arr.(u) <- d;
    List.iter (fun v -> if arr.(v) > n then mark arr v (d+1)) a.(u)
  in
  let d1 =
    let arr = Array.make (n+1) (n+1) in
    mark arr u 0; arr
  and d2 =
    let arr = Array.make (n+1) (n+1) in
    mark arr v 0; arr
  in
  fix (fun f i v ->
    if i > n then v else
      let l1, l2 = d1.(i), d2.(i) in
      if l1 > l2 then f (i+1) v else f (i+1) (max v (l2-1))) 1 0
  |> Printf.printf "%d\n"
        



Measured memory_bytes: 19584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int r;
  cin>>r;
  double pi=3.1415;
  cout<<2*r*pi<<endl;
}


Measured memory_bytes: 3784
#include<iostream>
#include<stdio.h>

using namespace std;

int main(){
	int x, y;
	for (;;){
		cin >> x >> y;
		if (x == 0 && y == 0){
			break;
		}
		if (y < x){
			cout << y << " " << x << endl;
		}
		else if (x<=y){
			cout << x << " " << y << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 2976
n, m = gets.chomp.split(' ').map(&:to_i)
a = gets.chomp.split(' ').map(&:to_i)
count = 0
b = a.sum / (4.0 * m)
a.each{|i|
  if(i >= b)
    count += 1
  end
}

if(count < m)
  puts "No"
else
  puts "Yes"
end



Measured memory_bytes: 14280
def main():
    from itertools import accumulate as ac
    n = int(input())
    a = [int(input()) for _ in [0]*n]
    a_ac = [0]+list(ac(a))
    s = a_ac[-1]

    dp0 = [0]*(n+1)
    dp1 = [0]*(n+1)
    dp2 = [0]*(n+1)
    dp3 = [0]*(n+1)

    for i in range(1, n+1):
        p = dp0[i-1]
        q = dp1[i-1]
        ai = a[i-1]
        dp0[i] = min(p+((ai+1) % 2), q+(ai % 2 if ai > 0 else 2), a_ac[i])
        dp1[i] = min(q+(ai % 2 if ai > 0 else 2), a_ac[i])

    for i in range(n-1, -1, -1):
        p = dp2[i+1]
        q = dp3[i+1]
        ai = a[i]
        dp2[i] = min(p+((ai+1) % 2), q+(ai % 2 if ai > 0 else 2), s-a_ac[i])
        dp3[i] = min(q+(ai % 2 if ai > 0 else 2), s-a_ac[i])

    dp_l = [min(i, j) for i, j in zip(dp0, dp1)]
    dp_r = [min(i, j) for i, j in zip(dp2, dp3)]
    print(min([i+j for i, j in zip(dp_l, dp_r)]))


main()


Measured memory_bytes: 63264
#include <stdio.h>
#include <stdlib.h>
#include  <math.h>
int main()
{
   int i,n,cont=0;
    long long  a[10010];
   scanf("%d",&n);
   for(i=0;i<n;i++)
    scanf("%lld",&a[i]);
   for(i=0;i<n;i++)
   {
      while(a[i]%2==0)
      {
          cont++;
          a[i]=a[i]/2;
      }
   }
 printf("%d\n",cont);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a>=b){
		if(a>=c){
			printf("%d",10*a+b+c);
		}else{
			printf("%d",10*c+a+b);
		}
	}else if(b>=c){
		printf("%d",10*b+c+a);
	}
	return 0;
}

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

#define mod 1000000007
#define ll long long int
#define mk make_pair
#define pb push_back
#define xx first
#define yy second
#define ar array
#define del 1e-8

template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }

double pi=3.141592653589793238;
const int M = 1e9+7;
const int Nmax=5005;
const int MM = 998244353;
const int N=1000005;


int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0);
	int T=1;
	//cin>>T;
	while(T--){
      ll n;
      cin>>n;
      ll ans=0;
      for(int i=1;i<n;i++){
        ans+=(n-1)/i;
      }
      cout<<ans<<"\n";
    }
	return 0;
}


Measured memory_bytes: 3628
// abc143_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;

    vector<int> d(N);
    REP(i, N) cin >> d[i];

    ll ans = 0;
    REP(i, N) REPN(j, i+1, N){
        ans += d[i] * d[j];
    }

    print(ans);


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=300005;
int n,L;
int x[N],t[N],type[N];
LL ans=1;
int main(){
	n=read(),L=read();
	For(i,1,n)
		x[i]=read();
	ans+=n;
	For(i,1,n){
		t[i]=read();
		ans+=t[i]/(L*2);
		t[i]%=L*2;
		if (t[i]==0)
			ans--,type[i]=-2;
		else {
			if (t[i]>x[i]*2&&t[i]>(L-x[i])*2)
				type[i]=2;
			if (t[i]<=x[i]*2)
				type[i]--;
			if (t[i]<=(L-x[i])*2)
				type[i]++;
		}
	}
	int l=0,r=0;
	For(i,1,n){
		if (t[i]){
			if (i==n)
				l++;
			if (type[i]==-1)
				l++;
			else if (type[i]==1){
				if (l>0)
					l--,ans--;
				else if (r>0)
					r--,l++;
			}
			else if (type[i]==0){
				if (l>0)
					l--,r++,ans--;
				else
					l++;
			}
		}
	}
	cout<<ans*2*L<<endl;
	return 0;
}

Measured memory_bytes: 3712
from sys import stdin
a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
if a % d == 0:
    aa = a / d
else:
    aa = a//d +1
if c % b == 0:
    bb = c / b
else:
    bb = c//b +1
if aa >= bb:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9124
//I read the news today, oh boy
//About a lucky man who made the grade
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ll((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define roF(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;

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

const ll N=1e6;
const ll MOD = 1e9+7;

int n;
bool broken[N];
ll dp[N];

ll go(ll x){
	if(dp[x]!=-1) return dp[x];
	if(broken[x]) return dp[x]=0;
	return dp[x] = (go(x-1)+go(x-2))%MOD;
}	

int main(){
	fastio;
	cin>>n;
	int m; cin>>m;
	For(i,0,m){
		ll x; cin>>x;
		broken[x]=1;
	}
	For(i,1,n+1) dp[i]=-1;
	dp[0]=1;
	cout << go(n) << endl;
	return 0;
}



Measured memory_bytes: 7472
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	int n;
	cin >> n;
	for(int i = 1;i<=n;i++)
	{
		int x = i;
		if(x%3 == 0)
		{
			cout<<' '<<i;
		}
		else
		{
			while (x)
			{
				if(x%10 == 3)
				{
					cout<<' '<<i;
					break;
				}
				x/=10;
			}
		}
	}
	cout<<endl;
	return 0;
}


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

using namespace std;

int main(void){
    int W, a, b;
    cin >> W >> a >> b;
    if (a+W<b) cout << b-(a+W) << endl;
    else if(b+W < a) cout << a-(b+W) << endl;
    else cout << 0 << endl;
    return 0; 
}

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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define ALL(x) (x).begin(), (x).end()
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
#define fst first
#define snd second
typedef vector<int> vi;typedef vector<vi> vvi;typedef pair<int,int> pii;typedef vector<pii> vpii;
typedef long long ll;

void Main() {
  int N;
  ll L;
  scanf("%d%lld", &N, &L);
  vector<ll> A(N);
  rep(i, N) scanf("%lld", &A[i]);

  rep(i, N-1) {
    ll l2 = A[i] + A[i+1];
    if (l2 >= L) {
      // i と i+1 を最後に
      puts("Possible");
      rep(j, i) _p("%d\n", j+1);
      rrep(j, i, N-1) _p("%d\n", j+1);
      return;
    }
  }
  puts("Impossible");
}
int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 1664
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int N,K;
    cin >> N >> K;
    vector<int> h(N);
    int ans=0;
    for(int i=0;i<N;i++) cin >> h.at(i);
    for(int i=0;i<N;i++){
        if(h.at(i)>=K) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

int N, M, S;
int dp[50][3001];//dp[i][j][k] i????????°??§ j??????????????????????????°
const int MOD = 100000;

int main() {
	while (cin >> N >> M >> S, N * M) {
		dp[0][0] = 1;
		for (int m = 1; m <= M ; m++) {
			for (int n = N * N; n > 0; n--) {
				for (int s = m; s <= S; s++) {
					dp[n][s] += dp[n - 1][s - m];
					dp[n][s] %= MOD;
				}
			}
		}
		cout << dp[N * N][S] % MOD << endl;
		for (int i = 0; i <= N * N; i++)for (int j = 1; j <= S; j++)dp[i][j] = 0;
	}
	return 0;
}

//I have a little question about this problem.

Measured memory_bytes: 3568
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;


int base;
int k;
bool isVisited[1000010];	//存余数 

int main()
{
	scanf("%d", &k);
	int count = 1;
	base = 7;
	for (int i = 0 ; i <= k ; i++)
		isVisited[i] = false;
		
	int r = 0;
	while (true) {
		r = base % k;
		if (isVisited[r] == true) {
			printf("-1\n");
			return 0;
		}
		if (r == 0)
			break;
		isVisited[r] = true;
		base = r * 10 + 7;
		count++;
	}
	
	printf("%d\n", count);
	
	return 0;
}



Measured memory_bytes: 2652
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
int main() {
    ll n;
    cin >> n;
    ll div = 2;
    ll ret = 0;
    if (n == 2){
        ret--;
    }
    while (div < sqrt(n) + 1) {
        ll temp = n;
        if (temp % div == 0) {
            while(temp % div == 0) {
                temp /= div;
            }
            if (temp % div == 1) {
                ret++;
            }
        }
        div++;
    }
    n -= 1;
    ll div2 = 1;
    ll count = 0;
    while (div2 * div2 <= n) {
        if (n % div2 == 0) {
            if (div2 * div2 == n) {
                count ++;
            }
            else{
                 count += 2;
            }
        }
        div2++;
    }
    ret += count;
    cout << ret;
    return 0;
    }

Measured memory_bytes: 256
n,d=map(int,input().split())
list_a = []
for i in range(n):
    List = [int(j) for j in input().split()]
    list_a.append(List)
    
#print(list_a)

ans=0
for i in range(n):
    for j in range(i+1,n):
        kyorino2zyou=0
        for k in range(d):
            kyorino2zyou=kyorino2zyou+(list_a[i][k]-list_a[j][k])**2
            kyori=(kyorino2zyou)**(1/2)
            kyori2=int(kyori)
           # print(kyori)
          
        if kyori2-kyori==0:
                ans=ans+1
print(ans)

Measured memory_bytes: 40496
#include <bits/stdc++.h>
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; }

int main(){
    int k, s;
    cin >> k >> s;
    int cnt = 0;
    for(int x = 0; x <= k; x++) {
        for(int y = 0; y <= k; y++) {
            int z = s - x - y;
            if(0 <= z && z <= k){
                cnt++;
            }
            }
        }
    cout << cnt << endl;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N = Scanner.int()
    ans = 0
    for j in range(1, N + 1):
        k = N // j
        ans += k * (k + 1) // 2 * j
    print(ans)


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 10648
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007


double a, b;
int main() {
	cin >> a >> b;
	cout << fixed << 1 / (1 / a + 1 / b) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll in()
{
    ll res=0,p=1;
    char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') p=-1; c=getchar();}
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return p*res;
}
void out(ll x)
{
    if (x>9) out(x/10);
    putchar(x%10+48);
}

const int maxn = 1e5 + 5 + 32;
const int mod = 1e9 + 7;

string s, s1;
int ss[30],ss1[30];
int main()
{

cin>>s>>s1;
int a,b;a=s.size();b=s1.size();
 for(int i=1;i<=a;i++)
    ss[s[i]-'a']++,ss1[s1[i]-'a']++;
    for(int i=1;i<=a;i++)
    if(s[i]!=s1[i]&&ss[s[i]-'a']!=ss1[s1[i]-'a']){cout<<"No\n";return 0;}
    cout<<"Yes\n";
return 0;
}



Measured memory_bytes: 776
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    string s1,s2,s3;
    cin >> s1 >> s2 >>s3;
    string ans=s1.substr(0,1)+s2.substr(0,1)+s3.substr(0,1);
    transform(ans.begin(), ans.end(), ans.begin(), ::toupper);
    cout << ans;
    return 0;
}


Measured memory_bytes: 764
import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int M  = keyboard.nextInt();
		
		int[] B = new int[N+1];
        
        for(int i = 0; i < M; i++){
          int tmp  = keyboard.nextInt();
          B[tmp]= 1; 
        }
        
		long[] sum = new long[N+1];
		sum[0] = 1;
		sum[1] = 1 - B[1] ;
		
		for(int j = 2; j < N+1; j++){
			if(B[j] != 1){
          sum[j] = (sum[j-1]+sum[j-2])%1000000007 ;
          }
        }
        
		System.out.println(sum[N]);
		keyboard.close();	
	}
}


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

using ll = long long;

int main() {
    int N, M;
    while(cin >> N >> M, N) {
        vector<vector<int>> imos(M, vector<int>(1262));
        int r;
        cin >> r;
        for(int i=0; i<r; ++i) {
            int t, n, m, s;
            cin >> t >> n >> m >> s;
            m--;
            imos[m][t] += (s == 0 ? -1 : 1);
        }
        for(int i=0; i<M; ++i) {
            for(int j=1; j<imos[i].size(); ++j) {
                imos[i][j] += imos[i][j-1];
            }
            assert(imos[i][1261] == 0);
        }
        int q;
        cin >> q;
        for(int i=0; i<q; ++i) {
            int ts, te, m;
            cin >> ts >> te >> m;
            m--;
            int res = 0;
            for(int t=ts; t<te; ++t) {
                res += (imos[m][t] > 0);
            }
            cout << res << endl;
        }
    }
}

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

using namespace std;

typedef long long int big;

int main(){
	int n,k,s;
	cin>>n>>k>>s;
	vector<big> arr;
	for(big i=0;i<k;i++){
		arr.push_back(s);
	}
	for(big i=k;i<n;i++){
		if(s!=1000000000)
		{
			arr.push_back(s+1);
		}
		else{
			arr.push_back(s-1);
		}
	}
	for(auto x:arr){
		cout<<x<<" ";
	}
	//cout<<endl;
	//cin>>n;
	return 0;
}

Measured memory_bytes: 2164
import System.IO (isEOF)

main = main' []
    where
    main' xs = do
        quit <- isEOF
        if quit then return () else do
            x <- readLn
            xs' <- operate xs x
            main' xs'

operate :: [Int] -> Int -> IO [Int]
operate (x:xs) 0 = do
    print x
    return xs
operate xs x = return (x:xs)

Measured memory_bytes: 4048
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back

signed main(){
    int n,q;
    cin>>n>>q;
    int diff = 0;
    rep(i,q){
        int type, k;
        cin>>type>>k;
        if(type==0)cout<<(k-1-diff+n)%n+1<<endl;
        else diff = (diff-k+n)%n;
    }
}



Measured memory_bytes: 3136
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.ST                 as ST
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Foldable                 as DF
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import qualified Data.Sequence                 as SQ
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
readInts n = replicateM n readInt
readString = map BS.unpack . BS.words <$> BS.getLine
readStrings n = replicateM n <$> readString
toPair [x, y] = (x, y)

main = do
  s <- getLine
  let s' = map length $ group $ sort s in if length s' == 1 then print 0 else print $ minimum s' * 2


Measured memory_bytes: 13692
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define pi 3.14159265358979323846
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

ll dp[2001];

ll dfs(int S)
{
    if(S<0) return 0;
    if(S==0)
    {
        //ans=(ans+1)%mod;
        return 1;
    }
    if(dp[S]!=-1)
    {
        //ans=(ans+dp[S])%mod;
        return dp[S];
    }

    ll p=0;
    for(int i=3;i<=S;i++)
    {
        p=(p+dfs(S-i))%mod;
    }
    dp[S]=p;
    //ans=(ans+p)%mod;
    return dp[S];
}

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

    memset(dp,-1,sizeof(dp));
    cout<<dfs(S)<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

const string YES = "Yes";
const string NO = "No";

void solve(ll N) {
  string S = to_string(N);
  bool pred = S[1] == S[2] && (S[0] == S[1] || S[2] == S[3]);
  cout << (pred ? YES : NO) << endl;
}

int main() {
  ll N;
  cin >> N;
  solve(N);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int stone[100000];
	int num[100000];
	int pos = 0;
	int n;
	int i;
	int d;

	while(scanf("%d",&n) && n){
		scanf("%d",&d);
		stone[pos] = d;
		num[pos] = 1;

		for(i=1;i<n;i++){
			scanf("%d",&d);
			if(stone[pos]==d){
				num[pos]++;
			}else{
				if((i+1) & 0x0001){
					//奇数
					pos++;
					stone[pos]=d;
					num[pos]=1;
				}else{
					//偶数
					if(pos>0){
						if(stone[pos-1]!=stone[pos]){
							num[pos]++;
							num[pos-1]+=num[pos];
							pos--;
						}else{
							stone[pos]=d;
							num[pos]++;
						}
					}else{
						stone[pos]=d;
						num[pos]++;
					}
				}
			}
		}
		
		d=0;
		for(i=0;i<=pos;i++){
			if(stone[i]==0){
				d+=num[i];
			}
		}
		printf("%d\n",d);
		
		pos=0;
	}
}

Measured memory_bytes: 608
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  int N; cin >> N;
  vector<ll> A(N+1), B(N);
  for(int i=0; i<=N; i++)
    cin >> A[i];
  for(int i=0; i<N; i++)
    cin >> B[i];
  
  ll Ar, ans, kill;
  ans = 0;
  Ar = A[N];
  for(int i=N-1; i>=0; i--){
    kill = min(Ar+A[i], B[i]);
    ans += kill;
    if (kill - Ar < 0)
      Ar = A[i];
    else
      Ar = A[i] - (kill - Ar);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int A, B, C, D, E, F, w[3001], s[3001], ans_w, ans_s;
int main() {
    cin >> A >> B >> C >> D >> E >> F;
    for(int i{}; i <= F; i += 100 * A)
        for(int j{ i }; j <= F; j += 100 * B)
            w[j] = 1;
    for(int i{}; i <= F; i += C)
        for(int j{ i }; j <= F; j += D)
            s[j] = 1;
    for(int i{}; i <= F; ++i)
        for(int j{}; i + j <= F; ++j) {
            if(!w[i] || !s[j] || j * (100 + E) > E * (i + j)) continue;
            if(!ans_w || ans_s * (i + j) < j * (ans_w + ans_s))
                ans_w = i, ans_s = j;
        }
    cout << ans_w + ans_s << ' ' << ans_s << endl;
}


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


typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  bool end = false;
  int ans = 0;
  while(true){
    for(int i = 0; i < n; ++i){
      if((a[i] % 2) == 0) a[i] /= 2;
      else {
        end = true;
        break;
      }
    }
    if(end) break;
    ans++;
  }

  cout << ans << endl;
}


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

#define ll long long
#define pb push_back
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define inf 0x3f3f3f3f
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/* 
* stuff you should look for
* int overflow, array bounds
* special cases (n=1?), set tle
*/

int main(){
    fcin;
	int n;
	cin >> n;
	double s = 0.0;
	for(int i = 0; i < n; i++){
		int x;	cin >> x;
		s += 1.0/(double)x;
	}

	cout << 1.0/s << endl;
    return 0;
}



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

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String readStr;
    while ((readStr = reader.readLine()) != null) {
      int n = Integer.parseInt(readStr);
      int c = 0;

      for (int i = 0; i <= 9; i++)
        for (int j = 0; j <= 9; j++)
          for (int k = 0; k <= 9; k++)
            for (int l = 0; l <= 9; l++)
              if (i + j + k + l == n)
                c++;

      System.out.println(c);
    }
  }

}

Measured memory_bytes: 18492
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main(){
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.size()-1]==b[0]&& b[b.size() - 1] == c[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

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

int main(){
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    bool ODD = false;
    int ans = 0;
    while(1){
        for (int i = 0; i < N; i++)
        {
            if(A[i]%2 != 0){
                ODD = true;
                break;
            }
        }
        if(ODD == false){
            ans++;
            for (int i = 0; i < N; i++)
            {
                A[i] /= 2;
            }
            
        }
        else{
            cout << ans << endl;
            return 0;
        }
    }
    return -1;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

bool f(string s) {
    cerr << s << endl;
    int n = s.size();
    for (int i = 0; i < n; ++i) {
        int j = n - i - 1;
        if (s[i] != s[j]) return false;
    }
    return true;
}

int main() {
    string s;
    cin >> s;
    int n = s.size();
    bool ok = f(s) && f(s.substr(0, (n - 1) / 2)) && f(s.substr((n + 3) / 2 - 1));
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256