akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
v = LI()
a = []
b = []
for i in range(n):
    if i % 2 == 0:
        a.append(v[i])
    else:
        b.append(v[i])
a = list(Counter(a).items())
b = list(Counter(b).items())
a.sort(key = lambda x:x[1], reverse=1)
b.sort(key = lambda x:x[1], reverse=1)
if len(a) == 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print(n//2)
    else:
        print(0)
elif len(a) > 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print((n-1)//2 + 1 - a[1][1])
    else:
        print((n-1)//2 + 1 - a[0][1])
elif len(a) == 1 and len(b) > 1:
    if a[0][0] == b[0][0]:
        print(n//2 - b[1][1])
    else:
        print(n//2 - b[0][1])
else:
    if a[0][0] == b[0][0]:
        print(min((n-1)//2 + 1 - a[1][1] + (n // 2) - b[0][1], (n-1)//2 + 1 - a[0][1] + (n // 2) - b[1][1]))
    else:
        print(min((n-1)//2 + 1 - a[0][1] + (n // 2) - b[0][1], (n-1)//2 + 1 - a[0][1] + (n // 2) - b[0][1]))


Measured memory_bytes: 62304
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define ll                  long long int
#define ull                 unsigned long long int
#define ld                  long double
#define fi                  first
#define se                  second
#define pb                  push_back
#define pbb                 pop_back
#define mp                  make_pair
#define popcount            __builtin_popcountll
#define pii     	        pair<int,int>
#define all(x)              x.begin(), x.end()
#define uniq(x)             x.erase(unique(x.begin(),x.end()),x.end())
#define mem(array, value)   memset(array, value, sizeof(array))
#define lcm(a,b)            (abs(a)/gcd(a,b))*abs(b)
#define random(a, b)        ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
#define PI      	        2*acos(0.0)
#define EPS     	        1e-8
#define line                cout << "\n==========\n"
#define fastRead 	        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define trace(...)          __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " , ";
    __f(comma + 1, args...);
}
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

const int INF = 1e9+9;
const int mod = 1e9+7;
const int nax = 2005;

ll fac[nax];

ll big_mod(ll a, ll p)
{
    if (p == 0){
        return 1;
    }
    if (p & 1){
        return (a * big_mod(a, p-1)) % mod;
    }
    ll y = big_mod(a, p/2);
    return (y*y) % mod;
}

ll mod_inv(ll a)
{
    return big_mod(a, mod-2) % mod;
}

void pre_cal()
{
    fac[0] = 1;
    for (ll i = 1; i < nax; i++){
        fac[i] = (i * fac[i-1]) % mod;
    }
}

ll nCr(ll n , ll r) {
    if (r == 0){
        return 1;
    }
    if (r > n){
        return 0;
    }
    if (n == r){
        return 1;
    }
    return (fac[n] * (mod_inv(fac[r]) * mod_inv(fac[n-r]) % mod)) % mod;
}

int main ()
{
    #ifdef Lollipop
        freopen ("input.txt", "r", stdin);
        //freopen ("output.txt", "w", stdout);
    #endif

    pre_cal();

    int n, k;
    cin >> n >> k;

    for (int i = 1; i <= k; i++){
        ll ans = (nCr(n-k+1, i) * nCr(k-1, i-1)) % mod;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
	int A,B;
	cin >> A >> B;

	if (A >= 13)cout << B << endl;
	else if (A <= 5)cout << 0 << endl;
	else cout << B / 2 << endl;

	return 0;
}


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

string s;
ll l[505050], r[505050];

int main(){
  cin >> s;
  int n = s.size();
  l[0] = 0;
  r[n] = 0;
  rep(i, n){
    if(s[i] == '<'){
      l[i + 1] = l[i] + 1LL;
    }
  }
  for(int i = n - 1; i >= 0; i--){
    if(s[i] == '>'){
      r[i] = r[i + 1] + 1LL;
    }
  }
  
  ll res = 0;
  rep(i, n + 1) res += max(l[i], r[i]);
  cout << res << endl;
  
  return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}





void _main() {
        int n; cin >> n;
        int t = 0, x = 0, y = 0;
        while (n--) {
                int when, x1, y1; cin >> when >> x1 >> y1;
                int bet = when - t;
                int dx = abs(x - x1), dy = abs(y - y1);
                if (dx + dy > bet || (dx + dy) % 2 != bet % 2) {
                        cout << "No";
                        return;
                }

                t = when, x = x1, y = y1;
        }

        cout << "Yes";
}




signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


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

sys.setrecursionlimit(10000)


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


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


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


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


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


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


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


def mt(f):
    import time

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

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

    return wrap


@mt
def slv(S, T, ABCD):

    S_ = [0]
    for c in S:
        S_.append((1 if c == 'A' else 2) + S_[-1])
    T_ = [0]
    for c in T:
        T_.append((1 if c == 'A' else 2) + T_[-1])

    for a, b, c, d in ABCD:
        s = (S_[b]-S_[a-1]) % 3
        t = (T_[d]-T_[c-1]) % 3
        if s == t:
            print('YES')
        else:
            print('NO')


def main():
    S = read_str()
    T = read_str()
    q = read_int()
    ABCD = [read_int_n() for _ in range(q)]
    slv(S, T, ABCD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 92628
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)

const string YES = "Possible";
const string NO = "Impossible";

bool impossible_checker(int N, string S) {
    assert((int)(S.length()) == (1 << N));
    if (S[0] == '0') return true;
    REP(a, 1 << N)
    {
        REP(b, 1 << N) if (((~b) & a) == 0) {
            if (S[b] == '1' and S[a] == '0') return true;
        }
    }
    return false;
}

vector<vector<int>> S(9);

int x_now, y_now;

vector<pint> ret;

void up() {
    y_now++;
    ret.emplace_back(x_now, y_now);
}
void down() {
    y_now--;
    ret.emplace_back(x_now, y_now);
}
void right() {
    x_now++;
    ret.emplace_back(x_now, y_now);
}
void left() {
    x_now--;
    ret.emplace_back(x_now, y_now);
}

void do_rloop(int X)
{
    if (y_now == 0) {
        up();
    }
    while (x_now < X) right();
    while (x_now > X) left();
    right();
    down();
    left();
    up();
}

void do_lloop(int X) {
    if (y_now == 0) {
        up();
    }
    while (x_now < X) right();
    while (x_now > X) left();
    down();
    right();
    up();
    left();
}

void go_origin() {
    if (y_now == 0) up();
    while (x_now > 0) left();
    down();
}

int main()
{
    int N;
    string A;
    cin >> N >> A;
    if (impossible_checker(N, A)) {
        cout << NO << endl;
        return 0;
    }

    S[1] = {+1};
    S[2] = {+1, +2, -1, -2};
    FOR(d, 3, S.size()) {
        S[d] = {d};
        vector<int> prev = S[d - 1];
        S[d].insert(S[d].end(), ALL(prev));
        S[d].push_back(-d);
        reverse(ALL(prev));
        for (auto &x : prev) x *= -1;
        S[d].insert(S[d].end(), ALL(prev));
    }

    up();
    down();

    REP(subset, 1 << N) if (A[subset] == '0') {
        bool must = true;
        REP(ss, 1 << N) if (((~subset) & ss) == 0 and ss < subset) {
            if (A[ss] == '0') must = false;
        }
        if (!must) continue;
        int cnt = __builtin_popcount(subset);
        if (cnt == 1) {
            int i = 0;
            while ((subset >> i) % 2 == 0) i++;
            do_rloop(i);
            continue;
        }

        vector<int> ns;
        REP(i, N) if ((subset >> i) & 1) ns.push_back(i);
        for (auto dict : S[cnt]) {
            int id_ = abs(dict) - 1;
            if (dict > 0) do_rloop(ns[id_]);
            else do_lloop(ns[id_]);
        }
    }
    go_origin();
    up();

    cout << YES << "\n";
    cout << ret.size() - 1 << "\n";
    for (auto p : ret) cout << p.first << " " << p.second << "\n";
}


Measured memory_bytes: 516
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        if(n % 2 != 0) System.out.println(0);
        else{
            n /= 2;
            long ans = 0L;
            for (int i = 25; i > 0; i--) {
                long a = n / (long)Math.pow(5, i);
                ans += a;
            }
            System.out.println(ans);

        }
        sc.close();

    }

}


Measured memory_bytes: 23892
#!/usr/bin/env python3
import sys
from operator import itemgetter
# gcd
# from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
# from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
# fin = open('in_2.txt', 'r')
# sys.stdin = fin
# 提出時はコメントアウト+上のshebangを有効にする
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template

MOD = 1000000007  # type: int

def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


if __name__ == '__main__':

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    setA = set(a)
    # write code
    dp = [0 for i in range(N + 10)]
    dp[0] = 1
    if 1 not in setA:
        dp[1] = 1
    else:
        dp[1] = 0
    if 2 not in setA:
        dp[2] = dp[1]+1
    else:
        dp[2]=0
    for i in range(3,N+1):
        if i-1 in setA and i-2 in setA:
            dp[i] = 0
        elif i - 1 in setA:
            dp[i] = dp[i - 2] % MOD
        elif i - 2 in setA:
            dp[i] = dp[i-1]%MOD
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % MOD

    print(dp[N])

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,X,T=MI()
    
    cnt=(N+X-1)//X
    ans=cnt*T
    print(ans)

main()


Measured memory_bytes: 61840
#include <iostream>
#define MAX_N 200000
using namespace std;
int main(void){
  int n;
  int a[MAX_N];
  int shine_button;
  cin >> n;
  for(int i = 1; i <= n; i++) cin >> a[i];
  shine_button = 1;
  for(int i = 1; i <= n; i++){
    shine_button = a[shine_button];
    if(shine_button == 2){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int maxn=307;
int n,K,mod;
int C[maxn][maxn];
int f[maxn][maxn];
int s[maxn][maxn];
int main(){
	scanf("%d%d%d",&n,&K,&mod),++n;
	for(int i=0;i<=n;i++){
		C[i][0]=1;
		for(int j=1;j<=i;j++)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
	for(int x=0;x<=K;x++)f[1][x]=1,s[1][x]=K-x+1;
	for(int i=2;i<=n;i++){
		for(int j=0;j<=K;j++){
			for(int k=1;k<i;k++){
				(f[i][j]+=C[i-2][k-1]*1ll*s[k][j+1]%mod*f[i-k][j]%mod)%=mod;
			}
		}
		for(int j=K;j>=0;j--)s[i][j]=(s[i][j+1]+f[i][j])%mod;
	}
	printf("%d\n",f[n][0]);
	return 0;
}



Measured memory_bytes: 1280
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N, K;
    std::cin >> N >> K;

    std::vector<int64_t> A;
    for (int64_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A.push_back(t);
    }

    int64_t g = A[0];

    for (int64_t i = 1; i < N; ++i) {
        g = boost::math::gcd(g, A[i]);
    }

    if (K % g != 0 || K > *std::max_element(A.begin(), A.end())) {
        std::cout << "IMPOSSIBLE" << std::endl;
    }
    else {
        std::cout << "POSSIBLE" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 1400
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

map<ll, ll> prime_factor(ll n){
	map<ll, ll> res;
	for(ll i = 2; i*i <= n; i++){
		while(n%i == 0){
			res[i]++;
			n /= i;
		}
	}
	if(n != 1) res[n] = 1;
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, p;
	cin >> n >> p;
	ll ans = 1;
	for(auto e : prime_factor(p)){
		ll num = e.second / n;
		rep(i,num) ans *= e.first;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner  sc = new Scanner(System.in);
        int a,b,ans;
        a=sc.nextInt();
        b=sc.nextInt();
        ans = (a*2)+(b*2);
        System.out.println(a*b+" "+ans);
    }
    
}


Measured memory_bytes: 26296
A, B, C, D, E, F = map(int, input().split())
dens = 0
ans_water = 100*min(A, B)
ans_sugar = 0
for i in range(31):
    for j in range((F-(100*A*i))//(100*B)+1):
        for k in range((F-(100*A*i)-(100*B*j))//C+1):
            for l in range((F-(100*A*i)-(100*B*j)-(C*k))//D+1):
                water = 100*A*i+100*B*j
                sugar = C*k+D*l
                if water == 0:
                    break
                if sugar <= E*(A*i+B*j):
                    if dens<sugar/(sugar+water):
                        dens = sugar/(sugar+water)
                        ans_water = water
                        ans_sugar = sugar
print(ans_water+ans_sugar, ans_sugar)

Measured memory_bytes: 9208
n,m,k = map(int,input().split())
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
ans = [-1]*n
uf = UnionFind(n)
for i in range(m):
  a,b = map(int,input().split())
  ans[a-1] -= 1
  ans[b-1] -= 1
  uf.union(a-1,b-1)
for i in range(n):
  ans[i] += uf.size(i)
root = [uf.find(i)-1 for i in range(n)]
for i in range(k):
  c,d = map(int,input().split())
  if root[c-1]==root[d-1]:
    ans[c-1] -= 1
    ans[d-1] -= 1
print(*ans)

Measured memory_bytes: 85720
n = gets.chop.to_i
a = gets.chop.split.map(&:to_i)

sum_a = a.inject(:+)

tmp = 0
i = 0
while 1 do
  tmp += a[i]
  if tmp >= sum_a/2
    index = i
    break
  end

  i += 1
end

if index == 0
  p (a[0]- a[1..n-1].inject(:+)).abs
else
  if index != n-1
    ans_1 = a.slice(0..index).inject(:+) - a.slice(index+1..n-1).inject(:+)
  else
    ans_1 = a[n-1] - a.slice(0..n-2).inject(:+)
  end
  ans_2 = a.slice(index..n-1).inject(:+) - a.slice(0..index-1).inject(:+)


  p [ans_1.abs, ans_2.abs].min
end






Measured memory_bytes: 19844
# ruby 2.7 + numo/ndarray
require "numo/narray"

class PriorityQueue
  attr_accessor :heap, :size
  def initialize(n)
    @heap = Numo::Int64.zeros(n)
    @size = 0
  end

  def <<(x)
    i = size
    self.size += 1
    while i > 0
      j = (i - 1) / 2
      break if heap[j] >= x # <
      heap[i] = heap[j]
      i = j
    end
    heap[i] = x
  end

  def pop
    ret = heap[0]
    self.size -= 1
    x = heap[size]
    i = 0
    while i * 2 + 1 < size
      a = i * 2 + 1
      b = i * 2 + 2
      a = b if b < size && heap[b] > heap[a] # <
      break if heap[a] <= x #<
      heap[i] = heap[a]
      i = a
    end
    heap[i] = x
    ret
  end
end

class Problem
  attr_accessor :a, :b, :c, :n, :m, :k, :h, :w, :x, :y, :ans, :q
  def initialize
    @n = gets.to_s.to_i
    @a = gets.to_s.split.map{ |v| v.to_i }.sort!.reverse!
    @q = PriorityQueue.new(200_000)
    v = a.shift
    q << v
  end

  def solve
    ans = 0
    while a.size > 0
      v = a.shift
      t = q.pop
      ans += t
      q << v
      q << v
    end
    puts ans
  end
end

pb = Problem.new
pb.solve


Measured memory_bytes: 30900
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n,c=0;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;++i)cin>>a[i];
  for(int i=0;i<n;++i){
    for(int j=n-1;i<j;--j){
      if(a[j]<a[j-1]){swap(a[j-1],a[j]);++c;}
    }
  }
  for(int i=0;i<n;++i) cout<<a[i]<<((i==n-1)?"\n":" ");
  cout<<c<<endl;
  return 0;
}


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

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;


fn main() {
  let n = read::<i64>();
  let m = read::<i64>();
  let x = read::<i64>();
  let mut m_vec = vec![];

  for _ in 0..m {
    m_vec.push(read::<i64>())
  }

  m_vec.sort();

  let mut to_zero = 0;
  let mut to_n = 0;
  for i in m_vec {
    if i < x {
      to_zero += 1;
    } else {
      to_n += 1;
    }
  }

  println!("{}", min(to_zero, to_n));

}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
ll ceil(ll a,ll b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    int t;
    t=1;
    while(t--)
    {
        int a,b,c,k,i;
        cin>>a>>b>>c>>k;
        int cnt=0;
        while(b<=a) {
            b*=2;
            cnt++;
        }
        while(c<=b) {
            c*=2;
            cnt++;
        }
        if(cnt<=k)
            cout<<"Yes"<<endl;
        else
        {
            cout<<"No"<<endl;
        }
        
    }
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return a1.size() - a2.size();
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

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

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

int main() {
  std::cout << std::setprecision(9);
  long a;
  cin >> a;

  double b;
  cin >> b;

  long c = b * 100 + 0.5;
  long d = a * c;
  cout << d / 100 << endl;
}

Measured memory_bytes: 3732
#include<bits/stdc++.h>
#define ll long long
#define re register
#define ull usigned ll
using namespace std;
inline int read(){
	int s=0,t=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
	return s*t;
}
const int N=(1<<19);
int n,m,U,Num,s[19],p[N];
int L[19][N],R[19][N],dl[N],dr[N];
int Calc(int m){
	int lim=0;
	while(m)s[lim++]=m,m>>=1;
	return ++lim;
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read(),m=Calc(read()),U=(1<<m)-1;
	for(int i=1;i<=n;i++)p[i]=read();
	for(int k=0;k<m;k++){
		for(int i=1,j=0;i<=n;){
			for(j=i;j<n&&p[j+1]-p[j]<=s[k];j++);
			for(;i<=j;i++)R[k][i]=j;
		}
		for(int i=n,j=0;i>=1;){
			for(j=i;j>1&&p[j]-p[j-1]<=s[k];j--);
			for(;i>=j;i--)L[k][i]=j;
		}		
	}
	
	for(int S=0;S<=U;S++)dl[S]=0,dr[S]=n+1;
	for(int S=0;S<=U;S++){
		for(int i=0;i<m;i++)
		if(!(S>>i&1)){
			int T=S|(1<<i);
			dl[T]=max(dl[T],min(n,R[i][dl[S]+1]));
			dr[T]=min(dr[T],max(1,L[i][dr[S]-1]));
		}
	}
	for(int i=1;i<=n;i=R[0][i]+1)Num++;
	if(Num>m){for(int i=1;i<=n;i++)puts("Impossible");return 0;}
	for(int i=1;i<=n;i=R[0][i]+1){
		int l=i,r=R[0][i],t=0;
		for(int S=0;S<=U;S++)
		if((S&U-1)==S){if(dl[S]>=l-1&&dr[U-1^S]<=r+1)t=1;}
		for(int j=l;j<=r;j++)puts(t?"Possible":"Impossible");
	}
	return 0;
}

Measured memory_bytes: 38228
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    S = set(A)

    if len(S) == N:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 123144
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N = next(it)
    A = [next(it) for i in range(N)]

    if N == 1:
        print(1)
        return

    ax = max(A)+1
    dp = [0]*ax
    for ai in A:
        da = dp[ai]
        if da > 1:
            continue
        if da == 0:
            dp[ai] = 1
            for aj in range(2*ai, ax, ai):
                dp[aj] = 2
        else:
            dp[ai] = 2
    ans = 0
    for ai in A:
        if dp[ai] == 1:
            ans += 1
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 98092
N = int(input())
A = list(map(int,input().split()))
dp = [{} for _ in range(N+1)]
INF = -float('inf')
for i in range(1,N+1):
    mid = i//2
    dp[i][mid-2],dp[i][mid-1],dp[i][mid],dp[i][mid+1],dp[i][mid+2]=INF,INF,INF,INF,INF
dp[1][1] = A[0]
dp[2][1] = max(A[1],dp[1][1])
dp[1][0],dp[2][0]=0,0

for i in range(2,N):
  a = A[i]
  ma = (i+2)//2
  mi = i//2
  dp[i+1][ma] = max(dp[i][ma],dp[i-1][ma-1]+a)
  dp[i+1][mi] = max(dp[i][mi],dp[i-1][mi-1]+a)

print(dp[-1][N//2])

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

using namespace std;

int main(){
	int num, human, one, two;
	int i, j, nans, wans;
	while(cin >> num){
		if(num == 0) break;
		int tmp = 0;
		for(i = 0; i < num; ++i){
			cin >> human >> one >> two;
			if(one + two > tmp){
				tmp = one + two;
				nans = human;
				wans = tmp;
			}
		}
		cout << nans << " " << wans << endl;
 	}
	return 0;
}

Measured memory_bytes: 3004
#include<stdio.h>
#include<string.h>
char S[11];
int main(){
	scanf("%s", S);
	int l = strlen(S);
	long sum = 0;
	for(int i=0; i<(1<<l-1); i++){
		long k=1;
		sum += S[l-1] - 48;
		for(int j=0; j<l-1; j++){
			if((i>>j)&1){
				k *= 10;
			}else {
				k = 1;
			}
			sum += (S[l-2-j]-48) * k;
		}
	}
	printf("%ld\n", sum);
	return 0;
}

Measured memory_bytes: 1720
import java.util.Scanner;

public class Main {
    public Main () {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        int ans;
        int sum = 0;

        String s = String.valueOf(n);

        int a = s.charAt(0) - '0';

        ans = a - 1 + (s.length() - 1) * 9;

        for(int i = 0; i< s.length(); i++)
            sum += s.charAt(i) - '0';

        if (ans < sum)
            ans = sum;

        System.out.println(ans);
    }


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

}


Measured memory_bytes: 23252
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String t = scan.next();
    String g = "abcdefghijklmnopqrstuvwxyza";
    for (int i=0;i<g.length();i++){
      if (g.charAt(i) == t.charAt(0)){
        System.out.println(g.charAt(i+1));
        return;
      }
    }
  }
}


Measured memory_bytes: 35556
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
inline char nc() {
    return getchar();
    static char buf[100000], *l = buf, *r = buf;
    return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x) {
    x = 0; int f = 1, ch = nc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
    while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
    x *= f;
}
typedef long long LL;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 50;
int n;
char s[maxn];
int a[maxn];
int solve() {
    n <<= 1;
    for(int i = 1; i <= n; ++i) {
        a[i] = s[i] == 'B';
    }
    for(int i = n; i >= 1; --i) {
        a[i] ^= a[i - 1];
    }
    a[0] = 1;
    for(int i = 1; i <= n; ++i) {
        a[i] ^= a[i - 1] ^ 1;
    }
    int an = 1, cnt = 0;
    for(int i = 1; i <= n; ++i) {
        if(a[i]) ++cnt;
        else {
            if(cnt == 0) return 0;
            an = (LL)an * cnt % mod;
            --cnt;
        }
    }
    if(cnt) return 0;
    n >>= 1;
    for(int i = 1; i <= n; ++i) {
        an = (LL)an * i % mod;
    }
    return an;
}
int main() {
    read(n);
    scanf("%s", s + 1);
    printf("%d\n", solve());
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,K;
  cin>>N>>K;
  vector <int64_t> H(N);
  for(int i=0;i<N;i++){
  cin>>H.at(i);
  }
  sort(H.begin(),H.end());
 int64_t sum=0;
  if(K<N){
  for(int i=0;i<N-K;i++){
  sum+=H.at(i);
   }
  }cout<<sum<<endl;
 return 0;
}

Measured memory_bytes: 1792
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!(
    n: usize,
    a: [usize; n]
    );
    let mut ans = "APPROVED";
    for i in a {
        if i & 1 == 0 {
            if i % 3 != 0 && i % 5 != 0 {
                ans = "DENIED";
                break;
            }
        }
    }

    print!("{}", ans);
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, k, r, s, p, c=0;
  string t, o="";
  cin >> n >> k >> r >> s >> p >> t;
  forll(i, 0, n){
	if (k > i){
	  if (t[i] == 'r'){
		c += p;
		o += "p";
	  }
	  else if (t[i] == 's'){
		c += r;
		o += "r";
	  }
	  else if (t[i] == 'p'){
		c += s;
		o += "s";
	  }
	}
	else{
	  if (t[i] == 'r' && o[i-k] != 'p'){
		c += p;
		o += "p";
	  }
	  else if (t[i] == 's' && o[i-k] != 'r'){
		c += r;
		o += "r";
	  }
	  else if (t[i] == 'p' && o[i-k] != 's'){
		c += s;
		o += "s";
	  }else
		o += "x";
	}
  }
  cout << c << endl;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
LL a;
int  l,r;
int main() {
  scanf("%lld",&a);
  scanf("%d.%d",&l,&r);
  l*=100;
  l+=r;
  cout<<a*l/100<<'\n';
  return 0;
}

Measured memory_bytes: 3684
#include <stdio.h>

int main(void)
{

	long long int N, i, ans = 0;
	scanf("%ld", &N);
	int A[N + 1], B[N];

	for (i = 0;i < N + 1;i++)scanf("%ld", &A[i]);
	for (i = 0;i < N;i++)scanf("%ld", &B[i]);
	for (i = 0;i < N;i++) {
		if (A[i] >= B[i]) {
			A[i] -= B[i];
			ans += B[i];
		}
		else {
			ans += A[i];
			if (A[i + 1] >= (B[i] - A[i])) {
				A[i + 1] -= (B[i] - A[i]);
				ans += (B[i] - A[i]);
			}
			else {
				ans += A[i + 1];
				A[i + 1] = 0;
			}
		}
	}
	printf("%ld", ans);
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j;
  ll n,a,b; cin>>n>>a>>b;
  //ll a,b,c,d,e,f; cin>>a>>b;
  //ll a,b,c,d,e,f; cin>>a>>b>>c;
  //ll a,b,c,d,e,f; cin>>a>>b>>c>>d;
  //string s; cin >> s;
  ll result = 0;
  ll buf = 0;
  ll buf2 = 0;
  ll buf3 = 0;
  bool judge = true;
  //cout<<<<endl;
  for(i=1;i<=n;i++){
    for(buf=0,buf2=i;buf2!=0;buf2/=10)buf+=buf2%10;
    if(buf>=a&&buf<=b)result+=i;
  }
  cout<<result<<endl;
  /*
  vector<ll> a(n);
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  for(i=0;i<n;i++){

  }
  */

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define FF first
#define SS second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define PLL pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define LP lower_bound
#define UP upper_bound
#define MP make_pair
#define rep1 for(i=1;i<=n;i++)
#define VLL vector<ll>
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define UMP unordered_map
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
    fastio
    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r, t,u,w,x,y,z;
    string str, ss, str1;
    /*
    **  author : mahiman12
    **  created : 2020-05-03 17:30 
    */
    cin>>str;
    if(str=="ABC")
        cout<<"ARC";
    else
        cout<<"ABC";
}

Measured memory_bytes: 3656
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long int ll;
#define MOD (1e9+7);
#define INF (2e9)

int main(void){
	ll x,y;
	cin>>x>>y;
	if(x-y==1||x-y==0||x-y==-1){
		cout<<"Brown"<<endl;
	}else{
		cout<<"Alice"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define rnt register int
using namespace std;
int dp[1<<13],n,m,t;
int w[1010],b,d[1010];
int main()
{
	memset(dp,0x3f,sizeof(dp));
	scanf("%d %d",&n,&m);
	for(rnt i=0;i<m;i=-~i)
	{
		scanf("%d %d",&w[i],&b);
		for(rnt j=0;j<b;j=-~j)
		{
			scanf("%d",&t);
			d[i]|=1<<t-1;
		}
	}dp[0]=0;
	for(rnt i=0;i<=(1<<n)-1;i=-~i)
		for(rnt j=0;j<m;j=-~j)
			if(dp[i]+w[j]<dp[i|d[j]])
				dp[i|d[j]]=dp[i]+w[j];
	if(dp[(1<<n)-1]>=1e9) puts("-1");
	else printf("%d",dp[(1<<n)-1]);
	return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop


def get_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            heappush(divisors, -i)
            if i != n // i:
                heappush(divisors, -(n // i))

    return divisors


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

    sum_A = sum(A)

    divisors = get_divisors(sum_A)
    n = len(divisors)
    for _ in range(n):
        h = -heappop(divisors)
        sub_list = []
        for a in A:
            sub_list.append(a % h)

        x = sum(sub_list)
        sub_list.sort()
        
        if sum(sub_list[:-x // h]) <= K:
            print(h)
            exit()

    print(0)


if __name__ == '__main__':
    p_e()


Measured memory_bytes: 44124
S=input()
T=input()
candidates=[]
strings=[]
for i in range(len(S)-len(T)+1):
    flag=1
    for j in range(len(T)):
        if S[i+j]=='?':
            pass
        else:
            if S[i+j]!=T[j]:
                flag=0
                break
            else:
                pass
    if flag:
        replacement=S[:i]+T+S[i+len(T):]
        strings.append(replacement)

for string in strings:
    s=''
    for i in range(len(string)):
        if string[i]=='?':
            s=s+'a'
        else:
            s=s+string[i]
    candidates.append(s)

if len(candidates)==0:
    print("UNRESTORABLE")
    quit()
elif len(candidates)==1:
    print(candidates[0])
    quit()
else:
    candidates.sort()
    print(candidates[0])
    quit()

Measured memory_bytes: 3064
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int solve(string s){
  dump(s);
  int n = SZ(s);
  if(s.find('1') == string::npos){
    if(s.find('2') == string::npos) return 0;
    rep(i, n)if(s[i] == '2') s[i]--;
    return solve(s)*2;
  }else{
    string t;
    int m = 1;
    while(m <= n) m <<= 1;
    m >>= 1;
    if(n == m){
      int cnt = 0;
      rep(i, n){
        cnt += s[i] == '1';
      }
      return cnt%2;
    }
    int cnt = 0;
    rep(i, m){
      cnt += s[i] == '1';
    }
    t += (cnt%2 == 0 ? '0' : '1');
    repr(i, m, n){
      cnt += s[i] == '1';
      cnt -= s[i-m] == '1';
      t += (cnt%2 == 0 ? '0' : '1');
    }
    return solve(t);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int n;
  cin >> n;
  string s;
  cin >> s;
  rep(i, SZ(s)) s[i]--;
  print(solve(s));
}


Measured memory_bytes: 4764
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int n; cin >> n;
    vector<int> h(n), dp(n);
    for(int i = 0; i < n; ++i){
        cin >> h[i];
    }
    dp[0] = 0; dp[1] = abs(h[0]-h[1]);
    for(int i = 2; i < n; ++i){
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
results = []

loop do

	locs = []

	n = gets.to_i
	break if n == 0
	n.times do
		s = gets.split ' '
		x = s.first.to_i
		y = s.last.to_i
		locs << [x, y]
	end

	m = gets.to_i
	m.times do
		s   = gets.split ' '
		dir = s.first
		dis = s.last.to_i
		dis.times do
			case dir
				when 'N'
					locs.map! { |l| [l[0], l[1] -= 1] }
				when 'S'
					locs.map! { |l| [l[0], l[1] += 1] }
				when 'E'
					locs.map! { |l| [l[0] -= 1, l[1]] }
				when 'W'
					locs.map! { |l| [l[0] += 1, l[1]] }
			end
			locs.reject! { |l| l[0] == 10 && l[1] == 10 }
		end
	end
	results << (locs.length == 0 ? 'Yes' : 'No')
end

results.each { |r| puts r }

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

int n, m, k, psum[11][1001];

int Solve(int mask){
  vector <pii> memo;
  int pre = 1; int cnt = n - 1;
  for (int i = 0; i < n - 1; i++){
    if ((mask >> i) & 1){
      memo.push_back(pii(pre, i + 1));
      pre = i + 2;
    }
    else cnt--;
  }
  memo.push_back(pii(pre, n));
  vector <int> F(memo.size(), 0);
  for (int i = 1; i <= m; i++){
    bool Ok = true;
    for (int j = 0; j < memo.size(); j++){
      int l = memo[j].first; int r = memo[j].second;
      if (psum[r][i] - psum[l - 1][i] > k) return INF;
      F[j] += psum[r][i] - psum[l - 1][i];
      if (F[j] > k) Ok = false;    
    }    
    if (!Ok){
      for (int j = 0; j < memo.size(); j++){
        int l = memo[j].first; int r = memo[j].second;
        F[j] = psum[r][i] - psum[l - 1][i];   
      }  
      cnt++;
    }
  }
  return cnt;
}

int main()
{
  fastio;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++){
    for (int j = 1; j <= m; j++){
      char c; cin >> c;
      psum[i][j] = psum[i - 1][j] + (c - '0');
    }
  }
  int res = INF;
  for (int mask = 0; mask < (1 << (n - 1)); mask++) res = min(res, Solve(mask));
  cout << res;
  return 0;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
s = list(map(int, input().split()))
evenL = []
oddL = []
for i, v in enumerate(s):
  if i % 2 == 0:
    evenL.append(v)
  else:
    oddL.append(v)
    
evenLc = Counter(evenL)
oddLc = Counter(oddL)

evenLcs = sorted(evenLc.items(), key=lambda x: -x[1])
oddLcs = sorted(oddLc.items(), key=lambda x: -x[1])

if evenLcs[0][0] != oddLcs[0][0]:
  print(n - evenLcs[0][1] - oddLcs[0][1])
else:
  if len(evenLc) == 1 and len(oddLc) == 1:
    print(n - len(evenL))
    exit()
  if evenLcs[0][1] > oddLcs[0][1]:
    print(n - evenLcs[0][1] - oddLcs[1][1])
  elif evenLcs[0][1] < oddLcs[0][1]:
    print(n - evenLcs[1][1] - oddLcs[0][1])
  else:
    print(n - evenLcs[0][1] - max(evenLcs[1][1], oddLcs[1][1]))

Measured memory_bytes: 23776
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,w,ans;
	cin>>w>>a>>b;
	if(b<=a+w&&b+w>=a+w){
		ans=0;
	}
	else if(a+w<b){
		ans=b-(a+w);
	}
	else if(b<a&&b+w<=a){
		ans=a-(b+w); 
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] cells = new int[N];
		for (int i = 0; i < cells.length; i++) {
			cells[i] = sc.nextInt();
		}
		sc.close();

		Deque<Integer> bfs = new ArrayDeque<Integer>();
		bfs.add(0);
		int[] dp = new int[N];
		Arrays.fill(dp, 10000000);
		dp[0] = 0;
		while (!bfs.isEmpty()) {
			int poll = bfs.pollFirst();
			if (cells[poll] == 0) {
				for (int d = 1; d <= 6; d++) {
					int jump = Math.min(poll + d, N - 1);
					if (dp[jump] > dp[poll] + 1) {
						dp[jump] = dp[poll] + 1;
						bfs.addLast(jump);
					}
				}
			} else {
				int jump = poll + cells[poll];
				if (dp[jump] > dp[poll]) {
					dp[jump] = dp[poll];
					bfs.addFirst(jump);
				}
			}
		}
		System.out.println(dp[N - 1]);

	}
}

Measured memory_bytes: 64268
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;

// 最大公約数
ll d(int f, int s)
{
    if (s % f == 0)
        return f;
    else
        return d(s % f, f);
}
int main()
{
    int N;
    cin >> N;
    vector<ll> A;

    for (int i = 0; i < N; i++)
    {
        ll ai;
        cin >> ai;
        A.push_back(ai);
    }
    sort(A.begin(), A.end());
    if (A[0] == A[N - 1])
    {
        cout << A[N - 1] << endl;
        return 0;
    }

    ll common = A[0];
    for (int i = 1; i < N; i++)
    {
        common = d(common, A[i]);
    }
    cout << common << endl;
}

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] cell = new int[r+1][c+1];
		
		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				cell[i][j] = sc.nextInt();
				
			}
			
		}

		for(int i = 0; i < r; i++) {
			int sum = 0;
			for(int j = 0; j < c; j++) {
				sum += cell[i][j];
				System.out.printf("%d ",cell[i][j]);
				
			}
			System.out.printf("%d",sum);
			System.out.println();
		}
		
		int total = 0;
		for(int j = 0; j < c; j++) {
			int sum = 0;
			for(int i = 0; i < r; i++) {
				sum += cell[i][j];
				}
			System.out.printf("%d ",sum);
			total += sum;
		}
		System.out.printf("%d",total);
		System.out.println();
		

	}
}


Measured memory_bytes: 52772