akhauriyash/Code-Regression huggingface dataset:
#define DEBUG 0
/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 6/16/2019, 8:53:16 PM
 * Powered by Visual Studio Code
 */
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <functional>
#include <random>
#include <chrono>
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
typedef long long ll;
void Yes()
{
  cout << "Yes" << endl;
  exit(0);
}
void No()
{
  cout << "No" << endl;
  exit(0);
}
const int MAX_SIZE = 1000010;
class mint
{
public:
  static ll MOD;
  ll x;
  mint() : x(0) {}
  mint(ll x) : x(x % MOD) {}
  mint operator-() const { return x ? MOD - x : 0; }
  mint &operator+=(const mint &a)
  {
    if ((x += a.x) >= MOD)
    {
      x -= MOD;
    }
    return *this;
  }
  mint &operator-=(const mint &a) { return *this += -a; }
  mint &operator*=(const mint &a)
  {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint &operator/=(const mint &a) { return (*this *= power(MOD - 2)); }
  mint operator+(const mint &a) const { return mint(*this) += a; }
  mint operator-(const mint &a) const { return mint(*this) -= a; }
  mint operator*(const mint &a) const { return mint(*this) *= a; }
  mint operator/(const mint &a) const { return mint(*this) /= a; }
  bool operator<(const mint &a) const { return x < a.x; }
  bool operator==(const mint &a) const { return x == a.x; }
  const mint power(ll N)
  {
    if (N == 0)
    {
      return 1;
    }
    else if (N % 2 == 1)
    {
      return *this * power(N - 1);
    }
    else
    {
      mint half = power(N / 2);
      return half * half;
    }
  }
};
ll mint::MOD = 1e9 + 7;
istream &operator>>(istream &stream, mint &a) { return stream >> a.x; }
ostream &operator<<(ostream &stream, const mint &a) { return stream << a.x; }
mint inv[MAX_SIZE];
mint fact[MAX_SIZE];
mint factinv[MAX_SIZE];
void init()
{
  inv[1] = 1;
  for (int i = 2; i < MAX_SIZE; i++)
  {
    inv[i] = (-inv[mint::MOD % i]) * (mint::MOD / i);
  }
  fact[0] = factinv[0] = 1;
  for (int i = 1; i < MAX_SIZE; i++)
  {
    fact[i] = mint(i) * fact[i - 1];
    factinv[i] = inv[i] * factinv[i - 1];
  }
}
mint choose(int n, int k)
{
  if (n >= 0 && k >= 0 && n - k >= 0)
  {
    return fact[n] * factinv[k] * factinv[n - k];
  }
  return 0;
}
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// const double epsilon = 1e-10;
// const ll infty = 1000000000000000LL;
// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

int main()
{
  // init();
  int X, A;
  cin >> X >> A;
  if (X < A)
  {
    cout << 0 << endl;
  }
  else
  {
    cout << 10 << endl;
  }
}

Measured memory_bytes: 23680
N, K = map(int, input().split())

mp = {}
for i in range(1, N+1):
    mp[i] = 0
for _ in range(K):
    _ = int(input())
    A = list(map(int, input().split()))
    for a in A:
        mp[a] += 1
ans = 0
for i in mp.values():
    if i == 0:
        ans += 1
print(ans)

Measured memory_bytes: 67752
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
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++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int a,b,c,k;cin >> a >> b >> c >> k;
    //a<b<c
    int num=0;
    while(a>=b){
        b*=2;
        num++;
    }
    while(b>=c){
        c*=2;
        num++;
    }
    cout << (num<=k ? "Yes" : "No") << endl;
}

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

int main(){
  int N, H;
  cin >> N >> H;
  int a[N], b[N];
  int a_max = 0;
  rep(i, N){
    cin >> a[i] >> b[i];
    a_max = max(a[i], a_max);
  }
  sort(b, b + N);
  int ans = 0;
  int u = lower_bound(b,b+N,a_max) - b;
  for(int i = N-1; i >= u; i--){
    H -= b[i];
    ans++;
    if(H <= 0){
      cout << ans << endl;
      return 0;
    }
  }
  cout << ans + (H + a_max - 1)/a_max << endl;
  return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  int d = max(a,b);
  if (a > b){
    a--;
  }
  if (b > a){
    b--;
  }
  cout << d + max(a,b) << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
// 1-indexed BIT
class BIT{
    public:
    vector<ll>bit;
    int N;
    void init(int n){
        N = n;
        bit = vector<ll>(N, 0);
    }
    // [1, n] = {}
    BIT(int n = 0){
        init(n);
    }
    // sum [1, i]
    ll sum(int i){
        ll s = 0;
        while(i > 0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    ll sum(ll l, ll r){
        if(l > r)return 0;
        if(l == 1)return sum(r);
        return sum(r) - sum(l - 1);
    }
    void add(int i, ll x){
        if(i == 0)return;
        while(i <= N){
            bit[i] += x;
            i += i & -i;
        }
    }
};

class MIN_MAX_QUEUE{
    private:
    unordered_map<ll, ll>cnt;
    ll sz;
    priority_queue<ll>mx_que;
    priority_queue<ll, vector<ll>, greater<ll> >mn_que;

    public:
    MIN_MAX_QUEUE(){
        sz = 0;
    }
    void push(ll x){
        cnt[x]++;
        sz++;
        mx_que.push(x);
        mn_que.push(x);
    }
    void pop(ll x){
        if(cnt[x] <= 0)return;
        sz--;
        cnt[x]--;
    }
    ll size(){
        return sz;
    }
    ll min(){
        if(sz <= 0)return 0;
        while(cnt[mn_que.top()] <= 0)mn_que.pop();
        return mn_que.top();
    }
    ll max(){
        if(sz <= 0)return 0;
        while(cnt[mx_que.top()] <= 0)mx_que.pop();
        return mx_que.top();
    }

};

ll A[202020];

int main(){

    ll N, K;
    cin >> N >> K;
    BIT down(202020);
    rep1(i, N){
        cin >> A[i];
        A[i]++;
        if(A[i] < A[i - 1]){
            down.add(i, 1);
        }
    }
    A[0] = 200020;
    MIN_MAX_QUEUE mmq;
    for(ll i = 0; i < K; i++)mmq.push(A[i]);
    ll ans = 0;
    ll def = 0;
    for(ll i = 1; i + K - 1 <= N; i++){
        ll l = i, r = l + K - 1;
        ll mn = mmq.min();
        ll mx = mmq.max();
        mmq.pop(A[l - 1]);
        mmq.push(A[r]);
        if(down.sum(l + 1, r) == 0){
            def = 1;
            continue;
        }
        if(mn == A[l - 1] && mx < A[r]){
            continue;
        }
        else{
            ans++;
        }
    }

    cout << ans + def << endl;

    return 0;
}

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

int main(){
	
	int n;
	cin>>n;
	vector<int>v;
	for(int t;cin>>t;)v.push_back(t);
	reverse(v.begin(),v.end());
	for(int i=0;i<n;i++)cout<<v[i]<<(i+1==n?"\n":" ");
	
	return 0;
}


Measured memory_bytes: 1216
//
//  Created by 赵宏祝 .
//

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <iterator>

#define FOR0(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define FOR1(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define FOR(i, l, r) for(int (i) = (l); (i) <= (r); (i)++)
#define lowbit(x) (x)&(-x)
#define MEMSET(x, y) memset((x), (y), sizeof(x))

using namespace std;
//============================
int ans1[250000], ans2[250000];
int a[250000], b[250000];
int C[1000000], maxr = 1000000;

//============================

void add(int x, int a) {
    while (x < maxr) {
        C[x] += a;
        x += lowbit(x);
    }
}
int sum(int x) {
    //if (x == 0) return -1;
    int ret = 0;
    while(x > 0) {
        ret += C[x];
        x -= lowbit(x);
    }
    return ret;
}

int main(){
    int N;
    long long ans = 0;
    cin >> N;
    FOR1(i, N) {
        scanf("%d", &a[i]);
        b[a[i]] = i;
    }
    //add(1, 1);
    add(N + 1, 1);
    FOR1(i, N) {
        int now = sum(b[i]);
        int l = 0, r = b[i];
        while (l < r - 1) {
            int mid = (r + l) / 2;
            if (sum(mid) != now) {
                l = mid;
            }
            else r = mid;
        }
        if (sum(l) == now) r = l;
        //if (r == 1) r = 0;
        ans1[b[i]] = b[i] - r;
        //tans = r;
        //cout << ans1[b[i]] << " ";
        //cout << r << " ";
        l = b[i], r = N + 1;
        while (l < r - 1) {
            int mid = (r + l) / 2;
            if (sum(mid) != now) {
                r = mid;
            }
            else l = mid;
        }
        if (sum(r) == now) l = r;
        ans2[b[i]] = l - b[i] + 1;
        //ans1[b[i]] = l - tans + 1;
        add(b[i], 1);
        //cout << /*ans2[b[i]]*/l << endl;
    }
    
    
    FOR1(i, N) {
        ans += (long long)ans1[i] * ans2[i] * a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
#include<iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	int count = 0;
	for (int i = 0;i < n;i++) {
		count = 4 * i;
		if (count == n) {
			cout << "Yes" << endl;
			return 0;
		}
		for (int i0 = 0;i0 < n;i0++) {
			count = 4 * i + i0 * 7;
			if (count == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import math
n,d=map(int,input().split())
a=[]
x=[]
count=0
c=0
ans=0
for i in range(n):
    a=list(map(int,input().split()))
    for j in range(d):
        x.append(a[j])
for i in range(1,n):
    for j in range(i+1,n+1):
        for k in range(d):
            y=x[(i-1)*d+k]
            z=x[(j-1)*d+k]
            c=y-z
            count+=c*c
        e=math.sqrt(count)
        if e%1==0:
            ans+=1
        count=0
print(ans)


Measured memory_bytes: 3064
nu = gets.to_i
tra = gets.chomp.split(" ").map(&:to_i)
skip = [tra[1].abs]
for i in 1..nu - 2
  skip[i] = (tra[i - 1] - tra[i + 1]).abs
end
skip[nu - 1] = tra[nu - 2].abs
move = [tra[0].abs]
for i in 1..nu - 1
  move[i] = (tra[i - 1] - tra[i]).abs
end
move[nu] = tra[nu - 1].abs
sum = 0
for i in 0..nu
  sum += move[i]
end

for i in 0..nu - 1
  puts sum - move[i] - move[i + 1] + skip[i]
end


Measured memory_bytes: 13708
#include<cstdio>
#include<map>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=202202;
int a[N];
int n,k;
int main(){
	scanf("%d%d",&n,&k);
	for (int i=1; i<=n; i++)
		scanf("%d",&a[i]);
	int sum=0;
	for (int i=1; i<=k; i++)
		sum=sum+a[i];
	int mx=sum;
	for (int i=k+1; i<=n; i++)
		sum=sum+a[i]-a[i-k],mx=max(mx,sum);
	printf("%lf\n",1.0*(mx+k)/2);
	return 0;
}

Measured memory_bytes: 896
import numpy as np

n, m = input().split()
n = int(n)
m = int(m)

# a[i] = 0 の床は踏めない
a = np.ones(n+1, dtype=np.bool)
for _ in range(m):
    a[int(input())] = 0

mod = 1e9 + 7

# pos[i]はi段目まで登る場合の数
pos = np.zeros(n+1)
pos[0] = 1
for i in range(n-1):
    if a[i+1]:
        pos[i+1] += pos[i]
        pos[i+1] %= mod
    if a[i+2]:
        pos[i+2] += pos[i]
        pos[i+2] %= mod

pos[n] += pos[n-1]

print(int(pos[n] % mod))

Measured memory_bytes: 13360
import sys

for line in sys.stdin:
    a,b,c,d,e,f = [float(i) for i in line.split()]
    x = round((1/a)*(c-b*((a*f-c*d)/(a*e-b*d))),3)
    y = round((a*f-c*d)/(a*e-b*d),3)
    print(
        '{:.3f}'.format(x),'{:.3f}'.format(y),
    )


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e15;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double dbl;
#define pb push_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define all(a) a.begin(),a.end()
bool debug = 0;
const int MAXN = 1e5 + 100;
const int LOG = 20;
const int mod = 1e9 + 7;
const int MX = 1e6 + 100;
typedef long long li;
const li MOD = 1000000000949747713ll;


int a[32][32];
int dp[21][1<<21];

inline void upd(int& x){
    if(x >= mod)
        x-=mod;
}
void solve() {
    int n;
    cin >> n;
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            cin >> a[i][j];
        }
    }
    for(int i=0;i<n;++i){
        if(a[0][i]){
            dp[0][1<<i] = 1;
        }
    }
    for(int i=1;i<n;++i){
        for(int mask = 0;mask < (1<<n);++mask){
            if(dp[i-1][mask]){
                for(int j = 0;j < n;++j){
                    if(!(mask & (1<<j)) && a[i][j]){
                        dp[i][mask|(1<<j)] += dp[i-1][mask];
                        upd(dp[i][mask|(1<<j)]);
                    }
                }
            }
        }
    }
    cout << dp[n-1][(1<<n)-1];


}

signed main() {
#ifdef zxc
    debug = 1;
    freopen("../input.txt", "r", stdin);
#else

#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(20);

    int t = 1;

    while (t--)
        solve();
    dout << endl << (1.0 * clock() / CLOCKS_PER_SEC) << endl;
}

Measured memory_bytes: 160000
N, M = list(map(int, input().split()))
a = []
b = []
c = []
d = []
for i in range(N):
    aa, bb = list(map(int, input().split()))
    a.append(aa)
    b.append(bb)

for i in range(M):
    cc, dd = list(map(int, input().split()))
    c.append(cc)
    d.append(dd)

ans = []
for i in range(N):
    x = a[i]
    y = b[i]
    ind = 0
    distance = 4*10**8
    for j in range(M):
        if(distance > abs(x - c[j]) + abs(y - d[j])):
            ind = j
            distance = abs(x - c[j]) + abs(y - d[j])
    ans.append(ind)

for i in range(N):
    print(ans[i] + 1)


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    int ans = t;
    for(int i=0; i<n-1; ++i)
        ans += min(a[i+1] - a[i], t);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;

int main(){

    int n, m;
    cin >> n >> m;
    vector<vector<int> > pf(n, vector<int>()); 
    vector<int> p(m,-1);
    vector<int> y(m,-1);

    for(int i = 0; i < m; i++)
    {
        cin >> p[i] >> y[i];
        pf[p[i]-1].push_back(y[i]);
    }

    for(int i = 0; i < n; i++)
    {
        sort(pf[i].begin(), pf[i].end());
    }

    for(int i = 0; i < m; i++)
    {
        vector<int>::iterator it = lower_bound(pf[p[i]-1].begin(), pf[p[i]-1].end(), y[i]);
        int index = it - pf[p[i]-1].begin() + 1;
        
        string name = to_string(p[i]);
        while(name.length() < 6){
            name = '0' + name; 
        }

        string number = to_string(index);
        while(number.length() < 6){
            number = '0' + number; 
        }

        cout << name + number << endl;

    }

    return 0;
    
}

Measured memory_bytes: 7808
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

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

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
int main(){
	ll n, m;
	cin >> n >> m;
	ll ans = (-1*(ll)INF);
	whei(ll) a(n, hei(ll)(3));
	rep(i, 0, n)rep(j,0,3)cin >> a[i][j];
	rep(bit, 0, 8) {
		hei(ll)s;
		rep(i, 0, n) {
			ll sum = 0;
			rep(j, 0, 3) { if ((bit/(1 << j))%2==0)sum += a[i][j]; else sum -= a[i][j]; }
			s.push_back(sum);
		}
		sort(s.begin(), s.end());
		reverse(s);
		ll SUM = 0;
		rep(j, 0, m) {
			SUM += s[j];
		}
		ans = max(ans, SUM);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
while True:
    table = input().split()

    a = int(table[0])
    op = table[1]
    b = int(table[2])

    if op == '?':
        break

    if op == '+':
        print("%d"%(a+b))
    elif op == '-':
        print("%d"%(a-b))
    elif op == '/':
        print("%d"%(a/b))
    else:
        print("%d"%(a*b))


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



i64 n, k, a[101010];
//コンビネーション
//けんちょんさんありがとう
const int MAX = 101010, MOD = INF;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long C(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
////
void solve(){
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a,a+n);
	
	COMinit();
	i64 ans = 0;
	for(int i = 0; i <= n-k; i++){
		ans -= a[i] * C(n-1-i,k-1);
		ans = mod(ans,INF);
		ans += a[n-1-i] * C(n-1-i,k-1);
		ans = mod(ans,INF);
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    int n, m;
    cin >> n >> m;
    int num[n];
    bool red[n];
    rep(i, n)
    {
        num[i] = 1;
        red[i] = false;
    }
    red[0] = true;
    rep(i, m)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        if (red[x])
            red[y] = true;
        num[x]--;
        num[y]++;
        if (num[x] == 0)
            red[x] = false;
    }
    int ans = 0;
    rep(i, n)
    {
        if (red[i])
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a[100010],b[100010],cnt=0;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i]>>b[i];
    }
    sort(b,b+n);
    sort(a,a+n,greater<int>());
    cout<<a[0]+b[0]<<'\n';
    return(0);
}

Measured memory_bytes: 1024
//Robs Code
/***********HEADER***************/
#include<bits/stdc++.h>
/***********MACROS***************/
#define ll long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 10000007
#define mxval 1e9
#define grt [](auto x,auto y){return x>y;}
#define pii pair<ll,ll>
/*********VARIABLE****************/
using namespace std;
ll i,j,n,m,k,l,q,t,a,b,sum[3],tot[3],cnt[3];
/***********MAIN******************/
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	string s;
    cin>>s;
    ll mx=0;
    for(i=0;i<(ll)s.length();i++){
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T') cnt[0]++;
        else mx=max(cnt[0],mx),cnt[0]=0;
    }
    mx=max(cnt[0],mx);
    cout<<mx;
    return 0;
}
//.........

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=1e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
#endif
}
int n,a[N];
int q[N],top;
void input()
{
	n=read<int>();
	For(i,1,n)a[i]=q[i]=read<int>();
	sort(q+1,q+n+1);
	top=unique(q+1,q+n+1)-q-1;
}
int sum[N<<1];
void add(int x,int v)
{
	x+=n+1;
	for(;x<=n*2+1;x+=x&-x)sum[x]+=v;
}
int cal(int x)
{
	x+=n+1;
	int res=0;
	for(;x;x-=x&-x)res+=sum[x];
	return res;
}
bool check(int d)
{
	memset(sum,0,sizeof sum);
	int res=0;
	ll num=0;
	add(0,1);
	For(i,1,n)
	{
		if(a[i]>=d)res++;
		else res--;
		num+=2*cal(res)-i;
		add(res,1);
	}
	//cerr<<d<<' '<<num<<endl;
	return num>=0;
}
void work()
{
	int l=1,r=top,mid,ans=-1;
	while(l<=r)
	{
		mid=(l+r)>>1;
		if(check(q[mid]))ans=q[mid],l=mid+1;
		else r=mid-1;
	}
	write(ans,'\n');
}
int main()
{
//	file();
	input();
	work();
	return 0;
}


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

int main() {
	int a, b, c, d, e, f, mixedAns = 0, sugarAns = 0;
	cin >> a >> b >> c >> d >> e >> f;
	double conc = -1;

	for (int ai = 0; ai <= f; ai += 100 * a) {
		for (int bi = 0; ai+bi <= f; bi += 100 * b) {
			int water = ai + bi; if (water == 0)continue;
			for (int ci = 0; water + ci <= f; ci += c) {
				for (int di = 0; water + ci + di <= f; di += d) {
					int sugar = ci + di;
					double nowConc = 100.0 * sugar / (water + sugar);
					int limitSugar = water / 100 * e;
					if (sugar <= limitSugar && nowConc > conc) {
						conc = nowConc;
						mixedAns = water + sugar; sugarAns = sugar;
					}
				}
			}
		}
	}
	cout << mixedAns << ' ' << sugarAns << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<bits/stdc++.h>
using namespace std;

/*define*/
#define rep(i, n) for(int i=0; i<n; ++i)
#define endl "\n"
typedef long long ll;
//typedef pair<int, int> P;
//vector<long long> a(max_n);
//map<int, int> m;
static const int max_n = 200002, max_m = 102;
static const ll  INF = 1000000000;
const long long mod = 1e18;
int ci;

int n;
vector<ll> a(max_n);
int main(){
    cin >> n;
    ll res = 0;
    rep(i, n){
        cin >> a[i];
        res ^= a[i];
    }
    rep(i, n){
        ll ans;
        ans = res ^ a[i];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4684
N, Y  = map( int, input().split())
Y = Y/1000
ichiman = -1
gosen = -1
sen = -1
Flag = False
if N*10 < Y:
    Flag = True
for i in range(N+1):
    for j in range(N-i+1):
        if i*10 + j*5 + (N-i-j) == Y:
            ichiman = i
            gosen = j
            sen = N-i-j
            Flag = True
            break
    if Flag:
        break

print('{} ' '{} ' '{}'.format(ichiman, gosen, sen))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, a, b;
ll Max, Min, ans;
int main(){
    cin >> n >> a >> b;
    if(a > b) {cout << "0"; return 0;}
    if(n == 1 && a == b) {cout << "1"; return 0;}
    if(n == 1 && a != b){cout << "0"; return 0;}
    if(n == 2 && a == b){cout << "0"; return 0;}
    if(n == 2 && a != b){cout << "1"; return 0;}
    Min = (n-2) * a;
    Max = (n-2) * b;
    ans = (Max - Min + 1);
    cout << ans << endl;

    return 0;
}

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

#define   ll     long long int

ll mod = 1000000007;

int main( )
{
    ll n, m, i, ans = 0;
    cin >> n >> m;
    if (n == m) {
        ans = 1;
        for (i = 1; i <= n; i++) {
            ans = (ans * i) % mod;
        }
        ans = (ans * ans) % mod;
        ans = (2 * ans) % mod;
    }
    else if (abs(n - m) == 1) {
        if (n > m) swap(n, m);
        ans = 1;
        for (i = 1; i <= n; i++) {
            ans = (ans * i) % mod;
        }
        ans = (ans * ans) % mod;
        ans = (m * ans) % mod;
    }
    cout << ans << '\n';
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <random>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int d;
vec c;
int s[365][26] = {};
int last[365][26] = {};
vec t;

lint update(int day, int type) {
    vec t2 = t;
    t2[day] = type;

    int last2[365][26] = {};

    lint res = 0;

    rep(i, d) {
        res += s[i][t2[i]];
        for (int j = i; j < d; j++) last2[j][t2[i]] = i+1;
        rep(j, 26) {
            res -= c[j] * (i+1 - last2[i][j]);
        }
    }

    return res;
}

lint score() {
    lint res = 0;

    rep(i, d) {
        res += s[i][t[i]];
        for (int j = i; j < d; j++) last[j][t[i]] = i+1;
        rep(j, 26) {
            res -= c[j] * (i+1 - last[i][j]);
        }
    }

    return res;
}

int main() {
    cin >> d;
    c.resize(26);
    rep(i, 26) cin >> c[i];
    rep(i, d) rep(j, 26) cin >> s[i][j];

    t.resize(d);
    lint now = 0;

    rep(i, d) {
        lint mx = 0;
        int selected = -1;
        rep(j, 26) {
            lint nw2 = now;

            nw2 += s[i][j];

            int tmp = last[i][j];
            last[i][j] = i+1;
            rep(k, 26) {
                nw2 -= c[k] * (i+1 - last[i][k]);
            }
            last[i][j] = tmp;

            if (nw2 > mx) {
                mx = nw2;
                selected = j;
                t[i] = j;
            }
        }
        for (int j = i; j < d; j++) last[j][selected] = i+1;
        // now += mx;
    }

    now = score();

    int cnt = 1000;
    random_device rnd;
    mt19937 mt(time(0));
    while (cnt--) {
        int day = mt() % d;
        int type = mt() % 26;
        lint now2 = update(day, type);
        if (now < now2) {
            t[day] = type;
            now = now2;
        }
    }

    rep(i, d) cout << t[i]+1 << endl;
    return 0;
}

Measured memory_bytes: 3748
#include <stdio.h>

int main(){

  int n,i,num;
  int s[15],h[15],c[15],d[15];
  char moji;

  for(i=1;i<=13;i++){
    s[i]=h[i]=c[i]=d[i]=i;
      }  
  scanf("%d",&n);
  
  for(i=0;i<n+1;i++){
    scanf(" %c %d",&moji,&num);
    
    if(moji=='S') s[num]=0;
    else if(moji=='H')h[num]=0;
    else if(moji=='C')c[num]=0;
    else if(moji=='D')d[num]=0;
  }
  
  for(i=1;i<=13;i++){
    if(s[i]!=0)printf("S %d\n",s[i]);
  }
  for(i=1;i<=13;i++){
    if(h[i]!=0)printf("H %d\n",h[i]);
  }
  for(i=1;i<=13;i++){
    if(c[i]!=0)printf("C %d\n",c[i]);
  }

  for(i=1;i<=13;i++){
    if(d[i]!=0)printf("D %d\n",d[i]);
  }

  

  return 0;
}



Measured memory_bytes: 2108
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

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

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

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

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

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

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

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

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

fn main() {
    input!{
        d: usize,
        g: i64,
        mut pc: [(i64, i64); d],
    }

    let mut ans = std::i64::MAX;
    for b in (0..1 << d) {
        let mut sum = 0;
        let mut cnt = 0;

        let mut choose = 0;

        for i in 0..d as i64 {
            if b & (1 << i) != 0 {
                sum += (i + 1) * 100 * pc[i as usize].0 + pc[i as usize].1;
                cnt += pc[i as usize].0;
            } else {
                choose = i;
            }
        }

        if sum < g {
            let s = 100 * (choose + 1);
            let need = (g - sum + s - 1) / s;

            if need >= pc[choose as usize].0 {
                continue;
            }
            cnt += need;
        }
        ans = min(ans, cnt);
    }
    println!("{}", ans);
}


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

int main()
{
    int x, y, z;
    cin >> x >> y;

    if (x <= 3 && x > 0)
        z += (4 - x) * 100000;
    if (y <= 3 && y > 0)
        z += (4 - y) * 100000;

    if (x == 1 && y == 1)
        z += 400000;

    cout << z << endl;
    return 0;
}

Measured memory_bytes: 256
S = gets.chomp.chars

completed = false

2.upto(3) do |i|
  break if completed
  S.each_cons(i).with_index do |s, j|
    (puts "#{j + 1} #{i + j}"; break) if completed = (s.uniq.size != i)
  end
end

puts "-1 -1" unless completed


Measured memory_bytes: 9468
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   int n;
           cin>>n;
           vin a(n);
           rep(i,0,n)cin>>a[i];
           int ans=inf;
           rep(i,0,n){
            int cnt=0;
             while(a[i]%2==0){
              a[i]/=2;
               cnt++;
             }
             chmin(ans,cnt);
           }
           cout<<ans<<endl;
}

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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    string s;
    cin >> s;

    u64 ans = 0;
    string temp{""};
    string prev{""};
    rep (i, s.size())
    {
        temp.insert(temp.end(), s[i]);
        if (temp != prev)
        {
            ++ans;
            prev = temp;
            temp = "";
        }
    }

    cout << ans << "\n";
    return 0;
}



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

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

fn main() {
    let v = read_vec::<usize>();
    let (h, w) = (v[0], v[1]);
    let mut edges: Vec<Vec<Edge>> = vec![vec![]; 10];
    for i in 0..10 {
        let v = read_vec::<i64>();
        for j in 0..10 {
            // edges[i].push(Edge { to: j, cost: v[j] });
            edges[j].push(Edge { to: i, cost: v[j] });
        }
    }

    let mut count = vec![0; 10];
    for i in 0..h {
        let v = read_vec::<i32>();
        for &elem in v.iter() {
            if elem == -1 {
                continue;
            }
            count[elem as usize] += 1;
        }
    }
    let costs = solve(&edges, 1, 10);
    debug!(costs);
    debug!(count);
    let mut ans = 0;
    for i in 0..10 {
        ans += count[i] * costs[i];
    }
    println!("{}", ans);
}

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

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

const INF: i64 = 100000_00000_00000;

#[derive(PartialEq, Debug)]
struct MinInt {
    value: i64,
}

impl Eq for MinInt {}

impl PartialOrd for MinInt {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        other.value.partial_cmp(&self.value)
    }
}

impl Ord for MinInt {
    fn cmp(&self, other: &MinInt) -> Ordering {
        other.value.cmp(&self.value)
    }
}

fn make_pair(x: i64, y: usize) -> (MinInt, usize) {
    (MinInt { value: x }, y)
}

#[derive(Debug, Clone)]
struct Edge {
    to: usize,
    cost: i64,
}

fn solve(edges: &Vec<Vec<Edge>>, start_idx: usize, num_apexes: usize) -> Vec<i64> {
    let mut d = vec![INF; num_apexes];
    d[start_idx] = 0;
    let mut que = BinaryHeap::new();
    que.push(make_pair(0, start_idx));

    while let Some((u, v)) = que.pop() {
        if d[v] < u.value {
            continue;
        }
        for e in &edges[v] {
            if d[v] != INF && d[e.to] > d[v] + e.cost {
                d[e.to] = d[v] + e.cost;
                que.push(make_pair(d[e.to], e.to));
            }
        }
    }
    d
}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

int main() {
	IOS;
	ll x;
	cin >> x;
	int ans = 1;
	while (1) {
		if (ans*(ans + 1) / 2 >= x)break;
		ans++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
def detletter(i,j,x,y):
    a = i%2
    b = j%2
    if a==0 and b==0:
        return x
    if a==1 and b==0:
        return y
    if a==0 and b==1:
        return y
    if a==1 and b==1:
        return x

h = []
w = []
while 1:
    h_, w_ = map(int, input().split())
    if h_==0 and w_==0:
        break
    h.append(h_)
    w.append(w_)

n = len(h)
for k in range(n):
    for i in range(h[k]):
        let = ""
        for j in range(w[k]):
            let += detletter(i,j,"#",".")
        print(let)
    print()
#print()


Measured memory_bytes: 5628
#include<iostream>
#include<vector>
#include<queue>
#include<cstdlib>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll n,k;
  cin >> n >> k;

  ll ans1 = n % k;

  ll ans2 = abs(ans1 - k);

  ll ans3 = min(ans1,ans2);

  cout << ans3 << endl;
  return 0;
}


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

 int main()
 {
     int N,K;
     vector<int> l(100);
     
     scanf("%d %d",&N,&K);
     for(int i=0;i<N;i++)
     {
         scanf("%d",&l[i]);
     }

     sort(l.begin(),l.end());

     int ans=0;
     for(int j=0;j<K;j++)
     {
         ans+=l.back();
         l.pop_back();
     }
     cout << ans << endl;
 } 

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# abc 127 d
from operator import itemgetter
# input
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
upd = []
for i in range(m):
    upd.append(list(map(int, input().split())))
upd.sort(key=itemgetter(1), reverse=True)
# print(upd)
# output
f = len(a)
p = 0
for t in upd:
    for i in range(p, p+t[0]):
        if p < f:
            if a[p] < t[1]:
                a[p] = t[1]
            else:
                break
        else:
            break
        p += 1
print(sum(a))

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

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto A = RD;

	writeln(N * N - A);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
// g++ -I ~/Documents/programming/cppLib -std=gnu++14 -o test ~/Documents/programming/cppLib/test.cpp && ./test && rm test
#include <bits/stdc++.h>
using namespace std;
template <typename T> using vector2 = vector <vector  <T>>;
template <typename T> using vector3 = vector <vector2 <T>>;
template <typename T> using vector4 = vector <vector3 <T>>;
using lint = long long;
#define FOR( i, a, b ) for( lint i=(a) ; i < (b) ; ++i )
#define REP( i, n )    for( lint i= 0  ; i < (n) ; ++i )
#define ALL( v )       (v).begin(), (v).end()

using T = tuple<int,string,int>;

bool comp( T a, T b ) {
    if( get<1>(a) == get<1>(b) ) {
        return get<2>(a) > get<2>(b);
    }
    return get<1>(a) < get<1>(b);
}

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

    vector<T> R(N);
    REP( i, N ) {
        get<0>(R[i]) = i+1;
        cin >> get<1>(R[i]) >> get<2>(R[i]);
    }

    sort( ALL(R), comp );

    REP( i, N ) {
        cout << get<0>(R[i]) << endl;
    }
}


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

const int N = 105;

int n;
int ans, b[N];

inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (!isdigit(ch))
        f = (ch == '-') ? -1 : 1, ch = getchar();
    while (isdigit(ch))
        x = x * 10 + (ch - '0'), ch = getchar();
    return x * f;
}

main()
{
    n = read();
    for (int i = 1; i < n; i++)
        b[i] = read();
    b[n] = 0x7fffffff;

    for (int i = n - 1; i > 0; i--)
        ans += min(b[i], b[i + 1]);
    ans += b[1];
    cout << ans << '\n';
    return 0;
}

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

using namespace std;

int main () {
  vector<int> lengths;
  int input;

  for (size_t i = 0; i < 3; i++) {
    cin >> input;
    lengths.push_back(input);
  }
  
  cout << (lengths[0] * lengths[1]) / 2 << endl;

  return 0;
}


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

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

fn main() {
    let A: u32 = read();
    let B: u32 = read();
    let C: u32 = read();
    let X: u32 = read();

    let mut count = 0;

    for a in (0..A+1) {
        for b in (0..B+1) {
            for c in (0..C+1) {
                if (500*a + 100*b + 50*c) == X {
                    count += 1;
                }
            }
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 4352
fun main(args: Array<String>) = yorukatsu6E()

fun yorukatsu6E() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val xyList = (1..n).map { readLine()!!.split(' ').map { it.toLong() } }
        .map { Xy(it[0], it[1]) }

    val xList = xyList.map { it.x }.sorted()
    val yList = xyList.map { it.y }.sorted()

    var answer = Long.MAX_VALUE

    for ((index1, left) in xList.withIndex()) {
        for (right in xList.drop(index1 + 1)) {
            for ((index2, down) in yList.withIndex()) {
                for (up in yList.drop(index2 + 1)) {
                    val inRectangle = xyList.count() { it.y in down..up && it.x in left..right }
                    if (inRectangle >= k) {
                        val area = Math.abs(right - left) * Math.abs(up - down)
                        answer = Math.min(answer, area)
                    }
                }
            }
        }
    }

    println(answer)
}

private data class Xy(val x: Long, val y: Long)


Measured memory_bytes: 56036
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int K = sc.nextInt();
        ArrayList<Integer> commonDivisors = new ArrayList<>();
        int idx = Math.min(A, B);

        for (int i = idx; i > 0; i--) {
            if (A % i == 0 && B % i == 0) {
                commonDivisors.add(i);
                if (commonDivisors.size() == K) {
                    break;
                }
            }
        }

        System.out.println(commonDivisors.get(K - 1));
    }

}





Measured memory_bytes: 21844
H,W = map(int, input().strip().split(' '))

if (H%3)*(W%3) == 0:
  print(0)
  exit()

ans = min(H,W)
for _ in range(2):
  for h in range(1,H//2+1):
    a = W*h
    b = (H-h)*(W//2)
    c = (H-h)*(W-W//2)
    ans = min(max(a,b,c)-min(a,b,c), ans)
  H,W = W,H
print(ans)


Measured memory_bytes: 3064