akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int left, right;
  left = A + B;
  right = C + D;
  if (left < right) {
    cout << "Right" << endl;
  }
  else if (left == right) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Left" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ld long double
long long const inf = 1e18;
int const mxn = 2e5+10;
 
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
 
 
 
 
 
int main(){
	long long h,a;
	cin>>h>>a;
	cout<<h/a+(h%a>0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string str;
    cin>>str;
    int len =str.length();
    int r=0,b=0;
    for(int i=0;i<len;i++){
        if(str[i]=='R')r++;
        else b++;
    }
    if(r>b)cout<<"Yes\n";
    else cout<<"No\n";
}


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

using namespace std;


int main(){
	
	string a;
	
	cin >> a;
	
	int b=atoi(a.c_str());
	
	int ans=0;
	
	for(int i=0;a[i];i++){
		ans += (a[i]-'0');
	}
	
	if(b%ans==0) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[5050];
map<char,int> trie[505050];
int n,cnt;
stack<char> st;
bool f(int cur){
    if(!n--) return true;
    for(int i=0;i<=256;i++){
        if(trie[cur].count(i)){
            if(f(trie[cur][i])){
                st.push(i);
                return true;
            }
        }
    }
    return false;
}
int main(){
    scanf("%s %d",s,&n);
    for(int i=0;s[i];i++){
        int cur = 0;
        for(int j=i;j<i+n && s[j];j++){
            if(!trie[cur][s[j]]) trie[cur][s[j]] = ++cnt;
            cur = trie[cur][s[j]];
        }
    }
    f(0);
    while(!st.empty()){
        printf("%c",st.top());
        st.pop();
    }
    puts("");
}


Measured memory_bytes: 24576
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;
template<typename T>
T gcd(T a, T b) {
    if(b == 0){
        return a;
    }else if(a == 0){
        return b;
    }else{
        return gcd(b, a % b);
    }
}

template<typename T>
T lcm(T a,T b){
    if(a == 0||b == 0){
        return 0;
    }else{
        return (a/gcd(b, a % b))*b;
    }
}
int main(){

    long long int a,b,c,d;
    cin>>a>>b>>c>>d;
    long long int result =b-a+1- (b / c + b / d - (b / (lcm(c,d)))) + ((a-1) / c + (a-1) / d - ((a-1) / (lcm(c,d))));
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> x(N), y(N), h(N);
	for (int i = 0; i < N; i++)
	{
		cin >> x[i] >> y[i] >> h[i];
	}

	//[0, 100]に座標があるのでMAXを定義すると楽
	int MAX = 100;

	for (int posY = 0; posY <= MAX; posY++)
	{
		for (int posX = 0; posX <= MAX; posX++)
		{
			//頂上がどれくらいの高さであってほしいか。
			//-1はまだ良く分からない時。0以上は確定してるとき
			//-2はダメだって分かった時
			int needH = -1;

			for (int i = 0; i < N; i++)
			{
				if (h[i] > 0) {
					//この頂点から見て、頂上がposY,posXの時に、
					//どれくらいの高さがあってほしいかを求める
					int tmp = h[i] + abs(posY - y[i]) + abs(posX - x[i]);
					if (needH == -1) {
						needH = tmp;
					}
					else {
						if (needH != tmp) {
							needH = -2;
							break;
						}
					}
				}
			}
			//ダメだったら別の場所を探す。
			if (needH == -2) continue;

			for (int i = 0; i < N; i++)
			{
				//高さが0の場合に矛盾してないか調べる
				if (h[i] == 0) {
					int dist = abs(posY - y[i]) + abs(posX - x[i]);
					if (needH > dist) {
						needH = -2;
						break;
					}
				}
			}

			if (needH == -2) continue;

			//見つけられたら答えをそのまま返す。
			cout << posX << " " << posY << " " << needH << endl;
			return 0;
		}
	}

}

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

int main(){
    int fib[50], n;
    rep(i, 50){
        if(i == 0 || i == 1){
            fib[i] = 1;
            continue;
        }
        fib[i] = fib[i - 1] + fib[i - 2];
    }
    
    cin >> n;
    
    cout << fib[n] << endl;
    
    return 0;
}


Measured memory_bytes: 3096
#import
import math
#import numpy as np
N = int(input())

first = "MARCH"

dic = {s:0 for s in first}

for _ in range(N):
    s = input()
    if s[0] in dic:
        dic[s[0]] += 1

t = []
for key in dic:
    if dic[key] > 0:
        t.append(dic[key])

if len(t) < 3:
    print(0)
else:
    tl = len(t)
    ans = 0
    for i in range(2 ** tl):
        cnt = []
        for j in range(tl):
            if (i >> j) & 1:
                cnt.append(j)

        if len(cnt) == 3:
            tans = 1
            for i in cnt:
                tans *= t[i]

            ans += tans
    
    print(ans)


Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int>A(N), B(N);
	long long Asum = 0, Bsum = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		Asum += A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
		Bsum += B[i];
	}
	if (Bsum > Asum) {
		cout << -1 << endl;
		return 0;
	}
	vector<int> C;
	int ans = 0;
	long long difsum = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] >= B[i]) C.push_back(A[i] - B[i]);
		else {
			ans++;
			difsum += B[i] - A[i];
		}
	}
	sort(C.begin(), C.end(), greater<int>());
	int i = 0;
	while (difsum > 0) {
		difsum -= C[i];
		i++;
		ans++;
	}
	cout << ans << endl;
}


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

int main(){
	int N, f1 = 0, f2 = 0, c1 = 0, c2 = 0;
	cin >> N;
	int a[N];
	for(int i=0; i<N; i++){
		cin >> a[i];
		if(!f1){
			f1 = a[i];
		}else if(f1 != a[i]){
			if(!f2){ f2 = a[i]; }
			else if(f2 != a[i]){ cout << "No" << endl; return 0; }
		}
		if(a[i] == f1) c1++;
		else c2++;
	}
	if(!f2){
		if(f1 == N-1 || f1 <= N/2){ cout << "Yes" << endl; }
		else{ cout << "No" << endl; }
	}else{
		if(f1 > f2){ swap(c1, c2); swap(f1, f2); }
		if(c1 <= f1 && f2 <= c2/2 + c1){ cout << "Yes" << endl; }
		else{ cout << "No" << endl; }
	}
	return 0;
}

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

void azhe(){
    cout<<"No\n";
    exit(0);
}

void solve(vector<int> a,vector<int> &b){
    const int n=a.size();
    map<int,int> dfn,num;
    for(int i=0;i<n;i++){
        dfn[a[i]]++;
        num[b[i]]++;
    }
    set<pair<int,int> > rnk;
    for(map<int,int>::iterator it=num.begin();it!=num.end();it++){
        pair<const int,int> &p=*it;
        rnk.insert(make_pair(dfn[p.first]+p.second,p.first));
        if(dfn[p.first]+p.second>n)azhe();
    }
    for(int i=0;i<n;i++){
        pair<int,int> ban(-1,-1);
        if(rnk.empty())azhe();
        if(rnk.rbegin()->second==a[i]){
            ban=*rnk.rbegin();
            rnk.erase(ban);
        }
        if(rnk.empty())azhe();
        pair<int,int> p=*rnk.rbegin();
        rnk.erase(p);
        b[i]=p.second;
        num[p.second]--;
        p.first--;
        if(num[p.second]==0){
            num.erase(p.second);
        }else{
            rnk.insert(p);
        }
        if(ban.first!=-1){
            rnk.insert(ban);
        }
        if(num[a[i]]){
            rnk.erase(make_pair(dfn[a[i]]--+num[a[i]],a[i]));
            rnk.insert(make_pair(dfn[a[i]]+num[a[i]],a[i]));
        }
    }
}

int main(){

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

    int n;
    cin>>n;
    vector<int> a(n),b(n);
    for(int &x:a)cin>>x;
    for(int &x:b)cin>>x;
    solve(a,b);
    cout<<"Yes\n";
    for(int &x:b)cout<<x<<' ';
    cout<<'\n';

    return 0;
}

Measured memory_bytes: 33728
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(a,b,c) for(ll a=b;a<c;a++)
#define ll long long
#define endl '\n'
#define pb(a) push_back(a)

int main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n;
    cin>>n;
    ll ans=0;
    ll divs[n+1]={0};
    rep(i,1,n+1){
        for(int j=i;j<n+1;j+=i){
            divs[j]++;
        }
    }
    rep(i,1,n+1){
        ans+=i*divs[i];
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 81768
import math

a, b, h, m = map(int, input().split())


def kaiten(n):
    return math.cos((n / 180) * math.pi), math.sin((n / 180) * math.pi)


xx, xy = kaiten(30 * h + 0.5 * m)
xx *= a
xy *= a

yx, yy = kaiten(6 * m)
yx *= b
yy *= b
kyori = math.sqrt((xx - yx) ** 2 + (xy - yy) ** 2)
print(kyori)


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

int main(void){
    
    //入力
    string S;
    cin >> S;
    
    //0が始めのパターンと１が始めのパターンを試す
    int start0 = 0;
    int start1 = 0;
    for (int i = 0; i < 2; i++){
        if (i == 0){
            for (int j = 0; j < S.size(); j++){
                if (j % 2 == 0 && S[j] != (char)(i + '0')) start0++;
                if (j % 2 != 0 && S[j] == (char)(i + '0')) start0++;
            }
        }
        else {
            for (int j = 0; j < S.size(); j++){
                if (j % 2 == 0 && S[j] != (char)(i + '0')) start1++;
                if (j % 2 != 0 && S[j] == (char)(i + '0')) start1++;
            }
        }
    }
    
    //塗り替えるタイルの枚数が小さい方を出力する
    cout << min(start0, start1) << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

vector<ll> gauss_jordan(vector<ll> a, ll k){
    int n = a.size(), m = 64;
    int cnt = 0;
    vector<int> v;
    for (int i = 63; i >= 0; --i) {
        if(!((k & (1LL << i)))) v.emplace_back(i);
    }
    for (int i = 63; i >= 0; --i) {
        if(((k & (1LL << i)))) v.emplace_back(i);
    }
    for (int cur = 0; cur < 64 && cnt != n; ++cur) {
        int i = v[cur];
        int p = cnt;
        for (int j = cnt; j < n; ++j) {
            if(a[j] & (1LL << i)){
                p = j;
                break;
            }
        }
        if((a[p] & (1LL << i)) == 0) continue;
        swap(a[cnt], a[p]);
        for (int j = 0; j < n; ++j) {
            if(cnt == j) continue;
            if(a[j] & (1LL << i)) a[j] ^= a[cnt];
        }
        cnt++;
    }
    return a;
}

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    ll X = 0;
    for (auto &&i : v) scanf("%lld", &i), X ^= i;
    ll ans = 0;
    auto p = gauss_jordan(v, X);
    for (int i = 0; i < n; ++i) {
        ans ^= p[i];
    }
    cout << ans + (ans ^ X) << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define forit(it, st) for(auto it : st)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);

void solve(){
	int a, b;
	cin >> a >> b;
	cout <<  6 - a - b;
}
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll a, b, c;
    cin >> a >> b >> c;
    ll ans = c -(a-b);
    if(ans<0) ans = 0;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def func1():
    i = 0
    j = 0
    p = [0] * N
    while True:
        if B[i] > A[j]:
            j += 1
            if j == N:
                while i < N:
                    p[i] = N
                    i += 1
                return p
        else:
            while B[i] <= A[j]:
                p[i] = j
                i += 1
                if i == N:
                    return p


def func2(p):
    i = 0
    j = 0
    point = 0
    q = [0] * N
    while True:
        if C[i] > B[j]:
            point += p[j]
            j += 1
            if j == N:
                while i < N:
                    q[i] = point
                    i += 1
                return q
        else:
            while C[i] <= B[j]:
                q[i] = point
                i += 1
                if i == N:
                    return q


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A)
B = sorted(B)
C = sorted(C)

p = func1()
q = func2(p)
print(sum(q), '\n')

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

vector<int> a(10000000);
int main(){
    int n;
    cin >> n;
    for(int i=0; i<n; i++) {
        a[i] = i+1;
    }

    long long ans = 0;
    for(int i=0; i<n; i++) {
        if( a[i] % 3 == 0 || a[i] % 5 == 0) {
            a[i] = 0;
            continue;
        }
        ans += a[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 42180
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int i,b;
char srt[100];
gets(srt);
b=strlen(srt);
for(i=b-1;i>=0;i--)
{
    printf("%c",srt[i]);
}
printf("\n");
}

Measured memory_bytes: 908
#include <stdio.h>

int main() {
    int a, b, c, i, n;
    scanf("%d %d %d\n", &a, &b, &c);
    n = 0;
    for(i = a; i <= b; i++){
        if(c % i == 0){
            n++;
        }
    }
    printf("%d\n", n);
}


Measured memory_bytes: 2052
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
//#define int long long
//#define ll long long
#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 340;
int mod = 1e9 + 7;
int a[N][N], s[N], b[N],c[N];
int ans[N][N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    int s = 0;
    int l = 0;
    for (int i = 1; i <= n; i++){
        int x, y;
        cin >> x >> y;
        s += x * y;
        l += y;
    }
    int ans = 0;
    if (s % 9 == 0) ans = s / 9 - 1; else ans = s / 9;
    ans += l;
    ans--;
    cout << ans;

}


Measured memory_bytes: 256
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln endl
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it<<ln;} cerr<<endl
#define dbgstlp32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cerr<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inp freopen("input.txt", "r", stdin)
#define outp freopen("output.txt", "w", stdout)
#define dbgm(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
typedef long long int  ll;
typedef long double  ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 2e5+5, MOD = 1e9+7, EPS = 1e-9;
int t,n,m,k,x,y;

ll sum[400][400];
ll a[400];

int main(){
	fastio;
	cin>>n;
	forn(i,n) cin>>a[i];
	forn(i,n){
		forn(j,n) sum[i][j]=1e18;
	}
	forn(i,n){
		sum[i][i] = a[i];
	}
	forsn(i,1,n+1){
		forn(j,n){
			if(j+i>=n) continue;
			forn(x,i){
				sum[j][j+i] = min(sum[j][j+i],sum[j][j+x]+sum[j+x+1][j+i]);
			}
		}
	}
	ll ans[n][n];
	forn(i,n){
		forn(j,n){
			ans[i][j]=0;
		}
	}
	// forn(i,n){
	// 	forn(j,n){
	// 		cout<<i<<" "<<j<<" "<<sum[i][j]<<ln;
	// 	}
	// }
//	forn(i,n) ans[i][i]=0;
	forsn(i,1,n+1){
		forn(j,n){
			if(j+i>=n) continue;
			ll mi = 1e18;
			forn(x,i){
//				if(ans[j][j+i]==-1) ans[j][j+i] = ans[j][j+x]+ans[j+x+1][j+i]+sum[j][i+j];
				mi = min(mi,ans[j][j+x]+ans[j+x+1][j+i]);
			}
			ans[j][j+i] = mi+sum[j][j+i];
		}
	}
	// forn(i,n){
	// 	forn(j,n){
	// 		cout<<i<<" "<<j<<" "<<sum[i][j]<<ln;
	// 	}
	// }

	cout<<ans[0][n-1]<<ln;
	return 0;
}

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

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

    ll a[n], b[n];
    ll sumA = 0, sumB = 0;
    rep(i, n) {
        cin >> a[i];
        sumA += a[i];
    }
    rep(i, n) {
        cin >> b[i];
        sumB += b[i];
    }

    if(sumA < sumB) {
        cout << -1 << endl;
        return 0;
    }

    ll c[n];
    rep(i, n) {
        c[i] = a[i] - b[i];
    }

    int ans = 0;
    ll sumhusoku = 0;
    rep(i, n) {
        if(c[i] < 0) {
            sumhusoku += abs(c[i]);
            ans++;
        }
    }

    sort(c, c+n);
    reverse(c, c+n);

    rep(i, n) {
        if(sumhusoku <= 0) {
            break;
        }
        sumhusoku -= c[i];
        ans++;
    }

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

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int n;
	cin >> n;
	vi a(n + 1), b(n + 1);
	for(int i = 1; i <= n; i++) cin >> a[i], b[i] = b[i - 1] + a[i];
	V<vi> dp(n + 2, vi(n + 2));
	for(int r = 1; r <= n; r++) {
		for(int l = r; l >= 1; l--) {
			dp[l][r] = max(dp[l][r], b[r] - b[l] - dp[l + 1][r] + a[l]);
			dp[l][r] = max(dp[l][r], b[r-1] - b[l-1] - dp[l][r-1] + a[r]);
		}
	}
	cout << 2 * dp[1][n] - b[n] << endl;

}



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

using namespace std;

#define INF 2<<29
#define F first
#define S second

typedef long long ll;
typedef pair<int,int>P;

int main(){
  ll n;
  string s[100005];
  ll cnt=1,ans=0;
  scanf("%lld",&n);
  for(int i=0;i<n;i++){
    cin>>s[i];
    sort(s[i].begin(),s[i].end());
  }
  sort(s,s+n);

  for(ll i=0;i<n-1;i++){
    if(s[i]==s[i+1]){
      cnt++;
    }else{
      ans+=cnt*(cnt-1)/2;
      cnt=1;
    }
  }
  ans+=cnt*(cnt-1)/2;

  printf("%lld\n",ans);
  
  return 0;
}



Measured memory_bytes: 7296
s = input()
k = int(input())

count = 0
i=0
join_flag =0
join_n = 0

if len(s)==1:
  print(k//2)
    
elif len(s)==2:
  if s[0]==s[1]:
    print(k)
  else:
    print(0)
  
elif len(set(s))==1:
  print(len(s)*k //2)
  
else:
  while i<len(s)-1:
    if s[i] == s[i+1]:
      count+=1
      i+=2
    else:
      i+=1
  
  if (s[-1] == s[0]) :
    join_flag =1
    
  if join_flag:      
    left_len = 1
    right_len = 1

    for i in range(len(s)-1):
      if s[i] == s[i+1]:
        left_len +=1
      else:
        break

    for i in range(len(s)-1):    
      if s[-1-i]==s[-2-i]:
        right_len +=1
      else:
        break            
    
    if left_len %2 ==1 and right_len %2 ==1:
      join_n = k-1
    else:
      join_n =0
    
  print(count*k + join_n)    

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

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    cout << (1.0*((n+1)/2))/n;
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	int ans = 0;
	int keta = 0;
	int ntmp = N;
	while (0 != ntmp) {
		++keta;
		ntmp /= 10; 
	}
	map<int, int>mp;
	mp[1] = 0;
	mp[2] = 9;
	mp[3] = 9;
	mp[4] = 909;
	mp[5] = 909;
	mp[6] = 90909;
	ans += mp[keta];
	if (1 == keta%2) {
		ans += N - pow(10, keta - 1) + 1;
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 3940
N, x = map(int,input().split())
a = list(map(int,input().split()))

a.sort()

ans = 0
for i in range(N):
    x -= a[i]
    if i == N-1:
        if x == 0:
            ans += 1
    elif x >= 0:
        ans += 1
print(ans)

Measured memory_bytes: 3060
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define pb push_back
# define pdd pair < db , db >
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n,a,b,c,d;
    fi>>n>>a>>b>>c>>d;
    const int mod = 1e9 + 7;
    static int dp[1 << 20];
    dp[0] = 1;
    static int F[1 << 20];
    static int CC[1 << 20];
    auto pow = [&](int a,int b,int mod)
    {
        int ans = 1;
        while (b)
        {
            if (b & 1) ans = (1ll * ans * a) % mod;
            a = (1ll * a * a) % mod;
            b /= 2;
        }
        return ans;
    };
    F[0] = 1;
    for (int i = 1;i <= n;++i)
        F[i] = (1ll * F[i - 1] * i) % mod;
    for (int i = 0;i <= n;++i)
        CC[i] = pow(F[i],mod - 2,mod);
    auto C = [&](int n,int k)
    {
        if (!(0 <= k && k <= n))
            return 0;
        int ans = F[n];
        ans = (1ll * ans * CC[k]) % mod;
        ans = (1ll * ans * CC[n - k]) % mod;
        return ans;
    };
    static int inv[1 << 20];
    for (int i = 0;i <= n;++i)
        inv[i] = pow(i,mod - 2,mod);
    for (int i = a;i <= b;++i)
    {
        for (int j = n;j + 1;--j)
            {
                int cnt = 0;
                int coef = 1;
                for (int k = 1;k < c && k * i <= j;++k)
                    coef = (1ll * coef * C(n - (j - k * i),i)) % mod,coef = (1ll * coef * inv[k]) % mod;
                for (int k = c;k <= d && k * i <= j;++k)
                    coef = (1ll * coef * C(n - (j - k * i),i)) % mod,coef = (1ll * coef * inv[k]) % mod,cnt = (cnt + 1ll * coef * dp[j - k * i]) % mod;
                dp[j] = (dp[j] + cnt) % mod;
            }
    }
    fo << dp[n] << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long a = long.Parse(Console.ReadLine());

            long result = a + a*a + a*a*a;

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


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

int main()
{
    int N, M, Q, L, R, p, q;
    cin >> N >> M >> Q;

    vector<vector<int>> ac(N + 1, vector<int> (N + 1, 0));
    for(int i = 0; i < M; i++) scanf("%d%d", &L, &R), ac[L][R]++;

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

    for(int i = 0; i < Q; i++){
        scanf("%d%d", &p, &q), p--;
        printf("%d\n", ac[q][q] - ac[p][q] - ac[q][p] + ac[p][p]);
    }

    return 0;
}


Measured memory_bytes: 1920
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var I = G;
		WriteLine(I.Max() - I.Min());
	}
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define G(a,b) get<a>(b)
#define VI vector<int>
#define VLL vector<long long>
 
#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
 
ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, unsigned ll y, unsigned ll m);
void pairsort(int a[], int b[], int n);
void pairsortll(ll a[],ll b[],ll n);
ll logint(ll x,ll y);
 
 
ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}
 
ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}
 
void pairsort(int a[],int b[],int n)
{
    pair<int,int> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
void pairsortll(ll a[],ll b[],ll n)
{
    pair<ll,ll> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */
 
    ll q=1;
    //cin>>q;
    while(q--)
    {
        string s;
        cin>>s;
        ll n=s.size();
        vector<tuple<ll,ll,ll>> v;
        REP(i,0,n)
        {
            v.PB(MT(0,0,0));
            ll i0=i;
            while(s[i0]=='R') i0++;
            G(0,v[v.size()-1])=i0-i;
            G(2,v[v.size()-1])=i0;
            i=i0;
            while(s[i0]=='L')
            {
                i0++;
                if(i0==n) break;
            }
            G(1,v[v.size()-1])=i0-i;
            i=i0-1;
        }
        ll nv=v.size();
        ll ans[n]={};
        REP(i,0,nv)
        {
            ans[G(2,v[i])-1]+=G(0,v[i])-G(0,v[i])/2+G(1,v[i])/2;
            ans[G(2,v[i])]+=G(1,v[i])-G(1,v[i])/2+G(0,v[i])/2;
        }
        REP(i,0,n)
        {
            cout<<ans[i]<<' ';
        }
    }
 
    return 0;
}

Measured memory_bytes: 2628
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

bool solve(){
  map<int,int> m;
  int n;
  cin>>n;
  rep(i,n){
    int d;
    cin>>d;
    m[d]++;
  }
  map<int,int> p;
  cin>>n;
  rep(i,n){
    int d;
    cin>>d;
    p[d]++;
  }

  for(auto &pa : p){
    if(m[pa.first] < pa.second) return false;
  }
  return true;
}

int main(){
  if(solve()) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 18944
use proconio::input;

fn main() {
/*
    1 - 2 - 4 - 3
            |
            5
    Yes
    1
    4
    2
    4

    edges
    1: [2]
    2: [1, 4]
    3: [4]
    4: [2,3,5]
    5: [4]
*/
    input! {
        (n, m): (usize, usize),
        abs: [(usize, usize); m]
    };

    let mut edges = vec![vec![]; n+1];
    for (a,b) in abs {
        edges[a].push(b);
        edges[b].push(a);
    }

    let mut dp = vec![std::usize::MAX; n+1];
    dp[1] = 0;
    let mut arrow = vec![0; n+1];

    let mut queue = std::collections::VecDeque::new();
    queue.push_back(1);

    while let Some(pos) = queue.pop_front() {
        for &n in edges[pos].iter() {
            if dp[n] < std::usize::MAX {
                continue;
            }

            dp[n] = dp[pos] + 1;
            arrow[n] = pos;
            queue.push_back(n);
        }
    }

    for i in 1..=n {
        if dp[i] == std::usize::MAX {
            println!("No");
            return;
        }
    }

    println!("Yes");
    for i in 2..=n {
        println!("{}", arrow[i]);
    }
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int d[] = {-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  map<pii,ll> m;
  ll h,w,n,a,b;
  cin >> h >> w >> n;
  vector<pii> v(n);
  ll d2[] = {0,-1,-2};
  rep(u,n){
    cin >> b >> a;
    --a,--b;
    v[u] = mp(a,b);
    rep(i,3){
      rep(j,3){
        ll dx = a + d2[j],dy=b+d2[i];
        if(value(dx,dy,w,h) && value(dx+2,dy+2,w,h)){
          m[mp(dx,dy)] = 0;
        }
      }
    }
  }
  rep(i,n){
    ll x = v[i].fi,y = v[i].se;
    rep(j,3){
      rep(k,3){
        ll dx = x+d2[k],dy = y+d2[j];
        if(m.count(mp(dx,dy))){
          m[mp(dx,dy)]++;
        }
      }
    }
  }
  ll ans[10]= {};
  ans[0] = (w-2)*(h-2);
  for(auto&& e:m){
    ans[e.se]++;
  }
  REP(i,1,10){
    ans[0] -= ans[i];
  }
  rep(i,10){
    cout << ans[i] << endl;
  }
  return 0;
}



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

using namespace std;

const int N = 305;

char board[N][N];

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

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> board[i];
    int A = 0, B = 0, ans = 0;
    while (B < n) {
        bool is_ans = true;
        for (int i = 0; i < n && is_ans; ++i)
            for (int j = 0; j < n && is_ans; ++j)
                if (board[i][(j + B) % n] != board[j][(i + B) % n])
                    is_ans = false;
        if (is_ans)
            ans += 1;
        B += 1;
    }
    cout << ans * n << endl;
    return 0;
}

Measured memory_bytes: 384
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.numeric, std.math, std.array;

  int n, x; rd(n, x);
  auto a=readln.split.to!(int[]);

  auto d=a.map!(e=>abs(e-x)).array;
  if(n==1){
    writeln(d[0]);
    return;
  }
  auto g=gcd(d[0], d[1]);
  foreach(i; 2..n) g=gcd(g, d[i]);
  writeln(g);
}


void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}


Measured memory_bytes: 4404
#include<iostream>
using namespace std;
int main()
{

    int A,B;
    cin>>A>>B;
    if(A!=1&&B!=1&&A>B)
    {
        cout<<"Alice";
    }
    if(A!=1&&B!=1&&A<B)
    {
        cout<<"Bob";
    }
    if(A==B)
    {
        cout<<"Draw";
    }
    if((A==1||B==1)&&A!=B&&A==1)
    {
        cout<<"Alice";
    }
    if((A==1||B==1)&&A!=B&&B==1)
    {
        cout<<"Bob";
    }
    return 0;
}


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


int main(){
    long long n,m;
    cin>>n>>m;
    if(n==1&&m==1) cout<<1<<endl;
    else if(n==1) cout<<m-2<<endl;
    else if(m==1) cout<<n-2<<endl;
    else cout<<(n-2)*(m-2)<<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF = 1LL << 60;


int main() {
  int N,K;
  cin>>N>>K;
  cout<<N-(K-1)<<endl;
   return 0;
  }

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i_len=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back
#define mp make_pair

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

int main()
{
    ll A, B;
    cin >> A >> B;
    ll L = A * B / gcd(A, B);
    PR(L);

    return 0;
}

/*



*/

Measured memory_bytes: 256
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		// your code goes here
		
		var c = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
		int a = c[0];
		int b = c[1];
		int t = c[2];
		int counter = 0;
		
		for(int i = 1;i<=t;i++){
			if(i%a == 0){
				counter = counter + b;
			}
		}
		
		Console.WriteLine(counter);
		
		
	}
}

Measured memory_bytes: 13268
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y", long, "cost");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, k;
    scan(n, k);
    auto l = n / k;
    writeln(min(n - l * k, abs(n - (l + 1) * k)));
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl "\n"
#include "string"


int32_t main(){
	boost;
	int n, d;
	cin >> n >> d;
	d = d * d;
	int ans = 0;
	for(int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		if(x * x + y * y <= d)
			ans++;
	}	
	cout << ans << endl;
}


Measured memory_bytes: 3692
#include <iostream>
#include <stack>

int main()
{
	std::stack<int> printStack;
	int stackSize, input;
	std::cin >> stackSize;

	for (int i = 0; i < stackSize; i++) {
		std::cin >> input;
		printStack.push(input);
	}

	while (printStack.size() > 1) {
		std::cout << printStack.top() << " ";
		printStack.pop();
	}
	std::cout << printStack.top();
	printStack.pop();
	std::cout << "\n";
    return 0;
}




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

typedef long long ll;
ll n, k;
ll ans = 0;

void cal(ll w, ll x) {
    if(x == 1) { ans += 2 * w - 1; return; }
    ll t = w / x;
    if(w % x == 0) {
        ans += 2 * t * x - x;
    }
    else if(w % x != 0){
        ans += 2 * t * x;
        cal(x, w % x);
    }
}



int main() {
    cin >> n >> k;
    if(k > n / 2) k = n - k;
    ans = ans + k + n - k;
    cal(n - k, k);
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
#define LL long long 
const int MaxN = 1e5 + 7;
LL a[MaxN], b[MaxN];  
LL x[MaxN], v[MaxN];

int main()
{
    LL n, c;
    scanf("%lld %lld", &n, &c);
    for(int i = 1; i <= n; i++) 
        scanf("%lld %lld", &x[i], &v[i]);
    
    for(LL i = 1; i <= n; i++) 
        a[i] = a[i - 1] + v[i] - (x[i] - x[i - 1]);  // 顺时针走到i点时的能量
    x[n + 1] = c;
    for(LL i = n; i >= 1; i--) 
        b[i] = b[i + 1] + v[i] - (x[i+1] - x[i]);  // 逆时针走到i点时的能量

    for(LL i = 2; i <= n; i++) 
        a[i] = max(a[i-1], a[i]);  //走或者不走（和走之前的值进行比较）
    for(LL i = n-1; i >= 1; i--) 
        b[i] = max(b[i], b[i + 1]);

    LL ans = 0;
    for(LL i = 1; i <= n; i++) {
        ans = max(ans, a[i] - x[i] + b[i + 1]);  // 顺时针走后并返回一次的值
        ans = max(ans, b[i] - (c - x[i]) + a[i - 1]);  // 逆时针走后返回一次的值
        ans = max(ans, a[i]);  // 顺时针的最大值
        ans = max(ans, b[i]); //逆时针的最大值
    }

    printf("%lld\n", ans);
}

Measured memory_bytes: 3328
from math import gcd
from collections import defaultdict


def sign(x):
    if x < 0:
        return -1
    if x > 0:
        return +1
    return 0


def power(a, b, m):
    res = 1
    base = a
    while b:
        if b & 1:
            res = res * base % m
        base = base * base % m
        b = b >> 1
    return res


N = int(input())
M = 1000000007
cnt = defaultdict(int)
case00 = 0

for _ in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:  # (0, 0) cannot pair with anyone
        case00 += 1
        continue

    s = sign(a) * sign(b)
    a, b = abs(a), abs(b)
    g = gcd(a, b)
    a, b = a // g, b // g
    cnt[s, a, b] += 1


ans = 1  # empty set
vis = set()
for (s, a, b) in cnt.keys():
    if (s, a, b) in vis:
        continue

    if (-s, b, a) in cnt:
        mul = 1  # empty set from (s, a, b) and (-s, b, a)
        mul += power(2, cnt[s, a, b], M) - 1  # non-empty subsets from (s, a, b)
        mul += power(2, cnt[-s, b, a], M) - 1  # non-empty subsets from (-s, b, a)
        ans = ans * (mul % M) % M
        vis.add((-s, b, a))
    else:
        ans = ans * power(2, cnt[s, a, b], M) % M

ans = (ans - 1 + M) % M  # Remove empty set
ans = (ans + case00) % M  # Special case
print(ans)


Measured memory_bytes: 46584
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = int_fast64_t;
using P = pair<int,int>;

int main(){
    int N;
    cin >> N;
    bool ok = false;
    for(int i = 1; i < 10; i++) {
        if(N % i == 0 && N / i < 10) ok = true;
    }

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		if(N / 10 == 9 || N % 10 == 9) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}


	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <cmath>

/**
 * find out minimum s + nf s.t. t < s + nf
 */
int get_ceil(int t, int s, int f)
{
  if(t < s) return s;

  int n = std::ceil((t - s) / float(f));
  return s + n * f;
}

/**
 * get minimum arrival time from i -> N
 */
int get_min_arrival_time(
    int i, int N,
    const std::vector<int> &C,
    const std::vector<int> &S,
    const std::vector<int> &F)
{
  int t = 0;
  //std::cout << "i=" << i << " N=" << N << std::endl;
  for(int j=i; j<N-1; j++) {
    //std::cout << "j=" << j << " t=" << t << std::endl;
    t = get_ceil(t, S[j], F[j]);
    //std::cout << "train at " << t << std::endl;
    t += C[j];
    //std::cout << "arrive at " << t << std::endl;
  }
  return t;
}


int main()
{
  int N;
  std::cin >> N;
  std::vector<int> C(N-1);
  std::vector<int> S(N-1);
  std::vector<int> F(N-1);

  for(int i=0; i<N-1; i++) {
    std::cin >> C[i] >> S[i] >> F[i];
  }

  for(int i=0; i<N; i++) {
    std::cout << get_min_arrival_time(i, N, C, S, F) << std::endl;
  }

  return 0;
}


Measured memory_bytes: 3600
#include <iostream>

std::string table[10] = {"",
                         ".,!? ",
                         "abc",
                         "def",
                         "ghi",
                         "jkl",
                         "mno",
                         "pqrs",
                         "tuv",
                         "wxyz"};

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

    for(;N--;){
        std::string S;
        std::cin >> S;

        int key = -1, index = -1;
        std::string T = "";
        for(char c : S){
            if(c == '0'){
                if(~key){
                    T += table[key][index];
                    key = -1;
                    index = -1;
                }
            }else{
                if(!~key){
                    key = c - '0';
                    index = 0;
                }else{
                    index = (index+1) % table[key].size();
                }
            }
        }

        std::cout << T << std::endl;
    }
}

Measured memory_bytes: 1212
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , 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,
        s: [chars; n]
    }

    let sc = s .into_iter().collect::<std::collections::HashSet<_>>();
    println!("{}", if sc.len() == 3 {"Three"} else {"Four"});
}

#[allow(dead_code)]
fn count<T: Eq + std::hash::Hash + Clone>(slice: &[T]) -> std::collections::HashMap<T, usize> {
    let mut hmap = std::collections::HashMap::new();
    for item in slice {
        *hmap.entry(item.clone()).or_insert(0) += 1;
    }
    hmap
}

Measured memory_bytes: 4352