akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define PI 3.14159265358979323846264338327950288

using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;


int main(){
    FAST_IO ;
    int N ; cin >> N ;
    int arr[N+1] ;
    for( int i = 0 ; i < N ; i++ )
        cin >> arr[i] ;
    bigint ans = 0 ;
    int curr_max = arr[0] ;
    for( int i = 0 ; i < N ; i++ ){
        curr_max = max( curr_max , arr[i] ) ;
        ans = ans + curr_max - arr[i] ;
    }
    cout << ans << endl ;
    return 0 ;
  }





// dp[x] = represents the expected value of steps to get gcd = 1 when current gcd = x


// Exepected Value  = 1 + sigma ( dp[i] / M ) from i = 1 to M ;

// 001
// 110
// 011
// 100


 



//
//string str ; cin >> str ;
//   int N ; cin >> N ;
//   unordered_set<string> s ;
//   for( int i = 0 ; i < N ; i++ ){
//       string x ; cin >> x ;
//       s.insert(x) ;
//   }
//   dp[0] = 0 ;
//   int L = ( int ) str.length() ;
//   dp[L] = 1 ;
//   for( int i = L - 1 ; i >= 0 ; i-- ){
//       string word ;
//       for( int j = i ; j < L ; j++ ){
//           word.push_back(str[j]) ;
//           if( s.find(word) != s.end() && dp[j+1] != 0 )
//               dp[i] = dp[j+1] ;
//       }
//   }
//   cout << dp[0] << endl ;











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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

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

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

int N, W;
vector<ll> w;
vector<ll> v;
vector<vector<ll>> dp(110, vector<ll>(100100, INF));

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

    cin >> N >> W;

    w.resize(N + 1);
    v.resize(N + 1);

    REP(i, N) {
        cin >> w[i + 1] >> v[i + 1];
    }

    dp[0][0] = 0;
    

    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < 100100; j++) {
            if (v[i] <= j) {
                chmin(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
            }
            chmin(dp[i][j], dp[i - 1][j]);
        }
    }

    int ans = 0;

    for (int i = 0; i < 100100; i++) {
        if (dp.at(N).at(i) <= W) {
            chmax(ans, i);
        }
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 87296
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        p1: [i64;2],
        p2: [i64;2]
    }

    let r = vec![
        vec![0, -1],
        vec![1, 0]
    ];

    let p3 = add(&mul_matvec(&r, &sub(&p2, &p1)), &p2);
    let p4 = add(&mul_matvec(&r, &sub(&p3, &p2)), &p3);
    println!("{} {} {} {}", p3[0], p3[1], p4[0], p4[1]);
}

#[allow(dead_code)]
fn dot(a: &[i64], b: &[i64]) -> i64 {
    let mut c = 0;
    for i in 0..a.len() {
        c += a[i] * b[i];
    }
    c
}

fn sub(a: &[i64], b: &[i64]) -> Vec<i64> {
    let mut c = vec![];
    for i in 0..a.len() {
        c.push(a[i] - b[i]);
    }
    c
}

fn add(a: &[i64], b: &[i64]) -> Vec<i64> {
    let mut c = vec![];
    for i in 0..a.len() {
        c.push(a[i] + b[i]);
    }
    c
}

fn mul_matvec(a: &[Vec<i64>], b: &[i64]) -> Vec<i64> {
    let mut c = vec![];
    for i in 0..a.len() {
        c.push(dot(&a[i], b));
    }
    c
}

Measured memory_bytes: 4352
/*
 * Author       : YangDavid
 * Created Time : 2019年07月12日 星期五 10时47分11秒
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 2222;
vector<int> G[maxn];
vector<pii> e;
int n, k, vis[maxn], rem;

void check_p(int v) {
    memset(vis, 0, sizeof(int) * (n + 10));
    queue<pii> q;
    vis[v] = true;
    q.emplace(v, 0);

    int mx = 0;
    while(!q.empty()) {
        auto f = q.front(); q.pop();
        for(auto g : G[f.first]) {
            if(f.second + 1 + mx > k) break;
            if(vis[g]) continue;
            q.emplace(g, f.second + 1);
            vis[g] = true;
            mx = max(mx, f.second + 1);
        }
    }

    int cnt = 0;
    rep(i, n) if(vis[i]) cnt++;
    rem = max(rem, cnt);
}

void check_e(int u, int v) {
    memset(vis, 0, sizeof(int) * (n + 10));
    queue<pii> q;
    
    int mx = 1, lim = k + 1, hf = lim / 2 + (lim & 1);
    q.emplace(u, 1), q.emplace(v, 1);
    vis[u] = vis[v] = true;

    while(!q.empty()) {
        auto f = q.front(); q.pop();
        for(auto g : G[f.first]) {
            if(f.second + 1 + mx > lim) break;
            if(vis[g]) continue;
            q.emplace(g, f.second + 1);
            vis[g] = true;
            mx = max(mx, f.second + 1);
        }
    }

    int cnt = 0;
    rep(i, n) if(vis[i]) cnt++;
    rem = max(rem, cnt);
}
int main() {
    scanf("%d%d", &n, &k);
    for(int i = 1; i < n; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        G[u].push_back(v);
        G[v].push_back(u);
        e.emplace_back(u, v);
    }
    rep(i, n) check_p(i);
    for(auto g : e) 
        check_e(g.first, g.second);
    printf("%d\n", n - rem);

    return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
# 2019 6/7
# ABC 103 D Island War

from operator import itemgetter
from collections import deque


def find_ans(queue):
    cnt = 0
    while len(queue):
        head = queue.popleft()
        i = 0
        while i < len(queue):
            if head[1] <= queue[i][0]:
                break
            queue.popleft()
        cnt += 1

    return cnt


if __name__ == '__main__':
    N, M = map(int, input().split())
    islands = []
    queue = deque()
    for i in range(M):
        island = list(map(int, input().split()))
        islands.append(island)
    # islands.sort(key=lambda x: x[1])
    islands.sort(key=itemgetter(1))
    for i in range(M):
        queue.append(islands[i])
    print(find_ans(queue))

Measured memory_bytes: 29444
#[allow(unused)]
use std::io::Write;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let s: usize = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s.parse().unwrap()
    };

    let n = 1_000_000_000;
    let x1 = n;
    let x2 = 1;
    let y1 = (n - (s % n)) % n;
    let y2 = (s + y1) / n;
    println!("0 0 {} {} {} {}", x1, y1, x2, y2);
}


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

int main()
{
	long long n,s=0;
	cin>>n;
	long long a[n+1],f[n+1],ans=0LL;
	for(int i=1; i<=n; i++)
	{
		cin>>a[i];
		s+=a[i];
		f[i]=s;
	}
	for(int i=1; i<n; i++){
		ans+=((a[i]%1000000007)*((s-f[i])%1000000007))%1000000007;
		ans%=1000000007;
	}	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6752
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 0;
    rep(i, 0, s.size() / 2){
        if(s[i] != s[s.size() - 1 - i]) ans++;
    }
    cout << ans << endl;
}

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

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#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 _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define slice(l, r) substr(l, r-l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
    #include "lib/dump.hpp"
#else
    #define dump(...) 42
    #define dump_1d(...) 42
    #define dump_2d(...) 42
    #define cerrendl 42
#endif
//}}}

signed main() {
    int k;cin>>k;

    if (1<=k && k<=9){
        cout << k << endl;
        return 0;
    }

    vector<vector<string>> x(10);
    rep(i, 10) x[i] = {to_string(i)};
    dump(x);
    vector<string> y;
    rep(i, 1, 10) y.pb(to_string(i));

    int c = 9;

    rep(d, 13){
        vector<vector<string>> tmp(10);
        rep(i, 10){
            // i-1
            if (i-1>=0){
                each(el, x[i-1]){
                    string t = to_string(i);
                    t += el;
                    tmp[i].pb(t);
                }
            }
            // i
                each(el, x[i]){
                    string t = to_string(i);
                    t += el;
                    tmp[i].pb(t);
                }
            // i+1
            if (i+1<=9){
                each(el, x[i+1]){
                    string t = to_string(i);
                    t += el;
                    tmp[i].pb(t);
                }
            }
        }
        x = tmp;
        rep(i, 1, 10){
            each(el, x[i]){
                y.pb(el);
                c++;
                if (c==k){
                    cout << el << endl;
                    return 0;
                }
            }
        }
        // dump(y);
    }

    return 0;
}


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

using namespace std;
using LL = long long;
using VI = vector<int>;
using PI = pair<int, int>;

struct Dice {
	Dice() { d = new int[6]; }
	~Dice() { delete[] d; }

	void get() {
		for (int i = 0; i < 6; i++) {
			cin >> d[i];
		}
	}
	void roll(char c) {
		int t = d[0];
		int tmp = d[1];
		switch (c) {
		case 'N':
			d[0] = d[1]; d[1] = d[5]; d[5] = d[4]; d[4] = t;
			break;
		case 'S':
			d[0] = d[4]; d[4] = d[5]; d[5] = d[1]; d[1] = t;
			break;
		case 'W':
			d[0] = d[2]; d[2] = d[5]; d[5] = d[3]; d[3] = t;
			break;
		case 'E':
			d[0] = d[3]; d[3] = d[5]; d[5] = d[2]; d[2] = t;
			break;
		case 'r':
			d[1] = d[2]; d[2] = d[4]; d[4] = d[3]; d[3] = tmp;
			break;
		default:
			break;
		}
	}
	int top() { return d[0]; }
	int right() { return d[2]; }
	int front() { return d[1]; }
	int left() { return d[3]; }
	bool operator==(Dice & obj) {
		for (int i = 0; i < 6; i++) {
			if (this->d[i] != obj.d[i]) { return false; }
		}
		return true;
	}
	int* d;
};

int main() {
	Dice d[100];
	bool f = true;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		d[i].get();
	}
	for (int k = 1; k < n; k++) {
		for (auto & e : "WWWNNNN") {
			for (int i = 0; i < 4; i++) {
				if (d[0] == d[k]) {
					f = false;
				}
				d[k].roll('r');
			}
			d[k].roll(e);
		}
	}
	cout << (f ? "Yes" : "No") << endl;
	return 0;
}



Measured memory_bytes: 3104
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n; cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    static int dp[200200][6];
    rep(i, 200200) {
        rep(j, 6) {
            dp[i][j] = -INF;
        }
    }
    dp[1][0] = a[0];
    dp[2][1] = a[1];
    dp[3][2] = a[2];
    for(int i = 1; i < n; ++ i) {
        rep(j, 3) {
            if(i + 1 < n) chmax(dp[i + 2][j], dp[i][j] + a[i + 1]);
            if(i + 2 < n) chmax(dp[i + 3][j + 1], dp[i][j] + a[i + 2]);
            if(i + 3 < n) chmax(dp[i + 4][j + 2], dp[i][j] + a[i + 3]);
        }
    }
    if(n % 2 == 0) {
        cout << max(dp[n - 1][0], dp[n][1]) << endl;
    } else {
        cout << max({dp[n - 2][0], dp[n - 1][1], dp[n][2]}) << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 14260
#include <stdio.h>

int main(void) {
	static int tokuhyo[1000]={};
	static int cost[1000];
	int max,maxid;
	int N,M;
	int i;
	scanf("%d%d",&N,&M);
	for(i=0;i<N;i++)scanf("%d",&cost[i]);
	for(i=0;i<M;i++) {
		int B;
		int j;
		scanf("%d",&B);
		for(j=0;j<N;j++) {
			if(cost[j]<=B) {
				tokuhyo[j]++;
				break;
			}
		}
	}
	max=0;maxid=-1;
	for(i=0;i<N;i++) {
		if(tokuhyo[i]>max) {
			max=tokuhyo[i];
			maxid=i;
		}
	}
	printf("%d\n",maxid+1);
	return 0;
}

Measured memory_bytes: 604
N, A, B = map(int, input().split())

if (B-A) % 2 == 0:
    print((B-A) // 2)
elif (A-1) < (N - B):
    print(A + (B-A-1)//2)
else:
    print((N-B + 1) + (N-(A+N-B + 1))//2)


Measured memory_bytes: 2940
use std::io::*;
use std::str::FromStr;

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

fn parse_pair<T: FromStr, U: FromStr>() -> (T, U) {
    let line = parse_line::<String>();
    let mut iter = line.split_whitespace();
    (
        iter.next().unwrap().parse().ok().unwrap(),
        iter.next().unwrap().parse().ok().unwrap(),
    )
}

fn println<T: ToString>(s: T) {
    println!("{}", s.to_string());
}

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

fn main() {
    let (x, a) = parse_pair::<usize, usize>();

    println(if x < a { 0 } else { 10 });
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll p=998244353ll;
const int N=200005;
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
int main(){
	int n,i,a,mx=0,id,se=0;
	scanf("%d",&n);
	for(i=1;i<=n;++i){
		scanf("%d",&a);
		if(a>=mx){se=mx;mx=a;id=i;}
		else cmax(se,a);
	}
	for(i=1;i<=n;++i)printf("%d\n",i==id?se:mx);
	return 0;
}

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

long long int x[50],y[50];

int main() {

    int n,k;

    cin >> n >> k;

    for(int i=0; i<n; i++){
        cin >> x[i] >> y[i];
    }

    long long int ans = 9222372036854775807;

    for(int a=0;a<n;a++){
        for(int b=0;b<n;b++){
            for(int c=0;c<n;c++){
                for(int d=0;d<n;d++){
                    if(x[a] < x[b] && y[c] < y[d]){
                        int count = 0;
                        for(int i=0; i<n; i++){
                            if(x[a] <= x[i] && x[i] <= x[b] && y[c] <= y[i] && y[i] <= y[d]){
                                count++;
                            }
                        }
                        if(count >= k){
                            ans = min(ans,(x[b]-x[a])*(y[d]-y[c]));
                        }
                    }
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
class Stack():
    def __init__(self):
        self.stack = [0 for _ in range(1000)]
        self.top = 0

    def push(self, n):
        self.top += 1
        self.stack[self.top] = n

    def pop(self):
        a = self.stack[self.top]
        del self.stack[self.top]
        self.top -= 1
        return a

    def lol(self):
        return self.stack[self.top]


def main():
    input_data = raw_input()
    data = input_data.strip().split(" ")
    st = Stack()
    for l in data:
        if l == "+":
            a = st.pop()
            b = st.pop()
            st.push(a + b)

        elif l == "-":
            a = st.pop()
            b = st.pop()
            st.push(b - a)

        elif l == "*":
            a = st.pop()
            b = st.pop()
            st.push(a * b)

        else:
            st.push(int(l))

    print st.lol()


if __name__ == '__main__':
    main()

Measured memory_bytes: 6324
#include <iostream>
#include <utility>
#include <functional>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

int main(){
    ll n, m, sum=0;
    cin >> n >> m;
    vector<ll> vec(n, 0);
    rep(i,n){
        cin >> vec[i];
        sum += vec[i];
    }
    sort(vec.rbegin(),vec.rend());
    if (vec[m-1] * 4 * m >= sum){
        cout << "Yes"<<endl;
    }else{
        cout << "No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define forn(i,a,n) for(int i =a; i < n; i++)
#define fi first
#define se second
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef long long int lli;

int main(){__
    string s;
    cin >> s;
    int n = (int) s.size();
    int sum = (s[0] == '1')? 1 : -1;
    int ans =0;
    forn(i,1,n){
    	int x = (s[i] == '1') ? 1 : -1;
    	if(sum > 0){
    		if(x < 0) ans++;
    	}
    	else if(sum < 0){
    		if(x > 0) ans++;
    	}
    	sum+=x;
    }
    cout << ans*2 << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100000
#define MAX_M 100000
#define vec vector<int>
#define vecst vector<string>
#define vecch vector<char>
#define vecf vector<float>
#define vecvec vector<vector<int>>
using ll=long long;
const int INF = 1e9;
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

int main(){
  int n,q,ans=0;
  string s;
  cin>>n>>q;
  cin>>s;
  int st[MAX_N];
  for(int i=1;i<n;i++){
    if(s[i-1]=='A'&&s[i]=='C'){
      ans++;
    }
    st[i]=ans;
  }
  for(q;q>0;q--){
    int b,e;
    cin>>b>>e;
    if(st[e-1]-st[b-1]<0){
      cout<<0<<endl;
    }
    else{
      cout<<st[e-1]-st[b-1]<<endl;
    }
  }
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int a[200005],b[200005];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=1; i<=n; i++)
    {
        int x;
        cin>>x;
        a[x]++;
    }
    int f=0;
    for(int i=1; i<=n; i++)
    {
        if(a[i])b[f++]=a[i];
    }
    sort(b,b+f);
    int num=0;
    for(int i=0; i<f-k; i++)
        num+=b[i];
    printf("%d",num);
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  ll h, w;
  cin >> h >> w;
  
  ll m = INF;
  for (int i = 1; i < w; i++){
    ll s1  = h * i;
    ll r = max(s1, (h + 1)/2 * (w - i)) - min(s1, h / 2 * (w - i));
    m = min(r, m);
  }
  for (int i = 1; i < w; i++){
    ll r;
    ll s1  = h * i;
    r = max(s1, (w - i + 1)/2 * h) - min(s1, (w - i) / 2 * h);
    m = min(r, m);
  }
  for (int i = 1; i < h; i++){
    ll r;
    ll s1  = w * i;
    r = max(s1, (w + 1)/2 * (h - i)) - min(s1, w / 2 * (h - i));
    m = min(r, m);
  }
  for (int i = 1; i < h; i++){
    ll r;
    ll s1  = w * i;
    r = max(s1, (h - i + 1)/2 * w) - min(s1, (h - i) / 2 * w);
    m = min(r, m);
  }

  cout << m << endl;






  return 0;
}


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

using namespace std;

int main() {

	int n;
	string s;
	cin >> n >> s;

	vector<int> l(27, 0);
	vector<int> r(27, 0);
	int maxcounter = 0;
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < 27; j++) {
			l[j] = 0;
			r[j] = 0;
		}

		for (int j = 0; j < n; j++) {
			if (j < i) {
				l[s[j]-'a']++;
			}
			else {
				r[s[j] - 'a']++;
			}
		}

		int counter = 0;

		for (int j = 0; j < 27; j++) {
			if (l[j] != 0 && r[j] != 0) {
				counter++;
			}
		}
		maxcounter = max(counter, maxcounter);
	}
	cout << maxcounter << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,A[200001];
    cin >> n;
    for(int i = 0; i < n; i ++){
        cin >> A[i];
    }
    
    int maxv = -2000000000;
    int minv = A[0];
    
    for(int i = 1; i < n; i ++){
        maxv = max(maxv,A[i] - minv);
        minv = min(minv,A[i]);
    }
    cout << maxv << endl;
    return 0;
}


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

int main(){
	int N, a[200], b[200], c[200], score[200] = {0};
	cin >> N;
	for(int i=0 ; i < N ; i++ ){
		cin >> a[i] >> b[i] >> c[i];
	}
	for(int i=0 ; i < N ; i++ ){
		bool A = true, B = true, C = true;
		for(int j=0 ; j < N ; j++ ){
			if( i == j ) continue;
			if( a[i] == a[j] ) A = false;
			if( b[i] == b[j] ) B = false;
			if( c[i] == c[j] ) C = false;
		}
		if( A ) score[i] += a[i];
		if( B ) score[i] += b[i];
		if( C ) score[i] += c[i];
	}
	for(int i=0 ; i < N ; i++ ){
		cout << score[i] << endl;
	}
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

int cnt[2];

void solve(){
	int n, a;
	scanf("%d", &n);
	REP(i, 0, n){
		scanf("%d", &a);
		a &= 1;
		cnt[a]++;
	}
	cnt[0] += cnt[1] / 2;
	cnt[1] &= 1;
	if (cnt[0] && cnt[1]){
		printf("NO\n");
	} else {
		printf("YES\n");
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(v) for(int k=head[v];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=1e6+5,M=1e7+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
#define pw(a) (1<<(a))
int e[15][15],g[pw(15)+5];
int f[pw(15)+5][15],n,m;
int main(){
	read(n,m);rep(i,1,m){int x,y,z;read(x,y,z);x--;y--;e[x][y]=e[y][x]=z;}
	re(i,0,pw(n))re(j,0,n)re(k,j,n)if(i&pw(j))if(i&pw(k))g[i]+=e[j][k];
	re(i,0,pw(n))re(j,0,n)f[i][j]=-INF;
	int ans=-INF;
	f[1][0]=0;
	for(int i=1;i<pw(n);i+=2)re(j,0,n)if(pw(j)&i){
		int rv=pw(n)-1-i;
		for(int k=rv;k;k=(k-1)&rv)
			gmax(f[i|k][j],f[i][j]+g[k|pw(j)]);
		re(k,0,n)if((rv&pw(k))&&e[j][k])gmax(f[i|pw(k)][k],f[i][j]+e[j][k]);
		if(j==n-1)gmax(ans,f[i][j]);
	}
	cout<<g[pw(n)-1]-ans;
}

Measured memory_bytes: 2304
// Aizu 1119: Exploring Caves
// 2017.9.15 bal4u@uu

#include <stdio.h>

int main()
{
	int n, dx, dy, d, x, y, tx, ty, ans;

	scanf("%d", &n);
	while (n-- > 0) {
		ans = 0, x = y = 0, tx = ty = 0;
		while (1) {
			scanf("%d%d", &dx, &dy); if (!dx && !dy) break;
			x += dx, y += dy;
			if ((d = x*x+y*y) > ans) ans = d, tx = x, ty = y;
			else if (d == ans && tx < x) tx = x, ty = y;
		}
		printf("%d %d\n", tx, ty);
	}
	return 0;
}

Measured memory_bytes: 1796
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
using namespace std;
using ll=long long;
//using R=double;

const int INF = 10000000;
typedef pair<int, int> p;

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

int main(){

    int N,M,X,Y;
    cin >> N >> M >> X >> Y;

    int x[N];
    int y[M];
    for(int i = 0; i < N; i++){
        cin >> x[i];
    }
    for(int i = 0; i < M; i++){
        cin >> y[i];
    }

    sort(x,x+N);
    sort(y,y+M);


    for(int c = -100; c < 101; c++){
        if(c > x[N-1] && c <= y[0] && c > X && c <= Y){
            puts("No War");
            return 0;
        }
    }
    
    puts("War");
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    
    ll N, X, Y; 
    cin >> N >> X >> Y;
    vector<vector<pair<ll,ll>>> G(N+1);
    rep(i, 1, N){
        G[i].push_back({i+1, 1});
        G[i+1].push_back({i, 1});
    }
    G[X].push_back({Y,1});
    G[Y].push_back({X,1});

    vector<ll> ans(N+1, 0);
    rep(i, 1, N+1){
        ll srt = i;
        vector<ll> d(N+1, 1e18);
        /* dijkstra's scope */{
            priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> que;
            que.push({0, srt});
            d[srt] = 0;
            while(!que.empty()){
                auto q = que.top();
                que.pop();
                if(q.first > d[q.second]) continue;
                for(auto g : G[q.second]){
                    if(d[g.first] <= q.first + g.second) continue;
                    d[g.first] = q.first + g.second;
                    que.push({d[g.first], g.first});
                }
            }
        }
        rep(j, 1, N+1){
            if(i >= j) continue;
            ans[d[j]]++;
        }
    }
    rep(i, 1, N){
        cout << ans[i] << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
    int a,b,k;
    cin>>a>>b>>k;

    int num=min(a,b);
    int cnt=0;
    while(1){
        if(a%num==0 && b%num==0){
            cnt++;
        }
        if(cnt==k)
            break;
        num--;
    }
    cout<<num;
}


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

void solve(int TestCase) {
    int n, k, s;
    cin >> n >> k >> s;

    vector<int> ret(n, 1e9);
    if(s == 1e9) {
        for(auto i = k; i < n; ++i)
            ret[i] = 1;
    }
    else {
        for(auto i = 0; i < k; ++i)
            ret[i] = s;
    }
    for(auto i = 0; i < n; ++i) {
        cout << ret[i] << " ";
    }
    cout << endl;
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int t = 1;
    //cin >> t;
    for(auto i = 1; i <= t; ++i)
        solve(i);
}


Measured memory_bytes: 1792
n,m,l=map(int,input().split())
A=[ list(map(int,input().split())) for i in range(n) ]
B=[ list(map(int,input().split())) for i in range(m) ]
C=[ [0 for i in range(l)] for j in range(n) ]

for i in range(n):
	for j in range(l):
		for k in range(m):
			C[i][j]+=A[i][k]*B[k][j]
for i in range(n):
	for j in range(l):
		print(str(C[i][j]),end="")
		if j<l-1:
			print(" ",end="")
		else:
			print("")


Measured memory_bytes: 7148
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
int dx[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dy[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
void DFS(vector<vector<int>>&A, P p, int H, int W) {
	A.at(p.first).at(p.second) = 0;
	for (int i = -1; i <= 1; i++) {
		for (int j = -1; j <= 1; j++) {
			if (i == 0 && j == 0) continue;
			int nx = p.second + i;
			int ny = p.first + j;
			if (0 <= nx && nx < W && 0 <= ny && ny < H && A.at(ny).at(nx) == 1) DFS(A, make_pair(ny, nx), H, W);
		}
	}
	return;
}
int main() {
	int W, H;
	cin >> W >> H;
	while (W != 0 && H != 0) {
		vector<vector<int>>A(H, vector<int>(W));
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cin >> A.at(i).at(j);
			}
		}
		vector<vector<bool>>reach(H, vector<bool>(W, false));
		int ans = 0;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (A.at(i).at(j) == 1) {
					DFS(A, make_pair(i, j), H, W);
					ans++;
				}
			}
		}
		cout << ans << endl;
		cin >> W >> H;
	}
}


Measured memory_bytes: 3332
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <set>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define P pair<int, int>

#define MOD 1000000007
#define INF 2147483647
#define NINF (-2147483647-1)
#define LLINF 9223372036854775807
using ll = long long;
using namespace std; 

int main() {
    int A, B ,S = 0;
    cin >> A >> B;
    S = max(S, A + A - 1);
    S = max(S, A + B);
    S = max(S, B + B - 1);
    cout << S << endl;
    getchar(); getchar();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
        // setw(6) << setfill('0')
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << "(" << v.first << ", " << v.second << ")";
    return ostr;
}

vector<string> split(const string &s, char delim) {
    vector<string> result;
    stringstream ss(s);
    string item;
    while (getline(ss, item, delim)) {
        if (!item.empty()) {
            result.push_back(item);
        }
    }
    return result;
}

#define M map<int64, int64>
M f(int64 n) {
    M m;

    while (n % 2 == 0) {
        m[2]++;
        n = n / 2;
    }

    int64 c = 3;
    while (c * c <= n) {
        if (n % c == 0) {
            n = n / c;
            m[c]++;
        } else {
            c += 2;
        }
    }
    if (n != 1) m[n]++;
    return m;
}

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

    M m;
    reps(1, i, n+1) {
        for (auto v : f(i)) m[v.first] += v.second;
    }
    // cout << m << endl;

    int64 ans = 1;
    for (auto v : m) {
        ans *= (v.second + 1);
        ans %= 1000000007;
    }

    cout << ans << endl;
}


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

namespace test
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			string[] s = Console.ReadLine().Split(' ');
			int n = int.Parse(s[0]);
			int W = int.Parse(s[1]);
			int[] w = new int[n];
			int[] v = new int[n];
			for (int i = 0; i < n; i++)
			{
				string[] tmp = Console.ReadLine().Split(' ');
				v[i] = int.Parse(tmp[0]);
				w[i] = int.Parse(tmp[1]);
			}

			int[,] dp = new int[n + 1, W + 1];
			for (int i = n - 1; i >= 0; i--)
			{
				for (int j = 0; j <= W; j++)
				{
					if (j < w[i])
						dp[i, j] = dp[i + 1, j];
					else
						dp[i, j] = Math.Max(dp[i + 1, j], dp[i + 1, j - w[i]] + v[i]);
				}
			}
			Console.WriteLine(dp[0,W]);
		}
	}
}

Measured memory_bytes: 13168
#include <iostream>

using namespace std;

int n,m;
int b[100],A[100][100],c[100];

int main(){
    for(int i=0;i<100;i++){
        c[i] = 0;
    }

    cin >> n >> m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> A[i][j];
        }
    }
    for(int j=0;j<m;j++){
        cin >> b[j];
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            c[i] += A[i][j] * b[j];
        }
    }

    for(int i=0;i<n;i++){
        cout << c[i] << endl;
    }



    
   return 0;
}


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

// マクロ //
#define rep(i,N) for(int i = 0; i < (int)N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
template<class T> lint gcd(T a, T b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T> lint lcm(T a, T b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

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

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

// 定数 //
#define pi acos(-1)
#define mod 1000000007
#define MOD 998244353
#define inf ((1LL << 62) - 1 + (1LL << 62))

// キーワード //
#define elif else if

// End of Template //



int main() {

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

    string S, Srev;
    cin >> S;
    Srev = S;
    vi ans(S.size(), 0);
    reverse(all(Srev));
    int Rconseq = 0, Lconseq = 0;
    rep(i, S.size()) {
        if (S[i] == 'L') {
            if (Rconseq) {
                ans[i - 1] += ((Rconseq + 1) / 2);
                ans[i] += (Rconseq / 2);
                Rconseq = 0;
            }
        }
        else {
            Rconseq++;
        }
    }

    reverse(all(ans));

    rep(i, S.size()) {
        if (Srev[i] == 'R') {
            if (Lconseq) {
                ans[i - 1] += ((Lconseq + 1) / 2);
                ans[i] += (Lconseq / 2);
                Lconseq = 0;
            }
        }
        else {
            Lconseq++;
        }
    }

    reverse(all(ans));

    rep(i, ans.size() - 1) {
        cout << ans[i] << " ";
    }
    cou(ans[ans.size() - 1]);
}

Measured memory_bytes: 1104
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int count=0;
    int idx=1;
    for(int i=1;i<=n;i++){
        int a;
        cin>>a;
        if(a!=idx)count++;
        else idx++;
    }
    if(count==n)cout<<-1<<endl;
    else cout<<count<<endl;
    return 0;
}


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

using namespace std;

#define int 		long long
#define endl 		"\n"
#define mod 		1000000007
#define inf 		1e18
#define IOS 		ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int32_t main() {

	IOS;

	int x;
	cin >> x;
	cout << !x;

	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
#include<set>
#include<iomanip>
using namespace std;
using ll=long long int;

int main() {

	string s;

	while (cin >> s, s != "#") {
		int y, m, d;
		cin >> y >> m >> d;

		if (y > 31 || (y == 31 && m >= 5)) {
			s = "?";
			y -= 30;
		}

		cout << s << " " << y << " " << m << " " << d << endl;



	}

	return 0;
}



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

using namespace std;

int main()
{
    vector<vector<int>> set{{1, 3, 5, 7, 8, 10, 12}, {4, 6, 9, 11}, {2}};

    int x, y;
    cin >> x >> y;

    int pos = 0;
    for (int i = 0; i < set.size(); i++) {
        for (int j = 0; j < set[i].size(); j++) {
            if (set[i][j] == x) pos = i;
        }
    }   

    bool is_similar = false;
    for (int i = 0; i < set.size(); i++) {
        for (int j = 0; j < set[i].size(); j++) {
            if (set[i][j] == y) {
                if (pos == i) is_similar = true;
                break;
            };
        }
    }    
 
    cout << (is_similar ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import math
import collections
import functools


def solve():
    N = int(input())
    P = 10**9+7

    if N == 1:
        return 1

    fn = math.factorial(N)

    divisors = prime_factorize(fn)

    c = collections.Counter(divisors)

    ans = functools.reduce(lambda x, y: x * y, map(lambda x: x + 1, c.values()))

    return ans % P


def prime_factorize(n):
    res = []
    while n % 2 == 0:
        res.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            res.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        res.append(n)
    return res


if __name__ == '__main__':
    res = solve()
    print(res)


Measured memory_bytes: 39024
from collections import deque

dx,dy = [1,0,-1,0],[0,1,0,-1]

while True:
	w,h = map(int,input().split())
	if w == 0 and h == 0:
		break
	field = [input() for i in range(h)]
	for i in range(h):
		if '@' in field[i]:
			sx,sy = i,field[i].find('@')
	visited = [[False for i in range(w)] for j in range(h)]
	que = deque()
	que.append((sx,sy))
	visited[sx][sy] = True
	while que:
		p = que.popleft()
		for i in range(4):
			nx,ny = p[0] + dx[i],p[1] + dy[i]
			if 0 <= nx < h and 0 <= ny < w and field[nx][ny] != '#' and not visited[nx][ny]:
				visited[nx][ny] = True
				que.append((nx,ny))
	cnt = 0
	for i in range(h):
		for j in range(w):
			cnt += visited[i][j]
	print(cnt)



Measured memory_bytes: 6012
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	string a, b;
	cin >> a >> b;
	if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0]){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import collections
import math
n = int(input())
ai = [int(i) for i in input().split()]

mod = 10**9+7

if n == 1:
    print(1)
    exit()
    
    
# 素因数分解、辞書で返すやつ
# mathをimportする
def prime(n):
    factor = {}
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            if not num in factor.keys():
                factor[num] = 1
            else:
                factor[num] += 1
        if num > n:
            break
    if n != 1:
        if not n in factor.keys():
            factor[n] = 1
        else:
            factor[n] += 1
    return factor


dic = {}
for a in ai:
    pr = prime(a)
    for num, count in pr.items():
        if not num in dic.keys():
            dic[num] = count
        else:
            if dic[num] < count:
                dic[num] = count

kari = 1
for num,count in dic.items():
    kari *= pow(num,count,mod)
    kari %= mod

kari_old = kari
ans = 0

for i in range(n):
    kari = kari_old
    #com_ab_new = copy.deepcopy(com_ab)
    #print(com_ab,com_ab_new)
    #kari = 1
    #for j in range(kosu):
    #kari *= pow(sosu_li[j][0],com_ab[sosu_li[j][0]],mod)
    kari *= pow(ai[i],mod-2,mod)
    ans += kari
    ans %= mod
    #print(ans)
    #print(ans)
        
print(ans)


Measured memory_bytes: 47068
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, B):
    
    ans = []
    while B:
        for i in range(len(B)-1, -1, -1):
            if i+1 == B[i]:
                B.pop(i)
                ans.append(i+1)
                break
        else:
            break
    
    if B:
        return [-1]
    else:
        return reversed(ans)


def main():
    N = read_int()
    B = read_int_n()
    for r in slv(N, B):
        print(r)




if __name__ == '__main__':
    main()


Measured memory_bytes: 6504
package main

import (
        "fmt"
        "strings"
)

func main() {
        var a int
        var b string
        fmt.Scan(&a)
        fmt.Scan(&b)
        c := strings.Split(b, "")
        r := 0
        for i := 0; i < a; i++ {
                if c[i] == "R" {
                        r++
                }
        }
        if r > a-r {
                fmt.Println("Yes")
        } else {
                fmt.Println("No")
        }
}

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

int main(){
    string s;
    cin >> s;
    if(s == "AAA") cout << "No" << endl;
    if(s == "AAB") cout << "Yes" << endl;
    if(s == "ABB") cout << "Yes" << endl;
    if(s == "ABA") cout << "Yes" << endl;
    if(s == "BBA") cout << "Yes" << endl;
    if(s == "BAB") cout << "Yes" << endl;
    if(s == "BAA") cout << "Yes" << endl;
    if(s == "BBB") cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define dump(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  vector<int> l(Q);
  vector<int> r(Q);
  REP(i, Q) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    l[i] = x;
    r[i] = y;
  }
  vector<int> R(N, 0);
  for(int i = 0; i < N - 1; i++) {
    if(S[i] == 'A' && S[i + 1] == 'C') {
      R[i + 1] = R[i] + 1;
    } else {
      R[i + 1] = R[i];
    }
  }
  for(int i = 0; i < Q; i++) {
    cout << R[r[i]] - R[l[i]] << endl;
  }

  return 0;
}

Measured memory_bytes: 2256