akhauriyash/Code-Regression huggingface dataset:
//
// tested with : g++ (GCC) 8.3.0
//

#include <iostream>
using namespace std;

int main() {
  int aka, midori, ao;
  cin >> aka >> midori >> ao;
  int line = aka * 100 + midori * 10 + ao;

  if (line % 4 == 0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
S = input()
A = int(S[:2])
B = int(S[2:])
if (1<=A and A<=12) and (1<=B and B<=12):
  print('AMBIGUOUS')
elif (1<=B and B<=12):
  print('YYMM')
elif (1<=A and A<=12):
  print('MMYY')
else:
  print('NA')

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

int main() {
	int n;
	cin >> n;
	int count = 0,ans=0;
	vector<int>a(n);
	for (int i = 0; i < n; ++i) cin >>a[i];
	sort(a.begin(), a.end());
	for (int i = 0; i < a.size()-1; ++i) {
		if (a[i]==a[i+1])++count;
		else {
			if (count % 2 == 0)++ans;
			count = 0;
		}
	}
	if (count % 2 == 0)++ans;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long N,K,S;
    cin>>N>>K;
    int arr[N+1];
    for(long long i=0;i<N;i++)
    {
        cin>>arr[i];
    }
    //S= sizeof(arr)/sizeof(arr[0]);
    sort(arr, arr+N);
    int Sum=0;
    for(long long i=0;i<K;i++)
    {
        Sum+=arr[i];
    }
    cout<<Sum<<endl;
}


Measured memory_bytes: 3640
//ABC 073 C
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iomanip>
#include <map>
using namespace std;

int main() {
	map <long long, long long> paper;
	int num;
	cin >> num;
	long long tmp,count=0;
	for (int i = 0; i < num; i++) {
		cin >> tmp;
		if (paper[tmp] == tmp) {
			//紙に数字が書かれていた
			paper[tmp] = 0;
			count--;
		}
		else {
			//紙に数字は書かれていない
			paper[tmp] = tmp;
			count++;
		}
	}

	cout << count;
	
	return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,q;
    string s;
    cin >> n >> q;
    cin >> s;
    vector<int> l(q,0);
    vector<int> r(q,0);
    vector<int> dp(n,0);
    
    for (int i = 0; i < q; i++)
    {
        cin >> l[i] >> r[i];
    }
   
	 
    for (int i = 0; i < n-1; i++)
    {
        if(s[i] == 'A' && s[i+1] == 'C'){
            dp[i+1]=dp[i]+1;
        }else{
            dp[i+1]=dp[i];
        }
    }
    
    
    for (size_t i = 0; i < q; i++)
    {
        cout<<dp[r[i]-1] - dp[l[i]-1]<<endl;
    }
    
}

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

int main() { // claudio van
  map<char, char> m;
  m['A'] = 'T';
  m['T'] = 'A';
  m['C'] = 'G';
  m['G'] = 'C';
  char c;
  cin >> c;
  cout << (char) m[c] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,M;
  cin >> N >> M;
  string s;
  cin >> s;
  vi ans;
  drep(i,N+1) {
    if(i == 0) break;
    int j = i-M;
    while((j < 0 || s[j] == '1') && j < i) {
      j++;
    }
    if(i == j) {
      cout << -1 << endl;
      return 0;
    }
    ans.push_back(i-j);
    i = j+1;
  }
  reverse(rng(ans));
  rep(i,sz(ans)) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1144
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
a = sorted(list(map(int, readline().split())))
bc = [tuple(map(int, readline().split())) for i in range(m)]
bc.sort(key=lambda x: x[1], reverse=True)
index = 0
cnt = 0
for i in range(n):
    if a[i] > bc[index][1]:
        break
    a[i] = bc[index][1]
    cnt += 1
    if cnt == bc[index][0]:
        cnt = 0
        index += 1
        if index == m:
            break
print(sum(a))


Measured memory_bytes: 22768
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

mod util {
    #[allow(dead_code)]
    pub fn chmin<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x > y && {
            *x = y;
            true
        }
    }

    #[allow(dead_code)]
    pub fn chmax<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x < y && {
            *x = y;
            true
        }
    }

    /// 整数除算切り上げ
    #[allow(dead_code)]
    pub fn roundup(a: i64, b: i64) -> i64 {
        (a + b - 1) / b
    }

    #[allow(dead_code)]
    pub fn ctoi(c: char) -> i64 {
        c as i64 - 48
    }
}

#[allow(unused_imports)]
use util::*;

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

fn main() {
    input! {
        n:usize,
        k:i64,
        hs:[i64;n]
    }

    let ans = hs.iter().filter(|x| **x >= k).count();
    println!("{}", ans);
}


Measured memory_bytes: 4352
<?php
fscanf(STDIN, "%d", $a);
fscanf(STDIN, "%d", $b);
fscanf(STDIN, "%d", $c);
fscanf(STDIN, "%d", $x);
$ans = 0;
for($i = 0; $i <= $a; $i++) {
    for($j = 0; $j <= $b; $j++) {
        for($k = 0; $k <= $c; $k++) {
            $selectCoin = $i * 500 + $j * 100 + $k * 50;
            if($selectCoin === $x) {
                $ans++;
            }
        }
    }
}
echo $ans;

Measured memory_bytes: 4604
#include<bits//stdc++.h>
using namespace std;
int main(){
    string str, t = "()[]";
    while(getline(cin,str) && str != "."){
        stack<char> s;bool judge = 1;
        for(char x : str){
            if(!count(t.begin(), t.end(), x))    continue;
            if(s.empty() || x == '(' || x == '['){
                s.push(x);
            }else if(!s.empty() && (x == ')' && s.top() == '(') || (x == ']' && s.top() == '[')){
                s.pop();
            }else{
                judge = 0;
                break;
            }
        }
        if(s.empty() && judge)  cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


Measured memory_bytes: 3224
x = int(input())


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


if x == 1:
    print(1)
else:
    while (1):
        a = prime_factorize(x)
        if len(a) == 1 and a[0] == x:
            print(x)
            exit()
        x += 1


Measured memory_bytes: 38384
package main

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

func main() {
	a := readInt64()
	b := readInt64()
	c := readInt64()
	d := readInt64()

	var ans int64
	e := lcm(c, d)
	ans = (b/c - a/c) + (b/d - a/d) - (b/e - a/e)
	if a%c == 0 {
		ans++
	}
	if a%d == 0 {
		ans++
	}
	if a%e == 0 {
		ans--
	}

	fmt.Println((b - a + 1) - ans)
}

func lcm(m, n int64) int64 {
	return m * n / gcd(m, n)
}

func gcd(m, n int64) int64 {
	var temp int64
	for m%n != 0 {
		temp = n
		n = m % n
		m = temp
	}
	return n
}


Measured memory_bytes: 640
class LazySegmentTreeBase
  def initialize(arr, l = 0, r = arr.size - 1)
    @l, @r = l, r
    @lazy = nil
    if l == r
      @agg = arr[l]
    else
      c = (l + r) / 2
      @left_child = self.class.new(arr, l, c)
      @right_child = self.class.new(arr, c + 1, r)
      @agg = aggregation_of(@left_child.agg, @right_child.agg)
    end
  end

  attr_reader :agg, :l, :r

  def update(l, r, x)
    if l == @l && r == @r
      defer(x)
    else
      force
      if r <= @left_child.r
        @left_child.update(l, r, x)
      elsif @right_child.l <= l
        @right_child.update(l, r, x)
      else
        @left_child.update(l, @left_child.r, x)
        @right_child.update(@right_child.l, r, x)
      end
      @left_child.force
      @right_child.force
      @agg = aggregation_of(@left_child.agg, @right_child.agg)
    end
  end

  def force
    return if !@lazy
    x = @lazy
    @lazy = nil
    whole_update(x)
    @left_child.update(@left_child.l, @left_child.r, x) if @left_child
    @right_child.update(@right_child.l, @right_child.r, x) if @right_child
  end

  def query(l, r)
    force
    return @agg if l == @l && r == @r
    if r <= @left_child.r
      return @left_child.query(l, r)
    elsif @right_child.l <= l
      return @right_child.query(l, r)
    else
      agg_left = @left_child.query(l, @left_child.r)
      agg_right = @right_child.query(@right_child.l, r)
      return aggregation_of(agg_left, agg_right)
    end
  end
end

class LazySegmentTree < LazySegmentTreeBase
  def initialize(arr, l = 0, r = arr.size - 1)
    @n = r - l + 1
    super(arr, l, r)
  end

  def defer(x)
    @lazy = x
  end

  def whole_update(x)
    @agg = x * @n
  end

  def aggregation_of(x, y)
    x + y
  end
end

n, q = gets.split.map(&:to_i)
seg = LazySegmentTree.new(Array.new(n, 0))
q.times do
  c, x, y, z = gets.split.map(&:to_i)
  if c == 0
    seg.update(x, y, z)
  else
    puts seg.query(x, y)
  end
end


Measured memory_bytes: 34924
import java.util.Scanner;

public class Main {
    public static void ABC086() {
        try (Scanner sc = new Scanner(System.in)) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            if ((a * b) % 2 == 0)
                System.out.println("Even");
            else
                System.out.println("Odd");
        }
    }

    public static void main(String[] args) {
        ABC086();
    }
}

Measured memory_bytes: 35768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll MAX_N = ll(1e5 + 5);
#define REP(i, n) for (int i = 0; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

vector<ll> divisor(int n) {
    vector<ll> res;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

int main() {
    ll n, m, ans = 1;
    cin >> n >> m;
    vector<ll> fac = divisor(m);
    for(auto i : fac){
        if(i * n <= m) ans = max(ans, i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

a,b = map(int,input().split())
if a+b>=10:
    print("error")
else:
    print(a+b)

Measured memory_bytes: 3316
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

long projection(double xp1, double yp1, double xp2, double yp2, double x, double y, double* px, double* py)
{
    if ( xp1 == xp2 && yp1 == yp2 ) {
        return 1;
    } else if ( xp1 == xp2 ) {
        *px = xp1;
        *py = y;
        return 0;
    } else {
        double dDist = sqrt(pow((xp2 - xp1), 2) + pow((yp2 - yp1), 2));
        double dCos = (xp2 - xp1) / dDist;
        double dSin = (yp2 - yp1) / dDist;
        double dXrot = dCos * (x - xp1) + dSin * (y - yp1);
        double dYrot = -dSin * (x - xp1) + dCos * (y - yp1);
        dYrot = 0;
        *px = dCos * dXrot - dSin * dYrot + xp1;
        *py = dSin * dXrot + dCos * dYrot + yp1;
        return 0;
    }
}


long CGL_1_A()
{
    long iRcF = 0;
	double xp1 = 0, yp1 = 0, xp2 = 0, yp2 = 0;
    long q = 0;
    double x = 0, y = 0;
    double* px = &x;
    double* py = &y;
	cin >> xp1 >> yp1 >> xp2 >> yp2;
	cin >> q;
    long i = 0;
    cout << fixed << setprecision(11);
    for ( i = 0; i < q; i++ ){
        cin >> x >> y;
        double projected_x = 0, projected_y = 0;
        iRcF = projection(xp1, yp1, xp2, yp2, x, y, &projected_x, &projected_y);
        if ( iRcF ) {
            throw "ERROR: cannot calculate projected points!";
        }
        cout << projected_x << " " << projected_y << endl;
    }
	return 0;
}

int main() {
    CGL_1_A();
    return 0;
}


Measured memory_bytes: 3288
using System;
using System.Collections.Generic;
using System.Linq;

class Cmondai
{
    static void Main()
    {
        var N = Int64.Parse(Console.ReadLine());
        const long constant = -2;
        var num = 1L;
        var ans = new Stack<char>();
        if (N == 0) ans.Push('0');
        while (N != 0)
        {
            //余りが0
            //1が立たないので数に変化なし
            if (N % (num * constant) == 0)
            {
                ans.Push('0');
            }
            //余りが1
            //1が立つのでその分Nから数を引く
            else
            {
                ans.Push('1');
                N -= num;
            }
            num *= (-2);
        }
        long count = ans.Count();
        for(long i=0;i<count;++i)Console.Write(ans.Pop());
        Console.WriteLine();
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    cins(all(a));
    a.push_back(-1);
    ll stock = 0,cnt = 0;
    rep(i,n+1){
        if (a[i] == i+1) stock++;
        else{
            if (stock%2) cnt += stock/2+1;
            else cnt += stock/2;
            stock = 0;
        }
    }
    PRINT(cnt);
}




Measured memory_bytes: 1792
n=int(input())
h=list(map(int,input().split()))
cnt=0
while any(h):
    f=True
    for i in range(n):
        if f and h[i]==0:
            continue
        if h[i] :
            f=False
            h[i]-=1
        else:
            break
    cnt+=1
    
print(cnt)


Measured memory_bytes: 40796
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 3e5 + 5;
const int MOD = 1e9 + 7;

int main(){
    fast;
    ll h, w, m;
    cin >> h >> w >> m;
    ll co[N], ro[N], mxc = 0, mxr = 0;
    map<int, bool> mp[N];
    memset(co, 0, sizeof(co));
    memset(ro, 0, sizeof(ro));
    for(int i = 0; i < m; ++i){
        ll x, y;
        cin >> x >> y;
        mp[x][y] = true;
        co[x]++, ro[y]++;
    }
    vector<ll> col, row;
    for(int i = 0; i < N; ++i){
        mxc = max(co[i], mxc);
        mxr = max(mxr, ro[i]);
    }
    for(int i = 0; i < N; ++i){
        if(co[i] == mxc) col.push_back(i);
        if(ro[i] == mxr) row.push_back(i);
    }
    ll cnt = 0, mx = 0;
    for(int i = 0; i < col.size(); ++i){
        for(int j = 0; j < row.size(); ++j){
            ++cnt;
            if(cnt > N*2) break;
            mx = max(mx, mxc + mxr - mp[col[i]][row[j]]);
        }
        if(cnt > N*2) break;
    }
    cout << mx;
    return 0;
}


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

using namespace std;

typedef long long ll;

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

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

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

    vector<ll> A(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }

    vector<ll> C(N);
    ll minus_sum = 0;
    int minus_count = 0;
    for (int i = 0; i < N; i++) {
        C[i] = A[i] - B[i];
        if (C[i] < 0) {
            minus_sum += C[i];
            minus_count++;
        }
    }

    if (minus_sum == 0) {
        cout << "0" << endl;
        return 0;
    }

    vector<ll> pluses;
    for (int i = 0; i < N; i++) {
        if (C[i] > 0) {
            pluses.push_back(C[i]);
        }
    }
    // sort by descending order
    sort(pluses.begin(), pluses.end(), [](const ll &a, const ll &b) {
            return a > b;
            });

    int plus_count = 0;
    for (int i = 0; i < (int) pluses.size(); i++) {
        minus_sum += pluses[i];
        plus_count++;
        if (minus_sum >= 0) break;
    }

    if (minus_sum < 0) {
        cout << "-1" << endl;
    } else {
        cout << minus_count + plus_count << endl;
    }

    return 0;
}


Measured memory_bytes: 3196
from datetime import date
from math import factorial
import functools
from heapq import*
from collections import deque
import collections
import math
from collections import defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
inf = float("inf")


def main():
    k = int(input())
    if k == 0:
        print(3)
        print("2 2 2")
        exit()
    elif k == 1:
        print(3)
        print("1 0 3")
        exit()
    a = min(k, 50)
    b = k % a
    ans = [i + k//a for i in range(a)]
    for i in range(b):
        ans.sort()
        for j in range(1, a):
            ans[j] -= 1
        ans[0] += a

    print(a)
    print(*ans)


if __name__ == '__main__':
    main()


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


int main()
{
	long long n, h, w;

	long long N,p,q;
	scanf("%lld", &N);
	for (n = 1; n <= 3500;n++)
	for (h = 1; h <= 3500; h++)
	{
		p = 4 * h*n - N*n - N*h;
		q = N*h*n;
		if (p > 0 && q%p == 0)
		{
			w = q / p;
			printf("%lld %lld %lld", n, h, w);

			return 0;
		}
	}
	

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Console.WriteLine(Solve() ? "Yes" : "No");
		Out.Flush();
	}
	int N, Q;
	List<Edge>[] g;
	int[] l, r, d, x;
	bool[] done;
	bool Solve()
	{
		var I = G;
		N = I[0];
		Q = I[1];
		l = new int[Q];
		r = new int[Q];
		d = new int[Q];
		var uf = new UnionFindTree(N);
		x = new int[N];
		done = new bool[N];
		g = new List<Edge>[N];
		for (var i = 0; i < N; i++) g[i] = new List<Edge>();
		for (var i = 0; i < Q; i++)
		{
			I = G;
			l[i] = I[0] - 1;
			r[i] = I[1] - 1;
			d[i] = I[2];
			g[l[i]].Add(new Edge(r[i], -d[i]));
			g[r[i]].Add(new Edge(l[i], +d[i]));
			uf.UniteCategory(l[i], r[i]);
		}
		for (var i = 0; i < N; i++) if (!done[uf.GetRootOf(i)] && !DFS(uf.GetRootOf(i), 0)) return false;
		return true;
	}
	bool DFS(int u, int y)
	{
		if (done[u])
		{
			if (x[u] != y) return false;
			return true;
		}
		x[u] = y;
		done[u] = true;
		foreach (var v in g[u]) if (!DFS(v.To, x[u] - v.D)) return false;
		return true;
	}
}
// x[i] - x[to] = d
struct Edge
{
	public readonly int To, D;
	public Edge(int t, int d) { To = t; D = d; }
}
class UnionFindTree
{
	int N;
	int[] parent, rank, size;
	public UnionFindTree(int capacity)
	{
		N = capacity;
		parent = new int[N];
		rank = new int[N];
		size = new int[N];
		for (var i = 0; i < N; i++) { parent[i] = i; size[i] = 1; }
	}
	public int GetSize(int x) => size[GetRootOf(x)];
	public int GetRootOf(int x) => parent[x] == x ? x : parent[x] = GetRootOf(parent[x]);
	public bool UniteCategory(int x, int y)
	{
		if ((x = GetRootOf(x)) == (y = GetRootOf(y))) return false;
		if (rank[x] < rank[y]) { parent[x] = y; size[y] += size[x]; }
		else
		{
			parent[y] = x; size[x] += size[y];
			if (rank[x] == rank[y]) rank[x]++;
		}
		return true;
	}
	public bool IsSameCategory(int x, int y) => GetRootOf(x) == GetRootOf(y);
}


Measured memory_bytes: 46068
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        int H = NextInt();
        int W = NextInt();
        int D = NextInt();
        int[][] A = Enumerable.Range(0, H).Select(v => LineInt()).ToArray();
        Pair[] B = new Pair[H * W + 10];
        for (int i = 0; i < H; i++)
            for (int j = 0; j < W; j++)
                B[A[i][j]] = new Pair(i, j);
        int[] memo = new int[H * W + 10];
        for (int i = 0; i < D; i++)
        {
            int n = i;
            memo[n] = 0;
            while (n + D <= H * W)
            {
                memo[n + D] = memo[n] + Math.Abs(B[n].x - B[n + D].x) + Math.Abs(B[n].y - B[n + D].y);
                n += D;
            }
        }
        int Q = NextInt();
        for (int i = 0; i < Q; i++)
        {
            int L = NextInt(), R = NextInt();
            Console.WriteLine(memo[R] - memo[L]);
        }
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


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

int main() {
	ios_base::sync_with_stdio( false );

	int N;
	string S;
	cin >> N >> S;

	int x = 0;
	int xmax = 0;

	for( int i = 0; i < N; ++i ) {
		if( S[i] == 'I' ) {
			x++;
		}
		else if( S[i] == 'D' ) {
			x--;
		}

		if( x > xmax ) {
			xmax = x;
		}
	}

	cout << xmax << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();

		int B = sc.nextInt();

		int K = sc.nextInt();

		boolean ab = false;


		for(int i=0;i<K;i++) {

			if(ab == false) {	//A

				if(A%2!=0) A -= 1;

				int a = A/2;

				A -= a;

				B += a;

				ab = true;

			}else {

				if(B%2!=0)  B -= 1;

				int b = B/2;

				B -= b;

				A += b;

				ab = false;
			}
		}

		System.out.println(A+" "+B);

	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1LL << 60;

int N, K;
ll h[100010];
ll dp[100010];

int main() {
    cin >> N >> K;
    rep(i, N) {
        cin >> h[i];
    }

    rep(i, 100010) {
        dp[i] = INF;
    }

    dp[0] = 0;

    rep(i, N) {
        for(int j = 1; j <= K; j++) {
            chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
        }
    }

    cout << dp[N-1];
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
nums = list(map(int, input().split()))

limit = pow(10, 18)

ans = 1

if 0 in nums:
    ans = 0
else:
    for e in nums:
        if ans > limit / e:
            ans = -1
            break
        else:
            ans *= e

if ans > limit:
    ans = -1

print(int(ans))


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

using namespace std;

#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)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;
const int MAX = 1e5;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; ++i) {
	fac[i] = fac[i - 1] * i % MOD;
	inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
	finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

ll COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	COMinit();
	int n, k;
	cin >> n >> k;
	FOR (i, 1, k + 1) {
	  ll res = COM(n - k + 1, i);
	  res = res * COM(k - 1, i - 1) % MOD;
	  cout << res << endl;
	}
    
    return 0;
}



Measured memory_bytes: 5944
import numpy as np
N,K = map(int,input().split())
X = np.array(input().split(), dtype=np.int64)

INF = 10 ** 18
neg = np.concatenate([-X[X <= 0][::-1], np.full(N+1,INF,dtype=np.int64)])[:K]
pos = np.concatenate([X[X > 0], np.full(N+1,INF,dtype=np.int64)])[:K]

answer = INF
# 左のみ
answer = min(answer, neg[-1])
# 右のみ
answer = min(answer, pos[-1])
if K >= 2:
  # 左にa個、右にK-a個
  answer = min(answer, (neg[:K-1] * 2 + pos[K-2::-1]).min())
  # 右にa個、右にK-a個
  answer = min(answer, (pos[:K-1] * 2 + neg[K-2::-1]).min())

print(answer)

Measured memory_bytes: 23984
package main

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

const inf = 1 << 60

func solve() {
	d, g := getInt(), getInt()
	ps, cs := make([]int, d), make([]int, d)
	for i := 0; i < d; i++ {
		ps[i] = getInt()
		cs[i] = getInt()
	}

	ans := inf
	for bit := 0; bit < (1 << uint(d)); bit++ {
		score := 0
		cnt := 0
		for i := 0; i < d; i++ {
			if mask := (1 << uint(i)); (bit & mask) > 0 {
				score += (100*(i+1))*ps[i] + cs[i]
				cnt += ps[i]
			}
		}

		if diff := g - score; diff > 0 {
			x := -1
			for i := d; i > 0; i-- {
				if bit&(1<<uint(i-1)) == 0 {
					x = i
					break
				}
			}
			if x == -1 {
				continue
			}

			nowScore := 100 * x
			add := (diff + nowScore - 1) / nowScore
			if add > ps[x-1] {
				continue
			}
			cnt += add
		}

		ans = min(ans, cnt)
	}

	fmt.Fprintln(wr, ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

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

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cstdio>

using namespace std;


int n;
int f[101][11];
int p[101][11];
int flag[101];
int ans = -1e9;

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 10; j++) cin >> f[i][j];
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= 10; j++) cin >> p[i][j];
    }

    for(int mask = 1; mask < (1 << 10); mask++){

        memset(flag, 0, sizeof(flag));

        for(int i = 0; i < n; i++){
            for(int j = 0; j < 10; j++){
                if(mask & (1 << j)){
                    if(f[i][j]) flag[i]++;
                }
            }
        }
        int res = 0;
        for(int k = 0; k < n; k++){
            res += p[k][flag[k]];
        }
        ans = max(ans, res);
    }

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


Measured memory_bytes: 256
#include <cstdio>
int a[110];
int b1[110];
int main()
{
	  int n , m;
	 scanf("%d",&n);
	for(int i = 1; i <= n; i++)
	   {
	     scanf("%d",&a[i]);
	        b1[i] = a[i];
	 }
	   scanf("%d",&m);
	   while(m--)
	   {
	   	   int k , b;
	   	   scanf("%d %d",&k,&b);
	   	       a[k] = b;
			 int sum = 0;
			for(int i = 1; i <= n; i++)
			     sum += a[i];
			   printf("%d\n",sum); 
			   a[k] = b1[k];
	   }
	return 0;
}


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

using namespace std;

int N;
long long int A[100005];

long long int ans[100005];

int main(void) {

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}

	long long int tmp = A[1];

	for (int i = 2; i <= N - 1; i++) {
		if (i % 2 == 0) { tmp -= A[i]; }
		else { tmp += A[i]; }
	}

	tmp += A[N];

	ans[1] = tmp / 2;

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

	for (int i = 1; i <= N; i++) {
		if (i != 1) { cout << " "; }
		cout << ans[i] * 2;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 2816
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        char[][] c = new char[h][w];
        for(int i = 0; i < h; i++){
            String s = sc.next();
            for(int j = 0; j < w; j++){
                c[i][j] = s.charAt(j);
            }
        }
        
        int[][] ans = new int[h][w];
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(i == 0 && j == 0){
                    if(c[i][j] == '#'){
                        ans[i][j] = 1;
                    }else{
                        ans[i][j] = 0;
                    }
                }else if(i == 0){
                    if(c[i][j] == '#' && c[i][j-1] == '.'){
                        ans[i][j] = ans[i][j-1] +1;
                    }else{
                        ans[i][j] = ans[i][j-1];
                    }
                }else if(j == 0){
                    if(c[i][j] == '#' && c[i-1][j] == '.'){
                        ans[i][j] = ans[i-1][j] +1;
                    }else{
                        ans[i][j] = ans[i-1][j];
                    }
                }else{
                    if(c[i][j] == '#'){
                        if(c[i-1][j] == '.' && c[i][j-1] == '.'){
                            ans[i][j] = Math.min(ans[i-1][j], ans[i][j-1]) +1;
                        }else if(c[i-1][j] == '.'){
                            ans[i][j] = Math.min(ans[i-1][j] +1, ans[i][j-1]);
                        }else if(c[i][j-1] == '.'){
                            ans[i][j] = Math.min(ans[i-1][j], ans[i][j-1] +1);
                        }else{
                            ans[i][j] = Math.min(ans[i-1][j], ans[i][j-1]);
                        }
                    }else{
                        ans[i][j] = Math.min(ans[i-1][j], ans[i][j-1]);
                    }
                }
            }
        }
        System.out.println(ans[h-1][w-1]);
    }
}

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

int n,m;

struct edge{
	int from, to;
};

edge e[3000];

bool arr[51][51];
bool visited[51];

void dfs(int x){
	visited[x] = true;
	for(int i=1;i<=n;i++){
		if(arr[x][i]&&!visited[i])
			dfs(i);
	}
}

int main(){
	int x, y;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>x>>y;
		arr[x][y] = true;
		arr[y][x] = true;
		e[i].from = x;
		e[i].to = y;
	}
	/*for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)
			cout<<arr[i][j];
		cout<<endl;
	}*/
	int cnt = 0;
	for(int i=0;i<m;i++){
		bool ans = true;
		memset(visited,false,51);
		arr[e[i].from][e[i].to] = false;
		arr[e[i].to][e[i].from] = false;

		/*for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++)
				cout<<arr[j][k];
			cout<<endl;
		}*/
		dfs(1);

		for(int j=1;j<=n;j++)
			if(!visited[j])
				ans = false;

		if(!ans)
			cnt++;

		arr[e[i].from][e[i].to] = true;
		arr[e[i].to][e[i].from] = true;
		/*for(int j=1;j<=n;j++)
			cout<<visited[j];
		cout<<endl;*/
	}

	cout<<cnt<<endl;
}


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003;

int main(){
    
    ll K,A,B;cin>>K>>A>>B;
    if(A+1<B){
        K++;
        if(K>=A+2){
        K-=(A+2);
        ll now=B;
        now+=(B-A)*(K/2);
        K-=(K/2)*2;
        if(K==1) now++;
        cout<<now<<endl;
        }else cout<<K<<endl;
        
    }else{
        cout<<K+1<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<cstdio>
using namespace std;
typedef pair<int,int> gaidou;//first=nextbangou,second=nowcost
main(){
  vector< gaidou > to[22];
  int min_cost[22];
  queue< gaidou > que;
  int n,m;
  int a,b,c,d;
  int x1,x2,y1,y2;
  int ans=0;
  gaidou g;
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    min_cost[i]=1<<21;
  }
  for(int i=0;i<m;i++){
    scanf("%d,%d,%d,%d",&a,&b,&c,&d);
    g.first=b;
    g.second=c;
    to[a].push_back(g);
    g.first=a;
    g.second=d;
    to[b].push_back(g);
  }
  scanf("%d,%d,%d,%d",&x1,&x2,&ans,&y2);
  ans-=y2;
  //cout<<"A"<<ans<<endl;
  g.first=x1;
  g.second=0;
  que.push(g);
  while(!que.empty()){
    gaidou now=que.front();
    int size=to[now.first].size();
    for(int i=0;i<size;i++){
      if(to[now.first][i].second+now.second<min_cost[to[now.first][i].first]){
	min_cost[to[now.first][i].first]=to[now.first][i].second+now.second;
	g.first=to[now.first][i].first;
	g.second=to[now.first][i].second+now.second;
	//cout<<g.first<<" | "<<g.second<<endl;
	que.push(g);
      }
    }
    que.pop();
  }
  while(!que.empty()){
    que.pop();
  }
  ans-=min_cost[x2];
  //cout<<"B"<<ans<<endl;
  for(int i=1;i<=n;i++){
    min_cost[i]=1<<21;
  }
  g.first=x2;
  g.second=0;
  que.push(g);
  while(!que.empty()){
    gaidou now=que.front();
    //cout<<"now="<<now.first<<" "<<now.second<<endl;
    int size=to[now.first].size();
    for(int i=0;i<size;i++){
      if(to[now.first][i].second+now.second<min_cost[to[now.first][i].first]){
	min_cost[to[now.first][i].first]=to[now.first][i].second+now.second;
	g.first=to[now.first][i].first;
	g.second=to[now.first][i].second+now.second;
	//cout<<g.first<<" | "<<g.second<<endl;
	que.push(g);
      }
    }
    que.pop();
  }
  while(!que.empty()){
    que.pop();
  }
  ans-=min_cost[x1];
  cout<<ans<<endl;
}

Measured memory_bytes: 1244
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    m, d = map(int, input().split())

    res = 0
    for i in range(4, m + 1):
        for j in range(22, d + 1):
            d1, d10 = divmod(j, 10)
            if i == d1 * d10 and d1 >= 2 and d10 >= 2:
                res += 1

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 38768
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll n,k;
int main() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>k>>n;
    if(n>1){
        cout<<abs(n-k)<<endl;
    }
    else cout<<"0"<<endl;
	return 0;
}


Measured memory_bytes: 256
/*
 * 
 * 110101
 * po pierwszej zmianie wartosc spada na <= 2 * 10^5
 * log2(
 * 
 */
#include <bits/stdc++.h>

using namespace std;

#define LL long long 
#define ULL unsigned LL
#define LD long double 

const int N = 2e5 + 2137;
int f[N]; // value of f(i) for i <= 2*10^5

// return 2^x mod MOD
LL pot(LL x, LL mod) {
	if(x == 0)
		return 1;
	if(x%2) {
		return ((LL) 2 * pot(x-1, mod))%mod;
	}
	else {
		LL wx = pot(x/2, mod)%mod;
		return (wx*wx) % mod;
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	f[0] = 0;
	for(int i=1; i<=2e5; i++) {
		int x = i;
		int w = 0;
		while(x) {
			x = x %__builtin_popcount(x);
			w++;
		}
		f[i] = w;
	}
	int n;
	cin>>n;
	string s;
	cin>>s;
	LL val[3];
	LL p = 0;
	for(int i=0; i<n; i++) {
		if(s[i] == '1')
			p++;
	}
	val[0] = val[1] = val[2] = 0;
	for(int i=0; i<n; i++) {
		if(p > 1)
			val[0] = (val[0]*(LL)2 + (s[i]=='1'?1:0))%(p-1);
		if(p > 0)
			val[1] = (val[1]*(LL)2 + (s[i]=='1'?1:0))%p;
		val[2] = (val[2]*(LL)2 + (s[i]=='1'?1:0))%(p+1);
	}
	//cerr<<val[0]<<" "<<val[1]<<" "<<val[2]<<"\n\n\n";
	for(int i=0; i<n; i++) {
		if(s[i] == '1') {
			if(p == 1) {
				cout<<0<<"\n";
				continue;
			}
			// -1
			// val[0]
			LL vx = val[0] - pot(n-i-1, p-1);
			//cerr<<"Wartosc vx = "<<vx<<"\n";
			vx%=((LL)(p-1));
			vx+=((LL)(p-1));
			vx%=((LL)(p-1));
			//cerr<<"Wartosc po modulacji, vx = "<<vx<<"\n";
			cout<<1+f[vx]<<"\n";
		}
		else {
			// +1
			// val[2]
			LL vx = val[2] + pot(n-i-1, p+1);
			//cerr<<"2 - Wartosc vx = "<<vx<<"\n";
			vx%=((LL)(p+1));
			vx+=((LL)(p+1));
			vx%=((LL)(p+1));
			//cerr<<"2 - Wartosc po modulacji, vx = "<<vx<<"\n";
			cout<<1+f[vx]<<"\n";
		}
		//cerr<<"\n\n";
	}
}


Measured memory_bytes: 4524
import java.util.Scanner;

//20180510
//03

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

		while (scanner.hasNext()) {
			String str = scanner.nextLine();
			char[] cha = str.toCharArray();

			for(int i = 0;i < cha.length;i++) {
				if(Character.isLowerCase(cha[i])) {
					cha[i] = Character.toUpperCase(cha[i]);
				} else 	if(Character.isUpperCase(cha[i])) {
					cha[i] = Character.toLowerCase(cha[i]);
				}
			}

			String output = String.valueOf(cha);
			System.out.print(output);
		}
		System.out.println();
		scanner.close();
    }
}


Measured memory_bytes: 26192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

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

  int tmp = N, mod = 0;
  while (tmp != 0) {
    mod += tmp % 10;
    tmp /= 10;
  }

  if (N % mod == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        //var nabc = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        //var ls = new int[nabc[0]];
        var num = ToInt32(ReadLine());
        var res = 0d;
        for(var i = 0; i < num; i++)
        {
            var input = ReadLine().Split(' ');
            if (input[1] == "JPY")
                res += int.Parse(input[0]);
            else
            {
                res += double.Parse(input[0]) * 380000;
            }
        }
        WriteLine(res);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}

Measured memory_bytes: 11220
#include<cstdio>
#include<algorithm>
#define INF 30000
using namespace std;
int main(){

  int h,w;
  char c[51][51];
  int memo[51][51];
  fill_n(*memo,51*51,INF);
  memo[0][0] = 0;

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

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      scanf(" %c",&c[i][j]);
      c[i][j] = c[i][j] - '0';
      if(i==0&&j!=0) memo[i][j] = memo[i][j-1]+c[i][j];
      if(i!=0&&j==0) memo[i][j] = memo[i-1][j]+c[i][j];
    }
  }
  
  for(int i=1;i<h;i++){
    for(int j=1;j<w;j++){
      memo[i][j] = min(memo[i][j],memo[i-1][j]+c[i][j]);
      memo[i][j] = min(memo[i][j],memo[i][j-1]+c[i][j]);
    }
  }

  printf("%d\n",memo[h-1][w-1]);
  return (0);
}

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


void solve(){
    int n; cin >> n;
    queue<string> q;
    for(int i=1; i<=9; i++)
        q.push(to_string(i));
    //cout << q.front() << endl;
    if(n <= 9) cout << n << endl;
    int start = 9;
    string ans;
    while(start < n){
        string k = q.front(); q.pop();
        //cout << start << " " << k << endl;
        if(k[0] == '9'){
            q.push('8'+k);
            start++;
            if(start == n){
                ans = '8'+k;
                break;
            }
            q.push('9'+k);
            start++;
            if(start == n){
                ans = '9'+k;
                break;
            }
        }
        else if(k[0] == '0'){
            q.push('0' + k);
            start++;
            if(start == n){
                ans = '0' + k;
                break;
            }
            q.push('1' + k);
            start++;
            if(start == n){
                ans = '1' + k;
                break;
            }
        }
        else{
            q.push(to_string(k[0] -'0' - 1) + k);
            start++;
            if(start == n){
                ans = to_string(k[0] -'0' - 1) + k;
                break;
            }
            q.push(k[0] + k);
            start++;
            if(start == n){
                ans = k[0] + k;
                break;
            }
            q.push(to_string(k[0] - '0' + 1) + k);
            start++;
            if(start == n){
                ans = to_string(k[0] - '0' + 1) + k;
                break;
            }
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    
}

int main(){
    int t = 1; //cin >> t;
    while(t--){
        solve();
    }
}

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

using namespace std;

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

  int t[10] = {0};
  int index = 0;
  for (string::iterator it = s.begin(); it != s.end(); it++) {
    if (*it == '0') {
      t[index++] = 0;
    } else if (*it == '1') {
      t[index++] = 1;
    } else if (*it == 'B') {
      if (index > 0) {
        index--;
      }
    }
  }
  for (int i = 0; i < index; i++) {
    cout<<t[i];
  }
  cout<<endl;

  return 0;
}


Measured memory_bytes: 3116
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int n, a[300009];
int main() {
	cin >> n;
	for (int i = 0; i < 3 * n; i++) cin >> a[i];
	sort(a, a + 3 * n);
	ll ret = 0;
	for (int i = 3 * n - 2; i >= n; i -= 2) ret += a[i];
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 1408