akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;

int main() {
    ll H, W;
    cin >> H >> W;
    ll sh, sw, gh, gw;
    cin >> sh >> sw;
    cin >> gh >> gw;
    sh--;
    sw--;
    gh--;
    gw--;

    // 道の一覧
    set<pair<ll, ll>> roads;
    for (ll h = 0; h < H; h++) {
        for (ll w = 0; w < W; w++) {
            char c;
            cin >> c;
            while (c != '.' && c != '#') {
                cin >> c;
            }
            if (c == '.') {
                roads.insert(make_pair(h, w));
            }
        }
    }

    vector<vector<ll>> distmap(H, vector<ll>(W, INF));
    vector<vector<bool>> done(H, vector<bool>(W, false));
    deque<pair<ll, ll>> bfs;
    bfs.push_front(make_pair(sh, sw));
    distmap[sh][sw] = 0;
    while (!bfs.empty()) {
        auto src = bfs.front();
        bfs.pop_front();
        ll h = src.first;
        ll w = src.second;
        if (done[h][w]) {
            continue;
        }
        done[h][w] = true;
        for (ll y = h - 2; y <= h + 2; y++) {
            for (ll x = w - 2; x <= w + 2; x++) {
                pair<ll, ll> dest = make_pair(y, x);
                if (y >= 0 && y < H && x >= 0 && x < W && roads.count(dest)) {
                    if (abs(x - w) + abs(y - h) == 1 && distmap[y][x] > distmap[h][w]) {
                        distmap[y][x] = distmap[h][w];
                        bfs.push_front(dest);
                    } else if (distmap[y][x] == INF) {
                        distmap[y][x] = distmap[h][w] + 1;
                        bfs.push_back(dest);
                    }
                }
            }
        }
    }
    if (distmap[gh][gw] == INF) {
        cout << -1 << endl;
    } else {
        cout << distmap[gh][gw] << endl;
    }
}


Measured memory_bytes: 43012
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f, MOD = 1000000007;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*-----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  int ans = 0;
  FOR(i, 1, n) {
    if (a[i] == a[i - 1]) {
      a[i] = 10000;
      ++ans;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(ll)(n);++i)
#define _repe3(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(ll)(b)-1;i>=(ll)(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define _rrepe2(i,n) for(ll i=(ll)(n);i>=0;i--)
#define _rrepe3(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)
#define rrepe(...) _overload3(__VA_ARGS__,_rrepe3,_rrepe2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

ll a;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> a;
    solve();
}

// 1 <= a <= 10
// a は整数である。

// ll a
// 値 a + a^2 + a^3 を整数として出力せよ。
void solve(){
    cout<<a+a*a+a*a*a<<endl;
}


Measured memory_bytes: 3608
import itertools
import sys

N, M, R = map(int, input().split())
r = [int(i) for i in input().split()]
r.sort()
a = [[sys.maxsize for j in range(N)] for i in range(N)]
for i in range(M):
	A, B, C = map(int, input().split())
	a[A - 1][B - 1] = C
	a[B - 1][A - 1] = C
for i in range(N):
	a[i][i] = 0
for i in range(N):
	for j in range(N):
		if a[j][i] == sys.maxsize:
			continue
		for k in range(N):
			if a[i][k] == sys.maxsize:
				continue
			a[j][k] = min(a[i][k] + a[j][i], a[j][k])
ans = sys.maxsize
for i in itertools.permutations(r):
	b = 0
	j = 1
	while j < R:
		b += a[i[j - 1] - 1][i[j] - 1]
		j += 1
	ans = min(b, ans)
print(ans)

Measured memory_bytes: 47192
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var num = Input.num;
        var adj = Enumerable.Repeat(0, num).Select(v => new List<int>()).ToArray();
        for(var i = 0; i < num-1; i++)
        {
            var inp = Input.ar;
            adj[inp[0] - 1].Add(inp[1] - 1);
            adj[inp[1] - 1].Add(inp[0] - 1);
        }
        var ct = new[] { 0, 0 };
        var th = new bool[num];
        th[0] = true;
        th[num - 1] = true;
        var que = new Queue<Pair>();
        que.Enqueue(new Pair(0, 0));
        que.Enqueue(new Pair(num-1, 1));
        while (que.Count != 0)
        {
            var p = que.Dequeue();
            ct[p.Item2]++;
            foreach (var ad in adj[p.Item1])
                if (!th[ad])
                {
                    th[ad] = true;
                    que.Enqueue(new Pair(ad, p.Item2));
                }
        }
        WriteLine(ct[0] > ct[1] ? "Fennec" : "Snuke");
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] twodim(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] twodimL(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 31112
s = input()

ans =[]

for i in range(len(s)-2):
  ans.append(int(s[i] +s[i+1] +s[i+2]))
  
num =[]

for i in range(len(ans)):
  num.append(abs(753-int(ans[i])))
               
num.sort()
               
print(num[0])



Measured memory_bytes: 3060
def get_score(day, contest, prev_list, loss_list, satisfied_matrix):
    plus = satisfied_matrix[day][contest]
    minus = 0
    for type, prev in enumerate(prev_list):
        if type == contest:
            continue
        spend = day - prev
        minus += loss_list[type] * spend

    return plus - minus



days = int(input())
loss_list = list(map(int, input().split()))
satisfied_matrix = [list(map(int, input().split())) for _ in range(days)]

prev_list = [-1] * 26

ans = []
for day in range(days):
    best_contest = 0
    best_score = 0
    for contest in range(26):
        score = get_score(day, contest, prev_list, loss_list, satisfied_matrix)
        if score > best_score:
            best_contest = contest
            best_score = score

    ans.append(best_contest+1)
    prev_list[best_contest] = day

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


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

int main()
{
  int h,w;
  string s;

  scanf("%d %d",&h,&w);

  cout << string(w+2,'#') << endl;

  for (int i=0;i<h;i++) {
    cin >> s;
    cout << "#" << s << "#" << endl;
  }

  cout << string(w+2,'#') << endl;
  
  return 0;
}


Measured memory_bytes: 256
N = int(input())
h_list = list(map(int, input().split()))

def split_list(_list):
    ret_list = []
    tmp_list = []
    for i in range(len(_list)):
        if _list[i] == 0:
            if len(tmp_list) != 0:
                ret_list.append(tmp_list)
                tmp_list = []

        else:
            tmp_list.append(_list[i])

    if len(tmp_list) != 0:
        ret_list.append(tmp_list)
    return ret_list

def give_min_water(_list):
    _min = min(_list)
    _list = [(num - _min) for num in _list]
    return _min, _list

ret = 0
new_list = split_list(h_list)
#print(new_list)
while len(new_list) != 0:
    new_list2 = []
    for _list in new_list:
        tmp_count, tmp_list = give_min_water(_list)
        # print(tmp_count)
        # print(tmp_list)
        ret += tmp_count
        tmp_list = split_list(tmp_list)
        if (len(tmp_list) != 0):
            for _list2 in tmp_list:
                new_list2.append(_list2)
    new_list = new_list2
print(ret)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    int y = sc.nextInt();
    int res[] = new int[n-1];
    Arrays.fill(res, 0);
    ArrayList<Road> list = new ArrayList<>();
    for (int i = 1; i < n; i++) {
      for (int j = i+1; j <= n; j++) {
        list.add(new Road(i, j, j-i));
      }
    }
    for (Road e: list) {
      e.len = Math.min(e.len, Math.abs(x-e.st)+1+Math.abs(y-e.en));
      res[e.len-1]++;
    }
    for (int i = 0; i < n-1; i++) {
      System.out.println(res[i]);
    }
    sc.close();
  }

  static class Road {
    int st, en, len;
    Road (int st, int en, int len) {
      this.st = st; this.en = en; this.len = len;
    }
  }
}

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

#define fastio  ios::sync_with_stdio(false); cin.tie(0);

class BeingZero{
    public:
        ll minCost(vector<int> a, int k){
            ll n = a.size();
            int dp[n];
            dp[0] = 0;
            dp[1] = abs(a[1]-a[0]);
            for(int i=2;i<n;i++){
                dp[i] = INT_MAX;
                for(int j=1;i-j>=0 && j<=k;j++)
                    dp[i] = min( dp[i], abs(a[i]-a[i-j]) + dp[i-j]);
            }
            return dp[n-1];
        }
};

int main() {
    fastio;
    BeingZero bz;
    int n, k;
    while(cin>>n>>k){
        if(n==-1) break;
        vector<int> v(n);
        for(int i=0;i<n;i++)
            cin>>v[i];
        cout<<bz.minCost(v, k)<<"\n";
    }
    return 0;
}



Measured memory_bytes: 4512
#![allow(unused_macros)]
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(unused_imports)]
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
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)*}
    };
}

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

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

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

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => (::std::cmp::max($x, max!( $($y),+)));
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => (::std::cmp::min($x, min!( $($y),+)));
}

// solution 
use std::cmp;
use std::collections::{HashMap, HashSet, BTreeMap, BTreeSet};
fn main() {
    input! {
        N: usize,
        V: [i64; N],
        C: [i64; N],
    }

    let mut sum = 0;
    for ind in 0..N {
        let tot = V[ind] - C[ind];
        if tot > 0 {
            sum += tot;
        }
    }
    println!("{}", sum);

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, K, L;
int par[2][200010];

int root(int idx, int x) {
  return par[idx][x] == x ? x : par[idx][x] = root(idx, par[idx][x]);
}

void merge(int idx, int x, int y) {
  x = root(idx, x);
  y = root(idx, y);
  if (x == y) return;
  par[idx][y] = x;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> K >> L;
  for (int i = 0; i < N; i++) {
    par[0][i] = par[1][i] = i;
  }
  for (int i = 0; i < K; i++) {
    int p, q;
    cin >> p >> q;
    p--; q--;
    merge(0, p, q);
  }  
  for (int i = 0; i < L; i++) {
    int r, s;
    cin >> r >> s;
    r--; s--;
    merge(1, r, s);
  }
  map<pii, int> mp;
  for (int i = 0; i < N; i++) {
    mp[pii(root(0, i), root(1, i))]++;
  }
  for (int i = 0; i < N; i++) {
    cout << mp[pii(root(0, i), root(1, i))] << " \n"[i + 1 == N];
  }

  return 0;
}

Measured memory_bytes: 13568
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int w = 0;
        int r = 0;
		String s = sc.next();      
        for(int i=0;i<a;i++){if(s.charAt(i)=='R'){r++;}
                            }   
        int ans = r;     
        for(int i=0;i<a;i++){if(s.charAt(i)=='W'){w++;}
                             else{r--;}
                            ans=Math.min(ans,Math.max(w,r));
                            }        
		System.out.println(ans);
	}
}


Measured memory_bytes: 40612
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int,int> pii;
typedef vector<lli> vi;
typedef vector<vi> vvi;
#define MAXN 3005
const lli limit= 1000000000000000000ll;
int main(){__
	lli n;
	cin >> n;
	lli tot = 0ll;
	for(lli i= 2; i*i <= n; i++){
		lli pot = 0;
		while(n%i == 0){
			n/=i;
			pot++;
		}
		if(pot){
			lli ans = 0ll;
			for(lli x = 1; true; x++){
				if((x*(x+1))/2 > pot) break;
				ans = x;
			}
			tot+=ans;
		}
	}
	if(n > 1){
		tot++;
	}
	cout << tot << endl;
	return 0;
}


Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int N = int.Parse(ReadLine());
            int ans = 0;int Ans = 1;

            for (int i = 1; i <= N; i++)
            {
                int a = i;
                int cnt = 0;
                while (true)
                {
                    if (a % 2 == 0)
                    {
                        a /= 2;
                        cnt++;
                    }
                    else
                    {
                        break;
                    }
                }
                if (cnt>ans)
                {
                    ans = cnt;
                    Ans = i;
                }
            }
            WriteLine(Ans);
        }
    }
}


Measured memory_bytes: 13140
def gcd(a,b):
    #a=min(a,b)
    #b=max(a,b)
    while b:
        a,b= b, a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)
T=[]
N=int(input())
for i in range(N):
    T.append(int(input()))

ans=1
for t in T:
    ans=lcm(ans, t)

print(int(ans))

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

// Problem https://atcoder.jp/contests/abc059/tasks/arc072_a
// Reference https://atcoder.jp/contests/arc072/submissions/2161263
// comment 最初の a[0] を正か負かを決めると芋づる式に決まります
// comment from https://qiita.com/drken/items/fd4e5e3630d0f5859067#%E7%AC%AC-9-%E5%95%8F--abc-049-c---daydream-300-%E7%82%B9

// 今までの合計が正になるように修正するコスト
long long plusCost(long long &sum){
    long long cost;
    cost = 0;
    if(sum >= 1){
        cost = 0; // 今までの合計が正ならば敢えて修正する必要は無い
    }
    else{   
        // sumが-Xなので+1に
        cost = abs(sum); // まず0にするのに必要なコスト
        cost = cost + 1; // +1にするのに必要なコスト
        sum = +1; // これで与えた変数そのものも+1にできる  
    }
    return cost;
}

// 今までの合計が負になるように修正するコスト
long long minusCost(long long &sum){
    long long cost;
    if(sum <= -1){ // sumがすでに負の数なので操作する必要は無い
        cost = 0;  
    }
    else
    {
        cost = (sum - 0) + 1; // sumが正の数ならばまず0に戻すコストその上に-1にするコストが必要 
        sum = -1;
    }
    return cost;
}


// 最初の和を正に取った場合の計算
long long plusSolver(int N,vector<long long> Ai){
    long long result = 0;
    long long  sum;
    sum = Ai[0];
    result = plusCost(sum);
    for(int j=1;j<N;j++){
        int guki=j%2;
        sum = sum + Ai.at(j);
        if(guki == 1){
            // 奇数番目は合計が負の数になる
            result = result + minusCost(sum);
        }
        else
        {
            // 偶数番目は合計が正の数になるようにする
            result = result + plusCost(sum);
        }
    }
    return result;
}

// 最初の数を負にした場合の計算
long long minusSolver(int N,vector<long long> Ai){
    long long result = 0;
    long long  sum;
    sum = Ai[0];
    result = minusCost(sum);
    for(int j=1;j<N;j++){
        int guki=j%2;
        sum = sum + Ai.at(j);
        if(guki == 1){
            // 奇数番目は合計が正の数になる
            result = result + plusCost(sum);
        }
        else
        {
            // 偶数番目は合計が負の数になるようにする
            result = result + minusCost(sum);
        }
    }
    return result;
}

int main(void){
    long long answer;
    int N;
    cin >> N ;
    vector<long long> Ai(N);
    for(int j=0;j<N;j++){
        cin >> Ai.at(j);
    }
    long long plusAns=0;
    long long minusAns=0;
    plusAns = plusSolver(N,Ai);
    minusAns = minusSolver(N,Ai);
    answer = min(plusAns,minusAns);
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 1804
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const long long MOD=1000000007;

// vector<p> cut(M); vector<vector<ll> > v(4);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()), sort(v.rbegin(), v.rend()); //sort
// char '' str ""
int main(void)
{
    int N;cin>>N;int max=0, sum=0;
    vector<int> L;
    for(int i=0; i<N;i++){
      int l; cin>>l;
      sum += l;
      if(max<l) max = l;
    }

    if(max < (sum-max)){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split(' ')))
mabs = abs(a[0])
s = 0
minus = 0
for i in a:
  if i < 0:
    i = abs(i)
    minus += 1
  if i < mabs:
    mabs = i
  s += i
if minus % 2 == 0:
  print(s)
else:
  print(s-2*mabs)

Measured memory_bytes: 14412
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main () {
    int n;
    cin >> n;
    n %= 10;
    if (n==2 || n==4 || n==5 || n==7 || n==9) cout << "hon" << endl;
    else if (n==0 || n==1 || n==6 || n==8) cout << "pon" << endl;
    else cout << "bon" << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100
void push(int,int*);
int pop(int*);
int top;
int main()
{
  int i,top,x,y,c,a;
  int array[101];
  char n[100];
  top=0;
  while(scanf("%s",n)!=EOF){
    if(n[0]=='+'){
      x=pop(array);
      y=pop(array);
      push(x+y,array);
    }
    else if(n[0]=='-'){
      x=pop(array);
      y=pop(array);
      push(y-x,array);
    }
    else if(n[0]=='*'){
      x=pop(array);
      y=pop(array);
      push(x*y,array);
    }
    else {
      c=atoi(n);
      push(c,array);
    }
  }
  printf("%d\n",array[1]);
  return 0;
}

void push(int c,int *array)
{
  top++;
  array[top]=c;
}

int pop(int *array)
{
  top--;
  return array[top+1];
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
  int a, b ;
  cin >> a >> b ;
  int n = b-a ;
  
  cout << n*(n+1)/2-b <<endl ;

  return 0 ;
}


Measured memory_bytes: 256
n = int(input())
c = list(map(int,input().split()))
b = [ 0 for _ in range(n) ]

q = int(input())
r = 0
for _ in range(q):
    [t,x,d] = map(int,input().split())
    if t == 1:   # 収穫
        b[x-1] += d
        if b[x-1] > c[x-1]:
            r = x
            break
    elif t == 2: # 出荷
        b[x-1] -= d
        if b[x-1] < 0:
            r = x
            break

print(r)



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

int main(){
    int h,w,n,sr,sc;
    string s,t,ans="YES";
    cin >> h >> w >> n >> sr >> sc >> s >> t;
    int u,d,l,r;
    u = sr,d = h-sr+1;
    l = sc,r = w-sc+1;

    int vu=0,vd=0,vl=0,vr=0;
    for(int i = 0;i < n;i ++){
        if(s[i]=='U') vu ++;
        if(s[i]=='D') vd ++;
        if(s[i]=='L') vl ++;
        if(s[i]=='R') vr ++;

        if(vu>=u || vd>=d || vl>=l || vr>=r) ans = "NO";

        if(-vd<u-1&&t[i]=='U') vd --;
        if(-vu<d-1&&t[i]=='D') vu --;
        if(-vr<l-1&&t[i]=='L') vr --;
        if(-vl<r-1&&t[i]=='R') vl --;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 776
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt() * 100,b = scanner.nextInt() * 100,c = scanner.nextInt();
		int d = scanner.nextInt(),e = scanner.nextInt(),f = scanner.nextInt();
		int water = 0,sugar = 0;
		for(int i=0;i<=f/a;i++){
			for(int j=0;j<=f/b;j++){
				for(int k=0;k<=f/c;k++){
					for(int l=0;l<=f/d;l++){
						int w = a * i + b * j;
						int s = c * k + d * l;
						if(s * 100 <= w * e && s + w <= f && s * water >= w * sugar){
							water = w;
							sugar = s;
						}
					}
				}
			}
		}
		System.out.println(water + sugar + " " + sugar);
	}

}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pl = pair<ll,ll>;

pl solve()
{
    string s;
    cin >>s;
    int S = s.size();

    ll p=1,q=1;

    int t=0,l=0,r=0;
    while(t<S && s[t]!='.') ++t;
    while(l<S && s[l]!='(') ++l;
    while(r<S && s[r]!=')') ++r;
    // dbg(t); dbg(l); dbg(r);
    rep(_,l-t-1) q*=10;

    ll num = 0;
    rep(i,l)if(isdigit(s[i])) num = num*10+s[i]-'0';

    if(l==r) p = num;
    else
    {
        ll num2 = 0;
        rep(i,r)if(isdigit(s[i])) num2 = num2*10+s[i]-'0';

        ll PW = 1;
        rep(_,r-l-1) PW*=10;
        p = num2 - num;
        q *= (PW-1);
    }

    ll g = __gcd(p,q);
    // dbg(p); dbg(q); dbg(g);
    p /= g;
    q /= g;
    return {p,q};
}

int main()
{
    pl ans = solve();
    cout << ans.fi << "/" << ans.se << endl;
    return 0;
}

Measured memory_bytes: 3176
import numpy as np
from decimal import Decimal

N = int(input())

nums = [Decimal(input()) for _ in range(N)]

two_fives = []


for i, num in enumerate(nums):
    int_converted = int(num * (10**9))
    
    two_div_count = 0
    while int_converted % 2 == 0:
        two_div_count += 1
        int_converted //= 2
    
    five_div_count = 0
    while int_converted % 5 == 0:
        five_div_count += 1
        int_converted //= 5

    two_fives.append((two_div_count,five_div_count))


ok_count = 0

two_five_exists = np.zeros((19,19), dtype=int)

for i in range(N):    
    two_count, five_count = two_fives[i]
    two_count = min(18, two_count)
    five_count = min(18, five_count)
    ok_count += two_five_exists[two_count, five_count]

    two_pair = 18 - two_count
    five_pair = 18 - five_count
    two_five_exists[two_pair:, five_pair:] += 1

print(ok_count)



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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#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++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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


modint ue(ll x, ll a){
    modint tmp=1;
    for(ll i=0; i<a; i++){
        tmp = modint(tmp*modint(x-i));
    }
    return tmp;
}

void solve() {
    ll n, a, b; cin >> n >> a >> b;
    modint X = modint(mod_pow(2, n, mod));
    modint Y = ue(n, a) / fact[a];
    modint Z = ue(n, b) / fact[b];
    ll ans = modint(X-modint(1) - Y - Z);

    cout << ans << endl;
}

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


Measured memory_bytes: 4352
def main():
    num = int(input())
    x_list = list(map(int, input().split()))
    ans = 0

    for i in range(num):
        x = x_list[i]
        while  x%2 == 0:
            ans += 1
            x = x//2

    print(ans)

    
if __name__ == '__main__':
    main()

Measured memory_bytes: 4148
#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(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int a, b;

int main(){
  cin >> a >> b;
  if(a - 2 * b >= 0){
    cout << a - 2 * b <<endl;
  }else{
    cout << 0;
  }
}

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

const int MAX = 1000001;
char p[MAX] = {0};
int a[31],n,x;

void solve(int dp[MAX]){
	
	for(int i=0 ; i < x ; i++ ){
		if( dp[i] ){
			for(int j=0 ; j < n ; j++ ){
				if( i+a[j] <= x ){
					dp[ i + a[j] ] = 1;
				}
			}
		}
	}
}

int main(){
	for(int i=2 ; i < MAX ; i++ ) p[i] = 1;
	for(int i=2 ; i < sqrt(MAX)+1 ; i++ ){
		if( p[i] ){
			for(int j=i+i ; j < MAX ; j += i ){
				p[j] = 0;
			}
		}
	}

	while( cin >> n >> x , n||x ){
		for(int i=0 ; i < n ; i++ ){
			cin >> a[i];
		}

		int dp[MAX] = {1};
		solve( dp );
		int ans = 0;
		for(int i=x ; i > 0 ; i-- ){
			if( dp[i] && p[i] ){
				ans = i;
				break;
			}
		}

		if( ans > 0 )
			cout << ans << endl;
		else
			cout << "NA" << endl;
	}
}

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

int main() {
    int64_t h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (auto& e : s) cin >> e;

    vector<int64_t> dxy { 0, 1, 0, -1, 0 };
    vector<vector<int64_t>> dist(h*w, vector<int64_t>(h*w, INT32_MAX));
    for (int i = 0; i < h*w; i++) dist[i][i] = 0;

    for (int hi = 0; hi < h; hi++) {
        for (int wi = 0; wi < w; wi++) {
            for (int d = 0; d < 4; d++) {
                int nhi = hi + dxy[d], nwi = wi + dxy[d+1];
                if (nhi < 0 || h <= nhi || nwi < 0 || w <= nwi) continue;
                if (s[hi][wi] != '.' || s[nhi][nwi] != '.') continue;
                dist[w*hi+wi][w*nhi+nwi] = 1;
            }
        }
    }

    for (int i = 0; i < h*w; i++) {
        for (int j = 0; j < h*w; j++) {
            for (int k = 0; k < h*w; k++) {
                if (dist[j][k] > dist[j][i] + dist[i][k]) {
                    dist[j][k] = dist[j][i] + dist[i][k];
                }
            }
        }
    }

    int64_t ans = 0;
    for (int hi1 = 0; hi1 < h; hi1++) {
        for (int wi1 = 0; wi1 < w; wi1++) {
            for (int hi2 = 0; hi2 < h; hi2++) {
                for (int wi2 = 0; wi2 < w; wi2++) {
                    if (s[hi1][wi1] != '.' || s[hi2][wi2] != '.') continue;
                    if (dist[w*hi1+wi1][w*hi2+wi2] == INT32_MAX) continue;
                    ans = max(ans, dist[w*hi1+wi1][w*hi2+wi2]);
                }
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
    long long x;
public:
    mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
    mint operator-() const {
        return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }

    mint operator^(const ll& t)const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream& operator<<(ostream& os, const mint& m) {
        os << m.x;
        return os;
    }
};

//////////////////////////


int main() {
    ll N;
    cin >> N;
    vector<ll> a(N + 1);
    repn(i, N) cin >> a[i];
    sort(++a.begin(), a.end(), greater<ll>());

    ll M = a[1];
    vector<ll> c(M + 1, 0);
    repn(i, N) c[a[i]]++;

    bool ans = 1;
   
    if (M % 2 == 0) {
        repn(i, M) {
            if (i < M / 2 && c[i] != 0) { ans = 0; }
            if (i == M / 2 && c[i] != 1) { ans = 0; }
            if (i > M / 2 && c[i] < 2) { ans = 0; }
        }
    }

    else {
        repn(i, M) {
            if (i < (M+1) / 2 && c[i] != 0) { ans = 0; }
            if (i == (M+1) / 2 && c[i] != 2) { ans = 0; }
            if (i > (M+1) / 2 && c[i] < 2) { ans = 0; }
        }
    }

    if (ans == 1) { cout << "Possible"; }
    else { cout << "Impossible"; }

    

	system("PAUSE");
}

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

int main()
{
  int a,b,c; //a red, b green, c blue
  cin >> a >> b >> c; //a < b < c
  
  int k;
  cin >> k;
  
  int count = 0;
  while(a >= b){
    b *= 2;
    count++;
  }
  while(b >= c){
    c *= 2;
    count++;
  }
  
  if(count <= k){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
void solve(){
	int n, mx=0, mn =INT_MAX;
	cin>>n;
	rep(i,0,n){
		int t;
		cin>>t;
		if(t>mx) mx = t;
		if(t<mn) mn = t;
	}
	cout<<mx-mn<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

int main() {
	string s;
	cin >> s;
	string ss = "AKIHABARA";
	if (s.size() > ss.size()) {
		puts("NO");
		return 0;
	}
	int ich = 0;
	for (int i = 0; i < s.size(); i++) {
		if (ich >= ss.size()) {
			puts("NO");
			return 0;
		}
		if (ss[ich] != s[i]) {
			if (ss[ich] == 'A') {
				ich++;
				i--;
				continue;
			}
			else {
				puts("NO");
				return 0;
			}
		}
		else {
			ich++;
			continue;
		}
	}
	for (int j = ich; j < ss.size(); j++) {
		if (ss[j] != 'A') {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 256
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var s = next();
  var mae = "";
  var ato = "";
  var isReverse = false;
  var Q = nextInt();
  for(var i = 0; i < Q; i++){
    var tmp = nextStrArray();
    if(tmp[0] == 1){
      isReverse = !isReverse;
    }else{
      if(tmp[1] == "1"){
        if(isReverse){
          ato += tmp[2];
        }else{
          mae += tmp[2];
        }
      }else{
        if(isReverse){
          mae += tmp[2];
        }else{
          ato += tmp[2];
        }
      }
    }
    //myerr(mae + " " + ato);
  }
  
  if(isReverse){
    var tmpS = "";
    for(var i = 0; i < s.length; i++){
      tmpS = s[i] + tmpS;
    }
    s = tmpS;
    var tmpAto = "";
    for(var i = 0; i < ato.length; i++){
      tmpAto = ato[i] + tmpAto;
    }
    ato = tmpAto;
    myout(ato + s + mae);
  }else{
    var tmpMae = "";
    for(var i = 0; i < mae.length; i++){
      tmpMae = mae[i] + tmpMae;
    }
    mae = tmpMae;
    myout(mae + s + ato);
  }
  
}

Measured memory_bytes: 57220
S=input()
N=len(S)+1
L=[0 for i in range(N)]
R=[0 for i in range(N)]
for i in range(1,N):
    if S[i-1]==">":
        L[i]=0
    else:
        L[i]=L[i-1]+1
for i in range(N-2,-1,-1):
    if S[i]=="<":
        R[i]=0
    else:
        R[i]=R[i+1]+1
#print(L)
#print(R)
X=[max(L[i],R[i]) for i in range(N)]
print(sum(X))

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

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++){
    cin >> d.at(i);
  }
  int ans = 1;
  sort(d.begin(), d.end());
  for (int i = 1; i < N; i++){
    if(d.at(i-1) != d.at(i)){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import Control.Applicative
import Data.List

getInt :: IO Int
getInt = (\a -> read a :: Int) <$> getLine

getInteger :: IO Integer
getInteger = (\a -> read a :: Integer) <$> getLine

getListInt :: IO [Int]
getListInt = ((map (\a -> read a :: Int)) . words) <$> getLine

getListInteger :: IO [Integer]
getListInteger = ((map (\a -> read a :: Integer)) . words) <$> getLine

findOne :: [Integer] -> Integer
findOne [] = 0
findOne (1:res) = 1
findOne (_:res) = 1 + findOne res

count :: Integer -> Integer -> Integer -> Integer
count n k a = 
    let others = n - 1
        in (div others (k - 1)) + (if 0 == mod others (k - 1) then 0 else 1)

main = do
    [n, k] <- getListInteger
    a <- findOne <$> getListInteger
    --print $ ((div (a - 1) (k - 1)) + (if 0 == mod (a - 1) (k - 1) then 0 else 1)) + (div (n - a) (k - 1) + (if 0 == mod (n - a) (k - 1) then 0 else 1))
    print $ count n k a


Measured memory_bytes: 18812
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


i64 n, a[202020], b[202020];
P p[202020];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
		p[i] = make_pair(b[i], a[i]);
	}
	sort(p, p+n);
	
	i64 cnt = 0;
	bool can = 1;
	for(int i = 0; i < n; i++){
		cnt += p[i].second;
		if(p[i].first < cnt){
			can = 0;
			break;
		}
	}
	if(can) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 6528
N = int(input())
a = list(map(int,input().split()))
b = []
for i in range(N):
    b.append(a[i])
count = 1
ans = 0
for i in range(N):
    if a[i] == count:
        count += 1
        continue
    else:
        ans += 1
if ans == N:
    ans = -1
print(ans)

Measured memory_bytes: 26012
#include<algorithm>
#include<cstdio>

int h[105];
int main(){
    int i,n,cmp=0,ans=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)scanf("%d",&h[i]);
    for(i=1;i<=n;i++)
        if(h[i]<=cmp)cmp=h[i];
        else ans+=h[i]-cmp,cmp=h[i];
    printf("%d",ans);
    return 0;
}

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

min = 0
cnt = 0
for i in range(N):
  if i == 0:
    cnt += 1
    min = A[i]
    continue
  if A[i] <= min:
    cnt += 1
    min = A[i]

print(cnt)

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n;
    cin >> n;
    double ans = (n % 2 == 0 ? 0.5 : (n / 2 + 1) / (double)n);
    printf("%.10f\n", ans);

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
     
int par[100000];
     
void init(int);
int dep(int);
int inp(void);
    
char *p;
char in[1500000];
int tree[100000][15],idx[100000];
    
int main(){
  int n,i,j,id,k,c;
    
  fread(in,sizeof(in),1,stdin);  
  p = in;
    
  n = inp(); init(n);
  for(i = 0 ; i < n ; i++){
    id = inp();
    k = inp();
    for(j = 0 ; j < k ; j++){
      c = inp();
      par[c] = id;
      tree[id][idx[id]++] = c;
    }
  }
     
  for(i = 0 ; i < n ; i++){
    printf("node %d: parent = %d, depth = %d, "
           ,i,par[i],dep(i));
        
    if(par[i] == -1){
      printf("root, [");
    }else if(!idx[i]){
      printf("leaf, [");
    }else{
      printf("internal node, [");
    }
    
    for(j = 0 ; j < idx[i] ; j++){
      printf("%d",tree[i][j]);
      if(j < idx[i]-1) printf(", ");
    }
    puts("]");
  }
  return 0;
}
    
void init(int n){
  int i;
  for(i = 0 ; i < n ; i++){
    par[i] = -1;
  }
}
    
int dep(int x){
  if(par[x] == -1) return 0;
  return dep(par[x]) + 1;
}
    
int inp(){
  int v = 0;
  while(!isdigit(*p)) ++p;
  v = *p++&15;
  while(isdigit(*p)){
    v = (v<<3)+(v<<1)+(*p++&15);
  }
  return v;
}

Measured memory_bytes: 4112
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  string ans = "No";
  cin >> a >> b >> c;
  if(a == b && c != b) ans = "Yes";
  if(a == c && a != b) ans = "Yes";
  if(b == c && a != b) ans = "Yes";
  cout << ans << endl;
 return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define llu unsigned long long
#define ll long long
#define INF 0x3f3f3f3f
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define to_lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define to_upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
using namespace std;

// scan vector
template <typename T> 
inline istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// print vector
template <typename T> 
inline ostream &operator<<(ostream &out, vector<T> &a) {
    for(auto &x : a) out << x <<" ";
    return out;
}
// scan pair
template <typename T, typename U> 
inline istream &operator>>(istream &in, pair<T,U> &a) {
    in >> a.first >> a.second; 
    return in;
}
const ll mod=1e9 + 7;
string k;
int D;
ll dp[10010][2][105];
ll solve(int pos, bool flag, int sum)
{
    if(pos==k.length())
        return sum==0;
    if(dp[pos][flag][sum]!=-1)
        return dp[pos][flag][sum];
    int limit = (flag)?(k[pos]-'0'):9;
    ll sum_so_far=0;
    for(int i=0; i<=limit; i++)
    {
        sum_so_far+=solve(pos+1,(flag && (i==limit)), (sum+i)%D);
    }
    return dp[pos][flag][sum]=sum_so_far%mod;

}
int main()    
{
    #ifdef SANS
        freopen("ongoingin.txt","r",stdin);
        freopen("ongoingout.txt","w",stdout);
    #endif
    fast
    int t=1;
    // cin>>t;
    while(t--)
    {
        cin>>k>>D;
        memset(dp,-1,sizeof(dp));
        ll ans=solve(0,1,0)-1;
        if(ans==-1)
            ans=mod-1;
        else if(ans>mod)
            ans-=mod;
        cout<<ans;
    }
    #ifdef SANS
        cout<<"\nTime Elapsed:"<<1.0*clock()/CLOCKS_PER_SEC <<"sec\n";
    #endif
}

Measured memory_bytes: 20840
# coding; utf-8
def main():
    N, M = map(int, input().split())
    K = []
    S = []
    for i in range(M):
        temp = list(map(int, input().split()))
        ki = int(temp[0])
        K.append(ki)
        si = list(temp[1:])
        S.append(si)

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

    ans = 0
    temp = [0] * N
    ans += method(temp, N, M, K, S, P, 0)
    print(ans)


def method(l, N, M, K, S, P, roop):
    ans = 0
    if roop < N:
        l[roop] = 0
        ans += method(l, N, M, K, S, P, roop+1)
        l[roop] = 1
        ans += method(l, N, M, K, S, P, roop+1)

    elif roop == N:
        flag = True
        # print(l)
        for i in range(M):
            s = 0
            for j in range(K[i]):
                if l[S[i][j]-1] > 0:
                    s += 1
            if s % 2 != P[i]:
                # print(s, P[i])
                flag = False
        if flag == True:
            ans += 1
        return ans
    else:
        # print("debug")
        return -99
    return ans


if __name__ == "__main__":
    main()


Measured memory_bytes: 43480