akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
	class Program2
	{
		static void Main(string[] args)
		{
			Console.ReadLine();
			var sh = Console.ReadLine().Split(' ');
			List<int> h = new List<int>();
			foreach (var s in sh)
			{
				h.Add(int.Parse(s));
			}

			int ans = 0;
			int max = h[0];
			foreach (var ih in h)
			{
				if (ih >= max)
				{
					ans++;
					max = ih;
				}
			}
			Console.Write(ans.ToString() + "\n");
//			Console.ReadLine();
		}
	}
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; 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 ALL(v) (v).begin(),(v).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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,k,d;cin >> x >> k >> d;
    x=abs(x);
    ll t=x/d;
    if(t>=k){
        cout << x-k*d << endl;
    }
    else{
        if((k-t)%2==0){
            cout << abs(x-t*d) << endl;
        }
        else{
            cout << abs(x-t*d-d) << endl;
        }
    }
}

Measured memory_bytes: 3656
def main():
    N = int(input())
    A = []
    for _ in range(N):
        X, L = map(int, input().split())
        A.append((X, L))
 
    A.sort()
    cnt = 0
    right = 0
    left = 0
    for i in range(N):
        if i == 0:
            left = A[i][0] - A[i][1]
            right = A[i][0] + A[i][1]
        else:
            tmp_left = A[i][0] - A[i][1]
            tmp_right = A[i][0] + A[i][1]
            if tmp_right < right:
                left = tmp_left
                right = tmp_right
                cnt += 1
            elif tmp_left < right:
                cnt += 1
            else:
                left = A[i][0] - A[i][1]
                right = A[i][0] + A[i][1]
 
    print(N - cnt)

if __name__ == "__main__":
    main()

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

int main() {
   
 string s;
 cin>>s;
 for(int i=0;i<s.length();i++)
 {
    if(i%2==0 && s[i]=='L')
     {
         cout<<"No"; return 0;
     }
     if(i%2==1 && s[i]=='R')
     {
         cout<<"No"; return 0;
     }
 }
      cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


n = int(input())

S = []
for _ in range(n):
    s = "".join(sorted(input().strip()))
    S.append(s)
S.sort()


answer = 0
count = 1
for i in range(n - 1):
    if S[i] == S[i + 1]:
        count += 1
    else:
        answer += count * (count - 1) // 2
        count = 1
answer += count * (count - 1) // 2


print(answer)


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

int main() {
  vector<int> prime_number(100001, 1);
  prime_number[0] = prime_number[1] = 0;
  for (int i = 2; i <= 100000; ++i) {
    if (prime_number[i]) {
      for (int j = 2 * i; j <= 100000; j += i) {
        prime_number[j] = 0;
      }
    }
  }

  vector<int> ans(100001, 0);
  for (int i = 0; i <= 100000; ++i) {
    if (prime_number[i] && prime_number[(i + 1) / 2]) ans[i] = 1;
  }

  for (int i = 1; i <= 100000; ++i) {
    ans[i] += ans[i - 1];
  }

  int q;
  cin >> q;

  while (q--) {
    int l, r;
    cin >> l >> r;

    cout << ans[r] - ans[l - 1] << endl;
  }
}


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
template <class T>
T GCD(T a, T b)
{
    T r;
    while (a)
        r = b, b = a, a = r % a;
    return b;
}
template <class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repe(i, n) for (ll i = 0; i <= (n); i++)
#define repd(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<ll> vl;
#define ERASE(x) x.erase(unique(ALL(x)), x.end()); // erase same elements
#define VEC(type, c, n)     \
    std::vector<type> c(n); \
    for (auto &i : c)       \
        std::cin >> i;

// input
#define INIT                          \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define VAR(type, ...) \
    type __VA_ARGS__;  \
    MACRO_VAR_Scan(__VA_ARGS__);
template <typename T>
void MACRO_VAR_Scan(T &t)
{
    std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &... rest)
{
    std::cin >> first;
    MACRO_VAR_Scan(rest...);
}

// output
template <typename T>
void MACRO_OUT(const T t) { std::cout << t; }

#define OUT(...) MACRO_OUT(__VA_ARGS__);
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define ENDL std::cout << std::endl;

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define yes() printf("yes\n")
#define no() printf("no\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
    cout << a;
    ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
    cout << a << ' ';
}

double ans = 0;
bool check = 0;
bool boo = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b, c, d, n, k, m = 1000000;
int x = 0, y = 0;
int sum;
char ch;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// cout << (conditon ? (result:  == 1 ): (==0)) << endl; <- output result of if
// long long 型が表せる値の上限はおよそ 9 × 10＾18 です．
int main()
{
    INIT;
    cin >> n >> k;
    rep(i, n)
    {
        cin >> a >> b;
        if (b <= k)
        {
            m = min(m, a);
        }
    }
    if (m == 1000000)
        pr("TLE");
    else
        pr(m);

    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  while(cin>>s){
    int cnt=0, ans=0;
    for(int i=0; i<s.size(); ++i){
      if(cnt>0){
        --cnt;
        if(s[i]=='g'){
          ++ans;
        }
      }
      else{
        if(s[i]=='p')
          --ans;
        ++cnt;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}




Measured memory_bytes: 512
op1,op2,op3=gets.chomp.split.map{|v|v.to_i}
until op1<=op2 && op2<=op3
        if op1>op2 then
                tmp=op2
                op2=op1
                op1=tmp
        end
        if op2>op3 then
                tmp=op3
                op3=op2
                op2=tmp
        end
end
print op1," ",op2," ",op3,"\n"

Measured memory_bytes: 6096
#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7;
int dp[45][(1 << 17) + 5];
int main() {
	int n, X, Y, Z;
	cin >> n >> X >> Y >> Z;
	int ban = (1 << Z - 1) | (1 << Y + Z - 1) | (1 << X + Y + Z - 1);
	dp[0][0] = 1;
	for(int i = 0; i < n; ++i) {
		for(int j = 1; j < 11; ++j) {
			for(int S = 0; S < 1 << 17; ++S) {
				int nxt = (S << j | 1 << j - 1) & ((1 << 17) - 1);
				if((nxt & ban) != ban) {
					dp[i + 1][nxt] = (dp[i + 1][nxt] + dp[i][S]) % P;
				}
			}
		}
	}
	int ans = 1;
	for(int i = 0; i < n; ++i) {
		ans = 1LL * ans * 10 % P;
	}
	for(int S = 0; S < 1 << 17; ++S) {
		ans = (ans - dp[n][S] + P) % P;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 22272
/*
 * Author: Anmol Choudhary
 */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nextl cout<<"\n"
#define deb(x) cout<<#x<<"="<<x<<"\n"
#define deb2(x,y) cout<<"["<<#x<<"="<<x<<"] , ["<<#y<<"="<<y<<"]"<<"\n"
const ll mod = 1000000007;
const ll maxn = 500005;
const ll mm = 1e+18;
ll power(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res;
}
void solve()
{
    ll x,y;
    cin>>x>>y;
    if(500*x>=y) cout<<"Yes";
    else cout<<"No";
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        //nextl;
    }
    return 0;
}


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

using namespace std;

string s;
int a[100005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s;
	int cnt = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'R') cnt++;
		else{
			if(cnt > 0){
				a[i-1] += (cnt+1)/2;
				a[i] += cnt/2;
			}
			cnt = 0;
		}
	}
	//for(int i = 0; i< s.size(); i++) cout << a[i] << " "; cout << endl;
	
	cnt = 0;
	for(int i = (int)s.size()-1; i >= 0; i--){
		if(s[i] == 'L') cnt++;
		else{
			if(cnt > 0){
				a[i+1] += (cnt+1)/2;
				a[i] += cnt/2;
			}
			cnt = 0;
		}
	}
	for(int i = 0; i< s.size(); i++) cout << a[i] << " "; cout << endl;
	
	return 0;
}

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

int main(void) {
    int D;cin>>D;
    if (D == 22) cout << "Christmas Eve Eve Eve" << endl;
    if (D == 23) cout << "Christmas Eve Eve" << endl;
    if (D == 24) cout << "Christmas Eve" << endl;
    if (D == 25) cout << "Christmas" << endl;
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))
x=[]
MOD=10**9+7
for i in range(n-1):
    x.append(X[i+1]-X[i])
y=[]
for i in range(m-1):
    y.append(Y[i+1]-Y[i])
xlen=0
for i in range(n-1):
    xlen+=((i+1)*((n-i-1)*x[i])%MOD)%MOD
ylen=0
for j in range(m-1):
    ylen+=(((j+1)*((m-j-1)*y[j])%MOD)%MOD)
print((xlen*ylen)%MOD)


Measured memory_bytes: 19088
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut a = vec![];
    let mut b = vec![];
    for i in 0..n {
        let v = read_vec::<i64>();
        a.push(v[0]);
        b.push(v[1]);
    }
    if (0..n).all(|i| a[i] == b[i]) {
        println!("0");
        return;
    }
    let mut resist = std::i64::MAX;
    for i in 0..n {
        if a[i] > b[i] {
            resist = min(resist, b[i]);
        }
    }
    let ans = b.iter().sum::<i64>() - resist;
    println!("{:?}", ans);
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <bitset>

using namespace std;

int main(){
   int N;
   cin >> N;
   int A[N];
   for( int i = 0; i < N; i++ ) cin >> A[i];
   int sum = 0;
   bitset<4000001> bs(string(4000000,'0')+"1");
   for( int i = 0 ; i < N; i++ ){
      bs |= (bs<<A[i]);
      sum += A[i];
   }
   for(int i = (sum+1)/2; i<=sum; i++){
      if( bs[i] ){
         cout << i << endl;
         return 0;
      }
   }

   return 0;
}


Measured memory_bytes: 4608
import scala.annotation.tailrec

object Main extends App {
    val ss = readInt
    val (hh, ss2) = f(3600, ss, 0)
    val (mm, ss3) = f(60, ss2, 0)
    println(f"$hh%d:$mm%d:$ss3%d")
    
    @tailrec
    def f (t: Int, r: Int, n: Int) : (Int, Int) = {
        if (r >= t) { f( t, (r - t), (n + 1) ) } else { (n, r) }
    }
}


Measured memory_bytes: 43972
n = int(input())
s = input()

ans = 0

for i in range(len(s)-1):
	k = s[0:i+1]
	t = s[i+1:len(s)]
	#print(k,t)
	maxstr = 0
	
	#文字列kの重複を削除
	k = ''.join(set(k))
	
	for j in range(len(k)):
		if t.count(k[j]) != 0:
			#print(k[j])
			maxstr = maxstr + 1
	if ans <= maxstr:
		ans = maxstr	

print(ans)




Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll r() {
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	if(c=='-')f=-1,c=getchar();
	while(isdigit(c))x=x*10+c-'0',c=getchar();
	return x*f;
}
#define d r()
ll a,b,c,k;
string ans="No";
void dfs(ll x,ll y,ll z,ll u){
	if(u==k+1){
		if(z>y&&y>x)ans="Yes";
		return;
	}
	dfs(x*2,y,z,u+1);
	dfs(x,y*2,z,u+1);
	dfs(x,y,z*2,u+1);
}
int main(){
	a=d,b=d,c=d;
	k=d;
	dfs(a,b,c,1);
	cout<<ans;	
	return 0;
}

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

const ll mod = 1000000007;
const long double eps = 1e-14;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    long double a, b, c;
    cin >> a >> b >> c;
    cout << ((sqrt(a) + sqrt(b) + eps < sqrt(c)) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int n,m,q,max;
int A[15];
int ai[55],bi[55],ci[55],di[55];
int check(){
	int ans=0;
	for(int i=1;i<=q;i++) if(A[bi[i]]-A[ai[i]]==ci[i]) ans+=di[i];
	return ans;
}
void make(int i,int t){
	if(i==n+1){
		int x=check();
		if(x>max) max=x;
		return ;
	}
	for(int j=t;j<=m;j++){
		A[i]=j;
		make(i+1,j);
	}
}
int main(){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=q;i++){
		scanf("%d%d%d%d",&ai[i],&bi[i],&ci[i],&di[i]);
	}
	make(1,1);
	printf("%d",max);
	return 0;
}

Measured memory_bytes: 1736
-- stack script --resolver lts-14.6
{-# LANGUAGE CPP #-}
module Main where

import qualified Data.Vector as V 
import qualified Data.Map.Strict as M
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

dump :: (Show a) => a -> IO()
#if __GLASGOW_HASKELL__ >= 800
dump x = print x
#else
dump _ = pure ()
#endif

readint :: IO Int
readint = (fst . fromJust . BS.readInt) <$> BS.getLine

readvec :: IO [Int]
readvec = (fmap (read . BS.unpack) . BS.words) <$> BS.getLine

-- "101010" -> [1,0,1,0,1,0]
readToList :: String -> [Int]
readToList [] = []
readToList (x:xs) = read [x] : readToList xs

newtype UF a = UF (M.Map a a) deriving (Show) -- Map node parent

makeuf :: Int -> UF Int
makeuf n = let m = M.fromList $ zip [0..n] [0..n]
                in UF m

union :: (Eq a, Ord a) => a -> a -> UF a -> UF a
union l r uf@(UF m) = let lp = find l uf
                          rp = find r uf
                      in if lp == rp
                         then uf
                         else if size l uf < size r uf
                              then UF $ M.update (const $ Just rp) lp m
                              else UF $ M.update (const $ Just lp) rp m

find :: (Eq a, Ord a) => a -> UF a -> a
find x uf@(UF m) = let px = m M.! x
                in if px == x
                   then px
                   else find px uf

size :: (Eq a, Ord a) => a -> UF a -> Int
size x (UF m) = M.size $ M.filter (\par -> par==x) m

main :: IO()
main = do
  s <-  readToList . BS.unpack <$> BS.getLine :: IO [Int]
  let count x = length $ filter (== x) s
  print $ (* 2) $ min (count 0) (count 1)




Measured memory_bytes: 4860
/*
 * 2407.cc: Simple Othello
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  string s;
  cin >> s;
  int n = s.size();

  int no = 0, nx = 0;
  char prv = '-';

  for (int i = 0; i < n; i++)
    if (prv != s[i]) {
      if (s[i] == 'o') no++;
      else nx++;
      prv = s[i];
    }

  cout << (no >= nx ? "o" : "x") << endl;
  return 0;
}

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

int main() {
  int n, r, min, max = -1000000000;
  cin >> n >> min;
  
  for (int i=1;i<n;i++) {
    cin >> r;
    if (max < r - min)
      max = r - min;
    if (min > r)
      min = r;
  }

  cout << max << endl;
}



Measured memory_bytes: 3116
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define DEBUG
#undef DEBUG

using ll = long long;

int N;
int A[100005];

// 結果の数列は+始まりか-始まりのいずれか
void solve()
{
    ll cost1 = 0;
    ll cost2 = 0;
    ll s;

    // +始まり
    s = 0;
    REP(i, N) {
        // S[i] が偶数番目で0なら A[i] を1増やせば S[i] = 1 となる
        if(s+A[i] == 0 && i%2 == 0) {
            cost1 += 1;
            s = 1;
        }
        // S[i] が奇数番目で0なら A[i] を1減らせば S[i] = -1 となる
        else if(s+A[i] == 0 && i%2 == 1) {
            cost1 += 1;
            s = -1;
        }
        // S[i] が偶数番目で正なら操作は不要。S[i] = S[i-1] + A[i]
        else if(s+A[i] > 0 && i%2 == 0) {
            s += A[i];
        }
        // S[i] が奇数番目で正なら A[i] を |S[i]|+1 減らせば S[i] = -1 となる
        else if(s+A[i] > 0 && i%2 == 1) {
            cost1 += abs(s+A[i]) + 1;
            s = -1;
        }
        // S[i] が偶数番目で負なら A[i] を |S[i]|+1 増やせば S[i] = 1 となる
        else if(s+A[i] < 0 && i%2 == 0) {
            cost1 += abs(s+A[i]) + 1;
            s = 1;
        }
        // S[i] が奇数番目で負なら操作は不要。S[i] = S[i-1] + A[i]
        else if(s+A[i] < 0 && i%2 == 1){
            s += A[i];
        }

#ifdef DEBUG
        cout << "s:     " << s << "\n";
        cout << "cost1: " << cost1 << "\n";
#endif
    }

    // -始まり
    s = 0;
    REP(i, N) {
        // S[i] が偶数番目で0なら A[i] を1減らせば S[i] = -1 となる
        if(s+A[i] == 0 && i%2 == 0) {
            cost2 += 1;
            s = -1;
        }
        // S[i] が奇数番目で0なら A[i] を1増やせば S[i] = 1 となる
        else if(s+A[i] == 0 && i%2 == 1) {
            cost2 += 1;
            s = 1;
        }
        // S[i] が偶数番目で正なら A[i] を |S[i]|+1 減らせば S[i] = -1 となる
        else if(s+A[i] > 0 && i%2 == 0) {
            cost2 += abs(s+A[i]) + 1;
            s = -1;
        }
        // S[i] が奇数番目で正なら操作は不要。S[i] = S[i-1] + A[i]
        else if(s+A[i] > 0 && i%2 == 1) {
            s += A[i];
        }
        // S[i] が偶数番目で負なら操作は不要。S[i] = S[i-1] + A[i]
        else if(s+A[i] < 0 && i%2 == 0){
            s += A[i];
        }
        // S[i] が奇数番目で負なら A[i] を |S[i]|+1 増やせば S[i] = 1 となる
        else if(s+A[i] < 0 && i%2 == 1) {
            cost2 += abs(s+A[i]) + 1;
            s = 1;
        }

#ifdef DEBUG
        cout << "s:     " << s << "\n";
        cout << "cost2: " << cost2 << "\n";
#endif
    }

    cout << min(cost1, cost2) << "\n";
}

int main()
{
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }

    solve();

    return 0;
}


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

// aを常に小さい値にする　大きい値にする
template<class T> bool chmin(T &a, T b){
    if(a>b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> void chmax(T &a, T b){ if(a<b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

/*
 *
 * */

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

    double res = N * 2 * 3.14159265;
    cout << res << endl;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int ss[maxn],n,m,ans=0,top=0;
struct point
{
	int id,x,y;
	bool operator<(const point& a)const
	{
		return x==a.x?y<a.y:x<a.x;
	}
}p[2*maxn];
int sign[maxn];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++) {
		int a,b;
		cin>>a>>b;
		p[2*i-1].x=a;
		p[2*i-1].y=1;
		p[2*i-1].id=i;
		p[2*i].x=b;
		p[2*i].y=-1;
		p[2*i].id=i;
	}
	sort(p+1,p+2*m+1);
	for(int i=1;i<=2*m;i++)
	{
		if(p[i].y<0)
		{
			if(sign[p[i].id]==1) continue;
			else
			{
				ans++;
				while(top)
				{
					sign[ss[top]]=1;
					top--;
				}
			}
		}
		if(p[i].y>0)
		{
			ss[++top]=p[i].id;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define ll  long long int
#define mod 1000000007
using namespace std;
int main() {
    string s;
    cin>>s;
    ll n=s.length();
    ll dp[n+1][13];
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(ll i=1;i<n+1;i++){
        ll nxt=s[i-1]-'0';
            for(ll j=0;j<=9;j++){
                if(s[i-1]=='?')nxt=j;
                for(ll k=0;k<13;k++){
                    ll rem=(10*k+nxt)%13;
                dp[i][rem]+=dp[i-1][k];
                    dp[i][rem]%=mod;}
                if(s[i-1]!='?')break;
            }
        
    }
    cout<<dp[n][5]<<"\n";
}




Measured memory_bytes: 10624
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    int n, k; cin >> n >> k;
    map<int, int> mp;
    rep(i, k){
        int d; cin >> d;
        rep(j, d){
            int a; cin >> a;
            mp[a]++;
        }
    }
    out(n-mp.size());
}

Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <string>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;

int main(void){
  string x;
  cin>>x;
  x="a"+x;
  int l=0;
  while(l<(x.size()-1)){
    if(x[l]=='S' && x[l+1]=='T'){
      x.erase(l,2);
      l--;
    }
    else l++;
  }
  cout<<x.size()-1<<endl;
  return 0;
}


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

using namespace std;

int main() {
	long a, b, c, k;
	cin >> a >> b >> c >> k;
	
	if (k <= a) {
		cout << k;
	}
	else {
		if (k <= a + b) {
			cout << a;
		}
		else {
			cout << a - (k - a - b);
		}
	}
	
	return 0;
}


Measured memory_bytes: 3636
// Copyright 2020 yaito3014
#include <bits/stdc++.h>
using namespace std;

int main() {
	cin.tie(nullptr); ios::sync_with_stdio(false);
	char X, Y;
	cin >> X >> Y;
	cout << (X == Y ? '=' : X < Y ? '<' : '>') << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		String s[] = sc.next().split(",");
		String answer = "";
		for(int i = 0;i < s.length-1;i++){
			answer += s[i]+" ";
		}
		answer += s[s.length-1];

		System.out.println(answer);
	}
}


Measured memory_bytes: 9676
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

    int ans = 0;
    for(int i = 1; i <= N; ++i){
        string tmp = to_string(i);
        if(tmp.size() % 2 != 0){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter

input = sys.stdin.readline


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

    S = [0] * (N+1)
    for i in range(N):
        S[i+1] = S[i] + A[i]

    c = Counter(S)
    ans = 0
    for v in c.values():
        ans += v*(v-1)//2
    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n,0);
	vector<int> b(n,0);
	vector<int> c(n,0);
	for(int i = 0;i<n;i++)
	{
		cin >> a.at(i);
	}
	for(int i = 0;i<n;i++)
	{
		cin >> b.at(i);
	}
	for(int i = 0;i<n;i++)
	{
		cin >> c.at(i);
	}
	int ss = 0;
	for(int i = 0;i<n;i++)
	{
		ss += b.at(i);
		if(i == 0)
		{
			continue;
		}
		else if(a.at(i - 1) == a.at(i) - 1)
		{
			ss += c.at(a.at(i - 1) - 1);
		}
	}
  cout << ss << endl;
}


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

int main(){
    int t,d,l;
    while(cin >> t >> d >> l && t!=0){
        int s = 0;
        int res = 0;
        rep(i,t){
            if(s > 0)res++;
            int x;
            cin >> x;
            if(x >= l){
                s = d+1;
            }
            s--;
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
import java.lang.annotation.Retention;
import java.util.*;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJ0203();
	}
	//一番最後の行に2が来ている時のケースを考える。

	class AOJ0203{
		int x,y;
		int[][] map;
		HashMap<String,Integer> memo;
		int dfs(int sx,int sy,int before_x){
			//			System.out.println(sx+" "+sy+" "+before_x);
			if(memo.containsKey(sx+" "+sy+" "+before_x))return memo.get(sx+" "+sy+" "+before_x);
			int result = 0;
			if(sy>=y-1){
				if(sy==y-1){
					if(map[sy][sx]==1){
						memo.put(sx+" "+sy+" "+before_x,0);
						return 0;
					}else if(map[sy][sx]==2&&before_x!=sx)return 0;
				}
				memo.put(sx+" "+sy+" "+before_x,1);
				return 1;
			}
			if(map[sy][sx]==1){
				memo.put(sx+" "+sy+" "+before_x, 0);
				return 0;
			}
			else if(map[sy][sx]==2){
				if(before_x!=sx){
					memo.put(sx+" "+sy+" "+before_x,0);
					return 0;
				}else{
					memo.put(sx+" "+sy+" "+before_x,dfs(sx,sy+2,sx));
					return memo.get(sx+" "+sy+" "+before_x);
				}
			}else if(map[sy][sx]==0){
				for(int i=-1;i<=1;i++){
					int nx=i+sx, ny=sy+1;
					if(nx<0||nx>=x||ny<0)continue;
					result+=dfs(nx, ny,sx);
				}
			}
			memo.put(sx+" "+sy+" "+before_x,result);
			return result;
		}


		public AOJ0203() {
			while(true){
				memo = new HashMap<String, Integer>();
				x = in.nextInt();
				y = in.nextInt();
				if(x==0&&y==0)break;
				map = new int[y+1][x];
				for(int i=0;i<y;i++)for(int s=0;s<x;s++)map[i][s] = in.nextInt();
				int result = 0;
				for(int i=0;i<x;i++)result += dfs(i,0,-1);
				System.out.println(result);
			}
		}
	}
}

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

#define ll long long
#define fi first
#define se second
#define mp make_pair

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;

const int mod = 1e9+7;
ll MAX=100000000009;

int main(){
	fastio();
	int n,ans=0,a1,a2,a3,a4;cin>>n;
	a1 = -1;
	a2 = -MAX;
	a3 = MAX;
	a4 = MAX;
	for(int i=0;i<n;i++){
		int  x,y;cin>>x>>y;
		a1 = max(a1,(x+y));
		a2 = max(a2,(x-y));
		a3 = min(a3,(x+y));
		a4 = min(a4,(x-y));
	}
	ans = max((a1-a3),abs(a4-a2));
	cout<<ans<<endl;
	//max ( (max(xi+yi)-min(xi+yi)), (max(xi-yi) - min(xi-yi)) ) 
	return 0;
}


Measured memory_bytes: 3612
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineerin College
    Date:23/03/2020
'''


from math import ceil
def main():
    
    
    
    n,m=map(int,input().split())
    print(ceil(n/m))
        
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
if __name__ =="__main__":
    main()

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, k;
	string s;
	cin>>n>>k>>s;
	int cnt=1;
	REP(i, n-1){
		if(s[i]!=s[i+1]){
			++cnt;
		}
	}
	while(k && cnt>2){
		--k;
		cnt-=2;
	}
	if(k){
		cnt=1;
	}
	cout<<n-cnt<<'\n';
	return 0;
}


Measured memory_bytes: 512
#include<cmath>
#include<queue>
#include<cstdio>

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

using namespace std;

typedef vector< vector<int> > graph;

// G を連結成分に分解する
vector<graph> decomp(const graph &G){
	int n=G.size();
	vector<graph> cc;
	vector<int> f(n); // G における頂点番号 -> 連結成分の番号
	vector<int> g(n); // G における頂点番号 -> 連結成分における頂点番号

	int c_id=0;
	vector<bool> vis(n);
	rep(u,n) if(!vis[u]) {
		vis[u]=true;

		vector<int> tmp; // 今調べている連結成分
		queue<int> Q; Q.push(u);
		while(!Q.empty()){
			int v=Q.front(); Q.pop();
			tmp.push_back(v);
			rep(i,G[v].size()){
				int w=G[v][i];
				if(!vis[w]) vis[w]=true, Q.push(w);
			}
		}

		cc.push_back(graph(tmp.size()));
		rep(i,tmp.size()){
			f[tmp[i]]=c_id;
			g[tmp[i]]=i;
		}
		c_id++;
	}

	rep(u,n) rep(i,G[u].size()) {
		int v=G[u][i];
		cc[f[u]][g[u]].push_back(g[v]);
	}

	return cc;
}

bool is_bipartite(const graph &G,int &L_res,int &R_res){
	int n=G.size();
	int L=0,R=0;
	vector<int> color(n,-1);

	rep(u,n) if(color[u]==-1) {
		color[u]=2*(L++);

		queue<int> Q; Q.push(u);
		while(!Q.empty()){
			int v=Q.front(); Q.pop();

			rep(i,G[v].size()){
				int w=G[v][i];
				if(color[w]%2==color[v]%2) return false;
				if(color[w]==-1){
					if(color[v]%2==0) color[w]=2*(R++)+1;
					else              color[w]=2*(L++);
					Q.push(w);
				}
			}
		}
	}

	L_res=L;
	R_res=R;
	return true;
}

vector<int> unify_ones(const vector<int> &a){
	vector<int> res;
	int one=0;
	rep(i,a.size()){
		if(a[i]==1) one++;
		else        res.push_back(a[i]);
	}

	int two=1;
	while(one>0){
		res.push_back(min(two,one));
		one-=min(two,one);
		two<<=1;
	}
	return res;
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	graph G(n);
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}

	vector<graph> cc=decomp(G);

	vector<int> L(cc.size()),R(cc.size()); // 二部グラフの左右の頂点数
	rep(i,cc.size()){
		if(!is_bipartite(cc[i],L[i],R[i])) return puts("-1"),0;
		if(L[i]>R[i]) swap(L[i],R[i]);
	}

	int L_sum=0;
	vector<int> add(cc.size());
	rep(i,cc.size()){
		L_sum+=L[i];
		add[i]=R[i]-L[i];
	}

	// add[i]==1 がたくさんあると部分和問題を解くのに時間がかかりすぎるので, 適当にまとめる ( 個数制約があるナップザックと同じ tips )
	add=unify_ones(add);

	// knapsack DP
	int N=L_sum; // 最適な左の頂点数 ( n/2 以下で最大になるよう振り分ける )
	vector<bool> dp(n+1); dp[0]=true;
	rep(i,add.size()){
		for(int j=n/2-L_sum-add[i];j>=0;j--){
			if(dp[j]){
				dp[j+add[i]]=true;
				if(abs(L_sum+j+add[i]-n/2.0)<abs(N-n/2.0)) N=L_sum+j+add[i];
			}
		}
	}

	printf("%u\n",N*(n-N)-m);

	return 0;
}

Measured memory_bytes: 13724
#include <iostream>
#include <vector>
#include <array>
using namespace std;
int main() {
    vector<array<int, 2>> v;
    while (true) {
        array<int, 2> a;
        cin >> a[0] >> a[1];
        if (a[0] == 0 && a[1] == 0) break;
        v.push_back(a);
    }
    
    for (auto a : v) {
        int H = a[0];
        int W = a[1];
        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3140
N = int(input())
Hs = list(map(int,input().split()))


count = 0
counts = []
max_count = 0
for i in reversed(range(1,N)):
    if Hs[i-1] >= Hs[i]:
        count += 1
    else:
        if max_count < count:
            max_count = count
        count = 0
if count > max_count:
    print(count)
else:
    print(max_count)


Measured memory_bytes: 14252
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		 Scanner stdin = new Scanner(System.in);
		while(stdin.hasNext()){
	        String[] human = stdin.nextLine().split(",");
	        double weight = Double.parseDouble(human[1]);
	        double height = Double.parseDouble(human[2]);
	        double bmi = (weight/(Math.pow(height, 2)));
	        if(bmi>=25)
	        System.out.println(human[0]);
	    }

		}
	}

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

using namespace std;

int main(){
    long long N;
    long long A,B,C,D,E;
    cin >> N;
    cin >> A >> B >> C >> D >> E;

    long long min_move = min({A,B,C,D,E});

    long long ans =0;
    if (N%min_move == 0) {
        ans = N/min_move + 4;
    }else
    {
        ans = N/min_move + 5;
    }
    
    cout << ans << endl;
    

}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a[10],i,j,box;
    for(i=0;i<10;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<9;i++){
        for(j=0;j<9;j++){
            if(a[j]<a[j+1]){
                box=a[j];
                a[j]=a[j+1];
                a[j+1]=box;
            }
        }
    }
    for(i=0;i<3;i++){
        printf("%d\n",a[i]);
    }
    return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    string C;
    cin >> N >> C;
    int a[N + 1]{};
    for (int i = 0; i < N; i++) {
        if (C[i] == 'R') {
            a[i + 1] = a[i] + 1;
        } else {
            a[i + 1] = a[i];
        }
    }
    int ans = N;
    for (int i = 0; i <= N; i++) {
        int t = max(i - a[i], a[N] - a[i]);
        ans = min(ans, t);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4536
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;
bool compare(string &a,string &b){
	return a.length()>b.length();
}

void solve(){
	int n;
	cin>>n;
	ll a[n];
	for(int i=1;i<=n;i++)cin>>a[i];
	vector<ll>dp(n+1);
	
	dp[1]=0;
	dp[2]=abs(a[1]-a[2]);
	for(int i=3;i<=n;i++){
		dp[i]=min(abs(a[i-1]-a[i])+dp[i-1],abs(abs(a[i]-a[i-2])+dp[i-2]));
	}
	cout<<dp[n]<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)solve();
}


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

int main()
{
    int N;
    cin >> N;
    ll res = 0;
    for(int i = 0; i < N; ++i) {
        ll l,r;
        cin >> l >> r;
        res += r - l + 1;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

class BIT2D:
    def __init__(self, H, W):
        self.H = H
        self.W = W
        self.data = [[0] * (H+1) for _ in range(W+1)]

    def add(self, a, b, x):
        a += 1
        b += 1
        i = a
        while i <= self.H:
            j = b
            while j <= self.W:
                self.data[i][j] += x
                j += j & -j
            i += i & -i

    def sum(self, a, b):
        a += 1
        b += 1
        ret = 0
        i = a
        while i > 0:
            j = b
            while j > 0:
                ret += self.data[i][j]
                j -= j & -j
            i -= i & -i
        return ret

N = int(input())
A = []
for _ in range(N):
    n = input().rstrip()
    if '.' not in n:
        A.append(int(n) * 10**9)
    else:
        a, b = n.split('.')
        b += '0' * (9 - len(b))
        A.append(int(a + b))
ans = 0
bit = BIT2D(100, 100)
for i in range(N):
    cnt2 = cnt5 = 0
    while A[i] % 2 == 0:
        A[i] //= 2
        cnt2 += 1
    while A[i] % 5 == 0:
        A[i] //= 5
        cnt5 += 1
    if cnt2 >= 18 and cnt5 >= 18:
        ans += i
    else:
        ans += i - bit.sum(99, 17 - cnt5) - bit.sum(17 - cnt2, 99) + bit.sum(17 - cnt2, 17 - cnt5)
    bit.add(cnt2, cnt5, 1)
print(ans)


Measured memory_bytes: 81116
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <iostream>
#include <iomanip> 
#include <algorithm>
#include <queue>
#include <list>
#include <numeric>
#include <stack>
#include <unordered_map>
#include <map>
#include <set>

using namespace std;

#define sz(a) int((a).size())
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
#define watch(x) cout << #x << " : " << x << endl;

#define FastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;

const int N = int(1e5)+10;
const int K = int(1e6)+10;
// const int MOD = int(1e9)+7;
const int INF = int(1e9)+5;
const ll INF64 = 2e18;

const ll MOD = 998244353;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

int dp[N],parent[N];
vi ans;

void solve () {
    int n,m;cin>>n>>m;
    string s;cin>>s;
    deque<ii> q;
    if (s[0] == '1' || s[n] == '1') {
        cout<<-1<<endl;
        return;
    }
    // Base Case.
    for (int i=1;i<=n;i++) dp[i] = INF;
    dp[0] = 0;
    q.pb({0,0});
    int l = 0;
    for (int i=1;i<=n;i++) {
        // Whether to kick out or not.
        if (!q.empty() && i >= m+1) {
            if (q.front().first == dp[l]) q.pop_front();
            l++;
        }
        if (s[i] == '1') continue;
        if (!q.empty()) {
            dp[i] = q.front().first + 1;
            parent[i] = q.front().second;
        }
        while (!q.empty() && dp[i] < q.back().first) q.pop_back();
        q.push_back({dp[i],i});
    }
    if (dp[n] == INF) {
        cout<<-1<<endl;
        return;
    }
    int curr = n;
    while (curr != 0) {
        ans.pb(curr);
        curr = parent[curr];
    }
    reverse(all(ans));
    int si = sz(ans);
    for (int i=0;i<si;i++) {
        if (i == 0) cout<<ans[i]-0<<" ";
        else cout<<ans[i]-ans[i-1]<<" ";
    }
}

int main () {
    FastIO
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    int t;
    // cin>>t;
    t = 1;
    while (t--) {
        solve();
    }
    return 0;
}

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

using namespace std;

ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int main(void){
  int n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i].first >> a[i].second;
  }
  sort(a.begin(), a.end());
  int id = -1;
  ll ret = 0;
  priority_queue<ll> Q;
  for (int i = 1; i <= m; i++){
    while (id + 1 < n && a[id + 1].first <= i){
      Q.push(a[id + 1].second);
      id++;
    }
    if (!Q.empty()){
      ret += Q.top();
      Q.pop();
    }
  }
  cout << ret << endl;

  return 0;
}


ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


Measured memory_bytes: 2936
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
long long gcd(long long a, long long b) { return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b) { return a/gcd(a,b)*b;}

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

int main() {
  long n, k;
  cin >> n >> k;
  vector<long> v;
  long sum, tmp;
  sum = 0;
  rep (i, n) {
    cin >> tmp;
    v.push_back(tmp);
  }
  sort(v.begin(), v.end(), greater<long>());
  if (k >= n) cout << 0 << endl;
  else {
    for (long i = k; i < v.size(); ++i)
    {
      sum += v[i];
    }
    cout << sum << endl;
  }


  return 0;
}

Measured memory_bytes: 2420
#include <stdio.h>

void right_triangle_check(int a, int b, int c);

int main(void)
{
	int set, x, y, z;
	scanf("%d", &set);
	for (int i = 0; i < set; i++) {
		scanf("%d %d %d", &x, &y, &z);
		right_triangle_check(x ,y ,z);
	}
	return 0;
}

void right_triangle_check(int a, int b, int c)
{
	if (a * a + b * b == c * c) {
		printf("YES\n");
	} else if (b * b + c * c == a * a) {
		printf("YES\n");
	} else if (c * c + a * a == b * b) {
		printf("YES\n");
	} else {
		printf("NO\n");
		}
}

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

int main(void){
    int n;
    cin >> n;
    
    vector<long long> a(n+1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    
    long long money = 1000;
    long long kabu = 0;
    vector<int> check(n+1,0);
    for (int i = 1; i <= n-1; i++){
        if (a[i+1] - a[i] > 0) check[i] = 1;
    }
    
    for (int i = 1; i <= n-1; i++){
        
        if (check[i] == 1 && money >= a[i]){
            kabu = money / a[i];
            money = money -  (kabu * a[i]);
        }
        else if (check[i] == 0){
            money += (kabu * a[i]);
            kabu = 0;
        }
    }
    
    if (kabu > 0) money += (kabu * a[n]);
    cout << money << endl;
    
}

/*
priority: https://blacktanktop.hatenablog.com/entry/2020/07/26/100829
*/

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define ll unsigned long long int
#define pb push_back
#define llu unsigned long long int
#define fo(i,n) for(int i=0;i<n;i++)
#define eb emplace_back
#define M 1000000007
#define vi vector<int>
#define vlli vector<lli>
#define pi pair<int,int>
#define mp make_pair
#define mapi map<int,int>

using namespace std;
ll max(ll x,ll y)
{
	if(x>y)
		return x;
	return y;
}
ll min(ll x,ll y)
{
	if(x<y)
		return x;
	return y;
}
int binaryToDecimal(string n) 
{ 
    string num = n; 
    int dec_value = 0;
    int base = 1; 
    int len = num.length(); 
    for (int i = len - 1; i >= 0; i--) 
	{ 
        if (num[i] == '1') 
            dec_value += base; 
        base = base * 2; 
    } 
    return dec_value; 
} 
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cin.ignore(numeric_limits<streamsize>::max(),'\n');
    //const unsigned ll M=1000000007;
    ll n,d;
    cin >> n >> d;
    ll count=0;
    d = d*d;
    for(int i=0;i<n;i++)
    {
    	ll t1,t2;
    	cin >> t1 >> t2;
    	ll temp = t1*t1 + t2*t2;
    	if(temp<=d) count++;
	}
	cout << count << endl;
    return 0;
}



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

using namespace std;

int main(){

  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A.begin(),A.end());
  int result = 0;
  int num = -1;

  for(int i=0;i<N;){
    int j,count = 0;
    for(j=i;j<N&&A[j]==A[i];j++){
      count ++;
    }
    if((count%2)==1)result++;
    i=j;
  }
  cout<<result<<endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());
  int ans = 0;
  for(int j=0; j < n; ++j) {
    for(int k=0; k < j; ++k) {
      int ab = v[j] + v[k];
      int r = lower_bound(v.begin(), v.end(), ab) - v.begin();
      int l = j+1;
      ans += max(0, r-l);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
Path = Struct.new(:node, :distance)

def calc_distances(from, distance)
  @neighbors[from].each do |n|
    next if @from_k[n.node] > -1
    d = distance + n.distance
    @from_k[n.node] = d
    calc_distances(n.node, d)
  end
end

def calc_distances_non_recursive(from)
  stack = [Path.new(from, 0)]

  until stack.empty?
    n = stack.pop
    @neighbors[n.node].each do |m|
      next if @from_k[m.node] != -1
      d = n.distance + m.distance
      @from_k[m.node] = d
      stack.push(Path.new(m.node, d))
    end
  end
end

n = gets.chomp.to_i

@neighbors = Array.new(n + 1) { [] }

(n - 1).times do
  a, b, distance = gets.chomp.split.map(&:to_i)
  @neighbors[a] << Path.new(b, distance)
  @neighbors[b] << Path.new(a, distance)
end

q, k = gets.chomp.split.map(&:to_i)
qs = q.times.map do
  gets.chomp.split.map(&:to_i)
end

@from_k = Array.new(n + 1) { -1 }
# @from_k[k] = 0
# calc_distances(k, 0)
calc_distances_non_recursive(k)

qs.each do |(a, b)|
  p @from_k[a] + @from_k[b]
end


Measured memory_bytes: 62236
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <tuple>
#include <unordered_map>
#include <map>
#include <cmath>

#define endl "\n"
#define eb emplace_back
#define ll long long

using namespace std;

int n;
int k;
int dp[100001];
int nums[100001];

int memoization(int ind) {

    if (ind >= n-1)
        return 0;

    if (dp[ind] != -1)
        return dp[ind];

    int minim = 1e9;
    for (int i = 1; i <= k && ind+i < n; i++) {
        int bruh = abs(nums[ind] - nums[ind+i]) + memoization(ind+i);
        if (bruh < minim)
            minim = bruh;
        dp[ind] = minim;
    }

    return minim;

}

int main() {

    cin.tie(nullptr); cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    cin >> n;
    cin >> k;

    fill(dp, dp+n+1, -1);

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

    cout << memoization(0);

    return 0;

}

Measured memory_bytes: 12192