akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

struct edge{ int to,cost; };
struct Bridge_Decomposition{
  vector<vector<edge>> G,Tree,NewTree; //グラフ, グラフ->木(後退辺を消す), 木->色をまとめた木
  vector<int> dp,depth,cmp; //葉から根までの累積和, 木の深さ, 色(同じ色で強連結)
  vector<pair<int,int>> bridge; //橋
  int color = 1;

  Bridge_Decomposition(vector<vector<edge>> G):G(G){
    int n = G.size();
    Tree.resize(n); NewTree.resize(n);
    dp.resize(n,0); depth.resize(n,-1); cmp.resize(n,0);
    dfs(0,-1,0); //木の構築
    dfs2(0,-1); //累積和
    dfs3(0,-1); //色塗り
    dfs4(0,-1); //同じ色をまとめた木にする, 橋の列挙, 関節点の列挙
  }

  void dfs(int u,int pre,int d){
    depth[u] = d;
    for(edge e : G[u]){
      if(e.to == pre) continue;
      if(depth[e.to] == -1){
        dfs(e.to,u,d+1);
        Tree[u].push_back(e);
        Tree[e.to].push_back({u,e.cost});
      }else {
        if(depth[e.to] < depth[u]){
          dp[u]++;
          dp[e.to]--;
        }
      }
    }
    return;
  }

  void dfs2(int u,int pre){
    for(edge e : Tree[u]){
      if(e.to == pre) continue;
      dfs2(e.to,u);
      dp[u] += dp[e.to];
    }
    return;
  }

  void dfs3(int u,int pre){
    for(edge e : Tree[u]){
      if(e.to == pre) continue;
      if(dp[e.to] == 0){
        cmp[e.to] = color++;
      }else {
        cmp[e.to] = cmp[u];
      }
      dfs3(e.to,u);
    }
    return;
  }

  void dfs4(int u,int pre){
    for(edge e : Tree[u]){
      if(e.to == pre) continue;
      int x = cmp[u], y = cmp[e.to];
      if(x != y){
        NewTree[x].push_back({y,e.cost});
        NewTree[y].push_back({x,e.cost});
        bridge.push_back(minmax(u,e.to));
      }
      dfs4(e.to,u);
    }
    return;
  }
};

signed main(){

  int n,m; cin >> n >> m;
  vector<vector<edge>> G(n);
  for(int i = 0; i < m; i++){
    int x,y; cin >> x >> y;
    G[x].push_back({y,1});
    G[y].push_back({x,1});
  }

  Bridge_Decomposition bd(G);
  sort(bd.bridge.begin(),bd.bridge.end());
  for(auto p : bd.bridge){
    cout << p.first << " " << p.second << endl;
  }

  return 0;
}



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

int main() {
    int n;
    cin >> n;
    vector<int> a(n + 2);
    for (int i = 1; i <= n; i++) cin >> a[i];

    a[n + 1] = 0;
    a[0] = 0;
    long long sum = 0;
    for (int i = 0; i <= n; i++) sum += abs(a[i] - a[i + 1]);

    for (int i = 1; i <= n; i++) {
        cout << sum + abs(a[i - 1] - a[i + 1]) - (abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1])) << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
using namespace std;
int main()
{
	long long a,b,c;
	cin >> a >> b >> c;
	if(b > a)b -= a;
		else
		    b = a - b;
	if(c > a)c -= a;
	    else
		    c = a - c;
	if(b > c)cout << "B" << endl;
		else
	    	cout << "A" << endl;	
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc171/tasks/abc171_d

use proconio::input;

fn main() {
    input! {
      n: i32,
      a_s: [usize; n],
      q: i32,
      bcs: [(usize, usize); q],
    }
    let mut acc = vec![0; 100001];
    for &a in a_s.iter() {
        acc[a] += 1;
    }
    let mut sum = acc
        .iter()
        .enumerate()
        .fold(0_u64, |pre, (i, &a)| pre + (i as u64) * (a as u64));
    for &(b, c) in bcs.iter() {
        let bb = acc[b];
        acc[c] += bb;
        acc[b] = 0;
        sum = (sum as i128 + bb as i128 * (c - b) as i128) as u64;
        println!("{}", sum);
    }
}


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

int main() {
  vector<int> vec(3, 15);
  for (int i = 0; i < 3; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  /*
  for (int i = 0; i < 3; i++ ) {
    cout << vec.at(i) << endl;ac
  }
  */
  if ((vec.at(0) == 5) && (vec.at(1) == 5) && (vec.at(2))) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
N = list(map(int, input().split()))
An = list(map(int,input().split()))
judge = True
count = 0
i = 0
while judge:
    if An[i]%2 == 0:
        An.append(An[i]/2)
        i += 1
    else:
        judge = False
        break
print(len(An)//N[0]-1)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#define rep(i,N) for(int i=0; i<N;i++)
using namespace std;

int factorial(int a){
    int ans=1;
    rep(i,a){
        ans*=(i+1);
    }
    return ans;
};


int main(){
    int N;
    cin >>N;
    vector<int> P(N),Q(N),countP(N),countQ(N);
    int orderP=1;int orderQ=1;
    int n1,n2;
    rep(i,N){
        cin >> P[i];
    }
    rep(i,N){
        cin >> Q[i];
    }
    rep(i,N){
        countP[i]=1;
        countQ[i]=1;
    }
    rep(i,N){
        n1=0;
        n2=0;
        rep(j,P[i]-1){
            n1+=countP[j];
        }
        rep(j,Q[i]-1){
            n2+=countQ[j];
        }
        orderP+=n1*factorial(N-i-1);
        orderQ+=n2*factorial(N-i-1);
        countP[P[i]-1]=0;
        countQ[Q[i]-1]=0;
    }
    cout << abs(orderP-orderQ) << endl;
}


Measured memory_bytes: 256
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
from math import ceil
def main(N, K, A):
    A.sort(reverse=True)

    def f(x):
        res = 0
        for a in A:
            if a > x:
                res += a // x
            else:
                break
        return res

    lo = 0
    hi = 10**9
    for _ in range(100):
        m = (lo + hi) / 2
        if f(m) > K: lo = m
        else: hi = m
    print(ceil(lo))

if __name__ == '__main__':
    input = sys.stdin.readline
    N, K = map(int, input().split())
    *A, = map(int, input().split())
    main(N, K, A)


Measured memory_bytes: 104384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9 + 7);
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e3) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int main() {
    int n,p[100005],cnt=0;
    cin >> n;
    REP(i,n)cin >> p[i];
    REP(i,n){
        if(i+1 == p[i]){
            swap(p[i],p[i+1]);
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>

#define div1 1000000007

using namespace std;

int main(void)
{
    long long H, ans=0, num=1;

    cin >> H;

    while(H > 0){
        H /= 2;

        ans += num;

        num *= 2;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main() {
    string S; cin >> S;
    list<char> acgt = {'A', 'C', 'G', 'T'};
    int result = 0, temp_len = 0;
    for (int i=0; i < S.length(); i++) {
        if (find(acgt.begin(), acgt.end(), (char)S[i]) != acgt.end()) {
            temp_len++;
        } else {
            result = max(result,temp_len);
            temp_len = 0;
        }
    }
    result = max(result,temp_len);

    cout << result << endl; 
}       

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(){
  int N,A[101];
  std::cin >> N;
  int max=0;
  int count=0;
  bool flag=false;
  for(int i=0;i<N;i++){
    std::cin >> A[i];
    if(A[i]==1){
      count++;
    }else{
      count=0;
    }

    if(count>max)max=count;
  }


  std::cout << max+1 << '\n';
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

void solve(){
 ll n,k;
  cin >> n >> k;
 vll a(n);
  rep(i,0,n) cin >> a[i];
 
  ll ans=0,ret=0;
  repr(bit,40,0){
    ll mask=(1ll<<bit);
    ll cnt=0;
    rep(i,0,n) {
      if(a[i]&mask) cnt++;
    }
    if(cnt>=n-cnt) {
      ans+=mask*cnt; // x_bit=0
    }else {
      if(mask+ret<=k) {
        ans+=(n-cnt)*mask; // x_bit=1
        ret+=mask;
      }else{
        ans+=mask*cnt; // x_bit=0
      }
    }
  }
 cout << ans << endl;
}

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const int INF = 1e9;
double temp_start = 100.0;
double temp_end = 0.001; 
int climb_loop = 300000;
double temp;

int main(){
  int seed = 12345;
  mt19937 eng(seed);
  uniform_real_distribution<> uniform_01;

  // input
  int D;
  cin >> D;
  int c[26];
  rep(i,26) cin >> c[i];
  int s[D+1][26];
  rep(i,D) rep(j,26) cin >> s[i+1][j];
  
  // define parameter
  int last[D+1][26];
  int t[D+1];
  rep(i,D+1) rep(j,26) last[i][j] = 0;
  
  // calculate initial content climbing
  int content = 0;
  for(int day = 1; day <= D; day++) {
    int content_after = -INF;
    int best_kind = 0;
    rep(kind,26) {
      int res = content + s[day][kind];
      rep(j,26) {
        if(j == kind) last[day][j] = day;
        else last[day][j] = last[day-1][j];
        res -= c[j] * (day - last[day][j]);
      }
      if(res > content_after) {
        best_kind = kind;
        content_after = res;
      }
    }
    t[day] = best_kind;
    content = content_after;
    rep(j,26) {
      if(j == t[day]) last[day][j] = day;
      else last[day][j] = last[day-1][j];
    }
  }
   
  // simulated annealing
  rep(x,climb_loop) {
    int d = eng() % D + 1;
    int q = eng() % 26;
    int diff = s[d][q] - s[d][t[d]];
    int cur = d;
    while(cur <= D && last[cur][t[d]] == d) {
      diff -= c[t[d]] * (d - last[cur-1][t[d]]);
      last[cur][t[d]] = last[cur-1][t[d]];
      cur++;
    }
    cur = d;
    while(cur <= D && last[cur][q] < d) {
      diff += c[q] * (d - last[cur][d]);
      last[cur][q] = d;
      cur++;
    }
    if(uniform_01(eng) < exp((double)diff/temp)) {
      t[d] = q;
      content += diff;
    } else {
      int day = d;
      while(day <= D && last[day][t[d]] < d) {
        last[day][t[d]] = d;
        day++;
      }
      day = d;
      while(day <= D && last[day][q] == d) {
        last[day][q] = last[day-1][q];
        day++;
      }
    }
  }
  // output
  for(int day = 1; day <= D; day++) cout << t[day]+1 << endl;
  return 0;
}


Measured memory_bytes: 3828
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)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,a,b=parseMap(split(readline()))
    println(min(a*n,b))
end
main()

Measured memory_bytes: 165456
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a.at(i);
    ll all = a.at(0);
    for(ll i=1; i<n; i++){
        all = all^(a.at(i));
    }
    rep(i,n) cout << (all^(a.at(i))) << endl;
}

Measured memory_bytes: 4776
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, Z, W] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    A = []
    input_raw = read_func().strip().split()
    for i in range(N):
        A.append(int(input_raw[i]))

    if N == 1:
        print abs(A[0] - W)
    else:
        print max(abs(A[N - 2] - A[N - 1]), abs(A[N - 1] - W))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3056
import sys
N = int(sys.stdin.readline()) #整数出力
L = [int(s) for s in sys.stdin.read().split()] #リスト作成
S = sum(L)
x = S // N
A_1 = sum([(s-x)**2 for s in L])
A_2 = sum([(s-x-1)**2 for s in L])
print(min(A_1,A_2))

Measured memory_bytes: 3060
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let n: usize = read();
    let cr: Vec<String> = readnc();

    let mut a: Vec<i64> = vec![];
    a.push(i64::parse(&cr[0]));

    for i in 1..n {
        let p = cr[i*2-1].to_string();
        let v = i64::parse(&cr[i*2]);
        if p == "+" {
            a.push(v);
        } else {
            a.push(-v);
        }
    }

    let mut ans = 0;
    let mut imos = vec![0; n+1];
    for i in (0..n).rev() {
        imos[i] = imos[i+1] + a[i].abs();
    }

    let mut sum = 0;
    let mut head = 0;
    while head < n {
        if a[head] < 0 {
            let mut to = head + 1;
            let mut part_minus = a[head];
            let mut hoge = a[head];
            while to < n && a[to] >= 1 {
                part_minus -= a[to];
                hoge += a[to];
                to += 1;
            }
            ans = max(ans, sum + part_minus + imos[to]);
            sum += hoge;
            head = to;
        } else {
            sum += a[head];
            head += 1;
        }
    }
    ans = max(ans, sum);

    println!("{}", ans);
}

Measured memory_bytes: 14940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
bool chk(ll n){
    for(ll i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return true;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    for(;;n++){
        if(chk(n))return cout<<n , 0;
    }
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
    int h,w;
    cin >> h >> w;
    VVL a(h+2,VL(w+2,0));
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> a[i][j];
        }
    }

    LL n = 0;
    VS ans;
    for (int i = 1; i <= h; i++) {
        if (i%2 == 1) {
            for (int j = 1; j < w; j++) {
                if (a[i][j] % 2 == 1) {
                    a[i][j]--;
                    a[i][j+1]++;
                    n++;
                    stringstream ss;
                    ss << i << ' ' << j << ' ' << i << ' ' << j+1;
                    ans.push_back(ss.str());
                }
            }
            if (i != h and a[i][w] % 2 == 1) {
                a[i][w]--;
                a[i+1][w]++;
                n++;
                stringstream ss;
                ss << i << ' ' << w << ' ' << i+1 << ' ' << w;
                ans.push_back(ss.str());
            }
        }
        else {
            for (int j = w; j > 1; j--) {
                if (a[i][j] % 2 == 1) {
                    a[i][j]--;
                    a[i][j-1]++;
                    n++;
                    stringstream ss;
                    ss << i << ' ' << j << ' ' << i << ' ' << j-1;
                    ans.push_back(ss.str());
                }
            }
            if (i != h and a[i][1] % 2 == 1) {
                a[i][1]--;
                a[i+1][1]++;
                n++;
                stringstream ss;
                ss << i << ' ' << 1 << ' ' << i+1 << ' ' << 1;
                ans.push_back(ss.str());
            }
        }
    }

    cout << n << endl;
    for (auto&& var : ans) {
        cout << var << endl;
    }
    return 0;

}


Measured memory_bytes: 10996
#include<stdio.h>
#include<string.h>

int main(void){
	int n;
	int a[100];
	int i;
	int ave;

	long long int ret;



	scanf("%d",&n);

	ave = 0;

	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		ave += a[i];
	}

	if(ave < 0){
		ave = (int)(double(ave) / (double)n - 0.5);
	}else{
		ave = (int)(double(ave) / (double)n + 0.5);
	}

	ret = 0;
	for(i=0;i<n;i++){
		ret += (a[i] - ave) * (a[i] - ave);
	}

	printf("%lld\n",ret);

	return 0;

}

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


def check(a_list :list, flg :int) -> int:
    # flg:  1 初項(奇数の項)の和が、正の数になるように操作する
    # flg: -1 　　　　〃　　　〃　　　　　、負の数になるように操作する

    count=0
    sum=0
    for num in a_list:
        sum_next = sum + num
        
        sum_next_p_m_sign = (sum_next>0) - (sum_next<0)
        
        sign_chck = flg * sum_next_p_m_sign

        if sign_chck == -1:
            # flgと符号が一致しなかった場合、+1 or -1まで操作
            diff = (abs(sum_next) + 1) * (-1)*sum_next_p_m_sign
            sum += num + diff
            count += abs(diff)
        
        elif sign_chck == 0:
            # sum_next=0の時
            diff = (1)*flg
            sum += num + diff
            count += abs(diff)
        
        else:
            sum = sum + num
 
        flg *= (-1)
    return count
        
#----------
n = int(input().strip())
a_list = list(map(int, input().rstrip().split()))
#----------
print( min(check(a_list, 1), check(a_list, -1)) )


Measured memory_bytes: 14468
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
using namespace std;


int main() {
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	long long int  s[200][200];
	//cout << fixed << setprecision(10);
	long long int n, m, res = 0, mi = 9999999999999, sum = 0;
	cin >> n>>m;
	if (m==1) {
		cout << 0;
	}
	else {
		cout << (n - m);
	}
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K, X = map(int, readline().split())

    ans = list(range(X - K + 1, X + K))
    print(*ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9032
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<ll> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    ll one = 0;
    ll buf = 0;
    for (int i=0; i<n; i++) {
        buf += a.at(i);
        if (i%2 == 0) {
            if (buf == 0) {
                buf = 1;
                one++;
            }
            else if (buf < 0) {
                one += 1 - buf;
                buf = 1;
            }
        }
        else {
            if (buf == 0) {
                buf = -1;
                one++;
            }
            else if (buf > 0) {
                one += buf + 1;
                buf = -1;
            }
        }
    }
    ll two = 0;
    buf = 0;
    for (int i=0; i<n; i++) {
        buf += a.at(i);
        if (i%2 == 0) {
            if (buf == 0) {
                buf = -1;
                two++;
            }
            else if (buf > 0) {
                two += buf + 1;
                buf = -1;
            }
        }
        else {
            if (buf == 0) {
                buf = 1;
                two++;
            }
            else if (buf < 0) {
                two += 1 - buf;
                buf = 1;
            }
        }
    }
    cout << min(one, two) << endl;
    return 0;
}


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


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (int i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (int i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
ll n, p;
multiset < ll > s;
vector < ll > pr;
int u[mxn];

ll bpow (ll a, ll b) {
	if (a == 1) return 1;

	ll res = 1;
	while (b > 0) {
		if (b & 1) {
			res *= a;
			res = min(res, p + 1);
		}
		b /= 2;
		if (b > 0 && p / a < a) {
			return p + 1;
		}
		
		a *= a;
		
	}
	return res;
}

int main () {               
    cin >> n >> p;
    ll ans = 1;
    for (ll i = 1; i * i <= p; i ++) {
    	if (p % i) continue;
        ll rev = p / i;
        if (p % bpow(i, n) == 0) {
        	ans = max(ans, i);
        }
        //cout << p << ' ' << bpow(rev, n) << '\n';
        if (p % bpow(rev, n) == 0) {
        	ans = max(ans, rev);
        }
    }
    
    cout << ans;
	return Accepted;
}

// Coded By OB

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

template<typename T, typename U>
T gcd(T u, U v) {
	if (u == 0)return v;
	if (v == 0)return u;
	T r;
	while (v) {
		r = u % v;
		u = v;
		v = r;
	}
	return u;
}


template<typename T, typename U>
long long lcm(T u, U v) {
	long long res = (long long)u / gcd(u, v);
	res *= v;
	return res;
}

template<typename T>
long long lcm(vector<T> a) {
	int l = a.size();
	long long res = 1;
	for (int i = 0; i < l; ++i) {
		res = lcm(res, a[i]);
	}
	return res;
}

int main() {
	IOS;
	int n;
	cin >> n;
	vector<int> a(n);
	REP(i, n) {
		cin >> a[i];
	}
	put(lcm(a));

	return 0;
}




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

int main() {
	int n;
	while(cin>>n)
	{
		int c=0;
		for(int i=0;i<10;i++)
		for(int j=0;j<10;j++)
		for(int k=0;k<10;k++)
		if(n-i-j-k>=0&&n-i-j-k<10)c++;
		cout<<c<<endl;
	}
	return 0;
}

Measured memory_bytes: 3008
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#define rep(i,x) for(int i = 0; i < x; i++)
typedef long long ll;
using namespace std;
const int N = 1e5+5;
vector<int> neigh[N];
int ans[N];
int m = 0;
int used[N];
vector<int> c(N);

int dfs(int v){
    used[v] = 1;
    ans[v] = c[m];
    m++;
    for(int u:neigh[v]){
        if(!used[u]){
            dfs(u);
        }
    }
}

int main(){
    int n; cin >> n;
    vector<int> a(n-1),b(n-1);
    rep(i,n-1){
        cin >> a.at(i) >> b.at(i);
        a.at(i)--;b.at(i)--;
    }
    
    rep(i,n){
        cin >> c.at(i);
    }
    sort(c.begin(),c.end(),greater<int>());
    // rep(i,n) cout << c[i] << endl;
    
    rep(i,n-1){
        neigh[a.at(i)].push_back(b.at(i));
        neigh[b.at(i)].push_back(a.at(i));
    }
    int sum = 0;
    for(int i = 1;i < n; i++){
        sum += c.at(i);
    }
    dfs(0);

    cout << sum << endl;
    rep(i,n) cout << ans[i] << " ";
    return 0;

}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll n,m,k; cin>>n>>m>>k;
    vector<ll> a(n+1,0);
    rep(i,n){
        ll ta; cin>>ta;
        a[i+1]=a[i]+ta;
    };
    vector<ll> b(m+1,0);
    rep(i,m){
        ll tb; cin>>tb;
        b[i+1]=b[i]+tb;
    }

    ll ans=0,j=m;
    for(ll i=0;i<=n;i++){
        if(a[i]>k) break;
        while(a[i]+b[j]>k) j--;
        ans=max(ans,i+j);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
	int n,d;
	cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d));
	rep(i,n)rep(j,d)cin >> x[i][j];
	int ans=0;
	double tmp;
	rep(i,n){
		for(int j=i+1; j<n; j++){
			double dist=0;
			rep(k,d){
				dist+=(x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
			}
			dist = sqrt(dist);
			if(modf(dist, &tmp) == 0)ans++;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

n,m = imap()
k,s = [],[]
for i in range(m):
    tmp = iarr()
    k.append(tmp[0])
    s.append([num-1 for num in tmp[1:]])
p = iarr()

ans = 0
for i in range(2**n):
    bin = iarr(n)
    for j in range(n):
        if i>>j&1: bin[j] = 1
    flag = 1
    for ii,ss in enumerate(s):
        cnt = 0
        for num in ss: cnt += bin[num]
        if cnt%2 == p[ii]: continue
        else: flag = 0; break
    if flag: ans += 1
print(ans)



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

using namespace std;

int a[1010];

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

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

    int ans = 1000000;

    for(int i=-100;i<101;i++)
    {
        int temp = 0;

        for(int j=0;j<n;j++)
            temp += (a[j]-i)*(a[j]-i);

        if(temp < ans)
            ans = temp;
    }

    cout << ans << endl;
}

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


int main()
{
    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;

    --k;

    if (s[k] == 'A') s[k] = 'a';
    if (s[k] == 'B') s[k] = 'b';
    if (s[k] == 'C') s[k] = 'c';

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.trim().split('\n');

while (line = lines.shift()) {
    const numbers = line.split(' ').map(Number);

    // Edit from here
    let a = numbers[0];
    let b = numbers[1];

    if ( a === 0 && b === 0 ) { break; }

    if ( a > b ) {
        const tmp = a;
        a = b;
        b = tmp;
    } 

    const output = a + ' ' + b;
    // to here
    
    console.log(output);
    
}


Measured memory_bytes: 18856
#include <stdio.h>

int min(int a, int b)
{
    return a < b? a: b;
}

int main(void)
{
    int q, h, s, d;
    long long n;
    scanf("%d%d%d%d%lld", &q, &h, &s, &d, &n);
    h = min(h, q * 2);
    s = min(s, h * 2);
    d = min(d, s * 2);
    long long ans = n / 2 * d + n % 2 * s;
    printf("%lld\n", ans);
    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

#define MAX_N 1000

int n;

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>n;
		if(n==0)break;
		string s;
		bool state=false;
		bool l=false,r=false;
		int res=0;
		rep(i,n){
			cin>>s;
			if(s=="lu")l=true;
			if(s=="ru")r=true;
			if(s=="ld")l=false;
			if(s=="rd")r=false;
			if(!state&&l&&r){
				res++;
				state=true;
			}else if(state&&!l&&!r){
				res++;
				state=false;
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include <iostream>

using namespace std;

int main(void)
{
    int N, M, x;
    int A[100] = {0};
    cin >> N >> M >> x;
    for(int i = 0; i < M; i++){
        int c;
        cin >> c;
        A[c] = 1;
    }
    int cost0 = 0;
    for(int i = x; i >= 0; i--){
        cost0 += A[i];
    }
    int costN = 0;
    for(int i = x; i < N; i++){
        costN += A[i];
    }
    if(cost0 < costN){
        cout << cost0 << endl;
    }else{
        cout << costN << endl;
    }
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long mod = 1000000007;
int n;
int x[200000];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> x[i];
  
  long ans = 1;
  int pos = 0;
  int cnt = 0;
  for (int z = 0; z < n; ++z) {
    while (pos < n - 1 && x[pos] > 2 * cnt) {
      ++pos;
      ++cnt;
    }
    ans = ans * (cnt + 1) % mod;
    --cnt;
  }
  cout << ans << endl;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = 1<<29;

int main() {
  int N, K; cin >> N >> K;
  vector<int> x(N);
  rep(i, N) cin >> x[i];
  int ans = inf;
  rep(i, N - K + 1) {
    if (x[i] < 0) {
      int cand = -x[i] * 2;
      if (x[i + K - 1] > 0) cand += x[i + K - 1];
      ans = std::min(ans, cand);
      if (x[i + K - 1] > 0) {
        cand = x[i + K - 1];
        if (x[i] < 0) cand += x[i + K - 1] - x[i];
        ans = std::min(ans, cand);
      }
    }
    if (x[i] >= 0) {
      ans = std::min(ans, x[i + K - 1]);
    }
    if (x[i] < 0 && x[i + K - 1] <= 0) {
      ans = std::min(ans, -x[i]);
    }
  }
  cout << ans << "\n";
}


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

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



int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string S; cin >> S;
	ll cnt{0};
	for (auto e : S)
		(cnt += (e - '0')) %= 9;
	
	if (cnt == 0)
		std::cout << "Yes"<< std::endl;
	else
		std::cout << "No" << std::endl;
		
	return 0;
}










Measured memory_bytes: 3740
#include <iostream>
using namespace std;
  
int main(){
    int n, m, l;
    cin >> n >> m >> l;
 
    int A[n][m];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> A[i][j];
 
    int B[m][l];
    for (int i = 0; i < m; i++)
        for (int j = 0; j < l; j++)
            cin >> B[i][j];
 
    for (int i = 0; i < n; i++){
        for (int j = 0; j < l; j++){
            long value = 0;
            for (int k = 0; k < m; k++)
                value += A[i][k] * B[k][j];
            cout << value;
            if (j != l - 1) cout << " ";
        }
        cout << endl;
    }
 
    return 0;
}


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

using namespace std;


void solve() {
    int K, X, Y;
    cin >> K >> X >> Y;
    bool is_nx = X < 0;
    bool is_ny = Y < 0;
    int neg[2] = {1, -1};
    X = abs(X), Y = abs(Y);
    bool is_sw = X > Y;
    if (is_sw) {
        swap(X, Y);
    }
    if (K%2 == 0 && (X+Y)%2 == 1) {
        cout << -1; return;
    }
    int i = 1;
    while ((i*K-X-Y)%2 != 0 || (i*K-X-Y) < 0 || (i==1 && (i*K-X-Y)>0)) {
        i++;
    }
    int A = (i*K + X+Y)/2;
    int B = (i*K - X-Y)/2;
    vector<pair<int, int>> res; res.reserve(i);
    int cx = 0, cy = 0;
    while (B > 0) {
        while (B >= K) {
            cy -= K;
            res.emplace_back(cx, cy);
            B -= K;
        }
        while (B > 0) {
            cx -= B;
            cy += K-B;
            res.emplace_back(cx, cy);
            A -= K-B;
            B -= B;
        }
    }
    assert(B == 0);
    while (A > 0) {
        while (X > cx) {
            while (X - cx >= K) {
                cx += K;
                res.emplace_back(cx, cy);
                A -= K;
            }
            while (X > cx) {
                int dx = X - cx;
                cx += dx; cy += K-dx;
                res.emplace_back(cx, cy);
                A -= K;
            }
        }
        assert(X == cx);
        assert((Y-cy) % K == 0);
        while (Y > cy) {
            cy += K;
            res.emplace_back(cx, cy);
            A -= K;
        }
    }
    assert(A == 0);
    assert(i == (int)res.size());

    cout << i << "\n";
    for (int j = 0; j < i; j++) {
        int x, y;
        tie(x, y) = res[j];
        if (is_sw) {
            swap(x, y);
        }
        x *= neg[is_nx];
        y *= neg[is_ny];
        cout << x << ' ' << y << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 3840
n = gets.chomp.to_i
txy = [[0, 0, 0]]
1.upto(n) do |i|
  txy.push gets.split.map(&:to_i)
end

0.upto(n-1) do |i|
  dt = txy[i + 1][0] - txy[i][0]
  dx = txy[i + 1][1] - txy[i][1]
  dy = txy[i + 1][2] - txy[i][2]
  dl = dx.abs + dy.abs
  if dl > dt || (dt - dl).odd?
    puts 'No'
    exit 0
  end
end

puts 'Yes'
exit 0


Measured memory_bytes: 9596
#include <bits/stdc++.h>
#define L long long

using namespace std;

L n,start,ans=1,realans=1000000;
vector<L>v[100010];
L chk[100010];
L dwn[100010];
L bel[100010];

void dfs1(L x){
	L i;
	for(i=0;i<v[x].size();i++)
	{
		if(!chk[v[x][i]])
		{
			chk[v[x][i]]=1;
			dwn[x]++;
			dfs1(v[x][i]);
			bel[x]|=bel[v[x][i]];
		}
	}
	if(dwn[x]>=2) bel[x]=1;
}

void dfs2(L x,L bury){
	L i,passed=0;
	//printf("%lld %lld\n",x,bury);
	for(i=0;i<v[x].size();i++)
	{
		if(!chk[v[x][i]])
		{
			if(!bel[v[x][i]])
			{
				if(!passed)
				{
					passed=1;
				}
				else
				{
					//printf("*%lld*\n",x);
					ans++;
					bury=0;
				}
			}
			else
			{
				chk[v[x][i]]=1;
				dfs2(v[x][i],1);
				bury=0;
			}
		}
	}
	if(bury) ans++;
}

int main()
{
	srand((int)time(NULL));
	scanf("%lld",&n);
	L i;
	for(i=1;i<n;i++)
	{
		L s,e;
		scanf("%lld %lld",&s,&e);
		s++;
		e++;
		v[s].push_back(e);
		v[e].push_back(s);
	}
	vector<L>starts;
	for(i=1;i<=n;i++)
	{
		if(v[i].size()==1) starts.push_back(i);
	}
	L lop=5;
	while(lop--)
	{
		ans=1;
		for(i=1;i<=n;i++)
		{
			chk[i]=dwn[i]=bel[i]=0;
		}
		start=starts[rand()%starts.size()];
		chk[start]=1;
		dfs1(start);
		for(i=1;i<=n;i++)
		{
			chk[i]=0;
		}
		chk[start]=1;
		dfs2(start,0);
		realans=min(realans,ans);
	}
		printf("%lld",realans);
}

Measured memory_bytes: 12800
n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

A=-(-n // a)
B=-(-n // b)
C=-(-n // c)
D=-(-n // d)
E=-(-n // e)

M=max([A,B,C,D,E])

X=M+4

print(X)

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

using namespace std;
using ull = unsigned long long;
using ll = long long;
using lli = long long int;
using ld = long double;
using pa = pair<int, int>;
using ppa = pair<pa, int>;
#define SORT(v, n) sort(v, v + n);
#define ALL(v) v.begin(), v.end()
#define VSORT(v) sort(ALL(v))
#define GRESORT(v) sort(ALL(v), greater<ll>())
#define REVERSE(v) reverse(ALL(v))
#define overlap(v) v.erase(unique(ALL(v)), v.end())
#define debug(x) cout << #x << ": " << x << endl
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (b - 1); i >= a; i--)
#define rrep(i, n) RFOR(i, 0, n)
#define INF INT_MAX
#define SUP INT_MIN
#define mins(a, b) a = min(a, b)
#define maxs(a, b) a = max(a, b)

// 4近傍
int dy[]={0, 1, 0, -1};
int dx[]={1, 0, -1, 0};

// 8近傍
// int dy[]={0,0,1,-1,1,1,-1,-1};
// int dx[]={1,-1,0,0,1,-1,1,-1};

// const ll MOD = 1000000007;

ll pow_mod(ll a, ll b, ll mod) {
    ll tmp = 1;
    a %= mod;
    if (b > 0) {
        tmp = pow_mod(a, b / 2, mod);
        if (b % 2)
            tmp = (((tmp * tmp) % mod) * a) % mod;
        else
            tmp = (tmp * tmp) % mod;
    }
    return tmp;
}

void solve() {
    string s; cin >> s;
    int r = 0, l = 0;
    int n = s.size();
    for(int i = 1; i < n; i++){
        if(s[i] != s[i-1]) l++;
    }
    for(int i = n - 1; i > 0; i--){
        if(s[i] != s[i-1]) r++;
    }
    cout << min(r,l) << endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int n,k,s;
    cin>>n>>k>>s;
    int padding;
    if (s == 1000000000)
    {
        padding = s - 1;
    }
    else {
        padding = 1000000000;

    }
    rep(i,k){
        cout << s << " ";
    }
    rep(i,n-k){
        cout << padding << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3636
from copy import deepcopy
n = int(input())
A = [int(input()) for i in range(n)]
A2 = deepcopy(A)
A2.sort()
for i in range(n):
    #print (A[i], A2[-1])
    if A[i] == A2[-1]:
        print (A2[-2])
    else:
        print (A2[-1])

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++)
    cin >> a.at(i);
  
  int ap=0, bp=0;
  int turn=0;
  
  for(int i=0; i<N; i++){
    int pts=0;
    int maxi=0;
    for(int j=0; j<N; j++){
      if(pts<a.at(j)){
        pts=a.at(j);
        maxi=j;
      }
    }
    
    if(turn==0){
      ap+=pts;
      turn=1;
    }
    else{
      bp+=pts;
      turn=0;
    }
    a.at(maxi)=0;
  }
  cout << ap-bp << endl;
}

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

using namespace std;
char S[300][300],S2[300][300];
int N;
bool check_symmetric(){
  for(int i=0;i<N-1;++i){
    for(int j=i+1;j<N;++j){
      if(S2[i][j] != S2[j][i]){
        return false;
      }
    }
  }
  return true;
}
int main(){
  cin >> N;
  for(int i=0;i<N;++i){
    for(int j=0;j<N;++j){
      cin >> S[i][j];
    }
  }

  int pat = 0;
  for(int B=0;B<N;++B){
    for(int i=0;i<N;++i){
      for(int j=0;j<N;++j){
        S2[i][j] = S[i][(j+B)%N];
      }
    }

    if(check_symmetric()){
      pat++;
    }
  }
  cout << N*pat << endl; 
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int p,r,t;
int L[333];
int lmp[333];
int tmp[333][333];
int n[333][333];
bool used[333];
int C[333];
vector<P> D;

bool isRelease( int id ){
  for(int i=0;i<r;i++)
    if( n[id][i] > L[i] ) return false;
  return true;
}

bool check(int h){

  for(int i=0;i<r;i++) L[i] = lmp[i];
  for(int i=0;i<p;i++){
    C[i] = r;
    for(int j=0;j<r;j++){
      n[i][j] = tmp[i][j];
      if( n[i][j] == 0 ) C[i]--;
    }
  }
  
  memset( used,0,sizeof( used ));
  for(int i=0;i<h;i++){
    if( L[ D[i].second ] == 0 ) return true;
    L[ D[i].second ]--;    
    n[ D[i].first ][ D[i].second ]--;
    assert( n[ D[i].first ][ D[i].second ] >= 0 );    
    if( n[ D[i].first ][ D[i].second ] == 0 ) C[ D[i].first ]--;

    if( C[ D[i].first ] == 0 ) {
      used[ D[i].first ] = true;
      for(int j=0;j<r;j++)
        L[ j ] += tmp[ D[i].first ][ j ];      
    }
  }

  /*
  cout << "time : " <<  h << endl;
  for(int i=0;i<r;i++) cout << L[i]<< " ";
  cout << endl;
  for(int i=0;i<p;i++){
    for(int j=0;j<r;j++) cout << n[i][j] << " ";
    cout << endl;
  }
  */


  bool loop = true;
  while( loop ){
    loop = false;
    for(int i=0;i<p;i++){
      if( used[i] ) continue;
      if( isRelease( i ) ) {
        for(int j=0;j<r;j++)
          L[ j ] += tmp[i][j] - n[i][j];
        used[i] = true;
        loop = true;
      }
    }
  }

  for(int i=0;i<p;i++)
    if( !used[i] ) return true;
  return false;
  
}

int main(){
  cin >> p >> r >> t;
  D.resize( t );
  for(int i=0;i<r;i++) {
    cin >> L[i]; lmp[i] = L[i];
  }
  for(int i=0;i<p;i++)
    for(int j=0;j<r;j++){
      cin >> n[i][j];
      tmp[i][j] = n[i][j];
    }
  for(int i=0;i<t;i++){
    cin >> D[i].first >> D[i].second;
    D[i].first--; D[i].second--;
  }

  int st = 0, ed = t;
  int res = -1;
  while( st <= ed ){
    int h = (st+ed)/2;
    if( check( h ) ) {
      ed = h-1; res = h;
    } else {
      st = h+1;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 5100
import math

N, M, X = (int(x) for x in input().split())
comp = [0] * M
CA = []
for i in range(N):
    CA.append(list(map(int,input().split())))


minimum = 10 ** 5 * 14
for i in range(2**N):
    comp = [0] * (M + 1)
    for j in range(N):
        if (i >> j) & 1:
            comp = [x + y for (x, y) in zip(comp, CA[j])]
    flag = True
    for j in range(M + 1):
        if j == 0:
            continue
        if comp[j] < X:
            flag = False
            break
    if minimum > comp[0] and flag:
        minimum = comp[0]

if minimum == 10 ** 5 * 14:
    minimum = -1
print(minimum)

Measured memory_bytes: 9004
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

int main() {
  int n; cin >> n;
  stack<int> ans;
  if(n==0) cout <<0;
  while(n) {
    if(n%2) {
      ans.push(1);
      n -= 1;
    }
    else {
      ans.push(0);
    }
    n /= -2;
  }
  while(ans.size()) {
    cout << ans.top();
    ans.pop();
  }
  cout << endl;
}


Measured memory_bytes: 3624