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

#define for_(i,a,b) for(int i=a;i<b;++i)

int N;

int main() {
	while (scanf("%d", &N), N) {		
		int ans = 1, f = 0;
		
		for_(i,0,N) {
			int k; scanf("%d", &k);
			if (k) ++ans;
			if (k > 1) f = 1;
		}
		
		if (f) printf("%d\n", ans);
		else printf("NA\n");
	}
	
	return 0;
}

Measured memory_bytes: 1196
def sumC(x):
  s = x%10
  s1 = (x-s)/10 %10
  s2 = (x-s-s1*10)/100 %10
  s3 = (x-s-s1*10-s2*100)/1000 %10
  s4 = (x-s-s1*10-s2*100-s3*1000)/10000 %10
  return(int(s+s1+s2+s3+s4))
  
n,a,b = map(int,input().split())
ans = 0
for i in range(1,n+1):
  if a<= sumC(i) <= b:
    ans += i
print(ans) 

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int x, y, z, f, a, b;
  	cin>> x>> y;
    string a3[x];
    for (int i = 0; i< x; i++){
        cin >> a3[i];
    }
    for (int i= 1; i<= y+2; i++){
        cout << "#";
    }
    cout<<endl;
    for (int i = 0; i<x; i++){
        cout <<"#" << a3[i]<< "#";
        cout<<endl;
    }
    for (int i= 1; i<= y+2; i++){
        cout << "#";
    }
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (int i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<long long, long long>;
const int INF = 1001001007;
const int MOD = 1000000007;
template <typename T>
void printvec(vector<T> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main(){
    ll a, b, c; cin >> a >> b >> c;
    if (a==b && a==c && a%2==0) cout << -1 << endl;
    else{
        int cnt = 0;
        while (a%2==0&&b%2==0&&c%2==0){
            int na = (b+c) / 2;
            int nb = (c+a) / 2;
            int nc = (a+b) / 2;
            a = na; b = nb; c = nc;
            cnt++;
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX=200005;
ll val[3][MAX];
ll a[3][MAX],n,fin;
int main(){
    scanf("%lld",&n);
    for(ll j=0;j<3;j++) for(ll i=0;i<n;i++) scanf("%lld",&a[j][i]);
    sort(a[0],a[0]+n);
    sort(a[1],a[1]+n);
    sort(a[2],a[2]+n);
    for(ll i=0;i<n;i++) val[2][i]=1;
    for(ll j=1;j>=0;j--){
        ll p=n-1,q=n-1,s=0;
        for(p=n-1;p>=0;p--){
            for(;q>=0&&a[j+1][q]>a[j][p];s+=val[j+1][q--]);
            val[j][p]=s;
        }
    }
    for(ll i=0;i<n;i++) fin+=val[0][i];
    printf("%lld\n",fin);
}


Measured memory_bytes: 8064
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
S = input()

ans = 0

for bits in range(2**N):
  bs = []; rs = []
  for i in range(N):
    if ((1 << i) & bits) == 0:
      rs.append(S[i])
    else:
      bs.append(S[i])
  rs.reverse(); bs.reverse()

  lenr = len(rs); lenb = len(bs)
  dp = [[0] * (lenb + 1) for _ in range(lenr + 1)]
  dp[0][0] = 1
  for i in range(lenr + 1):
    for j in range(lenb + 1):
      if i < lenr and rs[i] == S[N+i+j]:
        dp[i+1][j] += dp[i][j]
      if j < lenb and bs[j] == S[N+i+j]:
        dp[i][j+1] += dp[i][j]
  ans += dp[-1][-1]

print(ans)

Measured memory_bytes: 53596
import sys

N = int(input())

D = []
for i in range(N):
    d1,d2 = map(int,input().split())
    D.append([d1,d2])


for i in range(0,N-2,1):
    if D[i][0] == D[i][1] and D[i+1][0] == D[i+1][1] and D[i+2][0] == D[i+2][1]:
        print("Yes")
        sys.exit()
else:
    print("No")

Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    cout << N * (N-1) / 2 << endl;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

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

ll solve3(vector<ll> a, vector<ll> b, ll n){

  ll ret = 0;
  for(ll i = 0; i <= n; i++){
    for(ll j = 0; i + j <= n; j++){
      ll k = n - (i+j);
      ll tmp = 0;
      tmp += i / a[0] * b[0] + i % a[0];
      tmp += j / a[1] * b[1] + j % a[1];
      tmp += k / a[2] * b[2] + k % a[2];
      chmax(ret, tmp);
    }
  }
  return ret;
}

ll solve2(vector<ll> a, vector<ll> b, ll n){

  ll ret = 0;
  for(ll i = 0; i <= n; i++){
    ll j = n - i;
    ll tmp = 0;
    tmp += i / a[0] * b[0] + i % a[0];
    tmp += j / a[1] * b[1] + j % a[1];
    chmax(ret, tmp);
  }

  return ret;
}



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

  ll n;
  cin >> n;

  vector<ll> a(3), b(3);

  rep(i, 3) cin >> a[i];
  rep(i, 3) cin >> b[i];

  int cnt = 0;

  rep(i, 3){
    if(a[i] < b[i]){
      cnt++;
    }
  }

  ll ans = 0;
  if(cnt == 0){
    ans = solve3(b, a, n);
  }
  if(cnt == 3){
    ans = solve3(a, b, n);
  }

  if(cnt == 1){
    vector<ll> a_, b_;
    rep(i, 3){
      if(a[i] >= b[i]){
        a_.push_back(b[i]);
        b_.push_back(a[i]);
      }else{
        n = n / a[i] * b[i] + n % a[i];
      }
    }
    ans = solve2(a_, b_, n);
  }

  if(cnt == 2){
    vector<ll> a_, b_;
    rep(i, 3){
      if(a[i] < b[i]){
        a_.push_back(a[i]);
        b_.push_back(b[i]);
      }
    }

    ans = solve2(a_, b_, n);

    // このあとやる
    rep(i, 3){
      if(a[i] > b[i]){
        ans = ans / b[i] * a[i] + ans % b[i];
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(LL i=(a);i<(LL)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define FF first
#define SS second
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef priority_queue<pr,Vpr> PQ;
const ut INF=1LL<<60;
const LL p=3+1e6;
const int SIZE=105;

LL solve(LL n,LL a){
	if(n==0) return a;

	LL c=1;
	LL ans=0;
	while(c<=n){
		c*=10;
		ans+=solve(n/c,n%c+a);
	}
	return ans;
}
int main(){
	LL n;
	cin >> n;
	cout << solve(n,0) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x,re;
    cin >> x;
    int ans=1;
    
    for(int i=2;i<=x;i++){
        int num = pow(i, 2);
        while(x>=num){
            if(ans<=num) ans = num;
            num*=i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# K = int(input())
# N = int(input())
# A = [int(input()) for i in range(N)]
K, N = list(map(int,input().split()))
A = list(map(int,input().split()))
 
D = []
for i in range(N):
	D.append((K + A[i] - A[i - 1]) % K)
    
print(K - max(D))

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

typedef long long ll;

int main(){
  ll n;

  while(cin >> n){
    ll ans = 0;
    ll cnt[130];
    memset(cnt, 0, sizeof(cnt));

    for(int i = 0; i < n; i++){
      ll h;
      cin >> h;

      ans += h;

      for(int j = 1; j <= min(h, 125LL); j++){
        cnt[j]++;
      }
    }

    for(int i = 1; i <= 125; i++){
      ans -= max(0LL, cnt[i] - i * 4LL);
    }

    cout << ans + 1 << endl;
  }
}

Measured memory_bytes: 1160
s=input()
ans=0
for i in range(2**(len(s)-1)):
  t=""
  for j in range(len(s)-1):
    if format(i,"0"+str(len(s)-1)+"b")[j] == '1':
      t+=s[j]+"+"
    else:
      t+=s[j]
  t+=s[-1]
  ans+=eval(t)
print(ans)

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

//const ll INF=(ll)1e19;
const int INF=(1<<30);


int main(){
  int n;
  cin >> n;
  
  VI a(n);
  REP(i,n)cin >> a[i];
  sort(ALL(a));

  int a1=a[n-1];
  int d=INF;
  int a2;

  REP(i,n-1){
    if(abs(a[i]*2-a1)<d){
      a2=a[i];
      d=abs(a[i]*2-a1);
    }
  }
  cout << a1 << " " << a2 << endl;
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

const string LIST[3] = {"the", "this", "that"};

bool judge(string);

int main(void){
	for(string input; getline(cin, input); cout << input << endl){
		for(int i = 0; i < 25; i ++){
			if(judge(input)) break;
			for(int j = 0; j < input.length(); j ++){
				if('a' <= input[j] && input[j] <= 'z')
					input[j] = (input.at(j) != 'z') ? input.at(j) + 1: 'a';
			}
		}
	}

	return 0;
}

bool judge(string input){
	istringstream iss(input);
	do{
		string sub;
		iss >> sub;
		for(int i = 0; i < 3; i ++)
			if(sub == LIST[i]) return true;
	} while(iss);

	return false;
}

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

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back

using namespace std;

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

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

inline void proc_status()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) <<endl;
}

const int Maxn = 16 + 10, Maxs = (1 << 16) + 100;

int N, A[Maxn][Maxn];
LL f[Maxs], g[Maxs];

inline void Solve ()
{
	int ALL = (1 << N) - 1;

	for (int i = 0; i <= ALL; ++i)
	{
		int k = i ^ (i & (-i)), pos = __builtin_ctz(i) + 1;
		g[i] = g[k];
		for (int j = 1; j <= N; ++j)
			if (i & (1 << (j - 1)))
				g[i] += A[pos][j];
	}

	for (int i = 0; i <= ALL; ++i)
		for (int j = i; j <= ALL; j = (j + 1) | i)
			Chkmax(f[j], f[i] + g[j ^ i]);

	cout<<f[ALL]<<endl;
}

inline void Input ()
{
	N = read<int>();
	for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) A[i][j] = A[j][i] = read<int>();
}

int main()
{
#ifdef hk_cnyali
	freopen("U.in", "r", stdin);
	freopen("U.out", "w", stdout);
#endif
	Input();
	Solve();
	return 0;
}


Measured memory_bytes: 1280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.OptionalInt;
import java.util.regex.Pattern;
import java.util.stream.Stream;

public class Main {
  public static void main(String[] args) {

    new Main().run();
  }

  public void run() {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String line = br.readLine();
      final Pattern delim = Pattern.compile("\\s");
      int[] arrayS = delim
        .splitAsStream(line)
        .mapToInt(Integer::parseInt)
        .toArray();

      OptionalInt max =
        Arrays.stream(arrayS).max();

      dispIntArray( countingSort(arrayS, max.getAsInt()) );
    }
    catch ( IOException e ) {
      System.out.println("IOException!");
    }

  }

  public int[] countingSort(int[] a, int k) {

    int   aLength = a.length;
    int[] result  = new int[aLength];
    int[] counter = new int[k+1];

    for (int var : a) {
      counter[var]++;
    }

    for (int i=1, max=k+1; i < max; i++) {
      counter[i] += counter[i-1];
    }

    for (int i=aLength-1, val=0; i>=0; i--) {
      val = a[i];
      result[counter[val]-1] = val;
      counter[val]--;
    }

    return result;
  }

  public void dispIntArray(int[] target) {
    StringBuilder s = new StringBuilder();

    for (int i : target) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
}


Measured memory_bytes: 181948
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	vector<int>v1;
	int n, v, i;
	cin >> n;
	while (n--) {
		cin >> v;
		v1.push_back(v);
	}
	int ma = 0, index = 0, ma2 = 0, index2 = 0;
	for (i = 0; i < v1.size(); i++) {
		if (v1[i] > ma) {
			ma = v1[i];
			index = i;
		}
	}
	for (i = 0; i < v1.size(); i++) {
		if (v1[i] > ma2 && i != index) {
			ma2 = v1[i];
			index2 = i;
		}
	}
	vector<int>v2 = v1;
	for (i = 0; i < v1.size(); i++) {
		if (i != index) {
			cout << ma << endl;
		}
		else {
			cout << ma2 << endl;
		}
	}
}

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define INF 1e15
int qe,k;
vector<pair<ll,ll> > adj[100005];
vector<ll> dist(100005, INF); 

void shortestPath() 
{ 
    priority_queue< pair<ll,ll>, vector <pair<ll,ll>> , greater<pair<ll,ll>> > pq; 
    pq.push(make_pair(0, k)); 
    dist[k] = 0; 
    while (!pq.empty()) 
    { 
        ll u = pq.top().second; 
        pq.pop(); 
        for (auto i= adj[u].begin(); i != adj[u].end(); ++i) 
        { 
            ll v = (*i).first; 
            ll weight = (*i).second; 
  
            //  If there is shorted path to v through u. 
            if (dist[v] > dist[u] + weight) 
            { 
                dist[v] = dist[u] + weight; 
                pq.push(make_pair(dist[v], v)); 
            } 
        } 
    } 
} 


int main()
{
	ll t=1;while(t--){
	ll n,m;cin>>n;
	for(ll i=1;i<=n-1;i++)
	{
		ll u,v,w;
		cin>>u>>v>>w;
		adj[u].push_back({v,w});
		adj[v].push_back({u,w});
	}
	cin>>qe>>k;
	shortestPath();
	while(qe--)
	{
		ll a,b;cin>>a>>b;
		cout<<dist[a]+dist[b]<<endl;
	}
     
	
	




	
}}

Measured memory_bytes: 11120
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int n,m;
double l[21],a[21],b[21];
int data[21];
double res;

void dfs(int v,int nm){
	if(v==n){
		double val=0.0;
		for(int i=0;i<nm;i++){
			for(int j=i+1;j<nm;j++){
				val+=pow(l[data[i]]-l[data[j]],2)+pow(a[data[i]]-a[data[j]],2)+pow(b[data[i]]-b[data[j]],2);
			}
		}
		res=max(res,val);
		return;
	}
	dfs(v+1,nm);
	if(nm<m){
		data[nm]=v;
		dfs(v+1,nm+1);
	}
}

int main(void){
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%lf %lf %lf",&l[i],&a[i],&b[i]);
	}
	dfs(0,0);
	printf("%.20f\n",res);
	return 0;
}

Measured memory_bytes: 1096
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define INF 1000000001
#define MOD 1000000007

using namespace std;



class Dice {
public:
	int num[6] = { 0,0,0,0,0,0 };
	void setnum(int*);
	void roll(char);
	void dice3(Dice, Dice);
};

void Dice::roll(char c) {
	switch
 (c) {
		int tmp;
	case'N':
		tmp = num[0];
		num[0] = num[1];
		num[1] = num[5];
		num[5] = num[4];
		num[4] = tmp;
		break;
	case'S':
		tmp = num[0];
		num[0] = num[4];
		num[4] = num[5];
		num[5] = num[1];
		num[1] = tmp;
		break;
	case'E':
		tmp = num[0];
		num[0] = num[3];
		num[3] = num[5];
		num[5] = num[2];
		num[2] = tmp;
		break;
	case'W':
		tmp = num[0];
		num[0] = num[2];
		num[2] = num[5];
		num[5] = num[3];
		num[3] = tmp;
		break;
	default:
		cout << "invalid char" << endl;
	}
}

void Dice::setnum(int* a) {
	REP(i, 6) {
		num[i] = a[i];
	}
}

bool isSame(Dice d1, Dice d2) {
	int flag = 1;
	REP(i, 6) {
		if (d1.num[i] != d2.num[i]) {
			flag = 0;
		}
	}
	if (flag) return true;
	else return false;
}

bool dice4(Dice d1, Dice d2) {
	int flag0 = 0;
	int a  = d1.num[0];
	REP(i, 6) {
		if (a == d2.num[i]) {
			flag0 = 1;
		}
	}
	if (flag0) {
		REP(i, 3) {
			REP(j, 4) {
				if (isSame(d1, d2)) {
					return true;
				}
				d1.roll('E');
				d1.roll('N');
				d1.roll('W');
			}
			d1.roll('E');
			REP(j, 4) {
				if (isSame(d1, d2)) {
					return true;
				}
				d1.roll('E');
				d1.roll('N');
				d1.roll('W');
			}
			d1.roll('N');
		}
	}
	return false;
}




int main() {
	int n,flag=0;
	cin >> n;
	vector<Dice> dice;
	REP(i, n) {
		Dice d;
		dice.push_back(d);
		int tmp[6];
		REP(j, 6){ 
			int c;
			cin >> c;
			tmp[j]=c;
		}
		dice[i].setnum(tmp);
	}
	REP(i, n) {
		FOR(j, i+1, n) {
			if (dice4(dice[i], dice[j]))flag = 1;
		}
	}
	if (flag)cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3120
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int N;
    int[] d;

    private void solve() {
        N = nextInt();
        d = new int[N];
        for (int i = 0;i < N;i++) {
            d[i] = nextInt();
        }

        Arrays.sort(d);

        int ans = 1;
        for (int i = 1;i < N;i++) {
            if (d[i-1] < d[i]) {
                ans++;
            }
        }

        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 22740
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<set>
#include<map>
using namespace std;
inline int re_ad()
{
	int x=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=x*10+ch-48,ch=getchar();
	return x*f;
}
inline int ma(int x,int y){return x>y?x:y;}
inline int mi(int x,int y){return x<y?x:y;}
int n;
char s[1000010],t[1000010];
queue<int> q;
int main()
{
	bool fla=1;
	register int i,ml,x,ans=0,las;
	//freopen("copy.in","r",stdin);
	//freopen("copy.out","w",stdout);
	n=re_ad();scanf("%s",s+1);scanf("%s",t+1);las=n;
	for(i=1;i<=n;++i)if(s[i]!=t[i]){fla=0;break;}
	if(fla){cout<<0<<endl;return 0;}
	for(int i=n;i>=1;--i)
	{
	if(t[i]==t[i-1])continue;
	las=mi(i,las);
	while(las&&t[i]!=s[las])--las;
	if(!las){cout<<-1<<endl;return 0;}
	while(!q.empty()&&q.front()-q.size()+1>i) q.pop();
	q.push(las);
	if(i!=las)ans=ma(ans,q.size());
	}
	cout<<ans+1<<endl;return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
const int Maxn = 100010; 
int n, t, a[ Maxn ];
int main( )
{
	std::ios::sync_with_stdio( false );
	std::cin >> n >> t;
	int mx = 0, ans = 0, tot = 0;
	for( int i = 1; i <= n; ++i )
		std::cin >> a[ i ]; 
	for( int i = n; i; --i )
	{
		mx = std::max( a[ i ], mx );
		ans = std::max( ans, mx - a[ i ] ); 
	}
	mx = 0;
	for( int i = n; i; --i )
	{
		mx = std::max( a[ i ], mx );
		if( ans == mx - a[ i ] )
			tot++;
	}
	std::cout << tot;
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    
    if(s.length() < 3)
        cout << "No\n";
    else if(s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I')
        cout << "Yes\n";
    else
        cout << "No\n";
}

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

map<ll,int> prime_fac(ll n) {
  map<ll,int> res;
  for(ll i=2;i*i<=n;i++)
    while(n%i==0)
      res[i]++,n/=i;
  if(n>1) res[n]++;
  return res;
}

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  ll n;cin>>n;
  map<ll, int> mp = prime_fac(n);

  ll ans=0;
  for (auto& kv : mp) {
    if (kv.first==1)continue;
    auto rest=kv.second;
    for(int i=1;i<=100;i++){
      if(rest<i)break;
      rest-=i;
      ans++;
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


int main() {
  ll N; cin >> N;
  Vll a(N+2);
  cin >> a[0] >> a[1];
  rep(i, N) cin >> a[i+2];

  ll ans = max(abs(a[N+1]-a[N]), abs(a[N+1]-a[1]));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)
ans = [0]*n
s += "R"
lastl = -1
lastr = 0
for i in range(n):
    if s[i] == "R" and s[i+1] == "L":
        lastr = i
    if s[i] == "L" and s[i+1] == "R":
        su = i-lastl
        if su%2 == 0:
            ans[lastr],ans[lastr+1] = su//2,su//2
        else:
            #print((su+1)//2,(su-1)//2)
            ans[lastr],ans[lastr+1] = ((su+1)//2,(su-1)//2) if (lastr-lastl)%2!=0 else ((su-1)//2,(su+1)//2)
        lastl = i
print(*ans)


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

int n;

int main(void){
	cin >> n;
	vector<int> p(n), q(n);
	rep(i, n) cin >> p[i];
	rep(i, n) cin >> q[i];
	vector<int> a(n);
	rep(i, n) a[i] = i+1;
	int pi, qi;
	int c = 1;
	do{
		bool fp, fq;
		fp = fq = true;
		rep(i, n){
			if(a[i] != p[i]) fp = false;
			if(a[i] != q[i]) fq = false;
		}
		if(fp) pi = c;
		if(fq) qi = c;
		c++;
	}while(next_permutation(a.begin(), a.end()));
	cout << abs(pi-qi) << endl;
}


Measured memory_bytes: 3596
package main

import "fmt"

func main() {
	// Code for B - Collatz Problem
	var s int
	fmt.Scanf("%d", &s)

	var i int = 2
	var aAfter int
	var aBefore int = s
	a := make(map[int]int)
	a[s]++
	for {
		if aBefore%2 == 0 {
			aAfter = aBefore / 2
		} else {
			aAfter = 3*aBefore + 1
		}

		a[aAfter]++
		if a[aAfter] == 2 {
			fmt.Println(i)
			break
		}
		aBefore = aAfter
		i++
	}
}


Measured memory_bytes: 1860
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)

A,B,C,D=map(int ,input().split())
a = B//C-(A-1)//C
b = B//D-(A-1)//D
c  =lcm(C,D)
d = B//c-(A-1)//c
e = B - A +1 - a -b + d 
print(e)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cmath>
typedef long long ll;
#define inf 0x3f3f3f3f
using namespace std;
int main()
{
    ll n,i,j,a,sum=0,b;
    cin>>n>>a>>b;
    if(a+b==0)cout<<0;
    else if(n<=a+b)
    {
    	if(n>=a)cout<<a;
    	else cout<<n;
	}
    else 
    {
    	if(n%(a+b)<=a)sum+=n%(a+b);
    	else sum+=a;
    	sum+=(n/(a+b))*a;
    	cout<<sum;
	}
	return 0;
 } 

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

int nums[101];

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

	int n;
	int m;
	int sum = 0;

	std::cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		std::cin >> nums[i];
		sum += nums[i];
	}

	std::sort(nums + 1, nums + 1 + n, [](int a, int b) -> bool {
		return a > b;
		});

	if (sum / 4.0 / m <= nums[m]) {
		std::cout << "Yes";
	}
	else {
		std::cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

int n;
int cnt[100005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	
	int temp;
	
	int mn=1000000,mx=-1;
	
	rep(x,0,n){
		cin>>temp;
		mn=min(mn,temp);
		mx=max(mx,temp);
		
		cnt[temp]++;
	}
	
	if (mn==mx){
		if (mn==n-1 || mn<=n/2) cout<<"Yes";
		else cout<<"No";
	}
	else if (mx-mn==1){
		if (cnt[mn]+1<=mx && mx<=cnt[mn]+cnt[mx]/2) cout<<"Yes";
		else cout<<"No";
	}
	else{
		cout<<"No";
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
int main()
{
  vector<ll> a(7);
  rep(i,7) cin >> a[i];

  ll res = 0;
  res += a[1] * 2;
  if(a[0] == 0 || a[3] == 0 || a[4] == 0) {
    res += a[0] / 2 * 4;
    res += a[3] / 2 * 4;
    res += a[4] / 2 * 4;
  }
  else {
    ll cnt = (a[0] % 2) + (a[3] % 2) + (a[4] % 2);
    if(cnt == 0 || cnt == 1) {
      res += a[0] / 2 * 4;
      res += a[3] / 2 * 4;
      res += a[4] / 2 * 4;
    }
    else if(cnt == 2) {
      res += (a[0] - 1) / 2 * 4;
      res += (a[3] - 1) / 2 * 4;
      res += (a[4] - 1) / 2 * 4;
      res += 6;
    }
    else if(cnt == 3) {
      res += a[0] / 2 * 4;
      res += a[3] / 2 * 4;
      res += a[4] / 2 * 4;
      res += 6;
    }
  }
  cout << res/2 << "\n";
  
  return 0;
}


Measured memory_bytes: 256
import math

def dijkstra(s):
    d=[inf]*n
    pi=[inf]*n
    visited=[False]*n
    d[s]=0
    pi[s]=-1
    while True:
        mincost=inf
        for i in range(n):
            if not visited[i] and d[i]<mincost:
                mincost=d[i]
                u=i
        if mincost==inf:
            break
        visited[u]=True
        for v in range(n):
            if visited[v] or L[u][v]==inf:
                continue
            if d[u]+L[u][v]<d[v]:
                d[v]=d[u]+L[u][v]
                pi[v]=u
    return pi

def routing(pi,g):
    ans=[]
    i=g
    while i!=-1:
        ans.append(i+1)
        i=pi[i]
    return ans[::-1]

inf=100000
while True:
    n=input()
    if n==0:break
    L=[[inf]*n for i in range(n)]
    for i in range(n):
        L[i][i]=0
    B=[map(int,raw_input().split()) for i in range(n)]
    for i in range(n-1):
        for j in range(i+1,n):
            ba,xa,ya=B[i]
            bb,xb,yb=B[j]
            ba,bb=ba-1,bb-1
            d=math.sqrt(pow(xa-xb,2)+pow(ya-yb,2))
            if d<=50:
                L[ba][bb]=L[bb][ba]=d
    m=input()
    for i in range(m):
        s,g=map(int,raw_input().split())
        s,g=s-1,g-1
        pi=dijkstra(s)
        if pi[g]==inf:
            print "NA"
        else:
            ans=routing(pi,g)
            print " ".join(map(str,ans))

Measured memory_bytes: 4592
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const ll LINF = (ll)1 << 60;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
const long double PI=3.14159265358979323846264338327950;
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int count=0;
  vint a(3);
  set<tuple<int,int,int> > S;
  rep(i,n){
    cin>>a[0]>>a[1]>>a[2];
    sort(all(a));
    if(S.find(make_tuple(a[0],a[1],a[2]))==S.end()){
      S.insert(make_tuple(a[0],a[1],a[2]));
    }
    else{
      count++;
    }
  }
  cout<<count<<'\n';
  return(0);
}


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

using namespace std;

long long clac(long long A){
    if (A==0) return 0;
    A++;
    //10^3<=2^10
    //1000<=1024
    //10^12<=2^40
    //10^12 = 2進数で40桁ぐらい
    long long ans = 0;
    for(int i = 0; i < 50; i++)
    {
        //0桁目は周期2
        //1桁目は周期4
        long long loop = (1LL << (i+1));
        long long cnt = (A/loop) * (loop/2);
        // 00000000.....0011111....1111
        cnt += max(0LL,(A % loop) - (loop / 2));
        if(cnt%2==1){
            ans += 1LL << i;
        }
    }
    return ans;
}
int main(){
    long long A,B;
    cin >> A >> B;

    long long ans = clac(B) ^ clac(A-1);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}

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

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((a + d - 1) / d < (c + b - 1) / b)
  {
    cout << "No" << endl;
  }
  else
  {
    cout << "Yes" << endl;
  }
  return 0;
}

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

int main() {
	// your code goes here
	string s;
	cin>>s;
	bool vis[26];
	for(int i=0;i<s.size();++i){
			for(int j=0;j<s.size();++j){
				if(j==i)continue;
				if(s[i]==s[j]){
					cout<<"no"<<endl;
					return 0;
				}
			}

	}
	cout<<"yes"<<endl;
	return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,x,m;
    cin >> n >> x >> m;
    vector<ll> spare(m, -1);
    ll now = x;
    /**
    if(n <= 1e7){
        ll ans = 0;
        ll now = x;
        rep(i,n){
            ans += now;
            now = now*now%m;
        }
        cout << ans << endl;
        return 0;
    }**/
    rep(i,m){
        if(spare[now] != -1) break;
        else{
            spare[now] = i;
            now = now*now%m; 
        }
    }
    ll start = spare[now];
    ll end = i;
    ll shuuki = end-start;
    now = x;
    ll ans = 0;
    for(i = 0;i < start;++i){
        ans += now;
        now = now*now%m;
        --n;
        if(n == 0){
            cout << ans << endl;
            return 0;
        }
    }
    ll kurikaesi = 0;
    for(i = start;i < end;++i){
        kurikaesi += now;
        now = now*now % m;
    }
    ans += n/shuuki*kurikaesi;
    n %= shuuki;
    while(n){
        ans += now;
        now = now*now%m;
        --n;
    }
    cout << ans << endl;

    return 0;
}


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

bool cmp( pair<ll,ll>a, pair<ll,ll>b ){
    if( a.first == b.first ){
        return (a.second == 0);
    }
    return (a.first < b.first);
}

int main(){
    int n;
    while( cin >> n ){
        vector<pair<ll,ll>>v;
        for( int i = 0; i < n; i++ ){
            ll a, b;
            cin >> a >> b;
            ll st = a-b;
            ll en = a+b;
            v.push_back( {en, st} );
        }
        sort( v.begin(), v.end() );
        int res = 0;
        ll minLeft = -1000000000;
        for( int i = 0; i < n; i++ ){
            if( minLeft <= v[i].second ){
                res++;
                minLeft = v[i].first;
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 2420
import java.util.*;

public class Main {
	long count = 0;
	public static void main(String[] args) {
		new Main().runSort();
	}
	
	public void runSort() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] l = new int[n];
		for (int i = 0; i < n; i++) {
			l[i] = sc.nextInt();
		}
		sorting(l, 0, n);
		System.out.println(count);
	}

	public void sorting(int[] l, int nl, int nr) {
		if (nl + 1 < nr) {
			int nm = (nl + nr) / 2;
			sorting(l, nl, nm);
			sorting(l, nm, nr);
			merging(l, nl, nm, nr);
		}
	}

	public void merging(int[] list, int nl, int nm, int nr) {
		int n1 = nm - nl;
		int n2 = nr - nm;
		int[] l = new int[n1 + 1];
		int[] r = new int[n2 + 1];
		for (int i = 0; i < n1; i++) {
			l[i] = list[nl + i];
		}
		for (int i = 0; i < n2; i++) {
			r[i] = list[nm + i];
		}
		l[n1] = Integer.MAX_VALUE;
		r[n2] = Integer.MAX_VALUE;

		int LEFT = 0;
		int RIGHT = 0;
		for (int i = nl; i < nr; i++) {
			if (l[LEFT] <= r[RIGHT]) {
				list[i] = l[LEFT++];
				count = count + RIGHT;
			} else {
				list[i] = r[RIGHT++];
			}
		}
	}

}


Measured memory_bytes: 99684
def selection_sort(A, N):
    cnt = 0
    for i in range(N):
        min_j = i
        for j in range(i, N):
            if A[j] < A[min_j]:
                min_j = j
        if i != min_j:
            A[i], A[min_j] = A[min_j], A[i]
            cnt += 1        
    return A, cnt


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

A, cnt = selection_sort(A, N)
string = list(map(str, A))
print(' '.join(string))
print(cnt)


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

int main()
{
  ll n;
  cin >> n;
  map<string, ll> anagram;
  for (ll i = 0; i < n; i++)
  {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    anagram[s]++;
  }
  ll ans = 0;
  for (auto itr = anagram.begin(); itr != anagram.end(); itr++)
  {
    if (itr->second > 1)
    {
      ll num = itr->second;
      ans += (ll)num * (num - 1) / 2;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 11288
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define endl "\n" 
#define p pair<int, int>
#define arrinp(i, a, start, end); for(ll i = start; i <= end; i++) cin >> a[i];
#define arrout(i, a, start, end); for(ll i = start; i <= end; i++) cout << a[i] << " ";
#define swap(a, b) {a = a + b; b = a - b; a = a - b;
#define forfront(i, start, end) for(ll i = start; i <= end; i++)
#define forback(i, start, end) for(ll i = start; i >= end; i--)
#define out(x) cout << x << " "
#define outline(x) cout << x << endl;
#define sortvector(v) sort(v.begin(), v.end());
#define sortvectorrev(v) sort(v.rbegin(), v.rend());
int main()
{
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    ll a[n];
    arrinp(i, a, 0, n - 1);
    map<ll, ll> m;
    ll sum = 0;
    forfront(i, 0, n - 1)
    {
        m[a[i]]++;
        sum += a[i];
    }    
    ll q;
    cin >> q;
    while(q--)
    {
        ll b, c;
        cin >> b >> c;
        sum -= m[b]*b;
        sum += m[b]*c;
        ll count = m[b];
        m[b] = 0;
        m[c] += count;
        // out(c);
        // out(m[c]);
        outline(sum);
    }
    return 0;
}

Measured memory_bytes: 10208
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner kb = new Scanner(System.in);
		int n = kb.nextInt();
		int[] x = new int[n];
		for(int i = 0; i < n; i++) {
			x[i] = kb.nextInt();
		}
		
		
		int min = Integer.MAX_VALUE;
		for(int i = 0; i <= 100; i++) {
			int cost = 0;
			for(int j = 0; j < n; j++)
				cost += (x[j] - (i+1))*(x[j] - (i+1));
			min = Math.min(cost, min);
		}
		
		System.out.println(min);
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
long long int n,k,ans=0,b;
int main()
{
	scanf("%lld%lld",&n,&k);
	if (k==0)
	{
		printf("%lld",n*n);
		return 0;
	}
	for (b=k+1;b<=n;++b)
	{
		ans+=n;
		ans-=(n/b)*(k)+min(n%b,k-1);
//		printf("%d ",ans);
	}
	printf("%lld",ans);
	return 0;
}
//2
//
//1 2 3 4 5 
//
//3
//
//1 2 0 1 2



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int maxn=200005;
inline int read(){
	int x=0;char ch=getchar();
	while (!isdigit(ch)) ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x;
}
int n,a[maxn],b[maxn],x=0,to[maxn],ca[maxn],cb[maxn],N,bel[maxn],ans=0,id[maxn],lst[maxn];
vector<int> pos[maxn],vec;
int find(int x){
	if (bel[x]==x) return x;
	return bel[x]=find(bel[x]);
}
inline void unite(int x,int y){
	x=find(x),y=find(y);
	bel[x]=y;
}
int main(){
	n=read();
	for (int i=1;i<=n;++i) bel[i]=i;
	for (int i=1;i<=n;++i) a[i]=read(),x^=a[i];
	for (int i=1;i<=n;++i) b[i]=read();
	vec.push_back(x);
	for (int i=1;i<=n;++i){
		vec.push_back(a[i]);
		vec.push_back(b[i]);
	}
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());N=vec.size();
	x=lower_bound(vec.begin(),vec.end(),x)-vec.begin();
	for (int i=1;i<=n;++i){
		a[i]=lower_bound(vec.begin(),vec.end(),a[i])-vec.begin();
		b[i]=lower_bound(vec.begin(),vec.end(),b[i])-vec.begin();
		++ca[a[i]];++cb[b[i]];
	}
	bool flag=1;
	for (int i=0;i<N;++i) if (ca[i]!=cb[i]) flag=false;
	if (flag){
		for (int i=1;i<=n;++i){
			if (a[i]==b[i]) continue;
			pos[b[i]].push_back(i);
		}
		for (int i=1;i<=n;++i){
			if (a[i]==b[i]) continue;
			if (a[i]==x) ans=-1;
			to[i]=pos[a[i]][id[a[i]]++];
			unite(i,to[i]);
			if (lst[a[i]])
				unite(i,lst[a[i]]);
			lst[a[i]]=i;
		}
		for (int i=1;i<=n;++i){
			if (a[i]==b[i]) continue;
			++ans;
			if (find(i)==i) ++ans;
		}
		printf ("%d\n",ans);
	}
	else{
		++ca[x];
		for (int i=0;i<N;++i) if (ca[i]<cb[i]){
			puts("-1");
			return 0;
		}
		int t;ans=-1;
		for (int i=0;i<N;++i) if (ca[i]>cb[i]) t=i;
		int vis=0;
		for (int i=1;i<=n;++i){
			if (a[i]==b[i]) continue;
			if (a[i]==t&&!vis){
				vis=i;
				swap(x,a[i]);
			}
			pos[b[i]].push_back(i);
		}
		for (int i=1;i<=n;++i){
			if (a[i]==b[i]){
				if (i==vis) ans+=2;
				continue;
			}
			to[i]=pos[a[i]][id[a[i]]++];
			unite(i,to[i]);
			if (lst[a[i]])
				unite(i,lst[a[i]]);
			lst[a[i]]=i;
		}
		for (int i=1;i<=n;++i){
			if (a[i]==b[i]) continue;
			++ans;
			if (find(i)==i) ++ans;
		}
		printf ("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 14708
#pragma GCC optimize ("Ofast")
#pragma GCC target(*sse4.2*)
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define PB push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define vvii vector<vii>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define read(x) long long x;cin>>x;
#define FOR(a,b,c,d) for(int a=b;a<=c;a+=d)
#define MP make_pair
#define F first
#define S second
#define debug(x) cout<<("#x)<<": "<<(x)<<"\n"
#define SZ(x) x.size()
#define mod 1000000007
#define lg2(x) 63-(__builtin_ctzll(x))
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
typedef unsigned long long ull;
typedef long double d64;


int main(){
fast
read(n);

n=n%10;

if(n==2||n==4||n==5||n==7||n==9)cout<<"hon";
else if(n==0||n==1||n==6||n==8)cout<<"pon";
else cout<<"bon";



return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll ans;
ll mod = 1e9 + 7;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n; cin>>n;
    ans=1;
    ll cu=0;
    string s; cin>>s;
    for(int i=0;i<s.length();i++){
        int f=0;
        if(s[i]=='B')f=1;
        ll h= cu%2;
        if(h)f^=1;
        if(f)cu++;
        else{
            ans*=cu;
            cu--;
            if(cu<0){
                cout<<"0";return 0;
            }
            if(ans>=mod)ans%=mod;
        }
    }
    if(cu){
        cout<<"0";return 0;
    }
    for(ll i=1;i<=n;i++){
        ans*=i;
        if(ans>=mod)ans%=mod;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 720
n,a,b,c = map(int, input().split())
op = [input() for i in range(n)]

val=[a,b,c]
flag=True
ansls=list()

for i in range(n):
    s1=ord(op[i][0])-ord('A')
    s2=ord(op[i][1])-ord('A')
    if val[s1]>val[s2]:
        ansls.append(s2)
        val[s2]+=1
        val[s1]-=1
    elif val[s1]<val[s2] or i+1==n:
        ansls.append(s1)
        val[s1]+=1
        val[s2]-=1
    else:
        s1n = ord(op[i+1][0])-ord('A')
        s2n = ord(op[i+1][1])-ord('A')
        nxt = set([s1,s2]) & set([s1n,s2n])
        nxt = list(nxt)[0]
        ansls.append(nxt)
        val[nxt]+=1
        if nxt==s1:
            val[s2]-=1
        else:
            val[s1]-=1
    if min(val)<0:
        flag=False
        break

if flag:
    print('Yes')
    for i in range(n):
        print(chr(ansls[i]+ord('A')))
else:
    print('No')

    

Measured memory_bytes: 84920
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int c500 = N/500;
    int zan = N%500;
    int c5 = zan/5;
    System.out.println(c500*1000+ c5*5);   
    return;
  }
}



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

 int main() {
 int n;
 string s;
 cin >> n >> s;
 int ans = 0;
 for(int i = 0; i <= n - 3; i++) {
   if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
  }
 cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 07/25/20 20:57:10
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int a,b,c; cin>>a>>b>>c;
  int k; cin>>k;
  int cnt = k;
  while (cnt and a >= b) {
    b *= 2;
    cnt--;
  }
  while (cnt and b >= c) {
    c *= 2;
    cnt--;
  }
  bool ans = a < b and b < c;
  cout << (ans ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 3636
import java.util.*;
	public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            //入力
            int[][] list = new int[3][3];
            
            for(int i=0; i<3; i++){
            	for(int j=0; j<3; j++){
            		int a = Integer.parseInt(sc.next());
            		list[i][j] =a;
            	}
            }

            //出力
            if(list[0][0] - list[1][0] == list[0][1] - list[1][1] 
            		&& list[0][1] - list[1][1] == list[0][2] - list[1][2]
            				&& list[1][0] - list[2][0] == list[1][1] - list[2][1] 
            	            		&& list[1][1] - list[2][1] == list[1][2] - list[2][2]
            	            				&& list[0][0] - list[0][1] == list[1][0] - list[1][1] 
            	            	            		&& list[0][0] - list[0][1] == list[2][0] - list[2][1]
            	            	            				&& list[0][1] - list[0][2] == list[1][1] - list[1][2] 
            	            	            	            		&& list[0][1] - list[0][2] == list[2][1] - list[2][2]){
            	System.out.println("Yes");
            }else{
            	System.out.println("No");
            }
            sc.close();
        }
    }

Measured memory_bytes: 21844
#include<stdio.h>
int main(void)
{
	int W,H,x,y,r;
	scanf("%d",&W);
	scanf("%d",&H);
	scanf("%d",&x);
	scanf("%d",&y);
	scanf("%d",&r);

	if((x+r<=W)&&(x-r>=0)&&(y+r<=H)&&(y-r>=0))
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mxn= 5e4+5;
// check for forloop
// intialize variable
// overflow
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
//#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    rishabh();
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    int ans=0;
    for(int i=0;i<n;i++){
        while(arr[i]==arr[i+1])i++;
        if(arr[i+1]!=arr[i]){
            if(arr[i+1]<arr[i])
            while(arr[i+1]<=arr[i]&&i<n)i++;
            else while(arr[i]<=arr[i+1]&&i<n)i++;
        }
        
        ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 3980