akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(){
    int a;
    while(cin>>a){
        if(a==0)return 0;
    int b=1000-a;
    int count=0;
    if(b/500==1){
        b=b-500;
        count++;
    }
    if(b/100!=0){
            int c=b/100;
            count+=c;
            b=b-100*c;
        }
    if(b/50==1){
            b=b-50;
            count++;
        }
     if(b/10!=0){
            int d=b/10;
            count+=d;
            b=b-10*d;
        }
     if(b/5==1){
            b=b-5;
            count++;
        }
    count+=b%5;
    cout<<count<<endl;
    }
}

Measured memory_bytes: 2996
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int N;cin >> N;
    int a[100];
    for (int i = 0; i < N;i++)  cin >> a[i] ;
    sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート
    int Alice = 0;int Bob = 0;
    for (int i = 0; i < N; ++i) {
        if (i % 2 == 0) {Alice += a[i];}
        else {Bob += a[i];}
    }
    cout << Alice - Bob << endl;
}

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int N;
	cin >> N;
	vector<int> x, y, h;
	rep(i, 0, N) {
		int tmp_x, tmp_y, tmp_h;
		cin >> tmp_x >> tmp_y >> tmp_h;
		x.push_back(tmp_x);
		y.push_back(tmp_y);
		h.push_back(tmp_h);
	}

		rep(xi, 0, 101) rep(yi, 0, 101) {
			if(h[0] != 0) {
				int H = h[0] + abs(x[0] - xi) + abs(y[0] - yi);
				bool flag = true;
				rep(i, 0, N) {
					if(h[i] != max(H - abs(x[i] - xi) - abs(y[i] - yi), 0)) {
						flag = false;
						break;
					}
				}
				if(flag) {
					cout << xi << " " << yi << " " << H << endl;
					return 0;
				}
			} else {
				int max_h = abs(x[0] - xi) + abs(y[0] - yi);
				rep(hi, 0, max_h + 1) {
					bool flag = true;
					rep(i, 0, N) {
						if(h[i] != max(hi - abs(x[i] - xi) - abs(y[i] - yi), 0)) {
							flag = false;
							break;
						}
					}
					if(flag) {
						cout << xi << " " << yi << " " << hi << endl;
					}
				}
			}
		}
}



Measured memory_bytes: 256
Do = {"R","U","D"}
De = {"L","U","D"}
S = input().strip()
ind = 1
for i in range(len(S)):
    if (i+1)%2==1:
        if S[i] not in Do:
            ind = 0
            break
    elif (i+1)%2==0:
        if S[i] not in De:
            ind = 0
            break
if ind==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll x;
  cin >> x;
  if (x) {
    cout << 0 << "\n";
  }
  else {
    cout << 1 << "\n";
  }
}


Measured memory_bytes: 3604
/**
       ������������    ������������
		Author : Avi J Patel
		University : DA-IICT
       ������������    ������������
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair 
#define N 100000
#define mod 1000000007
int main()
{
    int a,b;
    cin>>a>>b;
    if(a<=5)
    {
    	cout<<"0";
	}
	else if(a<=12)
	{
		cout<<b/2;
	}
	else
	cout<<b;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

void solve(long long A, long long B, long long C, long long D, long long E)
{

    ll m = 11;

    ll ans = 0;
    ans += A / 10 * 10;
    if (A % 10 != 0)
    {
        ans += 10;
        m = min(m, A % 10);
    }
    ans += B / 10 * 10;
    if (B % 10 != 0)
    {
        ans += 10;
        m = min(m, B % 10);
    }
    ans += C / 10 * 10;
    if (C % 10 != 0)
    {
        ans += 10;
        m = min(m, C % 10);
    }
    ans += D / 10 * 10;
    if (D % 10 != 0)
    {
        ans += 10;
        m = min(m, D % 10);
    }
    ans += E / 10 * 10;
    if (E % 10 != 0)
    {
        ans += 10;
        m = min(m, E % 10);
    }

    if (m != 11)
    {
        cout << ans - (10 - m) << endl;
    }
    else
    {
        cout << ans << endl;
    }
}

int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    long long D;
    scanf("%lld", &D);
    long long E;
    scanf("%lld", &E);
    solve(A, B, C, D, E);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;


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

Measured memory_bytes: 4748
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n,k,s=0;
    cin>>n>>k;
    int p[n];
    for(int i=0;i<n;i++)
        cin>>p[i];
    sort(p,p+n);
    for(int j=0;j<k;j++)
        s=s+p[j];
    cout<<s;
}


Measured memory_bytes: 3620
fun main(args: Array<String>) {
    val mod = 1000000007L
    fun divWithMod(a: Long, b: Long): Long {
        return ((a % mod) * java.math.BigInteger.valueOf(b).modInverse(java.math.BigInteger.valueOf(mod)).toLong()) % mod
    }
    val (h, w, a, b) = readLine()!!.split(' ').map(String::toLong)
    val dataNum = (h + w).toInt()
    val facts = LongArray(dataNum + 1) { 1 }
    (1..dataNum).forEach { facts[it] = (facts[it - 1] * it) % mod }

    var ans = 0L
    for (tw in b + 1..w) {
        val th = h - a
        val m1_1 = facts[(th + tw - 2).toInt()]
        val m1_2 = if (th != 1L) divWithMod(m1_1, facts[th.toInt() - 1]) else m1_1
        val m1_3 = if (tw != 1L) divWithMod(m1_2, facts[tw.toInt() - 1]) else m1_2

        val m2_1 = facts[(a + (w - tw + 1) - 2).toInt()]
        val m2_2 = if (a != 1L) divWithMod(m2_1, facts[a.toInt() - 1]) else m2_1
        val m2_3 = if ((w - tw + 1) != 1L) divWithMod(m2_2, facts[(w - tw + 1).toInt() - 1]) else m2_2

        ans += (m1_3 * m2_3) % mod
        ans %= mod
    }
    println(ans)
}


Measured memory_bytes: 107552
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define REP(i,n) for(long long i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(),a.end()


void solve(std::string s){
    deque<char> que(ALL(s));
    ll cnt = 0;
    while(que.size()>1){
        char f=que.front(), b=que.back();
        if(f == 'x'){
            que.pop_front();
            if(b == 'x'){
                que.pop_back();
            }
            else{
                cnt ++;
            }
        }
        else{
            if(b == 'x'){
                que.pop_back();
                cnt++;
            }
            else if(b == f){
                que.pop_front();
                que.pop_back();
            }
            else{
                cout << -1 << endl;
                return;
            }
        }
    }
    cout << cnt << endl;
}

int main(){
    std::string s;
    std::cin >> s;
    solve(s);
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
int main(void) {
	int n, k; cin >> n >> k;
	int h[n], i;
	int ans = 1000000001;
	for (i = 0; i < n; i++) {
		cin >> h[i];
	}

	sort(h, h + n);

	for(i=0;i<=n-k;i++){
		if (ans > h[i + k - 1 ] - h[i]) {
			ans = h[i + k - 1 ] - h[i];
		}
	}

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



Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

class ModCalc
{
    LLONG m_mod = MOD;
    vector<LLONG> m_fac;
    vector<LLONG> m_ifac;

public:
    ModCalc(const LLONG mod)
    {
        m_mod = mod;
    }

    // Combinationを計算したいときの前処理：O(max)
    ModCalc(const int max, const LLONG mod)
    {
        m_mod = mod;
        m_fac = vector<LLONG>(max + 1);
        m_ifac = vector<LLONG>(max + 1);
        m_fac[0] = m_ifac[0] = 1;
        for (int i = 0; i < max; ++i)
        {
            m_fac[i + 1] = m_fac[i] * (i + 1) % mod;    // n! (mod M)
            m_ifac[i + 1] = m_ifac[i] * ModPow(i + 1, mod - 2) % mod;   // k!^(M-2) (mod M)
        }
    }

    const LLONG ModAdd(LLONG a, LLONG b) const
    {
        return (a + b) % m_mod;
    }

    const LLONG ModSubtract(LLONG a, LLONG b) const
    {
        LLONG diff = a - b;
        return diff >= 0 ? diff : diff + m_mod;
    }

    const LLONG ModMulti(LLONG a, LLONG b) const
    {
        LLONG prod = a * b % m_mod;
        return prod >= 0 ? prod : prod + m_mod;
    }

    const LLONG ModDiv(LLONG a, LLONG b) const
    {
        LLONG c = m_mod, u = 1, v = 0;
        while (c)
        {
            LLONG t = b / c;
            b -= t * c; swap(b, c);
            u -= t * v; swap(u, v);
        }
        u %= m_mod;
        if (u < 0) u += m_mod;
        return (a % m_mod) * u % m_mod;
    }

    const LLONG ModPow(LLONG x, LLONG n) const
    {
        LLONG ret = 1;
        while (n != 0)
        {
            if (n & 1) ret = ret * x % m_mod;
            x = x * x % m_mod;
            n = n >> 1;
        }
        return ret;
    }

    const LLONG ModComb(LLONG n, LLONG r) const
    {
        if (n == 0 && r == 0) return 1;
        if (n < r || n < 0) return 0;
        LLONG tmp = m_ifac[n - r] * m_ifac[r] % m_mod;
        return tmp * m_fac[n] % m_mod;
    }
};

int main()
{
    int N, P; cin >> N >> P;
    string S; cin >> S;
    vector<int> nums(N);
    for (int i = 0; i < N; ++i)
    {
        nums[i] = static_cast<int>(S[i] - '0');
    }
    // Pが10の約数のときは、右端がPで割り切れる数が全て解になる
    if (P == 2 || P == 5)
    {
        LLONG ans = 0LL;
        for (int i = 0; i < N; ++i)
        {
            if (nums[i] % P == 0)
            {
                ans += (i + 1);
            }
        }
        cout << ans << endl;
        return 0;
    }
    // Pが10の約数でないとき、右端から順に数を伸ばしていき
    // (modP)の値が等しくなるペアの数だけ解になる
    map<LLONG, LLONG> mod2NumMap;
    ModCalc modP(P);
    LLONG mod = 0;
    for (int i = 0; i < N; ++i)
    {
        LLONG newDigit = modP.ModMulti(nums[N - 1 - i], modP.ModPow(10, i));
        mod = modP.ModAdd(mod, newDigit);
        ++mod2NumMap[mod];
    }
    LLONG ans = mod2NumMap[0];  // Pの倍数になる場所は単体で答えになる
    for (const auto &kvp : mod2NumMap)
    {
        LLONG num = kvp.second;
        ans += num * (num - 1) / 2; // modPの値が等しい場所の間も解になる
    }
    cout << ans << endl;
}


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

const int INF = 1001001001;
//const ll INF = 1000000000000000000;

ll twoth(int x, int y, int z) {
	return x*x + y*y + z*z + x*y + y*z + z*x;
}

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

	vector<int> f(n, 0);
	for(int i = 1; i <= 100; i++) {
		if (twoth(i, 1, 1) > n) break;
		for(int j = 1; j <= 100; j++) {
			if (twoth(i, j, 1) > n) break;
			for(int k = 1; k <= 100; k++) {
				if (twoth(i, j, k) > n) break;
				f[twoth(i, j, k) - 1]++;
			}
		}
	}
 	rep(i,n) cout << f[i] << endl;
	return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
const int maxn=10000+10;
const int INF=1<<21;
typedef pair<int,int> P;
typedef struct{int to,cost;}Edge;
vector<Edge> g[maxn];
int d[maxn];
int n;
void dj(int s)
{
    fill(d,d+n,INF);
    d[s]=0;
    priority_queue<P,vector<P>,greater<P> > que;
    que.push(P(0,s));
    while(!que.empty())
    {
        P p=que.top();que.pop();
        int u=p.second;
        if(p.first>d[u]) continue;
        for(int i=0;i<g[u].size();i++)
        {
            Edge &e=g[u][i];
            if(d[e.to]>d[u]+e.cost)
            {
                d[e.to]=d[u]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        printf("%d %d\n",i,d[i]);
    }
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    int id,c;
    for(int i=0; i<n; i++)
    {
        scanf("%d%d",&id,&c);
        while(c--)
        {
            Edge e;
            scanf("%d%d",&e.to,&e.cost);
            g[id].push_back(e);
        }
    }
    dj(0);

    return 0;
}

Measured memory_bytes: 8108
(n, a, b), xx = [list(map(int, s.split())) for s in open(0)]

suc = xx.pop()

dx = []

while len(xx):
    prec = xx.pop()
    dx.append(suc-prec)
    suc = prec

dx = [min(d*a, b) for d in dx]

print(sum(dx))

Measured memory_bytes: 98432
class BinaryTree
  attr_accessor :key, :left, :right, :parent

  def initialize(key, left, right, parent)
    @key    = key.to_i
    @left   = left
    @right  = right
    @parent = parent
  end

  def root
    if parent
      parent.root
    else
      self
    end
  end

  def insert(z)
    x = root
    y = nil

    while x
      y = x
      if z.key < x.key
        x = x.left
      else
        x = x.right
      end
    end

    z.parent = y
    if y.nil?
      key = z.key
      left = z.left
      right = z.right
    elsif z.key < y.key
      y.left = z
    else
      y.right = z
    end
  end

  def find(k)
    k = k.to_i

    if k < key
      !!left&.find(k)
    elsif k > key
      !!right&.find(k)
    else
      k == key
    end
  end

  def show
    in_order
    puts "\n"
    pre_order
    puts "\n"
  end

  def in_order
    left&.in_order
    print " #{key}"
    right&.in_order
  end

  def pre_order
    print " #{key}"
    left&.pre_order
    right&.pre_order
  end
end

n = gets.chomp.to_i
bt = nil
n.times do
  op, key = gets.chomp.split

  case op
  when 'insert'
    if bt
      bt.insert(BinaryTree.new(key, nil, nil, nil))
    else
      bt = BinaryTree.new(key, nil, nil, nil)
    end
  when 'find'
    puts bt.find(key) ? 'yes' : 'no'
  when 'print'
    bt.show
  end
end


Measured memory_bytes: 49936
fun main(args: Array<String>) {
    val (D, G) = readLine()!!.split(" ").map { it.toLong() }
    val ps = Array(D.toInt()) {
        val (p, c) = readLine()!!.split(" ").map { it.toLong() }
        Pair(p, c)
    }

    var res = 1e10.toLong()
    for (s in 0 until (1 shl D.toInt())) {
        var a = 0L
        var n = 0L
        for (j in ps.indices) {
            if (s and (1 shl j) != 0) {
                a += 100 * (j + 1) * ps[j].first + ps[j].second
                n += ps[j].first
            }
        }

        for (k in (D - 1).toInt() downTo 0) {
            if (a >= G) break
            if ((s shr k) and 1 == 1) continue

            val m = Math.max(Math.min(ps[k].first, (G - a + 100 * (k + 1) - 1) / (100 * (k + 1))), 0)
            a += 100 * (k + 1) * m
            n += m
        }

        if (a >= G) {
            res = Math.min(res, n)
        }
    }

    println(res)
}


Measured memory_bytes: 37744
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int h,sum=0,k,i;
    cin>>h>>k;
    long long int a[h],d=h;
    for(i=0;i<d;i++)
    {
        cin>>a[i];
    }
    if(d<=k)
    {
        cout<<"0"<<endl;
    }
    else if(k==0)
    {
        for(int j=0;j<d;j++)
        {
            sum=sum+a[j];
        }
        cout<<sum<<endl;
    }
    else
    {
        sort(a,a+d);
        for(int j=0;j<d-k;j++)
        {
            sum=sum+a[j];
        }
        cout<<sum<<endl;
    }
}



Measured memory_bytes: 1792
N,L = map(int,input().split())

l = [0] * N
for i in range(N):
    l[i] = L + i

ans = sum(l)
res = 10 ** 9
d = 0
for i in range(N):
    tmp = l[:i] + l[i+1:]
    solve = sum(tmp)
    c = abs(ans - solve)

    if(res > c):
        res = c
        d = solve

print(d)

Measured memory_bytes: 3060
# coding: utf-8
#61

n = int(input())
TP = int()
HP = int()
W=[]
for i in range(n):
    tW,hW = input().split()
    W.append(tW)
    W.append(hW)
    W = sorted(W)
    
    if tW==hW:
        TP += 1
        HP += 1
    elif tW==W[0]:
        HP += 3
    else:
        TP += 3
    #print(tW,hW)
    #print(W)
    W=[]
print(TP,HP)
        



Measured memory_bytes: 5604
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <math.h>
using namespace std;

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

int main() {
  int N, M, X, Y; cin >> N >> M >> X >> Y;
  int Mx = -101;
  if (Y <= X) {
    cout << "War" << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    int x; cin >> x;
    Mx = max(Mx, x);
  }
  if (Mx >= Y) {
    cout << "War" << endl;
    return 0;
  }
  for (int i = 0; i < M; i++) {
    int y; cin >> y;
    if (y <= Mx || y <= X) {
      cout << "War" << endl;
      return 0;
    }
  }

  cout << "No War" << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var c1, c2 string
	fmt.Scan(&c1, &c2)

	ans := "NO"
	if c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0] {
		ans = "YES"
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int s = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        System.out.println(problem164a(s, w));
    }

    private static String problem164a(int s, int w) {
        return (s <= w) ? "unsafe" : "safe";
    }
}

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

using std::cout;
using std::cin;
using std::endl;

void selectionSort(int *a, int n){
  int minj;
  int cnt=0;
  for(int i=0;i<n;i++){
    minj=i;
    for(int j=i;j<n;j++){
      if(a[j]<a[minj]) minj=j;
    }
    if(i!=minj){
      std::swap(a[i], a[minj]);
      cnt++;
    }
  }
  for(int i=0;i<n;i++){
    if(i) cout << " ";
    cout << a[i];
  }
  cout << endl <<cnt << endl;
}

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++)
    cin >> a[i];
  selectionSort(a,n);
  return 0;
}



Measured memory_bytes: 3120
PROGRAM ATCODER

implicit none
character :: c

read(*,*) c

if ( c == 'a' .or. c == 'e' .or. c == 'i' .or. c == 'o' .or. c == 'u' ) then
  write(*,'(a)') 'vowel'
else
  write(*,'(a)') 'consonant'
end if

contains
!!!!!! サブルーチンは↓
!!!!!!

END PROGRAM ATCODER


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

const int inf = -1000;
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a /gcd(a, b) *b;
}
void bubble(vector<int> &v){
int n = v.size();
  for(int k=1;k<=n-1;++k){
    for(int i=1;i<n;++i){
        if(v[i]<v[i-1])
            swap(v[i],v[i-1]);
    }
  }
}
int main() {

   int a,b;
   cin>>a>>b;
   
   int sum = 0;
   
   if(a>=13)
      sum = b;
   
   else if(a>=6&&a<=12)
        sum = b/2;
   
   cout<<sum;

    return 0;

      }


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const int N = 3e2+5;
void solve(){
    int r,g,b,k;
    cin>>r>>g>>b>>k;
    while(g<=r){
        g*=2;
        k--;
    }
    while(b<=g){
        b*=2;
        k--;
    }
    if(k<0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#define Mod 1000000007
#define INF 1e14
typedef long long int ll;
const ll N=1e5+5;
bool x[N+1]={false};
ll fast(ll n,ll a)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll res=fast(n/2,a)%Mod;
        if(n%2==0)
        {
            return (((res%Mod)*(res%Mod))%Mod);
        }
        else{
            return (((((res%Mod)*a)%Mod)*res)%Mod);
        }
    }
}

int main()
{
  string s,r;
  cin>>s>>r;
  int i,j=0;
  for(i=0;i<3;i++)
  {
      if(s[i]==r[i])
        j++;
  }
  cout<<j;



}


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

typedef long long ll;
typedef long double ld;

#define test(t) int t;cin>>t;while(t--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
const int MOD = 1e9+7,MAX = 1e5+5;
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
vector<bool> is_prime(MAX+1, true);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
        	for (j = i * i; j <= MAX; j += i)
            	is_prime[j] = false;
    	}
	}
}
ll modInv(ll a)
{
	return powN(a,MOD-2);
}


int main()
{
	int n,i;
	cin>>n;
	int d[n];
	forn(i,n) cin>>d[i];
	ll sum=0;
	forn(i,n)
	{
		int j;
		for(j=i+1;j<n;j++)
		{
			sum+=d[i]*d[j];
		}
	}
	cout<<sum<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <queue>
#include <utility>
using namespace std;

#define SIZE 30

const int dy[4] = {-1, 0, 1, 0};
const int dx[4] = {0, 1, 0, -1};
int w, h;
bool walls[SIZE + 1][SIZE + 1][4];
int maze[SIZE + 1][SIZE + 1];

void run() {
    maze[0][0] = 1;
    queue<pair<int, int> > q;
    q.push(make_pair(0, 0));
    while (q.empty() == false) {
        int y = q.front().first, x = q.front().second;
        q.pop();
        for (int i = 0; i < 4; i++) {
            int ny = y + dy[i], nx = x + dx[i];
            if (0 <= ny && ny < h && 0 <= nx && nx < w && walls[y][x][i] == 0
                && (maze[ny][nx] == 0 || maze[y][x] + 1 < maze[ny][nx])) {
                maze[ny][nx] = maze[y][x] + 1;
                q.push(make_pair(ny, nx));
            }
        }
    }
}

int main() {
    while (true) {
        cin >> w >> h;
        if ((w | h) == 0) {
            break;
        }
        memset(maze, 0, sizeof(maze));
        memset(walls, false, sizeof(walls));
        for (int y = 0; y < h; y++) {
            int temp;
            for (int x = 0; x < w - 1; x++) {
                cin >> temp;
                walls[y][x][1] = walls[y][x + 1][3] = temp;
            }
            if (y < h - 1) {
                for (int x = 0; x < w; x++) {
                    cin >> temp;
                    walls[y][x][2] = walls[y + 1][x][0] = temp;
                }
            }
        }
        run();
        cout << maze[h - 1][w - 1] << endl;
    }
}

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

int N, M, Q;
int ans = 0;
vector<int> A;
vector<int> a, b, c, d;
void dfs(int cu = 0, int lst = 1) {
    if (cu == N) {
        int tot = 0;
        for (int i = 0; i < Q; i++) {
            if (A[b[i]]-A[a[i]] == c[i]) tot += d[i];
        }
        ans = max(ans, tot);
        return;
    }

    for (int nxt = lst; nxt < M+1; nxt++) {
        A[cu] = nxt;
        dfs(cu+1, nxt);
    }
}

int main() {
    cin >> N >> M >> Q;
    A.resize(N);
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    for (int i = 0; i < Q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }

    dfs();
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

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



int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if(a > c) {
    swap(a, c);
    swap(b, d);
  }

  if(c <= b && b <= d) cout << b-c << endl;
  else if(c <= b && d <= b) cout << d-c << endl;
  else cout << 0 << endl;

  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  ll n,a,b;
  cin >>n>>a>>b;

  ll ans=jou(2,n);
  ans=(ans+mod-1)%mod;
  
  ll s=1;
  for(ll i=n-a+1;i<=n;i++){
  s*=i;
  s%=mod;
  }
  
  ll x=1;
  repo(i,a+1){
  x*=i;
  x%=mod;
  }
  
  ll t=1;
  for(ll i=n-b+1;i<=n;i++){
  t*=i;
  t%=mod;
  }  
  
  ll y=1;
  repo(i,b+1){
  y*=i;
  y%=mod;
  }
    
  ans+=mod-(s*jou(x,mod-2))%mod+mod-(t*jou(y,mod-2))%mod;
  
  cout << ans%mod << endl;
  
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

dp = [[0 for i in range(N)] for i in range(N)]
res = 0

def f(l, r):
  if 0 < dp[l][r]:
    return dp[l][r]
  if l == r:
    return 0
  fans = float('inf')
  for m in range(r)[l:]:
    fans = min(fans, f(l, m)+f(m+1, r))
  dp[l][r] = fans + sum(A[l:r+1])
  return dp[l][r]
  
print(f(0,N-1))


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

using namespace std;

map<array<int, 2>, int> ans;
vector<vector<int>> E;
vector<bool> visited;

void dfs(int i, int prev){
    visited[i] = true;
    int c = 1;
    for (const auto &e: E[i]){
        if (c == prev)
            c++;
        if (visited[e])
            continue;
        ans[{i, e}] = c;
        ans[{e, i}] = c;
        dfs(e, c++);
    }
        
}

int main(){
    int n;
    cin >> n;
    vector<int> cnt(n + 1), cnt2(n + 1);
    vector<array<int, 2>> inputs(n - 1);
    E.assign(n + 1, vector<int>());
    visited.assign(n + 1, false);

    for (int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;
        cnt[a]++;
        cnt[b]++;
        inputs[i] = {a, b};
        E[a].push_back(b);
        E[b].push_back(a);
    }

    int c = accumulate(cnt.begin(), cnt.end(), 0, [](int l, int r){return max(l, r);});

    dfs(1, 0);
    cout << c << endl;
    for (const auto &input: inputs){
        cout << ans[input] << endl;
    }
}

Measured memory_bytes: 20096
h, w, k = list(map(int, input().split()))

ss = []
d = {"#":1, ".":0}
for _ in range(h):
	ss.append([d[x] for x in list(input())])

ans = []
skip_rows = 0
cur_num = 0
for i in range(h):
	if sum(ss[i]) == 0:
		skip_rows += 1
	else:
		cur_num += 1
		if sum(ss[i]) == 1:
			tmp = [cur_num for _ in range(w)]
		else:
			tmp = []
			for j in range(w):
				tmp.append(cur_num)
				if ss[i][j] == 1 and sum(ss[i]) != sum(ss[i][:(j + 1)]):
					cur_num += 1

		for _ in range(skip_rows + 1):
			ans.append(tmp)
		skip_rows = 0

for _ in range(skip_rows):
	ans.append(tmp)

for a in ans:
	print(*a)


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

typedef struct{
  int root,left,right;
} Node;
Node T[25];

void preorder(int root){
  if (root==-1)return;
  cout << " " << root;
  preorder(T[root].left);
  preorder(T[root].right);
}

void inorder(int root){
  if (root==-1)return;
  inorder(T[root].left);
  cout << " " << root;
  inorder(T[root].right);
}

void postorder(int root){
  if (root==-1)return;
  postorder(T[root].left);
  postorder(T[root].right);
  cout << " " << root;
}

int main(){
  int n,id,cl,cr,root;
  char *types[]={(char*)"root",(char*)"internal node",(char*)"leaf"};
  
  for (int i=0;i<25;i++){
    T[i].root=-1;
    T[i].left=-1;
    T[i].right=-1;
  }

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> id >> cl >> cr;
    T[id].left=cl;
    T[id].right=cr;
    if(cl!=-1)T[cl].root=id;
    if(cr!=-1)T[cr].root=id;
  }

  for (int i=0;i<n;i++){
    if (T[i].root==-1){
      root=i;
      break;
    }
  }
  cout << "Preorder" << endl;
  preorder( root);
  cout << endl;
 
  cout << "Inorder" << endl;
  inorder( root);
  cout << endl;
   
  cout << "Postorder" << endl;
  postorder( root);
  cout << endl;
 
  return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    ll N;
    cin >> N;
    vector<ll> H(N);
    for(int i=0;i<N;i++){
        cin >> H[i];
    }
    ll ma=H[0];
    ll ct=0;
    for(int i=0;i<N;i++){
        if(H[i]>=ma){
            ma=H[i];
            ct++;
        }
    }
    cout << ct << endl;
}

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

int main()
{
    int a,c=0;cin>>a;
    string s;cin>>s;
    for(int i=0;i<a;i++){
        if(s[i]=='A'){
            if(s[i+1]=='B'){
                if(s[i+2]=='C'){
                    c++;
                }
            }
        }
    }
    std::cout << c << std::endl;
}


Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int r = 0;
		for(int i = 0; i < n; i++) {
			int h = sc.nextInt();
			if(h >= k) r++;
		}
		sc.close();
		System.out.println(r);
	}
}

Measured memory_bytes: 46036
def conKey(i, j, k):
    return str(i)+'-'+str(j)+'-'+str(k)


def getKey(s):
    return map(int, s.split('-'))


import heapq
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

h = []
stack = set([])
ans = []
i, j, k = 0, 0, 0
heapq.heappush(h, (-(A[i]+B[j]+C[k]), conKey(i, j, k)))
stack.add(conKey(i, j, k))
for _ in range(K):
    tmp, key = heapq.heappop(h)
    print(-tmp)
    i, j, k = getKey(key)
    key_0 = [i, j, k]

    for m in range(3):
        key_tmp = key_0.copy()
        if key_tmp[m] >= (X, Y, Z)[m] - 1:
            continue
        key_tmp[m] += 1
        tmp_sum = A[key_tmp[0]] + B[key_tmp[1]] + C[key_tmp[2]]

        str_key = conKey(*key_tmp)

        if str_key not in stack:
            heapq.heappush(h, (-tmp_sum, str_key))
            stack.add(str_key)

Measured memory_bytes: 4700
#include <iostream>

using namespace std;

string s;
long n;

int main()
{
    int min = 0;
    int black = 0;
    int white = 0;
    cin >> n;
    cin >> s;

    long tmp;

    for (char c: s)
    {
        if (c == '.')
            white++;
    }
    min = white;

    for (char c: s)
    {
        if (c == '.')
        {
            white--;
        }
        else
        {
            black++;
        }
        if (min > white + black)
            min = white + black;
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 640
d,g = map(int,input().split())

p = [] # 問題数の格納
c = [] # ボーナス点の格納
ans = [] #　候補解の格納
ss = 0
cnt = 0

for _ in range(d): #問題数、ボーナス点の入力
    pp,cc = map(int,input().split())
    p.append(pp)
    c.append(cc)

for x in range(2**d): #bit全探索
    ss = 0 # 得点
    cnt = 0 #　問題数
    for i in range(d): #bit探索
        if (x >> i) & 1:
            ss += (i+1)*100*p[i] + c[i]
            cnt += p[i]
    
    if ss >= g: #　既に得点がg以上の時、ansに格納
        ans.append(cnt)
    
    else:
        for l in range(d)[::-1]:
            if ((x>>l)&1):
                continue
            for _ in range(1,p[l]):
                ss += (l+1) * 100
                cnt += 1
                
                if ss >= g:
                    ans.append(cnt)
                    break

print(min(ans))

Measured memory_bytes: 3064
#n=int(input())
#li=input().split()
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math
#li=list(map(int,input().split()))
#S=input()

lis=[[],[]]
for i in range(5):
    s=int(input())
    lis[0].append(s)
    lis[1].append(s%10)
for i in range(5):
    if lis[1][i]!=0:
        m=i
        break
m=0
for i in range(5):
    if lis[1][m]>lis[1][i] and lis[1][i]!=0:
        m=i
ans=0
for i in range(5):
    if i!=m:
        if lis[1][i]!=0:
            ans+=(lis[0][i]-lis[1][i]+10)
        else:
            ans+=lis[0][i]
ans+=lis[0][m]
print(ans)


Measured memory_bytes: 3064
import java.util.*;

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

      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int ans = 0;
      for (int i = a; i <= b; i++) {
        if (c % i == 0) {
          ans++;
        }
      }
      System.out.println(ans);

      sc.close();
  }
}


Measured memory_bytes: 26396
// B - 美しい文字列

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> s;
  if (s.size() % 2 == 1)
  {
    cout << "No" << endl;
    return 0;
  }
  else
  {
    rep(i, 0, s.size())
    {
      count = 1;
      rep(j, 0, s.size())
      {
        if (i != j && s[i] == s[j])
        {
          count++;
        }
      }
      if (count % 2 == 1)
      {
        cout << "No" << endl;
        return 0;
      }
      count = 1;
    }
  }
  cout << "Yes" << endl;
}

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

 int main() {
 int N;
 cin >> N;
 vector<int> a(N);
 int sum=0;

 for(int i=0;i<N;++i){
 cin >> a[i];
 sum += a[i];
 }


 
 int ans = sum;
 int another = 0;
 for(int i=0;i<N;++i){
 cin >> a[i];
 another += a[i];
 ans = min(ans, abs(another - (sum - another)));
 }

 cout << ans << endl;
 
 }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int n;
  cin >> n;
  vector<vector<pair<int, int> > > edge(n);
  for (int i = 0; i < n-1; i++) {
    int a, b;
    cin >> a >> b;
    edge[a-1].emplace_back(b-1, i);
    edge[b-1].emplace_back(a-1, i);
  }

  vector<int> ans(n-1);
  int maxK = 0;
  stack<pair<int, int> > st;
  st.emplace(0, 0);
  while (!st.empty()) {
    auto now = st.top();
    st.pop();
    int v = now.first;
    int last = now.second;
    int col = 1;
    for (auto &x: edge[v]) {
      if (col == last) col++;
      if (ans[x.second] > 0) continue;
      ans[x.second] = col;
      st.emplace(x.first, col);
      maxK = max(maxK, col);
      col++;
    }
  }

  cout << maxK << endl;
  for (auto &x: ans) cout << x << endl;

  return 0;
}


Measured memory_bytes: 6912
/*g++ file.cpp -o file.out*/
/*./file.out*/

#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define LL long long
#define Mod 1000000007
#define L_Mod 17100000013

#define MAX 100005
int prime[MAX],check[MAX];
void Primelist()
{
    memset(check,0,sizeof(check));
    int cnt=1,i,j;
    for(i=2;i<=MAX;i++)
    {
        if(!check[i])
            prime[cnt++]=i;
        for(j=1;j<=cnt;j++)
        {
            if(i*prime[j]>MAX)
                break;
            check[i*prime[j]]=1;
            if(i%prime[j]==0)
                break;
        }
    }
}
LL pow_mod(LL a, LL b, LL p){//a的b次方求余p
    LL ret = 1;
    while(b){
        if(b & 1) ret = (ret * a) % p;
        a = (a * a) % p;
        b >>= 1;
    }
    return ret;
}
LL b[1010];
int main()
{
    Primelist();
    LL n,sov=1;
    scanf("%lld",&n);
    int flag=0;
    while(1)
    {
        if(prime[flag]<=n)
        {
           flag++;
        }
        else
        {
            break;
        }
    }
    for(int i=1; i<flag; i++)
    {
        LL sum=0;
        for(int j=1; j<=n; j++)
        {
            if(pow_mod(prime[i],j,Mod)<=n)
            {
                sum+=(n/pow_mod(prime[i],j,Mod));
            }
            else
            {
                break;
            }
        }
        sov=(sov*(sum+1))%Mod;
    }
    printf("%lld\n",sov);
    return 0;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
K = int(input())
RUN = {
    0:[0, 1],
    1:[0, 1, 2],
    2:[1, 2, 3],
    3:[2, 3, 4],
    4:[3, 4, 5],
    5:[4, 5, 6],
    6:[5, 6, 7],
    7:[6, 7, 8],
    8:[7, 8, 9],
    9:[8, 9]
}
cnt = 0
for i10 in range(10):
    ans10 = i10 * 10 ** 9
    if ans10 == 0:
        i9s = range(10)
    else:
        i9s = RUN[i10]
    for i9 in i9s:
        ans9 = ans10 + i9 * 10 ** 8
        if ans9 == 0:
            i8s = range(10)
        else:
            i8s = RUN[i9]
        for i8 in i8s:
            ans8 = ans9 + i8 * 10 ** 7
            if ans8 == 0:
                i7s = range(10)
            else:
                i7s = RUN[i8]
            for i7 in i7s:
                ans7 = ans8 + i7 * 10 ** 6
                if ans7 == 0:
                    i6s = range(10)
                else:
                    i6s = RUN[i7]
                for i6 in i6s:
                    ans6 = ans7 + i6 * 10 ** 5
                    if ans6 == 0:
                        i5s = range(10)
                    else:
                        i5s = RUN[i6]
                    for i5 in i5s:
                        ans5 = ans6 + i5 * 10 ** 4
                        if ans5 == 0:
                            i4s = range(10)
                        else:
                            i4s = RUN[i5]
                        for i4 in i4s:
                            ans4 = ans5 + i4 * 10 ** 3
                            if ans4 == 0:
                                i3s = range(10)
                            else:
                                i3s = RUN[i4]
                            for i3 in i3s:
                                ans3 = ans4 + i3 * 10 ** 2
                                if ans3 == 0:
                                    i2s = range(10)
                                else:
                                    i2s = RUN[i3]
                                for i2 in i2s:
                                    ans2 = ans3 + i2 * 10
                                    if ans2 == 0:
                                        i1s = range(1, 10)
                                    else:
                                        i1s = RUN[i2]
                                    for i1 in i1s:
                                        ans1 = ans2 + i1
                                        cnt += 1
                                        # print(cnt, ans1)
                                        if cnt == K:
                                            print(ans1)
                                            exit()



Measured memory_bytes: 3192
#include <queue>
#include <string>
#include <vector>
#include <iostream>
#pragma warning(disable : 4996)
using namespace std;

// ------ Class ------ //
class Graph2 {
public:
	// ------ Variables ------ //
	static const long long INF = 1000000000000000000;
	int V, E; vector<vector<pair<int, long long> > > G;

	// ------ Constructors ------ //
	Graph2() : V(0), E(0), G(vector<vector<pair<int, long long> > >()) {}
	Graph2(int v) : V(v), E(0), G(vector<vector<pair<int, long long> > >(v)) {}
	Graph2(vector<vector<pair<int, long long> > > g) : V(g.size()), G(g) { for (int i = 0; i < g.size(); i++) E += g[i].size(); }

	// ------ Basic Functions ------ //
	int size() { return V; }
	void add1(int v1, int v2, long long w) { G[v1].push_back(make_pair(v2, w)); E++; }
	void add2(int v1, int v2, long long w) { add1(v1, v2, w); add1(v2, v1, w); }

	// ------ Operators ------ //
	friend bool operator==(const Graph2& g1, const Graph2& g2) { return g1.G == g2.G; }
	friend bool operator!=(const Graph2& g1, const Graph2& g2) { return g1.G != g2.G; }
	vector<pair<int, long long> > operator[](int x) { return G[x]; }

	// ------ Algorithms ------ //
	long long minspan() {
		vector<long long> d(V, INF);
		vector<bool> used(V, false);
		priority_queue<pair<long long, int> > que;
		for (int i = 0; i < V; i++) d[i] = INF;
		d[0] = 0; que.push(make_pair(0, 0));
		while (!que.empty()) {
			pair<long long, int> pa = que.top(); que.pop();
			int u = pa.second; used[u] = true;
			for (int i = 0; i < G[u].size(); i++) {
				int v = G[u][i].first;
				if (d[v] > G[u][i].second && !used[v]) {
					d[v] = G[u][i].second; que.push(make_pair(-d[v], v));
				}
			}
		}
		long long sum = 0;
		for (int i = 0; i < V; i++) sum += d[i];
		return sum;
	}
};

// ------ Main ------ //
int V, E, s, t, w;
int main() {
	scanf("%d%d", &V, &E);
	Graph2 G(V);
	for (int i = 0; i < E; i++) {
		scanf("%d%d%d", &s, &t, &w);
		G.add2(s, t, w);
	}
	printf("%d\n", G.minspan());
	return 0;
}

Measured memory_bytes: 8892
#include <cstdio>
#define SWAP(a,b) {a+=b,b=a-b,a-=b;}

using namespace std;

int W[30];

int main()
{
	int w,n,ai,bi;
	scanf("%d",&w);
	for(int i=0;i<w;++i) W[i]=i+1;
	scanf("%d",&n);
	for(int i=0;i<n;++i) {
		scanf("%d,%d",&ai,&bi);
		SWAP(W[ai-1],W[bi-1]);
	}
	for(int i=0;i<w;++i) { printf("%d\n",W[i]); }
	return 0;
}

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

using namespace std;

int main(void){
    int n, k;
    cin >> n >>k;
    long double ans = 0;
    for(int i = 1; i <= n; i++){
        long double now = i;
        long double score = 1;
        for(int j = 1; now < k; j++){
            now *= 2;
            score /= 2;
        }
        ans += score;
    }
    cout << fixed << setprecision(10) << ans / n << endl;
    return 0;
}

Measured memory_bytes: 256
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;
constexpr int M = 1'000'000'007;

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

    auto whole = 1LL;
    for (int i = 0; i < n; ++i) {
        whole *= 10;
        whole %= M;
    }
    auto no09 = 1LL;
    for (int i = 0; i < n; ++i) {
        no09 *= 8;
        no09 %= M;
    }
    auto no0 = 1LL;
    for (int i = 0; i < n; ++i) {
        no0 *= 9;
        no0 %= M;
    }
    auto no9 = no0;

    auto x = whole - (no0 + no9 - no09);
    while (x < 0)
        x += M;

    cout << x << endl;
    return 0;
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
int INF = numeric_limits<int>::max() / 2;
using ll = long long;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a1, a2, a3;
	cin >> a1 >> a2 >> a3;
	int a12 = abs(a1 - a2);
	int a13 = abs(a1 - a3);
	int a23 = abs(a2 - a3);
	cout << a12 + a13 + a23 - max(a23, max(a12, a13)) << endl;
	return 0;
}

Measured memory_bytes: 256