akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,y;
cin>>n>>y;
y=y/1000;
int a,b,c;
a=b=c=-1;
for(int i=0;10*i<=y;i++){
int z=(y-10*i)/5;
for(int j=0;j<=z;j++){
int k=y-10*i-5*j;
if(i+j+k==n){
a=k;
b=j;
c=i;
break;
}
}
}
cout <<c<<" "<<b<<" "<<a<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>	// upper_bound(A, A+N, num):>, lower_bound(A, A+N, num):>=
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>	// V[i],  push_back(x), pop_back(), insert(index, x), erase(index), sort(v.begin(), v.end(), greater<int>())
#include <list>		// push_front(x), push_back(x), pop_front(), pop_back(), insert(index, x)
#include <queue>	// push(x), front(), pop()
#include <deque>
#include <stack>	// push(x), top(), pop()
#include <map>		// M[key],  insert(key, val), erase(key), find(key), 
#include <set>		// insert(key), erase(key), find(key)

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

#define pi 3.141592653589793)
#define mod 1000000007

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

void solve() {
	ll x, y;
	cin >> x >> y;
	int ans = -1;
	if (!(x >= y && x % y == 0)) ans = x;
	cout << ans << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef priority_queue<int> Pr; typedef vector<int> V; typedef vector<P> Vp; typedef map<int,int> MP;
const int mod = 100000; const Int INF = 1145141919810893931;
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define END {cout<<ans<<'\n'; return 0;}
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) {}
	ModInt(signed sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while(b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if(u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}

	bool operator==(ModInt that) const { return x == that.x; }
	bool operator!=(ModInt that) const { return x != that.x; }
	ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
	ModInt<MOD> r = 1;
	while(k) {
		if(k & 1) r *= a;
		a *= a;
		k >>= 1;
	}
	return r;
}
typedef ModInt<mod> mint;

mint dp[50][2000];

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

    int n; cin>>n; pair<Int,pair<Int,Int>> s[n];
    for (int i = 0; i < n; i++){
        Int a,b; cin>>a>>b;
        s[i].first=a+b;
        s[i].second.first=a,s[i].second.second=b;
    }
    sort(s,s+n); Int sa=0,sb=0;
    for (int i = 0; i < n; i++){
        if(i%2)sb+=s[n-i-1].second.second;
        else sa+=s[n-i-1].second.first;
    }
    cout<<sa-sb<<'\n';
}

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

using namespace std;

int main(int argc, const char * argv[]) {
    string a,b,c;
    cin >> a >> b >> c;
    
    if(a[a.size()-1] == b[0] && b[b.size()-1]==c[0]){
        cout << "YES";
    }else{
        cout << "NO";
    }
    return 0;
}


Measured memory_bytes: 256
def sosu(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
    
    
n = int(input())
ans = 0
for i in range(n):
    m = int(input())
    if sosu(m):
        ans += 1
    else :
        ans += 0
print(ans)


Measured memory_bytes: 5708
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

macro_rules! stdin {
    () => ({
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    })
}

fn main() {
    let ans = solve(stdin!());
    println!("{}", ans);
}

fn solve(src: String) -> String {
    input!{
        source = src,
        abc: [usize; 3]
    }
    let mut abc = abc;
    abc.sort();
    let mut iter = abc.iter();
    let a = iter.next().unwrap();
    let b = iter.next().unwrap();
    let ans = a * b / 2;
    ans.to_string()
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => (
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input.to_string()), $output);
            )*
        }
    )
}

test! {
    "3 4 5" => "6",
    "5 12 13" => "30",
    "45 28 53" => "630",
}


Measured memory_bytes: 4352
import sys
sys.setrecursionlimit(10**9)
N,m=map(int,input().split())
s = set()
for i in range(m):
    s.add(int(input()))
memo={0:1}
mod=1000000007
def climb_stairs(n):
    if memo.__contains__(n):
        return memo[n]
    else:
        if s.__contains__(n):
            return 0
        elif n==1:
            return 1
        else:
            memo[n]=(climb_stairs(n-1)%mod + climb_stairs(n-2)%mod)%mod
            return memo[n]
print(climb_stairs(N))


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define IMP cout << "IMPOSSIBLE" << endl
#define Imp cout << "Impossible" << endl
#define imp cout << "impossible" << endl
#define M1 cout << "-1" << endl
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using vpint = vector<pint>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

int n, A, B, C;
int l[10];

int f(int i, int a, int b, int c, int x)
{
    int ret = INF;
    if (i == n)
    {
        if (a && b && c)
            ret = abs(A - a) + abs(B - b) + abs(C - c) + (x - 3) * 10;
        return ret;
    }

    ret = min(ret, f(i + 1, a, b, c, x));
    ret = min(ret, f(i + 1, a + l[i], b, c, x + 1));
    ret = min(ret, f(i + 1, a, b + l[i], c, x + 1));
    ret = min(ret, f(i + 1, a, b, c + l[i], x + 1));

    return ret;
}

void Main()
{
    cin >> n >> A >> B >> C;
    rep(i, n) cin >> l[i];
    cout << f(0, 0, 0, 0, 0) << endl;
}

signed main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

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

  vector<vector<int>> a(2, vector<int>(n + 1));
  for (int i = 0; i < 2; ++i) {
    for (int j = 1; j <= n; ++j) {
      cin >> a[i][j];
      a[i][j] += a[i][j - 1];
    }
  }

  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = max(ans, a[0][i] + a[1][n] - a[1][i - 1]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI a(n);
    int sum = 0;
    REP(i,n){
        a[i] = in();
        sum += a[i];
    }

    int ans = sum, x = 0;
    REP(i,n){
        x += a[i];
        chmin(ans, abs(sum - 2 * x));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
str = list(raw_input())
f = int(str[0]+str[1])
l = int(str[2]+str[3])
# 文字列の入力
if(f > 0 and 13 > f):
    if(l == 0):
        ans = "MMYY"
    if(l > 0 and 13 > l):
        ans = "AMBIGUOUS"
    if(l >= 13):
        ans= "MMYY"
elif(f == 0):
    if(l == 0):
        ans = "NA"
    if(l > 0 and 13> l):
        ans = "YYMM"
    if(l >= 13):
        ans= "NA"
elif(f>=13):
    if(l == 0):
        ans = "NA"
    if(l > 0 and 13> l):
        ans = "YYMM"
    if(l >= 13):
        ans= "NA"
print ans

Measured memory_bytes: 2692
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
using namespace std;
typedef pair<int, int> P;
typedef long long LL;

#define _CRT_SECURE_NO_WARNINGS
int N;
int C[505],S[505],F[505];
int main() {
	scanf("%d",&N);
	for (int i = 1; i <= N-1;i++) {
		scanf("%d %d %d",&C[i],&S[i],&F[i]);
	}
	for (int i = 1; i <= N - 1; i++) {
		int now = 0;
		now += S[i] + C[i];
		for (int j = i + 1; j <= N-1; j++) {
			if (now < S[j]) {
				now = S[j] + C[j];
			}
			else if (now%F[j]==0) {
				now += C[j];
			}
			else{
				now = now - now%F[j] + F[j]+C[j];
			}
		}
		printf("%d\n",now);
	}
	printf("0");
	return 0;
}

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

struct ac{
    int x, y;
}a[55], d[55];

int cmp1(ac b, ac c)
{
    return b.x < c.x;
}

int cmp2(ac b, ac c)
{
    return b.y<c.y;
}

int sl(int x1,int y1,int x2,int y2,int i)
{
    int xl = min(x1, x2), xr = max(x1, x2);
    int yl = min(y1, y2), yr = max(y1, y2);
    if(a[i].x >= xl && a[i].x <= xr && a[i].y >= yl && a[i].y <= yr)
    {
        return 1;
    }
    return 0;
}

int main()
{
    ll maxx = 1ll*10e9*10e9*4+2;
    int n, k1;
    cin >> n >> k1;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i].x >> a[i].y;
        d[i].x = a[i].x, d[i].y = a[i].y;
    }
    sort(a+1, a+1+n,cmp1);
    sort(d+1, d+n+1,cmp2);
    for(int i = 1; i <= n; i++)
    {
        for(int j = i+1; j <= n; j++)
        {
            for(int k = 1; k <= n; k++)
            {
                for(int l = k+1; l <= n; l++)
                {
                    int flag = 0;
                    for(int u = 1; u <= n; u++)
                    {
                        if(sl(a[i].x,d[k].y,a[j].x,d[l].y,u))
                        {
                            flag++;
                        }
                    }
                    if(flag >= k1)
                    {
                        maxx = min(maxx, (ll)abs(1ll*a[i].x-1ll*a[j].x)*abs(1ll*d[k].y-1ll*d[l].y));
                    }
                }
            }
        }

    }
   cout << maxx << endl;
    return 0;
}


Measured memory_bytes: 384
def main():
	N, M = map(int, input().split())
	food = [0 for i in range(M)]
	for i in range(N):
		K = input().split()
		hmt = int(K[0])
		for j in range(1, hmt + 1):
			food[int(K[j]) - 1] += 1
	count = 0
	for i in range(M):
		if food[i] == N:
			count += 1
	print(count)

if __name__ == '__main__':
	main()

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

int main(){
    int n;
    cin >> n;
    int H[n];
    for(int i = 0; i < n ;i++){
        cin >> H[i];
    }
    int count = 0;
    for(int i = 0; i < n; i++){
        bool counter = true;
        for(int j = 0; j < i; j++){
            if(H[j] > H[i]){
                counter = false;
                break;
            }
        }
        if(counter == true){
            count += 1;
        }
    }

    cout << count << endl;
    return 0;
}
 

Measured memory_bytes: 764
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim n As Integer = NextInt()
        Dim p As Integer = NextInt()
        Dim odd, even As Integer

        For i As Integer = 1 To n
            Dim a As Integer = NextInt()
            odd += a Mod 2
            even += (a Mod 2) Xor 1
        Next

        If odd = 0 Then
            WriteLine((2 ^ even) * Int(p = 0))
        Else
            WriteLine((2 ^ (odd - 1)) * (2 ^ even))
        End If
    End Sub

    Function Int(ok As Boolean) As Integer
        Return If(ok, 1, 0)
    End Function

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function
End Module


Measured memory_bytes: 20560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        static void SolveA(string[] args)
        {
            string sz = Console.ReadLine();
            string ans = "";
            for(int i=0;i<sz.Length;++i)
            {
                if( sz[i] == '1')
                {
                    ans += "9";
                }
                else
                {
                    ans += "1";
                }
            }
            int n = int.Parse(ans);
            Console.WriteLine(n);
        }
    }
}

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> a(N);
    ll c = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
        c += a[i];
    }
    ll ans = 2500000000,tmp = 0;
    for (int i = 0; i < N-1; i++)
    {
        c -= a[i];
        tmp += a[i];
        ans = min(ans, abs(c-tmp));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

long long dp[3010][3010];
const int MOD = 1000000007;
int main()
{
    int n, k;

    cin>>n>>k;
    
    dp[0][0] = 1;

    for(int i=1;i<=2000;i++)
        for(int j=1;j<=2000;j++)
        {
            dp[i][j] = dp[i-1][j-1] + dp[i-1][j];
            dp[i][j] = dp[i][j] % MOD;
        }
    for(int i=1;i<=k;i++)
    {
        long long ans = dp[k][i] * (dp[n-k][i] + dp[n-k][i] + dp[n-k][i-1] + dp[n-k][i+1]);
        cout<<ans%MOD<<endl;
    }
    
}

Measured memory_bytes: 46976
#ifndef ___Class_RangeTree
#define ___Class_RangeTree

// ------ Includes ------ //
#include <limits>
#include <vector>
#include <algorithm>

template<typename Type> class RangeTree {
private:
	int size_;
	std::vector<std::vector<Type> > dat;
	std::vector<std::vector<int> > vl;
	inline int query_(int a, int b, Type x, int k, int l, int r, int e) {
		// Find range [a, b) : value < x : Now k-th node and the range is [l, r) and e integers below x in the range
		if (r <= a || b <= l || e == 0) return 0;
		if (a <= l && r <= b) return e;
		int lc = query_(a, b, x, k << 1, l, (l + r) >> 1, vl[k][e - 1]);
		int rc = query_(a, b, x, k << 1 | 1, (l + r) >> 1, r, e - vl[k][e - 1]);
		return lc + rc;
	}
public:
	RangeTree() : size_(0), dat(std::vector<Type>()) {};
	template<class T>
	RangeTree(T begin_, T end_) {
		int n = (end_ - begin_);
		for (size_ = 1; size_ < n; size_ <<= 1);
		dat.resize(size_ << 1);
		vl.resize(size_);
		for (int i = 0; i < n; i++) dat[i + size_].push_back(*(begin_ + i));
		for (int i = size_ - 1; i > 0; i--) {
			dat[i].resize(dat[i << 1].size() + dat[i << 1 | 1].size());
			vl[i].resize(dat[i].size());
			int cl = 0;
			for (int j = 0; j < dat[i].size(); j++) {
				if (j - cl == dat[i << 1 | 1].size() || (cl != dat[i << 1].size() && dat[i << 1][cl] < dat[i << 1 | 1][j - cl])) dat[i][j] = dat[i << 1][cl++];
				else dat[i][j] = dat[i << 1 | 1][j - cl];
				vl[i][j] = cl;
			}
		}
	}
	inline int size() { return size_; }
	inline int query(int l, int r, Type x) {
		// Find range [a, b) : value < x
		int ptr = lower_bound(dat[1].begin(), dat[1].end(), x) - dat[1].begin();
		return query_(l, r, x, 1, 0, size_, ptr);
	}
};

#endif

#include <cstdio>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
struct query {
	int l, r;
};
bool compare(const query& q1, const query& q2) {
	return q1.r < q2.r;
}
// rc[k] : number of q[i].r < k
int N, M, dat[300009], rc[300009], val[300009], ret[300009]; query q[300009];
int main() {
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; i++) scanf("%d%d", &q[i].l, &q[i].r);
	sort(q, q + N, compare);
	for (int i = 0; i < N; i++) dat[i] = q[i].l;
	int ptr = 0;
	for (int i = 1; i <= M; i++) {
		while (ptr < N && q[ptr].r < i) ptr++;
		rc[i] = ptr;
	}
	RangeTree<int> Q(dat, dat + N);
	for (int i = 1; i <= M; i++) val[i] = Q.query(rc[i], N, i + 1);
	for (int i = 1; i <= M; i++) {
		for (int j = i; j <= M; j += i) {
			ret[i] += val[j];
			ret[i] -= Q.query(rc[j], N, j - i + 1);
		}
	}
	for (int i = 1; i <= M; i++) printf("%d\n", ret[i]);
	return 0;
}

Measured memory_bytes: 108288
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long fac[200020], finv[200020], inv[200020];
long long mod = 1000000007;
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < 200020; 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;
	}
}
long long COM(long long n, long long 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() {
	COMinit();
	long long n, k;
	cin >> n >> k;
	if (k > n - 1) {
		k = n - 1;
	}
	long long ans = 0;
	for (long long i = 0; i <= k; i++) {
		long long co = COM(n, i);
		co *= COM(n - 1, i);
		co %= 1000000007;
		ans += co;
		ans %= 1000000007;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8324
#include <iostream>

using namespace std;

int main(){
    long long n,m,ans;
    cin >> n >> m;
    
    if(n*2 > m){
        ans = m/2;
    }else if(n*2 < m){
        ans = m-n*2;
        ans/= 4;
        ans += n;
    }else{
        ans = n;
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
int main()
{
  ll x;
  cin >> x;
  ll cnt = 0;
  ll a = 100;
  while(a < x) {
    cnt++;
    a += a/100;
  }
  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 3632
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	kotae := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		kotae += a[i]
	}
	kotae -= n
	fmt.Println(kotae)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#ifndef LIB_REPEAT_HPP
#define LIB_REPEAT_HPP
#define repeat(i,n) for (int i = 0; i < (n); ++i)
#define repeat_from(i,m,n) for (int i = (m); i < (n); ++i)
#define repeat_one(i,n) for (int i = 1; i <= (n); ++i)
#define repeat_rev(i,n) for (int i = (n)-1; 0 <= i; --i)
#define foreach(it, cont) for (decltype(cont.begin()) it = cont.begin(); it != cont.end(); ++it)
#endif
#ifndef LIB_TYPEDEF_LL_HPP
#define LIB_TYPEDEF_LL_HPP
typedef long long ll;
typedef unsigned long long ull;
#endif
using namespace std;
const ll mod = 1000000007L;
int main() {
    ios_base::sync_with_stdio(false);
    int N; int W; cin >> N >> W;
    vector<int> fr(N); repeat (i,N) cin >> fr[i];
    sort(fr.begin(), fr.end());
    ll result = 0;
    int acc = 0;
    vector<int> dp[2];
    repeat (ign,N+1) {
        vector<int> & cur = dp[0];
        vector<int> & prv = dp[1];
        const int lft = W-acc-fr[ign]+1;
        const int rgt = W-acc+1;
        if (lft <= 0) break;
//cerr << "acc " << acc << " ignore " << fr[ign] << " left " << lft << " right " << rgt << endl;
        prv.clear(); prv.resize(lft);
        prv[0] = 1;
        repeat_from (i,ign+1,N) {
//cerr << "fr[i] " << fr[i] << endl;
            cur.clear(); cur.resize(lft);
            if (rgt <= fr[i]) break;
            repeat (w,lft) if (prv[w]) {
                cur[w] += prv[w];
                if (w+fr[i] < lft) cur[w+fr[i]] += prv[w];
                if (lft <= w+fr[i] and w+fr[i] < rgt) result += prv[w];
//cerr << "w+fr[i] " << w+fr[i] << endl;
            }
//repeat (i,W-acc-fr[ign]+1) cerr << cur[i]; cerr << endl;
            swap(cur,prv);
        }
        result %= mod;
        if (ign < N) acc += fr[ign];
    }
    cout << (result+1)%mod << endl;
    return 0;
}

Measured memory_bytes: 1280
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int h = Integer.parseInt(sc.next());
      	int a = Integer.parseInt(sc.next());
      	int count = 0;
      	while(h > 0){
        	h = h-a;
          	count++;
        }
      	System.out.println(count);
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 1e18;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int left, right;
    left = 1;
    right = N;
    for (int i = 0; i < M; i++) {
        int L, R;
        cin >> L >> R;
        left = max(left, L);
        right = min(right, R);
    }
    if (right - left >= 0) {
        cout << right - left + 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define for1(i,n) for(int i = 1;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define REP(a,i,b) for (int i = a;i<b;i++);

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}

bool IsPrime(ll n)
{
	if (n == 1)
		return false;
	if (n == 2)
		return true;

	for (ll i = 2; i*i <= n; i++)
		if (n%i == 0)
			return false;
	return true;
}

void solve()
{
	ll x;
	cin >> x;
	while (!IsPrime(x))
		x++;
	cout << x;

}

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


#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	//freopen("journey.in", "r", stdin);
	//freopen("journey.out", "w", stdout);


	int tst = 1;
	//cin >> tst;
	while (tst--)
		solve();


}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string N;
int main()
{
  cin >> N;
  int n = N.size();
  if(n==6){
    cout << 90909 << "\n";
  }
  else if(n==4){
    cout << 909 << "\n";
  }
  else if(n==2){
    cout << 9 << "\n";
  }
  else if(n==1){
    int x = stoi(N);
    cout << x << "\n";
  }
  else if(n==3){
    int x = stoi(N);
    cout << x-99+9 << "\n";
  }
  else if(n==5){
    int x = stoi(N);
    cout << x-9999+909 << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define inputv(arr,n) for(ll i=0;i<n;i++){ll value;cin>>value;arr.pb(value);}
#define sz(a) ((ll)(a).size())
#define len(a) ((ll)(a).length())
#define F first
#define S second
#define vi vector <int> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
inline ll max(ll a,ll b)
{return ((a>b)?a:b);}
inline ll min(ll a,ll b)
{return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b)
{if(b==0) return a;a%=b;return gcd(b,a);}
#define nl cout<<"\n"
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
// hashing for pairs
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};
//sort in reverse order
bool compare(ll x, ll y){
    return x>y;
}
void solve()
{
  char ch;
  cin>>ch;
  if(isupper(ch))
  {
    cout<<"A";nl;
  }
  else
  {
    cout<<"a";nl;
  }
  return;
}
int main()
{
    IOS;
    int T=1;
   // cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

ll n;
ll a[400];
ll dp[400][400];
ll sum(ll s,ll e){
	
	ll ans=0;
	for(ll i=s;i<=e;i++){
	ans+=a[i];
    }
	return ans;
}

ll minCost(ll i,ll j){
	if(i>=j)
	return 0;
	
	if(dp[i][j]!=-1)
	return dp[i][j];
	ll ret=LONG_MAX;
	for(ll k=i;k<j;k++){
		ret=min(ret,minCost(i,k) + minCost(k+1,j) + sum(i,k)+sum(k+1,j));
	}
	return dp[i][j]=ret;
}

int main(){
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	memset(dp,-1,sizeof(dp));
	cout<<minCost(0,n-1)<<endl;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define pp pair<ll,ll>
#define vi vector<pair<pp,pp> >
#define pq_min priority_queue<ll,vector<ll>,greater<ll>>
#define pq_max priority_queue<ll>
#define f(i,a,b) for(ll i=a;i<b;i++)
#define r(i,a,b) for(ll i=a;i>=b;i--)
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define ld long double
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef pair<pp,pp> ppll;
const ll mod=1e9+7;
const ll N=2e18 + 5;

ll power(ll a,ll b,ll p)
{
    a=a%p;
    ll ans=1;
    while(b>0)
    {
        if(b%2==1)
        {
            ans=(ans*a)%p;
        }
        b=b/2;
        a=(a*a)%p;
    }
    return ans;
}

 
int main()
{
    fast;
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<pp> p;
    ll x1;
    f(i,0,a) {cin>>x1;p.pb(mp(x1,1));}
    f(i,0,b) {cin>>x1;p.pb(mp(x1,2));}
    f(i,0,c) {cin>>x1;p.pb(mp(x1,3));}
    sort(p.rbegin(),p.rend());
    ll d=0;
    ll ans=0;
    ll m=x+y;
    for(ll i=0;i<p.size();i++)
    {
        if(d==m) break;
        if(x<=0 && p[i].ss==1) continue;
        if(y<=0 && p[i].ss==2) continue;
        ans += p[i].ff;
        d++;
        
        if(p[i].ss==1) x--;
        if(p[i].ss==2) y--;
    }
    cout<<ans;
}

Measured memory_bytes: 10476
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<cmath>
using namespace std;

typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;

ll gcd( ll a, ll b ){//最大公約数
    ll tmp;
    if( a < b ) { tmp = a; a = b; b = tmp; }
    if( b < 1 ) return -1;

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

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


//入力
int n, m;
int s[100010];
int e[100010];

int my_start, my_end;


int main(){

    cin >>  n >> m;
    for(int i = 0; i < m; i++){
        cin >> s[i] >> e[i];
    }

    my_start = -1; my_end = INF;

    for(int i = 0; i < m; i++){
        if(my_start < s[i]){
            my_start = s[i];
        }

        if(e[i] < my_end){
            my_end = e[i];
        }
    }

    if(my_start > my_end){
        cout << 0 << endl;
        return 0;
    }

    cout << my_end - my_start + 1 << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
typedef long long int ll;
#define fr(x,y) for(int x=0;x<y;x++)
#include <algorithm>
#include<vector>

using namespace std;

int main() {
	ll n, k;
	cin >> n >> k;
		n = n % k;
	 cout << min(k - n, n);

}



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

int main(){
    int n;
    cin >> n;
    int minR,maxdiff;
    maxdiff=-1e9-1;
    for(int i=0; i<n; i++){
        if(i==0) cin >> minR;
        else{
            int tmp;
            cin >> tmp;
            maxdiff=max(maxdiff,tmp-minR);
            minR=min(minR,tmp);
        }
    }
    cout << maxdiff << endl;
    return 0;
}


Measured memory_bytes: 3124
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <iostream>
using namespace std;
#define rg register
#define il inline
#define MX (2000 + 50)
#define mod (924844033LL)
#define LL long long

LL abs(LL a){return a > 0 ? a : -a;}
LL dp[MX][MX][2][2] ,fac[MX];
int vis[MX] ,tot ,A[MX];
int main(){
	fac[0] = 1;
	for(int i = 1 ; i < MX ; ++i)
		fac[i] = (fac[i - 1] * i) % mod;
	int n ,k;
	cin >> n >> k;
	for(int i = 1 ; i <= n ; ++i){
		if(vis[i])	continue;
		for(int j = i ; j <= n ; j += k){
			A[++tot] = j;
			vis[j] = true;
		}
	}
	dp[0][0][0][0] = 1;
	A[0] = -192608107;
	for(int i = 1 ; i <= n ; ++i){
		dp[i][0][0][0] = 1;
		for(int j = 1 ; j <= i ; ++j){
			dp[i][j][0][0]=(dp[i-1][j][1][0]+dp[i-1][j][0][0]+(A[i]-A[i-1]==k)*dp[i-1][j-1][0][0])%mod;
            dp[i][j][0][1]=(A[i+1]-A[i]==k)*(dp[i-1][j-1][1][0]+dp[i-1][j-1][0][0])%mod;
            dp[i][j][1][0]=(dp[i-1][j][0][1]+dp[i-1][j][1][1]+(A[i]-A[i-1]==k)*dp[i-1][j-1][0][1])%mod;
            dp[i][j][1][1]=(A[i+1]-A[i]==k)*(dp[i-1][j-1][0][1]+dp[i-1][j-1][1][1])%mod;
		}
	}
	LL Ans = 0;
	for(int i = 0 ; i <= n ; ++i){
		LL tmp = (dp[n][i][0][0] + dp[n][i][1][0] + dp[n][i][1][1] + dp[n][i][0][1]) % mod;
		// cerr << i << "-----------" << tmp << endl;
		if(i & 1)
			(Ans += mod - tmp * fac[n - i] % mod) %= mod;
		else
			(Ans += tmp * fac[n - i]) %= mod;
	}
	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 127360
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) puts("error")
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    inline int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> inline void add(T &x,const T y){x=mm(x+y);}
    inline ll qpower(ll x,ll e)
    {
        ll ans=1;GG(e<0);
        while(e){if(e&1)ans=ans*x%MOD;x=x*x%MOD;e>>=1;}return ans;
    }
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=17,M=1e6+10;

    ll fac[M],facinv[M];ll P(int n,int m){return n<m?0:fac[n]*facinv[n-m]%MOD;}
    int a[N];ll f[N][1<<N];
    void main()
    {
        fac[0]=1;for(int i=1;i<M;i++) fac[i]=fac[i-1]*i%MOD;
        facinv[M-1]=invm(fac[M-1]);for(int i=M-2;i>=0;i--) facinv[i]=facinv[i+1]*(i+1)%MOD;

        int n=qread(),m=qread();for(int i=1;i<=m;i++) a[i]=qread();
        f[0][0]=1;
        for(int i=m;i>=1;i--)
        {
            for(int cnt=m-i;cnt>=0;cnt--) for(int s=0;s<bin(n);s++) if(f[cnt][s])
            {
                if(bin(n)-a[i]-s<0)
                    puts("error");
                // printf("i=%d cnt=%d s=%d f=%lld\n",i,cnt,s,f[cnt][s]);
                for(int j=0;j<n;j++) if(!(s&bin(j))) add(f[cnt+1][s^bin(j)], f[cnt][s]*P( bin(n)-a[i]-s , bin(j)-1 )%MOD*bin(j)%MOD );
            }
        }
        ll ans=0;for(int s=0;s<bin(n);s++) for(int cnt=0;cnt<=m;cnt++) add(ans, ll(cnt&1?MOD-1:1)*f[cnt][s]%MOD*fac[bin(n)-1-s]%MOD );write(ans*bin(n)%MOD);
    }//(ans+MOD)%MOD
};
int main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 31232
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
#define sf(x) scanf("%d",&x)
#define sfl(x) scanf("%lld",&x)
#define lli long long int
#define ll64 int64_t
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define frr(i,a) for(int i=0;i<a;i++)
#define frl(i,a) for(lli i=0;i<a;i++)
int main()
{
    int n;
    cin>>n;
    if(n>=30)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> p;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int K, S;
    cin >> K >> S;

    int ans = 0;

    for(int i = 0; i <= K; i++) {
        for(int j = 0; j <= K; j++) {
            if(i + j <= S && S - (i + j) <= K) {
                //cerr << i << " " << j << endl;
                ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

typedef long long ll;

const int ALP = 26;
const int INF = 1e9 + 239;
const int N = 2e5 + 7;

namespace Fenw {
	int f[N];

	void add(int pos, int val) {
		for (int i = pos; i < N; i = (i | (i + 1))) {
			f[i] += val;
		}
	}

	int get(int pos) {
		int ans = 0;
		for (int i = pos; i >= 0; i = (i & (i + 1)) - 1) {
			ans += f[i];
		}
		return ans;
	}

	void init() {
		for (int i = 0; i < N; i++) {
			add(i, 1);
		}
	}
}

ll ans = 0;

int n;
string s;
vector<int> ps[ALP];
int pl[ALP];
int pr[ALP];

void init() {
	Fenw::init();
	for (int i = 0; i < n; i++) {
		ps[s[i] - 'a'].push_back(i);
	}
	for (int i = 0; i < ALP; i++) {
		pl[i] = 0;
		pr[i] = (int)ps[i].size() - 1;
	}
}

void doit(int &cl, int &cr) {
	int best = INF;
	int to = -1;
	for (int i = 0; i < ALP; i++) {
		if (pl[i] >= pr[i]) continue;
		if (best > (Fenw::get(ps[i][pl[i]]) - cl) + (cr - Fenw::get(ps[i][pr[i]]))) {
			best = (Fenw::get(ps[i][pl[i]]) - cl) + (cr  - Fenw::get(ps[i][pr[i]]));
			to = i;
		}
	}
	if (to == -1) {
		cout << -1 << endl;
		exit(0);
	}
	int l = ps[to][pl[to]];
	int r = ps[to][pr[to]];
	// cerr << "+ " << to << endl;
	// cerr << l << ' ' << r << endl;
	Fenw::add(l, -1);
	Fenw::add(r, -1);
	ans += (ll)best;
	cl++;
	cr--;
	pl[to]++;
	pr[to]--;
}

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

	cin >> s;
	n = (int)s.size();
	init();
	int cl = 0;
	int cr = n - 1;
	while (cr - cl + 1 >= 2) {
		doit(cl, cr);
	}
	cout << ans << endl;
}

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

int main()
{
    int N;
    cin>>N;
    vector<long long> A(N), B(N);
    for (long long &a: A)
        cin>>a;
    for (long long &b: B)
        cin>>b;

    set<int> S;
    for (int i=0; i<N; i++)
        S.insert(i);
    long long ans = 0;

    while (!S.empty())
    {
        int c = *S.begin();
        S.erase(S.begin());

        if (B[c]-B[(c+1)%N]-B[(c+N-1)%N]>=A[c])
        {
            long long n = (B[c]-A[c])/(B[(c+1)%N]+B[(c+N-1)%N]);
            B[c] -= (B[(c+1)%N]+B[(c+N-1)%N])*n;
            ans += n;
            S.insert(c);
            S.insert((c+1)%N);
            S.insert((c+N-1)%N);

            //cout<<c<<endl;
            //for (long long b: B)
            //    cout<<" "<<b;
            //cout<<endl;
        }
    }
    bool ok = true;
    for (int i=0; i<N; i++)
        if (A[i]!=B[i])
            ok = false;
    cout<<(ok?ans:-1)<<endl;
}


Measured memory_bytes: 14848
N, K=map(int, input().split())
p=list(map(int, input().split()))

expect=[(dice+1)/2 for dice in p]
for i in range(N-1):
    expect[i+1]+=expect[i]

plus_p=[expect[K-1]]
for i in range(1, N-K+1):
    plus_p.append(expect[i+K-1]-expect[i-1])
print(max(plus_p))

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

int main() {
    char a, b;
    cin >> a >> b;
    if (a == b){
        cout << 'H' << endl;
    }
    else {
        cout << 'D' << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>P;
const ll INF=1e18,MOD=1e9+7;
bool comp(ll a,ll b){
    return abs(a)>abs(b);
}
int main(){
    int n,k;
    cin>>n>>k;
    if(k==1)cout<<0<<endl;
    else cout<<n-k<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define PI 3.14159265358979323846
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef long double ld;
typedef string st;
const ll MOD = 1e9 + 7 ;
const ll INF=1e14;
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
ll mpow(ll a,ll b,ll p=MOD){a=a%p;ll res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const ll N=1005;

int main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);

      ll n,k;
      cin>>n>>k;
      ll a[n];
      forn(i,n) cin>>a[i];
      sort(a,a+n);
      ll ans=1e12;
      forn(i,n-k+1){
      	  //cout<<a[i]<<" "<<a[i+k-1]<<"\n";
          ans=min(ans,a[i+k-1]-a[i]);
      }
      cout<<ans;
}
/* If today were the last day of my life,would I want to do what I'm about to do today? */

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int saidaikouyakusuu(int a,int b){
    if(b==0) return a;
    return saidaikouyakusuu(b,a%b);
}
int saisyoukoubaisuu(int a,int b){
    return a*b/saidaikouyakusuu(a,b);
}
int n,m,cnt=0,aa[220000],o,p;
pair<int,int> pp[220000];
string s,ss[220000];
char c;
queue<int> que;
signed main(){
    cin>>n>>m;
    rep(i,n){
        cin>>aa[i];
    }
    sort(aa,aa+n);
    rep(i,m){
        cnt+=aa[i];
    }
    cout<<cnt;
}

Measured memory_bytes: 10504
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin>>S;
    int x=0;
    int y=0;
    for (int i=0;i<S.size();i++){
        if (S.at(i)=='1'){
            x++;
        }
        else{
            y++;
        }
    }
    cout<<S.size()-max(x,y)+min(x,y)<<endl;
}

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

//solution:
#define int int64_t

signed main() {
	int n, d, count = 0; cin >> n >> d;
  	while(n--) {
      int x, y; cin >> x >> y;
      if(hypot(x, y) <= d) count++;
    }
  	cout << count;
  	return 0;
} //farewell, until we meet again..

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
string str1 , str2;
int dp[5000][5000] , n , m;

int solve(int id1 , int id2 ){
    if( id1 == n || id2 == m ) return 0;
    if( dp[id1][id2] != -1 ) return dp[id1][id2];
    int ans = 0;
    if( str1[id1] == str2[id2] ) ans = max(ans , 1 + solve(id1+1 , id2+ 1) );
    else ans = max( solve(id1+1 , id2) , solve(id1 , id2+1) );
    return dp[id1][id2] = ans;
}

string printLCS() {
    int id1 =0 , id2 = 0;
    string str ="";
    while( id1 < n && id2 < m ) {
        if( str1[id1] == str2[id2] ) {
            str += str1[id1];
            id1++;
            id2++;
        }
        else if( dp[id1+1][id2] > dp[id1][id2+1] ) id1++;
        else id2++;
    }
    return str;
}

int main()
{
    cin>>str1>>str2;
    n = str1.size();
    m = str2.size();
    memset( dp , -1 , sizeof dp);
    solve(0,0);
    cout<<printLCS()<<endl;
    return 0;
}



Measured memory_bytes: 98176
import Control.Monad
import Text.Printf

ret [] sum = sum
ret ((x, u):xs) sum 
  | u == "JPY" = ret xs (sum + x)
  | u == "BTC" = ret xs (sum + x*380000)

main = do
  n <- read <$> getLine
  input <- (replicateM n ((\[x, y] -> (read x, y)) . words <$> getLine)) :: IO [(Double, String)]
  putStrLn $ printf "%.5f" $ ret input 0


Measured memory_bytes: 636