akhauriyash/Code-Regression huggingface dataset:
import itertools

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

ans1 = []
ans2 = []
for i in itertools.permutations(p):
    ans1.append(i)
for i in itertools.permutations(q):
    ans2.append(i)   
    
ans1 = sorted(ans1)
ans2 = sorted(ans2)

p = tuple(p)
q = tuple(q)

for i in range(len(ans1)):
    if ans1[i] == p:
        break
for j in range(len(ans2)):
    if ans2[j] == q:
        break

print(abs(i - j))

Measured memory_bytes: 50320
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    void sample(){
        ll sum=0;
        for(ll a=1;a<=10;a++){
            sum=sum^a;
            DEBUG2(a,sum);
        }
    }
    ll xor0_n(ll n){
        ll m=n%4;
        if(m==0)return n;
        if(m==1)return 1;
        if(m==2)return n+1;
        if(m==3)return 0;
    }
    void solve(){
        ll A,B;
        cin>>A>>B;
        if(A==0)cout<<xor0_n(B);
        else cout<<(xor0_n(A-1)^xor0_n(B));
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

int main()
{
	ll n;
	cin >> n;
	ll ans = 0;
	for (ll a = 1; a <= n; a++) {
		for (ll b = 1; b <= (n + a - 1) / a; b++) {
			if (a * b < n) {
				ll c = n - a * b;
				ans++;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3668
#include<stdio.h>

int main()
{
    int A, B;

    scanf("%d", &A);
    scanf("%d", &B);

    if( (A%3==0) || (B%3==0) || ((A+B)%3==0) ){
        printf("Possible");
    }else{
        printf("Impossible");
    }

    return 0;
}

Measured memory_bytes: 128
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve() 
{
	//happy coding


	int n;
	cin>>n;
	string s;
	cin>>s;
	int cnt  = 0;
	for(int i=0;i<n-2;i++){
		string a = s.substr(i,3);
		if(a=="ABC")cnt++;
	}
	cout<<cnt<<endl;

	
	return 0;
}
int main(){
	int test = 1;
  	//scanf("%d", &test);
  	while (test--)solve();return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

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

	ll diff=0, minus_sum=0;
	vector<ll> vp;
	int ans=0;
	for(int i=0; i<n; i++) {
		diff+=a[i]-b[i];
		if(a[i]-b[i]>0) vp.push_back(a[i]-b[i]);
		if(a[i]-b[i]<0){
			minus_sum+=a[i]-b[i];
			ans++;
		}
	}
	if(diff<0){
		cout << -1 << endl;
		return 0;
	}else if(ans==0){
		cout << ans << endl;
		return 0;
	}

	sort(vp.begin(), vp.end(), greater<ll>());
	int i=1;
	for(; i<=vp.size(); i++){
		if(minus_sum+vp[i-1]<0){
			minus_sum+=vp[i-1];
			vp[i-1]=0;
		}else{
			vp[i-1]+=minus_sum;
			minus_sum=0;
			break;
		}
	}
	cout << ans+i << endl;
	return 0;
}

Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const int INF = 1 << 29;
const ll LINF = 1l << 61;
const ld PI = abs(acos(-1));
#define pq priotity_queue
#define P pair<int, int>
#define P2 pair<int, P>
#define P3 pair<int, P2>
#define fr(i, a, b) for (int i = a; i < b; i++)    //[a, b)
#define frr(i, a, b) for (int i = b; i >= a; i--)  //[a, b]
#define rp(i, b) for (int i = 0; i < b; i++)       //[0, b)
#define rrp(i, b) for (int i = b; i >= 0; i--)     //[0, b]
#define cbuf(buf, init) memset(buf, init, sizeof(buf))

int A[4], OP[3];

bool rep(int i)
{
    if (i == 3) {
        int s = A[0];
        rp(j, 3) { s += OP[j] * A[j + 1]; }
        return s == 7;
    }

    OP[i] = 1;
    if (rep(i + 1)) return true;
    OP[i] = -1;
    if (rep(i + 1)) return true;
    return false;
}

int main()
{
    //
    int N;
    cin >> N;
    rrp(i, 3)
    {
        A[i] = N % 10;
        N /= 10;
    }

    rep(0);
    cout << A[0];
    rp(i, 3) { cout << (OP[i] > 0 ? '+' : '-') << A[i + 1]; }
    cout << "=7" << endl;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[100005];

int main()
{
    int N;
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }

    ll min = INF;
    {
        //! 奇数をマイナス
        ll sum = 0;
        ll m = 0;
        REP(i, N)
        {
            sum += A[i];
            if (i % 2 == 0 && sum >= 0)
            {
                m += abs(sum) + 1;
                sum = -1;
            }
            else if (i % 2 == 1 && sum <= 0)
            {
                m += abs(sum) + 1;
                sum = 1;
            }
        }
        min = std::min(min, m);
    }
    {
        //! 奇数をプラス
        ll sum = 0;
        ll m = 0;
        REP(i, N)
        {
            sum += A[i];
            if (i % 2 == 1 && sum >= 0)
            {
                m += abs(sum) + 1;
                sum = -1;
            }
            else if (i % 2 == 0 && sum <= 0)
            {
                m += abs(sum) + 1;
                sum = 1;
            }
        }
        min = std::min(min, m);
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 1024
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define debug(aa, a) fprintf(stderr, aa, a)

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n;
	scanf("%d", &n);
	vector<vector<int>> count(26, vector<int>(n));
	string s;
	rep(i, n) {
		scans(s);
		for (auto aa : s) {
			++count[aa - 'a'][i];
		}
	}
	rep(i, 26) {
		sort(all(count[i]));
	}
	rep(i, 26) {
		rep(j, count[i][0]) {
			printf("%c", 'a' + i);
		}
	}
	printf("\n");

	Please AC;
}

Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll N,A,B; cin>>N>>A>>B;
    vector<ll>a(N);
    rep(i,N)cin>>a[i];
    ll ans =0;
    rep(i,N-1){
        if((a[i+1]-a[i])*A<B){
            ans+=(a[i+1]-a[i])*A;
        }
        else ans+=B;
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	double l;
	cin >> l;
	double x = l / 3;
	cout << setprecision(10) << fixed << x * x * x;
	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

struct UnionFindTree{
    vector<int>par,sz;
    UnionFindTree(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool areSame(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

int N,M;
int A[111111];

vint lis[111111];

signed main(){
    cin>>N>>M;
    rep(i,N)cin>>A[i];
    UnionFindTree uf(N);
    rep(i,M){
        int a,b;
        cin>>a>>b;
        uf.unite(a,b);
    }

    int K=N-M;
    if(K==1){
        cout<<0<<endl;
        return 0;
    }

    if(K*2-2>N){
        cout<<"Impossible"<<endl;
        return 0;
    }
    rep(i,N)lis[uf.find(i)].pb(A[i]);

    vint latte;
    int ans=0;
    rep(i,N){
        sort(all(lis[i]));
        if(lis[i].size()){
            ans+=lis[i][0];
            for(int j=1;j<lis[i].size();j++)latte.pb(lis[i][j]);
        }
    }

    sort(all(latte));
    rep(i,K-2)ans+=latte[i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 7928
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	
	int t,x,y;
	int oldt,oldx,oldy;
	
	oldt=oldx=oldy=0;
	
	bool flag=true;
	
	for(int i=0;i<n;i++)
	{
		scanf("%d%d%d",&t,&x,&y);
		
		if(flag)
		{
			int del=fabs(x-oldx)+fabs(y-oldy);
			int delt=t-oldt;
			
			if(del>delt||(delt-del)%2!=0)
			{
				flag=false;
			}
			
			oldt=t;
			oldx=x;
			oldy=y;
		}
	}
	
	if(flag)
		printf("Yes");
	else 
		printf("No");
	
	return 0;
}

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

using namespace std;
#define pii pair <int , int>
#define F first
#define S second
const int N = 1e5 + 5, inf = 1e9 + 1;
int A[N], B[N], par[N], C, n, m;
long long W[N], Sum;
vector <int> g[N];
priority_queue <pii, vector<pii>, greater<pii>> pq[N];

void init() {
    C = n;
    for (int v = 1; v <= n; v++) {
        par[v] = v, W[v] = B[v];
        while (!pq[v].empty()) pq[v].pop();
        for (int u : g[v]) pq[v].push({A[u] - B[u], u});
    }
}
int getpar(int v) {return par[v] = (par[v] == v ? v : getpar(par[v]));}
void Union(int u, int v) {
    u = getpar(u);
    if (u == v) return ;
    par[u] = v, W[v] += W[u], C--;
    if (pq[u].size() > pq[v].size()) swap(pq[u], pq[v]);
    while (!pq[u].empty()) pq[v].push(pq[u].top()), pq[u].pop();
}
bool check(int w) {
    init();
    for (int v = 1; v <= n; v++) if (par[v] == v && w + W[v] >= A[v]) {
        while (!pq[v].empty()) {
            int u = pq[v].top().S;
            if (A[u] - B[u] > W[v] + w) break ;
            pq[v].pop(), Union(u, v);
        }
    }
    return C == 1;
}
int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> A[i] >> B[i], Sum += B[i];
    if (n == 1) return cout << max(A[1], B[1]) << "\n", 0;
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v;
        g[u].push_back(v), g[v].push_back(u);
    }
    int dw = -1, up = inf;
    while (up - dw > 1) {
        int md = (up+dw)>>1;
        if (check(md)) up = md;
        else dw = md;
    }
    cout << Sum + up << "\n";


    return 0;
}


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

int main() {
	int n;
	cin >> n;
	int *d = new int[n];
	for (int a = 0; a < n; ++a) {
		cin >> d[a];
	}
	int put;
	for (int i = 0; i < n; i++) {
		for (int j = n - 1; j>i; j--) {
			if (d[j] < d[j - 1]) {
				put = d[j];
				d[j] = d[j - 1];
				d[j - 1] = put;
			}
		}
	}
	int judge = d[0];
	int count = 1;
	for (int k = 0; k < n; ++k) {
		if (judge!=d[k]) {
			judge = d[k];
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
d = input().split()

a = int(d[0])
b = int(d[1])
c = int(d[2])

e = 0

e = a*10+b+c

if e < b*10+a+c:
    e = b*10+a+c
    if e < c*10+a+b:
        e = c*10+a+b

if e < c*10+a+b:
    e= c*10+a+b
    if e < b*10+a+c:
        e = b*10+a+c

print(e)


Measured memory_bytes: 3064
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>
#include <string.h>
#include <cctype>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

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

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

bool comp(int i, int j) {
	return i > j;
}

vector<int> d[200000];
long num[200000];

int main()
{
	int n;
	cin >> n;
	for (int i = 2; i <= n; i++)
	{
		int tmp;
		cin >> tmp;
		d[tmp - 1].push_back(i - 1);
	}

	for (int i = 0; i < n; i++)
	{
		cout << d[i].size() << endl;
	}
}


Measured memory_bytes: 45500
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,x,y;
  cin >> n >> x >> y;
  n-=x;
  ll d=x-y;
  if(n<=0) {
    pr(1);
    return;
  }
  if(d<=0) {
    pr(-1);
    return;
  }
  pr((ll)ceil((long double)n/d)*2+1);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 764
INF = float("inf")


def main():
    N, W = map(int, input().split())

    # dp[0..N][value]: weight
    dp = [[INF for i in range(1000 * 100 + 1)] for _ in range(N + 1)]
    dp[0][0] = 0

    for n in range(N):
        weight, value = map(int, input().split())

        for v in range(1000 * 100 + 1):
            if value <= v:
                dp[n + 1][v] = min(dp[n][v - value] + weight, dp[n][v])
            else:
                dp[n + 1][v] = dp[n][v]

    for v in range(1000 * 100, -1, -1):
        if dp[N][v] <= W:
            print(v)
            break


main()


Measured memory_bytes: 311736
#include <iostream>
typedef long long ll;
using namespace std;

ll gcd(ll, ll);
ll lcm(ll, ll);
int main(void) {
    ll A,B;
    cin>>A>>B;
    cout << lcm(A, B) << endl;
    return 0;
}

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

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

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

#include <cassert>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define FOR(i,a,b) for(ll i=(a); i < (b); i++)
#define RFOR(i,a,b) for(ll i=(b)-1; i >= (a); i--)
#define rep(i,n) FOR(i,0,(n))
#define rrep(i,n) RFOR(i,0,(n))

int main() {
	ll N, K;
	cin >> N >> K;
	ll res = 0;
	if(K == 0) {
		res = N*N;
	}
	else {
		for(ll b = K+1; b <= N; b++) {
			res += (N/b)*(b-K) + max(N%b-(K-1), 0ll);
		}
	}
	cout << res << endl;
	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;

void solve(){
	ll n,m;
	cin>>n>>m;
	vll cnt(n,0);
	for(int i=0;i<m;i++){
		ll u,v;cin>>u>>v;u--,v--;cnt[u]++,cnt[v]++;
	}
	for(auto i: cnt) cout<<i<<'\n';

}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	//ll t;cin>>t;while(t--)
	solve();

}


Measured memory_bytes: 256
#include <stdio.h>
 
void DICE(char x, int *dice1, int *dice2, int *dice3, int *dice4, int *dice5, int *dice6){
    int tmp1, tmp2, tmp3, tmp4;
    if(x=='S'){
        tmp1=*dice1;
        tmp2=*dice2;
        tmp3=*dice5;
        tmp4=*dice6;
        *dice1=tmp3;
        *dice2=tmp1;
        *dice5=tmp4;
        *dice6=tmp2;
    }
        else if(x=='W'){
        tmp1=*dice1;
        tmp2=*dice3;
        tmp3=*dice4;
        tmp4=*dice6;
        *dice1=tmp2;
        *dice3=tmp4;
        *dice4=tmp1;
        *dice6=tmp3;
    }
    else if(x=='N'){
        tmp1=*dice1;
        tmp2=*dice2;
        tmp3=*dice5;
        tmp4=*dice6;
        *dice1=tmp2;
        *dice2=tmp4;
        *dice5=tmp1;
        *dice6=tmp3;
    }
    else if(x=='E'){
        tmp1=*dice1;
        tmp2=*dice3;
        tmp3=*dice4;
        tmp4=*dice6;
        *dice1=tmp3;
        *dice3=tmp1;
        *dice4=tmp4;
        *dice6=tmp2;
    }
}
 
 
int main(void){
     
    int dice1, dice2, dice3, dice4, dice5, dice6, i;
    int d1, d2, d3, d4, d5, d6;
     
    scanf("%d %d %d %d %d %d\n%d %d %d %d %d %d", &dice1, &dice2, &dice3, &dice4, &dice5, &dice6, &d1, &d2, &d3, &d4, &d5, &d6);
     
    if(d2!=dice2){
        for(i=1; i<=6; i++){
                DICE('N', &dice1, &dice2, &dice3, &dice4, &dice5, &dice6);
                if(d2==dice2) break;
        }
        if(d2!=dice2){
            DICE('E', &dice1, &dice2, &dice3, &dice4, &dice5, &dice6);
            for(i=1; i<=6; i++){
                DICE('N', &dice1, &dice2, &dice3, &dice4, &dice5, &dice6);
                if(d2==dice2) break;
            }
        }
    }
         
    if(d1!=dice1){
        for(i=1; i<=6; i++){
            DICE('E', &dice1, &dice2, &dice3, &dice4, &dice5, &dice6);
            if(d1==dice1) break;
        }
    }
         
    if(d3==dice3 && d4==dice4 && d5==dice5 && d6==dice6) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N;cin>>N;
    vector<ll> a(N);
    REP(i,N)cin>>a[i];
    vector<ll> b(N);
    b[0]=a[0];
    FOR(i,1,N)b[i]=b[i-1]+a[i];
    sort(all(b));
    b.push_back(INF);
    ll res=0;
    ll cnt=1;
    REP(i,N){
        if(b[i+1]!=b[i]){
          if(b[i]==0)res+=cnt;
            res+=cnt*(cnt-1)/2;
            cnt=1;
        }else{
            cnt++;
        }
    }
    cout<<res<<endl;
    return 0;
}

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

namespace ABC172B
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            int count = 0;
            for(int i = 0; i < S.Length; i++)
            {
                if (S[i] != T[i])
                {
                    count += 1;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27524
// A - Sorted Arrays

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

const int UNCONF = 0;
const int INC = 1;
const int DEC = 2;

int A[100000];

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

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

	int cnt = 1;
	int state = UNCONF;
	for (int i=0; i<N-1; i++) {
		if (state == UNCONF) {
			if (A[i] < A[i+1]) state = INC;
			if (A[i] > A[i+1]) state = DEC;
		} else if (state == INC && A[i] > A[i+1]) {
			cnt++;
			state = UNCONF;
		} else if (state == DEC && A[i] < A[i+1]) {
			cnt++;
			state = UNCONF;
		}
	}

	int ans = cnt;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	int n=s.size(),m=t.size();
	rep(q,n-m+1){
		int i=n-m-q;
		bool ok=true;
		rep(j,m){
			if(s[i+j]=='?' or s[i+j]==t[j]) continue;
			ok=false;
		}
		if(ok){
			rep(j,m){
				s[i+j]=t[j];
			}
			rep(i,n)if(s[i]=='?')s[i]='a';
			puta(s);
			return 0;
		}
	}
	puta("UNRESTORABLE");
	return 0;
}

Measured memory_bytes: 256
N, D = map(int, input().split())
if N//2 <= D:
    print(1)
else:
    cnt = 0
    i = 1
    j = 1
    while i <= N:
    #     print(i)
        if i != 1 and (i-j) % D == 0:
            cnt += 1
            j += 1
    #         print(cnt)
            if ((i + D) < N) and ((i + 2*D) > N):
    #             print(cnt)
                cnt += 1
                break
            else:
                i += 2*D
        i += 1

    print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	string s;
	cin >> s;

	vector<vector<int>> numpos(10, vector<int>());
	for (int i = 0; i < n; i++) {
		numpos[s[i] - '0'].emplace_back(i);
	}

	int ans = 0;
	for (int i = 0; i <= 9; i++) {
		for (int k = 0; k <= 9; k++) {
			if (numpos[i].empty() || numpos[k].empty()) {
				continue;
			}

			int x = numpos[i].front();
			int z = numpos[k].back();
			if (x >= z) {
				continue;
			}

			for (int j = 0; j <= 9; j++) {
				auto it = upper_bound(numpos[j].begin(), numpos[j].end(), x);

				if (it == numpos[j].end()) {
					continue;
				}

				int y = *it;
				if (y < z) {
					ans++;
					// printf("find %d %d %d, %d %d\n", i, j, k, y, z);
				}
			}
		}
	}

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


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
long long aa;bool bb;char ch;
long long scan()
{
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	ch=='-'?(bb=1,aa=0):(bb=0,aa=ch-48);
	while(ch=getchar(),(ch>='0'&&ch<='9'))
		aa=aa*10+ch-48;
	return (bb?(-aa):(aa));
}
long long N,A,B,tmp;
long long h[100010];
bool check(long long mid)
{
	tmp=0;
	for(int i=1;i<=N;++i)
	{
		if(h[i]<=B*mid)
			continue;
		tmp+=(h[i]-B*mid)/A;
		if((h[i]-B*mid)%A!=0)
			++tmp;
		if(tmp>mid)
			return 0;
	}
	return 1;
}
int main()
{
	long long L,R,mid;
	scanf("%d%lld%lld",&N,&A,&B);
	A-=B;
	for(int i=1;i<=N;++i)
	{
		scanf("%lld",&h[i]);
	}
	L=1;R=1000000000;
	while(L<R)
	{
		//cout<<L<<" "<<R<<endl;
		mid=(L+R)/2;
		if(check(mid))
			R=mid;
		else
			L=mid+1;
		//cout<<L<<" "<<R<<endl;
	}
	cout<<L<<endl;
}

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

int main(){
    int p, q, r;
    cin >> p >> q >> r;

    int ans;

    if (p < q) {
        if(q < r) ans = p + q;
        else ans = p + r;
    }
    else if (p < r) ans = p + q;
    else ans = q + r;

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
import sys

s = input()
n = 3

for i in range(2**(n)):
	op = ["-"]*3
	for j in range(n):
		if i & (1<<j):
			op[j] = "+"

	res = ""
	for a,b in zip(s,op+[""]):
		res += a+b
	if eval(res) == 7:
		print(res+'=7')
		sys.exit()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
/* clang-format off */
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  ll x, m = 100, ans = -1;
  cin >> x;
  for (int i = 1;; i++) {
    m *= 1.01;
    if (m >= x) {
      ans = i;
      break;
    }
  }

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


Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
//#include <bits/stdc++.h>
#define pb push_back
#define FOR(x,st,n) for(int x = (st); x < (n); ++ x)

using namespace std;


typedef long long unsigned ll;
typedef pair<int,int> P;
//typedef vector<P> vp;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int N = 1e3+1;
//int n,m,k,q;

const int MOD = 1e9+7;
int main(){


    ll n,m,ret=0;
    cin>>n>>m;
    

    if(m/2 <= n){
        ret+=m/2;
    }else{
        ret+=n;
        m-=2*n;
        ret+=m/4;
    }

    cout<<ret<<endl;


    return 0;
}


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

using namespace std;

/**templates**/
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;

#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sull(x) scanf("%llu",&x)
#define sf(x) scanf("%lf",&x)
#define ss(x) scanf(" %s",x)
#define sc(x) scanf(" %c",&x)
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define aa first
#define bb second
#define sz(x) (ll)(x).size()
#define cas printf("Case %lld: ",++t)
#define casline printf("Case %lld:\n",++t)
//#define cas cout<<"Case "<<++t<<": "
//#define casline cout<<"Case "<<++t<<":"<<endl;
#define distance(x1,y1,x2,y2)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
#define endl "\n"
#define bug cout<<"bugggggggggggg "<<endl;
#define fast ios_base::sync_with_stdio(0);cin.tie(nullptr); ///no printf/scanf
#define clean fflush(stdout)

const ll mod = 1000000007;
const ll inf = 1LL<<62;
const ll mx = 100005;
const double eps = 1e-10;

ll dx[10]={1,0,-1,0};
ll dy[10]={0,-1,0,1};

ll power(ll a,ll b)
{
    if(b==0)return 1;
    ll x=power(a,b/2);
    x=x*x;
    if(b%2)x=x*a;
    return x;
}

ll bigmod(ll a,ll b)
{
    if(b==0)return 1;
    ll x=bigmod(a,b/2)%mod;
    x=(x*x)%mod;
    if(b%2)x=(x*a)%mod;
    return x;
}


ll Set(ll N,ll pos){return N=N | (1LL<<pos);}
ll reset(ll N,ll pos){return N= N & ~(1LL<<pos);}
bool check(ll N,ll pos){return (bool)(N & (1LL<<pos));}

/**
double cosine_rule(double a,double b,double c)
{
    double res=(a*a+b*b-c*c)/(2*a*b);
    res=acos(res);
    return res;
}
*/

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    fast; ///no printf/scanf
    /** Use "long double"(%Lf) instead of double for precision safety*/
    ll tst,a,b,c,k,n,m,res=0,ans=0,t=0;
    sl(n);
    a=1;
    while(n)
    {
        res+=a;
        a=a<<1;
        n/=2;
    }
    cout<<res<<endl;



    return 0;
}


Measured memory_bytes: 3764
N = int(input())

#https://img.atcoder.jp/abc178/editorial-E-phcdiydzyqa.pdf

z_list = list()
w_list = list()

for i in range(N):
    x,y = map(int, input().split())
    z_list.append(x + y)
    w_list.append(x - y)
    
print(max(max(z_list)-min(z_list),max(w_list)-min(w_list)))

Measured memory_bytes: 24776
#include <stdio.h>

int main(void) {
	int N;
	scanf("%d",&N);
	double a[N+1];
	for(int i=0;i<N;i++) scanf("%lf",&a[i+1]);
	double dp[N+1][N+1];
	
	for(int i=0;i<=N;i++) for(int j=0;j<=N;j++)dp[i][j] = 0;
	dp[0][0] = 1;
	for(int i=1;i<=N;i++) dp[i][0] = dp[i-1][0]*(1-a[i]);
	
	for(int i=1;i<=N;i++){
		for(int j=1;j<=i;j++){
			dp[i][j] = dp[i-1][j-1]*a[i] + dp[i-1][j]*(1-a[i]);
		}
	}
	
	double sum=0;
	for(int i=(N/2)+1;i<=N;i++) sum += dp[N][i];
	
	printf("%.10f",sum);
	
	/*for(int i=0;i<=N;i++){
		for(int j=0;j<=N;j++){
			printf("%f ",dp[i][j]);
		}
		printf("\n");
	}*/
	
	return 0;
}

Measured memory_bytes: 70528
import java.util.Scanner;

public class Main {

  static Scanner sc = new Scanner(System.in);


  public static void main(String[] args) {
    String a = sc.next();
    if(a.contains("a")&&a.contains("b")&&a.contains("c")){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23892
x = int(input())

U = 10**9

divisors = set()
for i in range(1, int(U**.5)+1):
    if x % i == 0:
        divisors |= {i, x//i}

def f(a, b):
    return a**5-b**5

for b in range(-1000, 1000):
    for div in divisors:
        a = div+b
        if f(a, b) == x:
            print(a, b)
            exit()

Measured memory_bytes: 9392
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();
        int[] l=new int[n];
        for (int i=0;i<n;i++)l[i]=sc.nextInt();
        int ans=Integer.MAX_VALUE;
        for (int i = 0; i < (1 << n); i++) {
            for (int j = 0; j < (1 << n); j++) {
                int la=0,lb=0,lc=0,mp=0;
                //11→aの材料、10→bの材料、01→cの材料、00→何もしない
                for (int k = 0; k < n; k++) {
                    int bit1=(i>>k)&1;
                    int bit2=(j>>k)&1;
                    if(bit1==1&&bit2==1){
                        if(la>0)mp+=10;
                        la+=l[k];
                    }else if(bit1==1&&bit2==0){
                        if(lb>0)mp+=10;
                        lb+=l[k];
                    }else if(bit1==0&&bit2==1){
                        if(lc>0)mp+=10;
                        lc+=l[k];
                    }
                }
                if(la>0&&lb>0&&lc>0){
                    ans=min(ans,mp+abs(a-la)+abs(b-lb)+abs(c-lc));
                }
            }
        }
        out.println(ans);
    }
}

Measured memory_bytes: 22992
//abc092_b.cpp
//Sun Mar 25 21:05:46 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;

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

	int a[n];
	int ans;

	for (int i=0;i<n;i++){
		cin >> a[i];
		ans = ((d-1)/a[i])+1 + ans;
	}

	cout << ans +x<< endl;
}

Measured memory_bytes: 888
import sys
def Ii():return int(sys.stdin.readline())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))

n = Ii()
a = Li()
sa = sum(a)
af = [0]*(10**5+1)
for i in a: 
  af[i]+=1
q = Ii()
for i in range(q):
  b,c = Mi()
  sa = sa + (c-b)*af[b]
  af[c] += af[b]
  af[b] = 0;
  print(sa)

Measured memory_bytes: 20124
N = int(input())
S = []
for n in range(N):
    s = input()
    S.append(s)

word_count = {}

for index in range(len(S)):
    word = S[index]
    if word in word_count:
        word_count[word] = word_count[word] + 1
    else:
        word_count[word] = 1

max = 0
for key in word_count.keys():
    count = word_count[key]
    if count > max:
        max = count

max_words = []
for key in word_count.keys():
    count = word_count[key]
    if count == max:
        max_words.append(key)

max_words.sort()
for word in max_words:
    print(word)


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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
// inline void CIN() {}
// template <class Head, class... Tail>
// inline void CIN(Head &&head, Tail &&... tail) {
//     cin >> head;
//     CIN(move(tail)...);
// }
// CIN(__VA_ARGS__)
// CIN(__VA_ARGS__)
// CIN(__VA_ARGS__)
// #define Yes(a) cout << (a ? "Yes" : "No") << "\n"
// #define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
// typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

ll d, n, m;
VL ds, ks;
map<string, int> dic;

int main() {
    while(true) {
        cin >> d;
        if(d == 0) return 0;
        cin >> n >> m;
        ds.resize(n);
        ks.resize(m);
        ds[0] = 0;
        REP(i, n - 1) cin >> ds[i + 1];
        sort(All(ds));
        VECCIN(ks);
        ll sum = 0;
        REP(i, m) {
            ll ans = 0;
            int idx = distance(ds.begin(), upper_bound(All(ds), ks[i]));
            if(idx != n) {
                ans = min(abs(ds[idx - 1] - ks[i]), abs(ds[idx] - ks[i]));
            } else {
                ans = min(abs(ds[idx - 1] - ks[i]), abs(d - ks[i]));
            }
            sum += ans;
        }
        cout << sum << "\n";
    }
}



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

void peach_apple( string& str )
{
    string peach = "peach";
    string apple = "apple";

    for( int j = 0; j < str.size(); j++ )
    {
        int k1 = j, k2 = j, s1 = 0, s2 = 0;
        for( int i = 0; i < 5; i++ )
        {
            if( peach[i] == str[k1] )
            {
                k1++;
                s1++;
                if( s1 == 5 )
                {
                    str[k1-1] = 'e'; str[k1-2] = 'l'; str[k1-3] = 'p'; 
                    str[k1-4] = 'p'; str[k1-5] = 'a';
                    break;
                }
            }
            if( apple[i] == str[k2] )
            {
                k2++;
                s2++;
                if( s2 == 5 )
                {
                    str[k2-1] = 'h'; str[k2-2] = 'c'; str[k2-3] = 'a'; 
                    str[k2-4] = 'e'; str[k2-5] = 'p';
                    break;
                }
            }
        }
    }
}

int main()
{
    string str;

    getline( cin , str );
    peach_apple( str );
    cout << str << endl;

    return 0;
}


Measured memory_bytes: 3176
//35
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;

struct S{
  vector<int> v;
  int t;
};

int main(){
  for(;;){
    vector<int> v(13);
    cin>>v[2]>>v[1]>>v[4]>>v[7]>>v[0]>>v[3]>>v[6]>>v[9]>>v[12]>>v[5]>>v[8]>>v[11]>>v[10];
    if(v[2]==-1)return 0;
    queue<S> que;
    S is={v,0};
    que.push(is);
    set<vector<int> > p;
    while(!que.empty()&&que.front().t<=20){
      S  c=que.front();
      int g[]={4,1,0,5,2,9,6,3,10,7,0,11,8};
      if(c.v==vector<int>(g,g+13))break;
      que.pop();
      if(p.count(c.v))continue;
      int nr=0;
      for(int i=0;i<13;i++){
	nr+=g[i]&&c.v[i]==g[i];
      }
      if(20-c.t<11-nr)continue;
      p.insert(c.v);
      for(int i=0;i<13;i++){
	if(c.v[i]==0){
	  for(int j=0;j<4;j++){
	    static int d[]={-2,3,2,-3};
	    static int b[][5]={{0,1,2,7,12},{2,7,12,11,10},{12,11,10,5,0},{10,5,0,1,2}};
	    int k;
	    for(k=0;k<5;k++){
	      if(i==b[j][k])break;
	    }
	    if(k==5){
	      vector<int> n=c.v;
	      swap(n[i],n[i+d[j]]);
	      S ns={n,c.t+1};
	      if(!p.count(n)){
		que.push(ns);
	      }
	    }
	  }
	}
      }
    }
    if(que.empty()||que.front().t>20){
      cout<<"NA"<<endl;
    }else{
      cout<<que.front().t<<endl;
    }
  }
  return 0;
}

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

int main() {
  int S, H = 60 * 60, M = 60;
  cin >> S;
  int s = S;
  int h = floor(s / H);
  s = s % H;
  int m = floor(s / M);
  s = s % M;
  printf("%d:%d:%d\n", h, m, s);
}


Measured memory_bytes: 3160
n = int(input())
def lookfor(n):
  m4 = n//4+1
  m7 = n//7+1
  for i4 in range(m4):
    for i7 in range(m7):
      total = 4*i4 + 7*i7
      
      if total == n:
        print('Yes')
        return
      elif total > n:
        break  
  print('No')
  return

lookfor(n)

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

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> f(h);
    rep(i,h) cin >> f[i];
    int c[10][1005];
    int ans = 1e9;
    rep(div,1<<(h-1)) {
        vector<int> id(h);
        int g = 0;
        rep(i,h) {
            id[i] = g;
            if (div >> i & 1) g++;
        }
        g++;
        rep(i,h)rep(j,w) c[i][j] = 0;
        rep(i,h)rep(j,w) c[id[i]][j] += f[i][j] - '0';
        bool ok_ = true; 
        rep(i,g)rep(j,w) if (c[i][j] > k) ok_ = false;
        if (!ok_) continue;
        vector<int> now(g);
        int num = g-1;
        rep(j,w) {
            rep(i,g){
                now[i] += c[i][j];
            }
            bool ok = true;
            rep(i,g) {
                if (now[i] > k) ok = false;
            }
            if (!ok) {
                num++;
                now = vector<int>(g);
                rep(i,g) now[i] += c[i][j];
            }
        }
        ans = min(ans,num);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# coding: utf-8
import sys


def main(argv=sys.argv):

    answers = ['1', '2', '3']

    a = input()

    answers.remove(a)

    b = input()

    answers.remove(b)

    print(answers[0])

    return 0


if __name__ == '__main__':
    sys.exit(main())


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<char> s(n);
  for(int i=0;i<n;i++) cin >> s[i];

  bool m = false;
  for(int i=0;i<n;i++){
    if(s[i] == 'Y') m = true;
  }

  if(m) cout << "Four" << endl;
  else cout << "Three" << endl;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;

int main()
{
    int A, B;
    cin >> A >> B;

    if (A > B)
    {
        int c = A;
        A = B;
        B = c;
    }

    if ((B + A) % 2 == 0)
    {
        OP((B + A) / 2)
    }
    else
    {
        OP("IMPOSSIBLE")
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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() {
    int S, W;
    cin >> S >> W;
    if (W >= S) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
    return 0;
}


Measured memory_bytes: 3572
from collections import Counter


def main():
    H, W, M = list(map(int, input().split()))
    bombs = [list(map(int, input().split())) for _ in range(M)]
    counter_row = Counter([h for h, _ in bombs])
    val_max_row, max_rows = 0, []
    for h, v in counter_row.items():
        if val_max_row < v:
            val_max_row = v
            max_rows = [h]
        elif val_max_row == v:
            max_rows.append(h)
    counter_col = Counter([w for _, w in bombs])
    val_max_col, max_cols = 0, []
    for w, v in counter_col.items():
        if val_max_col < v:
            val_max_col = v
            max_cols = [w]
        elif val_max_col == v:
            max_cols.append(w)
    # 基本的には val_max_row + val_max_col が答え。
    # 行・列で重複カウントになるケースだった場合はここから1引かないといけない。
    max_rows = Counter(max_rows)
    max_cols = Counter(max_cols)
    n_max_cells = len(max_rows.keys()) * len(max_cols.keys())
    n_cells = 0
    for h, w in bombs:
        if max_rows[h] > 0 and max_cols[w] > 0:
            n_cells += 1
    ans = val_max_row + val_max_col
    if n_cells >= n_max_cells:
        ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 119712
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<int, int>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const int MOD = 1000000007;

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

  int n;
  cin >> n;
  vector<ll> x(n), y(n), h(n);
  REP(i, n) cin >> x[i] >> y[i] >> h[i];

  if(h[0] == 0) {
    FOR(i, 1, n) {
      if(h[i] != 0) {
        swap(x[0], x[i]);
        swap(y[0], y[i]);
        swap(h[0], h[i]);
        break;
      }
    }
  }

  REP(cx, 101) REP(cy, 101) {
    ll height = h[0]+abs(cx-x[0])+abs(cy-y[0]);
    FOR(i, 1, n) {
      ll tmp = h[i]+abs(cx-x[i])+abs(cy-y[i]);
      if(h[i] == 0) {
        if(tmp < height) {
          height = -1;
          break;
        }
      } else {
        if(height != tmp) {
          height = -1;
          break;
        }
      }
    }
    if(height != -1) {
      cout << cx << " " << cy << " " << height << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256