akhauriyash/Code-Regression huggingface dataset:
inp = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')
N = inp.shift() * 1
b = {}
for (i=0; i<N; i++) {
    b[i] = {n: [], b: 0, u: {}, k: 0}
}
max = 0
for (i=0; i<N-1; i++) {
    l = inp[i].split(' ')
    j = l[0] - 1
    k = l[1] - 1
    b[j].n.push({ n: k, i: i })
    b[k].b += 1
    if (max < b[j].n.length + b[j].b) {
        max = b[j].n.length + b[j].b
    }
    if (max < b[k].n.length + b[k].b) {
        max = b[k].n.length + b[k].b
    }
}
a = []
for (i=0; i<N; i++) {
    for(j=0; j < b[i].n.length; j++) {
        o = b[i].n[j]
        f = false
        for (k = b[i].k + 1; k < max; k++) {
            if (!b[i].u[k]) {
                f = true
                break;
            }
        }
        if (!f) {
            for (k = 1; k < max; k++) {
                if (!b[i].u[k]) {
                    break;
                }
            }
        } 
        o.c = k
        b[i].u[o.c] = 1
        b[i].k = k
        b[o.n].u[o.c] = 1
        b[o.n].k = k
        a[o.i] = o.c
    }
}
console.log(max)
console.log(a.join("\n"))

Measured memory_bytes: 112872
#!/usr/local/bin/python3
# https://atcoder.jp/contests/abc064/tasks/abc064_c


def check(a):
    if a < 400:
        return 0
    elif a < 800:
        return 1
    elif a < 1200:
        return 2
    elif a < 1600:
        return 3
    elif a < 2000:
        return 4
    elif a < 2400:
        return 5
    elif a < 2800:
        return 6
    elif a < 3200:
        return 7
    else:
        return 8


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

ratings = [
    '1-399', '400-799', '800-1199', '1200-1599', '1600-1999',
    '2000-2399', '2400-2799', '2800-3199', '3200-']
d = {r: 0 for r in ratings}

for a in A:
    d[ratings[check(a)]] += 1

ans = 0
for k, v in d.items():
    if k != '3200-' and v != 0:
        ans += 1

top = d['3200-']
if top == 0:
    print(ans, ans)
elif ans == 0:
    print(1, top)
else:
    print(ans, ans+top)


Measured memory_bytes: 9196
from functools import reduce

def main():
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10

    # 1文字のみを読み込み
    # s = input().rstrip()
    
    # スペース区切りで標準入力を配列として読み込み
    # s = input().rstrip().split(' ')

    # 1文字ずつ標準入力を文字列として読み込み
    # s = list(input().rstrip())
    
    # 位置文字ずつ標準入力を数値配列として読み込み
    # X = [int(_) for _ in input().split()]
    
    N = int(input().rstrip())
    K = int(input().rstrip())
    X = int(input().rstrip())
    print(int((N+K)*X/2))   
   
if __name__ == '__main__':
    main()


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

using namespace std;

int nico(int a[]);

int main()
{
	int n, m;
	int tmp;

	while (true){
		scanf("%d", &n);

		if (n == 0){
			break;
		}

		int a[128][128] = {0};
		int info[128] = {0};

		for (int i = 1; i <= n; i++){
			scanf("%d", &m);

			for (int j = 0; j < m; j++){
				int pos;
				scanf("%d", &pos);

				a[i][pos] = 1;
			}
		}

		scanf("%d", &m);

		for (int i = 0; i < m; i++){
			int pos;
			scanf("%d", &pos);

			info[pos] = 1;
		}

		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= n; j++){
				a[i][j] *= info[j];
			}
		}

		int flag = 0;
		int pos;
		for (int i = 1; i <= n; i++){
			if (nico(a[i]) == m){
				flag++;
				pos = i;
			}
		}

		if (flag == 1){
			printf("%d\n", pos);
		}
		else {
			puts("-1");
		}
	}

	return (0);
}

int nico(int a[])
{
	int ret = 0;

	for (int i = 1; i <= 100; i++){
		if (a[i]){
			ret++;
		}
	}

	return (ret);
}

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

int memo[100000];

int rec(int i) {
    if (i == 0)
        return 0;
    
    if (memo[i] != -1)
        return memo[i];

    int res = i;

    for (int j = 1; j <= i; j *= 6) {
        res = min(res, rec(i - j) + 1);
    }
    for (int j = 1; j <= i; j *= 9) {
        res = min(res, rec(i - j) + 1);
    }
    return memo[i] = res;
}

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

    int n;
    cin >> n;

    for (int i = 0; i <= n; ++i) {
        memo[i] = -1;
    }

    cout << rec(n) << '\n';
    return 0;
}


Measured memory_bytes: 3712
import java.util.*;

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

		if(N == M)
		System.out.println("Yes");
		else
		System.out.println("No");
	}
}

Measured memory_bytes: 35712
def solve():
    mod = 10**9+7
    L = list(input())
    N = len(L)
    dp = [0]*2
    dp[0] = 1
    dp[1] = 2
    for i in range(1, N):
        if L[i]=='0':
            dp[0], dp[1]=dp[0]*3, dp[1]
        else:
            dp[0], dp[1]=dp[0]*3+dp[1], dp[1]*2
    print((dp[0]+dp[1])%mod)
solve()


Measured memory_bytes: 49392
#include<bits/stdc++.h>
using namespace std;
const double eps=1e-7;
typedef long long ll;
const ll maxx=2e5+10;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f;
int a[maxx];
int main(){
    int n; cin>>n;
    int f=1;
    for(int i=1;i<=n;i++){
        int x; cin>>x;
        if(x&1) continue;
        if(x%3==0||x%5==0) continue;
        f=0;
    }
    if(f) puts("APPROVED") ;
    else puts("DENIED");
}


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

int main(){

    long long x, y; cin >> x >> y;
    if(x == y || y == 1){
        cout << -1 << endl;
        return 0;
    }else{
        while(1){
            if(x % y != 0){
                cout << x << endl;
                return 0;
            }

            x += x;
            if(x <= 0) break;

        }
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cassert>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define irep(i,a,b) for(int i=(a);i>=(b);i--)

using namespace std;
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;


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


  int N;
  cin >> N;
  vi w(N);
  rep(i, 0, N) cin >> w[i];

  vi sur(N);

  int acc = 0;
  irep(i, N-1, 0) {
    acc += w[i];
    sur[i]= acc;
  }


  acc = 0;
  int ans = 1000*1000;
  rep(i, 0, N-2) {
    acc += w[i];
    ans = min(ans, abs( acc - sur[i+1]) );
  }

  cout << ans << endl;



}


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

using namespace std;

#define FOR(i,l,r) for (int i=(l); i<(r); ++i)
#define sz(x) (int)(x).size()
#define print(x) cout << (x) <<endl
#define dbg(x) cout << (#x) << " : " << (x) <<endl
#define all(x) (x).begin(), (x).end()

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

/* -------------------------- */

int main() {
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    if (a == 0) {
        cout << 1 << "\n";
    } if (b == 0) {
        cout << 2 << "\n";
    } if (c == 0) {
        cout << 3 << "\n";
    } if (d == 0) {
        cout << 4 << "\n";
    } if (e == 0) {
        cout << 5 << "\n";
    }
}


Measured memory_bytes: 3540
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;

#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

int main()
{
    string A, B, C, S;
    cin >> A >> B >> C;

    S.push_back(A[0]);
    S.push_back(B[0]);
    S.push_back(C[0]);

    cout << S << endl;
}

Measured memory_bytes: 256
import Data.IORef
import Control.Monad

main :: IO()
main = do
        n <- readLn
        x <- readLn
        y <- readLn
        print =<< solve (y - x) (min x y) [1..n-2]

solve :: Int -> Int -> [Int] -> IO Int
solve a b xs = do
                a' <- newIORef (a `seq` a)
                b' <- newIORef (b `seq` b)
                forM_ xs $! \_ -> do
                    z <- readLn
                    x <- readIORef a'
                    y <- readIORef b'
                    when (z - y > x) $! writeIORef a' (z - y)
                    when (z < y) $! writeIORef b' z
                readIORef a'

Measured memory_bytes: 4340
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double x = (60 * h - 11 * m) * M_PI / 360;
    double c = a * a + b * b - 2 * a * b * cos(x);
    cout << fixed << setprecision(20) << sqrt(c) << endl;
}

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

int main(){
    int D, G;
    cin >> D >> G;
    int p[D], c[D];
    for(int i = 0; i < D; ++i){
        cin >> p[i] >> c[i];
    }
 
    int ans = 1e9;
    for(int mask = 0; mask < (1 << D); ++mask){
        int s = 0, num = 0, rest_max = -1;
        for(int i = 0; i < D; ++i){
            if(mask >> i & 1){
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }else{
                rest_max = i;
            }
        }
        if(s < G){
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if(need >= p[rest_max]){
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

// reference: http://ir5.hatenablog.com/entry/20171209/1512821837

struct Scanner<'a> {
    cin: StdinLock<'a>,
}
 
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

use std::mem;
use std::cmp;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let N: usize = sc.read();
    let H: usize = sc.read();
    let W: usize = sc.read();
    let mut ans = 0;
    for i in 0..N {
        let a: usize = sc.read();
        let b: usize = sc.read();
        if a >= H && b >= W {
            ans += 1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin >> N;
    long long a[N];
    for(int i = 0; i < N; i++) cin >> a[i];
    long long po = 0, pe = 0;
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        if(i % 2 == 1 && sum + a[i] >= 0) {
            po += abs(- sum - 1 - a[i]);
            sum = -1;
        }
        else if(i % 2 == 0 && sum + a[i] <= 0) {
            po += abs(- sum - a[i] + 1);
            sum = 1;
        }
        else sum += a[i];
    }
    sum = 0;
    for (int i = 0; i < N; i++)
    {
        if(i % 2 == 1 && sum + a[i] <= 0) {
            pe += abs(- sum - a[i] + 1);
            sum = 1;
        }
        else if(i % 2 == 0 && sum + a[i] >= 0) {
            pe += abs(- sum - 1 - a[i]);
            sum = -1;
        }
        else sum += a[i];
    }

    cout << min(po, pe) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n,a,ans=BIG;
  cin>>n;
  rep(i,n){
    cin>>a;
    int cnt=0;
    while(a%2==0){
      a/=2;
      cnt++;
    }
    ans=min(ans,cnt);
  }
  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int A, B, K;
    cin >> A >> B >> K;
    set<int> st;
    int cnt{};
    for( int i = A; i <= B; ++i )
    {
        cnt++;
        if( cnt > K ) break;
        st.emplace( i );
    }
    cnt = 0;
    for( int i = B; i >= A; --i )
    {
        cnt++;
        if( cnt > K ) break;
        st.emplace( i );
    }
    for( const auto &x : st )
    {
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`

	100 4 16
				`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())
	//https://atcoder.jp/contests/abc165/tasks/abc165_f
	//https://www.dropbox.com/sh/nx3tnilzqz7df8a/AAA0887IQFx5BcrZcrpRD7uga/ABC165/F?dl=0&subfolder_nav_tracking=1

	n := nextInt()
	a := nextInt()
	b := nextInt()

	ans := 0

	for m := 0; m <= n/10000; m++ {
		for s := 0; m*10000+s*1000 <= n; s++ {
			if m+s <= b && s < 10 {
				for h := 0; m*10000+s*1000+h*100 <= n; h++ {
					if m+s+h <= b && h < 10 {
						for t := 0; m*10000+s*1000+h*100+t*10 <= n; t++ {
							if m+s+h+t <= b && t < 10 {
								for o := 0; m*10000+s*1000+h*100+t*10+o <= n; o++ {
									if a <= m+s+h+t+o && m+s+h+t+o <= b && o < 10 {
										ans += m*10000 + s*1000 + h*100 + t*10 + o
									}
								}
							}
						}
					}
				}
			}
		}
	}

	//	fmt.Fprintln(out, "[DEBUG]]", a)
	fmt.Fprintln(out, ans)
}

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

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}


Measured memory_bytes: 640
x, y, z, K = map(int, input().split())

A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

temp = []
for a in A:
	for b in B:
		temp.append(a+b)

temp = sorted(temp, reverse=True)
temp = temp[:K]

ans = []
for c in C:
	for num in temp:
		ans.append(num+c)

ans = sorted(ans, reverse=True)
for i in range(K):
	print(ans[i])

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int h,w; cin>>h>>w;
	vector<string>a(h); for(auto&i:a)cin>>i;
	for(int i=0;i<h;++i){
		bool any=false;
		for(int j=0;j<w;++j){
			if(a.at(i).at(j)=='#')any=true;
		}
		if(!any)for(int j=0;j<w;++j){
			a.at(i).at(j)='@';
		}
	}
	for(int i=0;i<w;++i){
		bool any=false;
		for(int j=0;j<h;++j){
			if(a.at(j).at(i)=='#')any=true;
		}
		if(!any)for(int j=0;j<h;++j){
			a.at(j).at(i)='@';
		}
	}
	for(int i=0;i<h;++i){
		int cnt=0;
		for(int j=0;j<w;++j){
			if(a.at(i).at(j)=='@')++cnt;
			else cout<<a.at(i).at(j);
		}
		if(cnt!=w)cout<<"\n"s;
	}
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>

using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//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())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}



int main(){
    int a[100000];
    int N; cin >> N;
    REP(i,N) cin >> a[i];

    map<int, int> mp;
    for(int i= 0; i < N ; ++i){
        mp[a[i]]++;
    }
    int ans=0;
    for(auto p:mp){
        int x = p.first;
        int n = p.second;
        if ( n< x) ans += n;
        else{
            ans+=n-x;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5120
K = int(input())


def f(n):
    return n / sum([int(s) for s in str(n)])


ans = [1]
for k in range(K - 1):
    min_f_val, next_snuke = float('inf'), None
    n = str(ans[-1] + 1)

    for i in range(len(n)):
        for x in range(int(n[i]), 10):
            X = n[:i] + str(x) + '9' * (len(n) - i - 1)
            f_val = f(int(X))

            if f_val < min_f_val:
                next_snuke = int(X)
                min_f_val = f_val

    ans.append(next_snuke)

print(*ans, sep='\n')


Measured memory_bytes: 3188
mod = 10**9+7
N,K = map(int,input().split())
ans= 0
for i in range(N+2):
    if i < K:
        continue
    else:
        a = (0+i-1)*i//2
        b = (N-i+1+N)*i//2
        ans += (b-a+1)%mod
        ans %= mod
print(ans)

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 100001
#define int ll
int N,A[maxn];
int ss[maxn];

int32_t main(){
	fast;
	
	cin>>N;
	FOR(i,0,N) cin>>A[i];
	
	if (A[0] >= 1){
		if (N == 0 && A[0] == 1) cout<<1;
		else cout<<-1;
		return 0;
	}
	
	
	ss[N] = A[N];
	DEC(i,N-1,0) ss[i] = ss[i+1] + A[i];
	
	int num = 1; //num of nodes;
	int ans = 0;
	
	FOR(i,1,N){
		if (num < 0){
			cout<<-1;
			return 0;
		}
		ans += num;
		
		num = num * 2 - A[i];
		num = min(num,ss[i] - A[i]);
	}
	if (num < 0){
		cout<<-1;
		return 0;
	}
	ans += num;

	cout<<ans + ss[0];
	
}



Measured memory_bytes: 5200
# ABC100 C - *3 or /2
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N):
    x = 0
    t = 0
    x = A[i]
    while x%2==0:
        x = x//2
        t += 1
    ans += t
print(ans)

Measured memory_bytes: 4148
n = int(input())
rgb = list(input())
rc, gc, bc = rgb.count('R'), rgb.count('G'), rgb.count('B')
c=rc*gc*bc
for i in range(n-2):
    for j in range(i+1, n-1):
        if rgb[i]!=rgb[j]:
            k = 2*j-i
            if k <= n-1:
                if rgb[k]!=rgb[i] and rgb[k]!=rgb[j]:
                    c-=1
print(c)

Measured memory_bytes: 9224
import Control.Applicative
import Data.Function
import Control.Monad
import Data.List
import Data.Char

f 'a' = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
f 'b' = [0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
f 'c' = [0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
f 'd' = [0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
f 'e' = [0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
f 'f' = [0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
f 'g' = [0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
f 'h' = [0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
f 'i' = [0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
f 'j' = [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
f 'k' = [0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
f 'l' = [0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
f 'm' = [0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0]
f 'n' = [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0]
f 'o' = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0]
f 'p' = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0]
f 'q' = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0]
f 'r' = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0]
f 's' = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0]
f 't' = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0]
f 'u' = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0]
f 'v' = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0]
f 'w' = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0]
f 'x' = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0]
f 'y' = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0]
f 'z' = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
f _   = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

main :: IO ()
main = do
    s <- getContents
    let result = foldr1 (zipWith (+)) $ map f $ map toLower s
    mapM_ putStrLn $ zipWith (\x y -> x : " : " ++ (show y)) "abcdefghijklmnopqrstuvwxyz" result


Measured memory_bytes: 6920
import java.util.Scanner;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String sentence = "";
		while(sc.hasNext()) {
			sentence += sc.nextLine();
		}

		// アルファベット数格納用
		TreeMap<Character, Integer> countAlph = new TreeMap<>();
		char alphabet = 'a';
		final int ALPHABET_SIZE = 'z' - 'a';
		for(int i=0; i<=ALPHABET_SIZE; i++) {
			countAlph.put(alphabet, 0);
			alphabet++;
		}

		for(int i=0; i<sentence.length(); i++) {
			if(sentence.charAt(i) == ' ') continue;
			String checkChar = String.valueOf(sentence.charAt(i));
			if(Character.isUpperCase(checkChar.charAt(0))) checkChar = checkChar.toLowerCase();
			Pattern p = Pattern.compile("[a-z]");
			Matcher m = p.matcher(checkChar);
			if(m.find()) countAlph.put(checkChar.toCharArray()[0], countAlph.get(checkChar.toCharArray()[0]) + 1);
		}

		// 出力
		alphabet = 'a';
		for(int i=0; i<=ALPHABET_SIZE; i++) {
			System.out.println(String.valueOf(alphabet) + " : " + countAlph.get(alphabet));
			alphabet++;
		}

		sc.close();

	}

}


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

int main() {
  int N,Z=0,B=0;
  cin>>N;
  int64_t T,A,K;
  cin>>T>>A;
  A*=1000;
  T*=1000;
  cin>>K;
  Z=abs(A-T+6*K);
  for(int i=1;i<N;i++){
    int64_t k;
    cin>>k;
    if(abs(A-T+6*k)<Z){
      Z=abs(A-T+6*k);
      B=i;
    }
  }
  B++;
  cout<<B<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int n; string s; cin >>n >>s;
  int cnt=0,ans=0;
  for(int i=0; i<n; i++) if(s[i]=='R') cnt++;
  for(int i=0; i<cnt; i++) if(s[i]=='W') ans++;
  cout <<ans;
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  solve();
return 0;}

Measured memory_bytes: 3772
def resolve():
    N = input()

    ans = ""
    if N[-1] in ("2","4","5","7","9"):
        ans = "hon"
    if N[-1] in ("0","1","6","8"):
        ans = "pon"
    if N[-1] == "3":
        ans = "bon"
    print(ans)

if __name__ == "__main__":
    resolve()

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

int A, B;

int main()
{
    cin >> A >> B;

    int ans = 0;
    if (A >= 13) {
        ans = B;
    } else if (A >= 6) {
        ans = B / 2;
    } else {
        ans = 0;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

#define reps(i, n, m) for (int i = (int) (n); i < (int) (m); i++)
#define rep(i, n) reps(i, 0, (n))
#define all(v) (v).begin(), (v).end()

int main() {
    int q; cin >> q;
    multimap<string, int> m;
    while (q--) {
        int a; cin >> a;
        if (a == 0) {
            string k;
            int x; cin >> k >> x;
            m.insert({k, x});
        } else if (a == 1) {
            string k; cin >> k;
            auto b = m.lower_bound(k);
            auto e = m.upper_bound(k);
            for (auto i = b; i != e; i++) {
                cout << (*i).second << endl;
            }
        } else if (a == 2) {
            string k; cin >> k;
            m.erase(k);
        } else {
            string l, r; cin >> l >> r;
            auto b = m.lower_bound(l);
            auto e = m.upper_bound(r);
            for (auto i = b; i != e; i++) {
                cout << (*i).first << " " << (*i).second << endl;
            }
        }
    }
}


Measured memory_bytes: 24864
#!/usr/bin/env python3
#
# まず1次元で考える
#   |  |   |  |
#   a  b   c  d
# とあるとき、長さの合計は
#  (b-a) + (c-a) + (d-a) + (c-b) + (d-b) + (d-c)
# = 3d + c - b - 3a
# これは、各点の座標を、<自分より左にある点の数> - <自分より右にある点の数> でかけたものの和である
#
# もとめる面積は X座標、Y座標それぞれについて蒸気を計算した積

MOD = 1000000007

def len_sum(Xs):
    size = len(Xs)
    ret = 0
    n = len(Xs) - 1
    # 負の値にMODをとることを防ぐため、座標の大きい点から計算する
    for x in reversed(Xs):
        ret += n * x
        ret %= MOD
        n -= 2
    return ret

def solve(Xs, Ys):
    x_len_sum = len_sum(Xs)
    y_len_sum = len_sum(Ys)
    return (x_len_sum * y_len_sum) % MOD

N, M = map(int, input().split())
Xs = list(map(int, input().split()))
Ys = list(map(int, input().split()))
print(solve(Xs, Ys))


Measured memory_bytes: 18624
import sys

N = int(input())
def c(s):
  return s[0] == s[1]
DS = [c(input().split()) for _ in range(N)]


for i in range(2, N):
  if DS[i-2] and DS[i-1] and DS[i]:
    print('Yes')
    sys.exit()

print('No')


Measured memory_bytes: 9168
while 1:
    l = [x for x in input()]
    if(l[0] == "-"):
        break
    num = int(input())
    a = []
    b = []
    for i in range(num):
        a.append(int(input()))
    for j in a:
        b = l[:j]
        del l[:j]
        l.extend(b)
        del b[:]
    for i in l:
        print(i,end ="")
    else:
        print()


Measured memory_bytes: 5620
#include <stdio.h>
int main(void){


  while(1){
  int x,y;
  scanf("%d %d",&x,&y);
      if(x == 0&&y==0) break;
 
  if(x<=y){
printf("%d %d\n",x,y);

}
else if(y<x){
printf("%d %d\n",y,x);
    
}
}
return 0;
}



Measured memory_bytes: 2100
//
//AtCoder Beginner Contest 079
//A
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>
#include <numeric>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    string n;
    cin >> n;
    char prv = 0;
    int cnt = 0;
    bool isOK = false;
    REP(i, n.size()){
        if (prv == n[i]){
            cnt++;
            if (cnt>=3) isOK=true;
        }else{
            cnt = 1;
        }
        prv = n[i];
    }
    if (isOK) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    vector<pair<char,int>> t(26);
    int x = 0;
    for (char a = 'a'; a <= 'z'; a++){
        t[x] = make_pair(a,0);
        x++;
    }
    
    for (int i = 0; i < s.size(); i++){
        for (int j = 0; j < 26; j++){
            if (s[i] == t[j].first){
                t[j].second = 1;
                break;
            }
        }
    }
    for (int i = 0; i < 26; i++){
        if (t[i].second == 0){
            cout << t[i].first << endl;
            return 0;
        }
    }

    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
/*

   Question Link :-   https://atcoder.jp/contests/abc134/tasks/abc134_c
   
*/


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long

int MOD = 1000000007;

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

	int N;
	cin >> N;

	vector<pair<int,int> > A(N);

	for (int i = 0; i < N; i++)
	{
		cin >> A[i].first;
		A[i].second = i;
	}
	
	sort(A.rbegin(), A.rend());
	
	for (int i = 0; i < N; i++)
	{
		if (A[0].second == i)
		{
			cout << A[1].first << endl;
		}
		else
		{
			cout << A[0].first << endl;
		}
	}
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
int h,w;
int arr[55][55];
int ret[55][55];
int dx[8]={-1,0,1,-1,1,-1,0,1};
int dy[8]={1,1,1,0,0,-1,-1,-1};
void f(int y,int x){
	int &r = ret[y][x];
	r = 0;
	for(int i=0; i<8; i++){
		int yy = y+dy[i];
		int xx = x+dx[i];
		r+=arr[yy][xx];
	}
}
int main(){
	memset(ret,-1,sizeof(ret));
	cin>>h>>w;
	for(int i=1; i<=h; i++){
		string s;
		cin>>s;
		for(int j=0; s[j]; j++){
			if(s[j]=='#') arr[i][j+1] = 1;
		}
	}
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w; j++){
			if(arr[i][j]==0) f(i,j);
		}
	}
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w; j++){
			if(ret[i][j]==-1) cout<<'#';
			else cout<<ret[i][j];
		}
		cout<<'\n';
	}
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
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; }
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound //[2,4)=lb(4)-lb(2)

ll K;
vector<ll> all;

void rec(ll n)
{
   for (ll i=-1;i<=1;i++)
   {
     if (n%10+i>=0 && n%10+i<=9)
     {
       if (10*n + n%10+i>0)
       {
         all.push_back(10*n + n%10+i);
         rec(10*n + n%10+i);
         if (10*n + n%10+i >= 3500000000) return;
       }
     }
   }
}
   
int main()
{
  cin>>K;
  for (ll i=1;i<=9;i++)
  {
    all.push_back(i);
    rec(i);
  }
  
  sort(all.begin(),all.end());
  cout<<all[K-1]<<endl;
}

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


int tmp[2] = {16,1};
string s[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};

int hoge[8][3] = {{0,0,0},{0,0,255},{0,255,0},{0,255,255},{255,0,0},
		  {255,0,255},{255,255,0},{255,255,255}};

int to_ten(string s){
  int ans=0;
  for(int i=0; i<2; i++){
    if(s[i] == 'a') ans += 10*tmp[i];
    else if(s[i] == 'b') ans += 11*tmp[i];
    else if(s[i] == 'c') ans += 12*tmp[i];
    else if(s[i] == 'd') ans += 13*tmp[i];
    else if(s[i] == 'e') ans += 14*tmp[i];
    else if(s[i] == 'f') ans += 15*tmp[i];
    else ans += stoi(s.substr(i,1))*tmp[i];
  }
  return ans;
}

double d(string r,string g,string b,int i){
  double ans = 0;
  ans += (to_ten(r) - hoge[i][0]) * (to_ten(r) - hoge[i][0]);
  ans += (to_ten(g) - hoge[i][1]) * (to_ten(g) - hoge[i][1]);
  ans += (to_ten(b) - hoge[i][2]) * (to_ten(b) - hoge[i][2]);
  return ans;
}

int main(){


  while(1){
    string in; cin >> in;
    if(in == "0") break;
    string r = in.substr(1,2);
    string g = in.substr(3,2);
    string b = in.substr(5,2);

    double min = (int)1e+308;
    int index=100;
    for(int i=0; i<8; i++){
      if(d(r,g,b,i) < min ){
	index = i;
	min = d(r,g,b,i);
      }
      //   cout  << d(r,g,b,i) << " ";
    }
    cout << s[index] << "\n";
  }


}

Measured memory_bytes: 3012
from collections import Counter


def main():
    n = int(input())
    cnt = Counter()
    ans = 0
    for i in range(n):
        s = "".join(sorted(input()))
        if cnt[s] == 0:
            cnt[s] = 1
        else:
            ans += cnt[s]
            cnt[s] += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 22372
/*
 *  Created on: 31 / 5 / 2020
 *  Author:     Eslam Waheed
 */
#include <bits/stdc++.h>
//#include <bits/BIGINT.h>
//#include <bits/Int128.h>
using namespace std;

//#define _CRT_SECURE_NO_WARNINGS
//#define __USE_MINGW_ANSI_STDIO
#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define dd   double
#define ld   long dd
#define ss   string

#define pb      push_back
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n);
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   (ll)(s.size())
#define endl    '\n'

#define loop(i,m,n)  for(ll i=m;i<n;i++)
#define test(t)      while(t--)

//ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

//const ld PI = acos(-1);
//const ll mod = 1e15 + 7;
//__int128
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
int main()
{
    //stp(0)
    Eslam__Waheed
        ll n; cin >> n;
    vector<ll>v(n);
    for (auto& it : v)
    {
        cin >> it;
    }
    sort(all(v));
    ll ans = 1;
    for (auto a : v)
    {
        if (a == 0)
        {
            cout << 0;
            return 0;
        }

        if (ans > LLONG_MAX / a)
        {
            cout << "-1\n";
            return 0;
        }
        ans *= a;
    }
    if (ans > (ll)1e18)
    {
        cout << -1;
        return 0;
    }
    cout << ans;
}
   

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

#define ll long long
#define ull unsigned long long

#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

bool isPalindrome(string s) {
    string t(s.rbegin(), s.rend());
    return s == t;
}

int main(void) {
    string a;
    cin >> a;
    if(a[0] == '7' || a[1] == '7' || a[2] == '7') puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3628
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()
AB = [LIST() for _ in range(N)]

cnt = 0
for A, B in AB[::-1]:
	if (A+cnt)%B != 0:
		cnt += B - (A+cnt)%B

print(cnt)



Measured memory_bytes: 30228
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;

int gcd(int a, int b) {
  return b != 0 ? gcd(b, a % b) : a;
}
ll lcm(ll a,ll b) {
  return a * b / gcd(a, b);
}int main() {
    int N,M;cin>>N>>M;
    vi a(N);
    for (int i = 0; i < N; i++){
        cin>>a[i];
        a[i]/=2;
    }
    int LCM=a[0];
    for (int i = 1; i < N; i++){
        LCM=lcm(LCM,a[i]);
        if(LCM>M){
            cout<<0<<endl;
            return 0;
        }
    }
    for (int i = 0; i < N; i++){
        if(LCM/a[i]%2==0){
            cout<<0<<endl;
            return 0;
        }
    }
    int ans=(M/LCM+1)/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 3664
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<list>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

ll n;
string s;

int main() {
   cin >> n;
   cin >> s;
   char a = s[0];
   int cnt = 1;
   for (int i = 0; i < n-1; i++)
   {
	  if (s[i + 1] != a) {
		 cnt++;
		 a = s[i + 1];
	  }
   }
   cout << cnt << endl;
}

Measured memory_bytes: 512
#include <stdio.h>

void init(int*, int);
int find(int*, int);
unsigned char same(int*, int, int);
void comb(int*, int, int);

int main(int argc, char **argv){
	int inputx, inputy;
	int par[12];
	init(par, 12);
	par[3] = par[5] = par[7] = par[8] = par[10] = par [12] = 1;
	par[6] = par[9] = par[11] = 4;
	
	(void)scanf("%d", &inputx);
	(void)scanf("%d", &inputy);
	
	if(same(par, inputx, inputy)){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
}


void init(int *par, int n){
	for(int i = 0; i < n; i++) par[i] = i;
}

int find(int *par, int x){
	if(par[x] == x){
		return x;
	}else{
		return par[x] = find(par, par[x]);
	}
}

unsigned char same(int *par, int x,int y){
	return find(par, x) == find(par, y);
}

void comb(int *par, int x, int y){
	par[x] = find(par, x);
	par[y] = find(par, y);
	if(par[x] == par[y]) return;
	
	par[x] = y;
}

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

int main(void) {
	double a;
	double b;
	scanf("%lf", &a);
	scanf("%lf", &b);
	if (a > b) {
		printf("GREATER");
	}
	else if (a < b) {
		printf("LESS");
	}
	else {
		printf("EQUAL");
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

int main(){
  string s;
  cin >> s;

  int l = s.size();

  REP(i, l - 1){
    if(s[i + 1] == s[i]){
      cout << i + 1 << " " << i + 2 << endl;
      return 0;
    }
  }
  if(l == 2){
    cout << "-1 -1" << endl;
    return 0;
  }
  else{
    REP(i, l - 2){
      if(s[i] == s[i + 2]){
        cout << i + 1 << " " << i + 3 << endl;
        return 0;
      }
    }
    cout << "-1 -1" << endl;
    return 0;
  }

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  	int a[5];
  	for(int i=1;i<=5;i++) cin>>a[i-1];
  sort(a,a+5);
  int k;
  cin>>k;
  if(a[4]-a[0]>k) cout<<":(";
  else cout<<"Yay!";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

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

  vector<ll> L(N+1);
  L[0] = 2;
  L[1] = 1;
  for(int i = 2; i <= N; i++) {
    L[i] = L[i-1] + L[i-2];
  }
  cout << L[N] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
bool check(int area)
{
	for(int i=1;2*i*i+2*i<=area;i++)if(i<area)
	{
		if((area-i)%(2*i+1)==0)return true;
	}
	return false;
}
int main()
{
	int n;
	cin >> n;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		int k;
		cin >> k;
		if(!check(k))ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

using ll =  long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T& a, T b) { a = a + b; }

using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}

	template<typename T>
	void Dump(T t) {
		std::cout << t << std::endl;
	}

	void Yes(bool q) {
		std::cout << ((q) ? "Yes" : "No") << std::endl;
	}

	void YES(bool q) {
		std::cout << ((q) ? "YES" : "NO") << std::endl;
	}
}


int main() {

	int n;
	std::cin >> n;
	std::vector<int> l(n);
	rep(i, n) std::cin >> l[i];

	std::sort(allof(l));

	int max_len = l[n - 1];
	int sum_len = 0;
	rep(i, n - 1) sum_len += l[i];

	::Yes(max_len < sum_len);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
    int n, b1[3][10], b2[3][10], b3[3][10], b4[3][10];
    int b, f, r, v;

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 10; j++){
            b1[i][j] = b2[i][j] = b3[i][j] = b4[i][j] = 0;
        }
    }

    cin >> n;
    for(int i = 0; i < n; i++){
        scanf("%d %d %d %d", &b ,&f ,&r ,&v);
        
        switch (b){
            case 1:
                b1[f - 1][r - 1] += v;
                break;
            case 2:
                b2[f - 1][r - 1] += v;
                break;    
            case 3:
                b3[f - 1][r - 1] += v;
                break;
            case 4:
                b4[f - 1][r - 1] += v;
                break;
        }
    }
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 10; j++){
            printf(" %d",b1[i][j]);
        }
        printf("\n");
    }
    printf("####################\n");
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 10; j++){
            printf(" %d",b2[i][j]); 
        }
        printf("\n");
    }
    printf("####################\n");
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 10; j++){
            printf(" %d",b3[i][j]);   
        }
        printf("\n");
    }
    printf("####################\n");
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 10; j++){
            printf(" %d",b4[i][j]);
        }printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3152
N = int(input()) 
A = list(map(int, input().split()))

biggest = 0
humidai = 0


for iter in range(N):
    if iter == 0:
        continue

    if A[iter-1] > A[iter]:
        biggest = A[iter-1]
        humidai += A[iter-1] - A[iter]
        A[iter] += A[iter-1] - A[iter]
        # print(humidai)


    if A[iter-1] < A[iter]:
        biggest = A[iter]


print(humidai)

Measured memory_bytes: 32376
s = int(input())
slist =[s]
for i in range(1000001):
  if s%2== 0:
    s = s//2
  else:
    s = 3*s + 1
  slist.append(s)
  if len(slist) != len(set(slist)):
    print(i+2)
    break

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int i,j,k,x,y,z,l,m,n,count1=0,count2=0;
void A(void);
void B(void);
void C(void);
void D(void);
void E(void);
void F(void);

int main(void){
    A();
}

void A(){
    int a,n;
    cin>>n;
    a=n%10;
    if(a==2||a==4||a==5||a==7||a==9){
        cout<<"hon"<<endl;
    }else if(a==3){
        cout<<"bon"<<endl;
    }else{
        cout<<"pon"<<endl;
    }
}

Measured memory_bytes: 3636
N, M = map(int, input().split())
mat = [[0 for _ in range(N)] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    mat[a][b] += 1
    mat[b][a] += 1
for i in range(N):
    cnt = 0
    for j in range(N):
        cnt += mat[i][j]
    print(cnt)

Measured memory_bytes: 3064