akhauriyash/Code-Regression huggingface dataset:
H, W, D = map(int, input().split())
X, Y, ans = [-1] * H * W, [-1] * H * W, [0] * H * W

for h in range(H):
    A = list(map(int, input().split()))
    for w in range(W):
        X[A[w] - 1], Y[A[w] - 1] = h, w

for d in range(D):
    while d + D < H * W:
        ans[d + D] = ans[d] + abs(X[d] - X[d + D]) + abs(Y[d] - Y[d + D])
        d += D

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    print(ans[R - 1] - ans[L - 1])


Measured memory_bytes: 9340
n=int(input())
a=[]
b=[]

for i in range(n):
    x,y=list(map(int,input().split()))
    a.append(x+y)
    b.append(x-y)

aaa=min(a)
aaaa=max(a)
bbb=min(b)
bbbb=max(b)

ans=[]

ans.append(aaaa-aaa)
ans.append(bbbb-bbb)
ans.append(bbb)
ans.append(bbbb)
ans.append(aaa-aaaa)

res=max(ans)
print(res)

Measured memory_bytes: 24880
import math
import itertools

# 引数のリストの全ての順列リストを返す
def fact_list(seq:list):
    return list(itertools.permutations(seq))

# n!を返す
def fact_num(n:int):
    seq = list(range(n))
    return len(fact_list(seq))

N = int(input())
n_fact_list = fact_list(list(range(N)))
n_fact_num = fact_num(N)
x, y = [], []
for i in range(N):
    xi, yi = map(int, input().split())
    x.append(xi)
    y.append(yi)

d = 0
for order in n_fact_list:
    for idx, i in enumerate(order[:-1]):
        j = order[idx+1]
        d += (math.sqrt( (x[i]-x[j])**2 + (y[i]-y[j])**2 ))
print(d/n_fact_num)

Measured memory_bytes: 12788
#include<bits/stdc++.h>
using namespace std;
//#define size(array) sizeof(array)/sizeof(int)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define loop(n) int n1c1r1=n;while(n1c1r1--)
#define read(a) for(int i=0;i<a.size();i++){cin>>a[i];}
#define read2d(a) for(int i=0;i<a.size();i++){for(int j=0;j<a[i].size();j++)cin>>a[i][j];}

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   long long int t=1;
   long long int a,b,c,d;
   cin>>a>>b>>c>>d;
   long long int p1=a*c;
   long long int p2=b*d;
   long long int p3=b*c;
   long long int p4=a*d;
   long long int ans=max(p1,p2);
   ans=max(ans,p3);
   ans=max(ans,p4);
   cout<<ans<<endl;
	return 0;

}


Measured memory_bytes: 3648
H,W=map(int,input().split())
a=[list(map(int,input().split())) for i in range(H)]

ans=[]
for i in range(H):
    for j in range(W):
        if a[i][j]%2:
            if i+1<H:
                a[i][j]-=1
                a[i+1][j]+=1
                ans.append((i+1,j+1,i+2,j+1))
            elif j+1<W:
                a[i][j]-=1
                a[i][j+1]+=1
                ans.append((i+1,j+1,i+1,j+2))
print(len(ans))
for x in ans:
    print(*x)

Measured memory_bytes: 97692
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    long long n, ans = 1e12;
    cin >> n;
    for (int i = 1; i <= sqrt(n); ++i) {
        if (n % i == 0) {
            ans = min(ans, i + n / i);
        }
    }
    cout << ans - 2 << endl;

    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}
// fold was added in D 2.071.0.
template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
        static if (S.length < 2) {
            return reduce!fun(seed, r);
        } else {
            return reduce!fun(tuple(seed), r);
        }
    }
}

void main() {
    int a, b, h;
    readf("%d\n%d\n%d\n", &a, &b, &h);
    writeln((a+b)*h/2);
}


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

int main() {
  int n; cin >> n;
  int F[50];
  F[0] = F[1] = 1;
  for ( int i = 2; i <= n; i++ ) F[i] = F[i - 1] + F[i - 2];

  cout << F[n] << endl;

  return 0;
}


Measured memory_bytes: 3112
// Problem : A - Not
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vint vector<int>
#define sint set<int>
#define mint map<int,int>
#define pint pair< int,int >
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define precision(x) cout<<fixed<<setprecision(x);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define present(container, element) (container.find(element)!=container.end())
#define fint fast;test
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void solve(){
	int n;
	rd(n);
	if(n)pp(0);
	else pp(1);	
	return;	
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long LL;

const int N=200005;
const int MOD=1000000007;

int n,a[N],b[N],jc[8005],ny[8005];
LL f[4005][4005];

int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int ksm(int x,int y)
{
    int ans=1;
    while (y)
    {
        if (y&1) ans=(LL)ans*x%MOD;
        x=(LL)x*x%MOD;y>>=1;
    }
    return ans;
}

int main()
{
    n=read();int mx=0;
    for (int i=1;i<=n;i++) a[i]=read(),b[i]=read(),mx=max(mx,max(a[i],b[i]));
    for (int i=1;i<=n;i++) f[a[i]+mx][b[i]+mx]++;
    jc[0]=ny[0]=1;
    for (int i=1;i<=mx*4;i++) jc[i]=(LL)jc[i-1]*i%MOD,ny[i]=ksm(jc[i],MOD-2);
    LL ans=0;
    for (int i=mx*2;i>=0;i--)
        for (int j=mx*2;j>=0;j--)
            (f[i][j]+=f[i+1][j]+f[i][j+1])%=MOD;
    for (int i=1;i<=n;i++) (ans+=f[mx-a[i]][mx-b[i]])%=MOD;
    for (int i=1;i<=n;i++) (ans-=(LL)jc[a[i]*2+b[i]*2]*ny[a[i]*2]%MOD*ny[b[i]*2])%=MOD;
    ans=ans*ksm(2,MOD-2)%MOD;
    printf("%lld",(ans+MOD)%MOD);
    return 0;
}

Measured memory_bytes: 127104
N = int(input())
l = list(map(int,input().split()))

l.insert(0, 0)
l.extend([0])
S = 0
ans = 0
for ix, i in enumerate(l[:-1]):
    S += abs(i - l[ix+1])

for ix in range(1,len(l)-1):
    S_i = S - abs(l[ix-1] - l[ix]) - abs(l[ix] - l[ix+1]) + abs(l[ix-1] - l[ix+1])
    print(S_i)

Measured memory_bytes: 14048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, th, hu, te, one;
  cin >> N;
  th = N / 1000;
  hu = (N - th * 1000) / 100;
  te = (N - hu * 100 - th * 1000) / 10;
  one = N - te * 10 - hu * 100 - th * 1000;
  
  if ((th == hu && hu == te) || (hu == te && te == one)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#create date: 2020-06-29 09:42

import sys
stdin = sys.stdin
from collections import defaultdict

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    counter = defaultdict(int)
    for ai in a:
        counter[ai] += 1
    asum = sum(a)

    q = ni()
    for i in range(q):
        b, c = na()
        asum += counter[b] * (c-b)
        counter[c] += counter[b]
        counter[b] = 0
        print(asum)

if __name__ == "__main__":
    main()

Measured memory_bytes: 94708
h,w = map(int,input().split())
c = [list(map(int,input().split())) for l in range(10)]
a = []
res = 0
for _ in range(h):
    a.extend(list(map(int,input().split())))

for k in range(10):
    for i in range(10):
        for j in range(10):
            if c[i][j] > c[i][k]+c[k][j]:
                c[i][j] = c[i][k]+c[k][j]

for sa in a:
    if sa != -1:
        res += c[sa][1]

print(res)

Measured memory_bytes: 3500
#include <iostream>
using namespace std;
int main(void){
    int k,s,cnt=0;
    cin>>k>>s;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            int z=s-i-j;
            if(0 <= z && z <= k){
                cnt=cnt+1;
            }
        }
    }
    cout<<cnt;
}


Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

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

  int n; cin >> n;
  vi a(n); rep(i, n) cin >> a[i];
  int m; cin >> m;
  vi b(m); rep(i, m) cin >> b[i];
  vi res;

  set_intersection(begin(a), end(a), begin(b), end(b), inserter(res, end(res)));

  for_each(begin(res), end(res), [](int x){cout << x << '\n';});

  return 0;
}


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

dic={0:'a',1:'b',2:'c',3:'d',4:'e',5:'f',6:'g',7:'h',8:'i',9:'j'} #標準形の文字列は同型の文字列の中で辞書順最小であることから、新たに付け加えるべき文字は順にa,b,c...となる
ans=[['a',1]]
for i in range(1, N):
 tmp=[]
 for prev,val in ans:
   for j in range(val+1): #(今見ている文字列に使われている文字の種類数+1)種類の文字を付け加える
     if j!=val: #今見ている文字列に使われている文字を付け加えるとき、文字の種類数は増加しない
       tmp.append([prev+dic[j],val])
     else: #今見ている文字列に使われていない文字を付け加えるとき、文字の種類数が増加する
       tmp.append([prev+dic[j],val+1])
 ans=tmp
ans=sorted(ans,key=lambda x:x[0]) #生成した標準形の文字列を辞書順昇順に並べ替える
for i in range(len(ans)):
 print(ans[i][0])

Measured memory_bytes: 25716
N=list(map(int,input().split(" ")))
ans=[int(input()) for i in range(N[2])]	

point=[N[1]-N[2] for i in range(N[0])]

for i in ans:
	point[i-1]+=1
#print(point)
for i in range(N[0]):
	if point[i]>0:
		print("Yes")
	else:
		print("No")

Measured memory_bytes: 11788
#include<stdio.h>
#define INFTY (1 << 21)
#define SHIRO 0
#define NEZUMI 1
#define KURO 2
#define MAX 100
#define NUL -1
int n;

int A[MAX][MAX];

int Prim();

int main(){
  int i;
  int j;
  int x;
  int P;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){

    for(j = 0 ; j < n ; j++){

      scanf("%d",&x);
      A[i][j] = x;
      if(A[i][j] == NUL) A[i][j] = INFTY;
    }
  }

  P = Prim();
  printf("%d\n",P);

  return 0;
}


int Prim(){
  int i;
  int t;
  int min;
  int a[MAX], b[MAX], iro[MAX];
  int sum = 0;

  for(i = 0 ; i < n ; i++){
    a[i] = INFTY;
    b[i] = NUL;
    iro[i] = SHIRO;
  }

  a[0] = 0;

  for(;;){

    min = INFTY;
    t = NUL;

    for(i = 0 ; i < n ; i++){
      if(min > a[i] && iro[i] != KURO){

	t = i;
	min = a[i];

      }
    }

    if(t == NUL) break;

    iro[t] = KURO;
    for(i = 0 ; i < n ; i++){
      if(iro[i] != KURO && A[t][i] != INFTY){
	if(a[i] > A[t][i]){
	  a[i] = A[t][i];
	  b[i] = t;
	  iro[i] = NEZUMI;
	}





      }
    }
  }

  for(i = 0 ; i < n ; i++){
    if(b[i] != NUL) sum += A[i][b[i]];
  }



  return sum;
}



Measured memory_bytes: 2056
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int ifsuu(int x){
    int if3=0,if5=0,if7=0;
    while(x){
        if(x%10==3)if3=1;
        if(x%10==5)if5=1;
        if(x%10==7)if7=1;
        x/=10;
    }
    return if3*if5*if7;
}
vector<long long>suu;
void search(long long x,long long n){
    if(x<=n){
        if(ifsuu(x))suu.push_back(x);
        search(x*10+3,n);
        search(x*10+5,n);
        search(x*10+7,n);
    }
}
int main() {
	long long n;
	cin>>n;
	search(0,n);
	cout<<suu.size();
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<map>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++)
	cin>>v[i];
    map<int,int> mp_left;
    map<int,int> mp_right;
    for(int i=0;i<n;i++){
	if(mp_left.find(v[i])==mp_left.end())
	   mp_left[v[i]]=1;
        else
	   mp_left[v[i]]++;
	i++;
	if(mp_right.find(v[i])==mp_right.end())
	    mp_right[v[i]]=1;
	else
	    mp_right[v[i]]++;
    }
    int max_left=0,max_right=0;
    pair<int,int> a0,a1;
    pair<int,int> b0,b1;
    for(auto x: mp_left)
	if(x.second>max_left){
        a0=x;
        max_left=a0.second;
	}
    for(auto x: mp_right)
	if(x.second>max_right){
        b0=x;
        max_right=b0.second;
	}
    if(a0.first!=b0.first)
        cout<<n-a0.second-b0.second<<endl;
    else{
        max_left=0;
        max_right=0;
        for(auto x: mp_left){
            if(x.second>max_left&& x.first!=a0.first){
                max_left=x.second;
                a1=x;
            }
        }
        for(auto x: mp_right){
            if((x.second>max_right)&& (x.first!=b0.first)){
                b1=x;
                max_right=x.second;
            }
        }
        int t=max(a0.second+b1.second,a1.second+b0.second);
        cout<<n-t<<endl;
    }
    return 0;
}


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

typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#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++)

int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	vector<int> d(n - 1);
	int ans = 0;
	int count = 0;
	rep(i, n) cin >> h.at(i);
	rep(i, n - 1) d.at(i) = h.at(i + 1) - h.at(i);
	rep(i, n - 1) {
		if (d.at(i) <= 0) {
			count++;
		}
		else {
			if (ans < count) ans = count;
			count = 0;
		}
	}
    if (ans < count) ans = count ; 
	cout << ans << endl;
    
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
 #define mod 1000000007
 const int N=100005;
 const int inf=1e18;
 
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int n;
	cin>>n;
	int a,b;
	cin>>a>>b;
	cout<<min(a*n,b);
	







	
	
return 0;	
}


Measured memory_bytes: 256
#include <stdio.h>
 
int gcd(int a, int b);
int main(void)
{
    int a, b, q, r;
     
    while (scanf("%d", &a) != EOF){
        scanf("%d", &b);
                 
        printf("%d %d\n", gcd(a, b), a / gcd(a, b) * b);
    }
     
    return (0);
}
 
int gcd(int a, int b)
{
    int temp;
     
    if (a <= b){
        temp = a;
        a = b;
        b = temp;
    }
     
    while (1){
        if (b == 0){
            return (a);
        }
         
        temp = b;
        b = a % b;
        a = temp;
    }
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
vector<char> s{'S', 'H', 'C', 'D'};
map<pair<char, int>, int> m;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        char c;
        int x;
        cin >> c >> x;
        m[make_pair(c, x)] = 1;
    }
    for (auto& c: s) {
        for (int i = 1; i <= 13; i++) {
            if (m[make_pair(c, i)] == 0) cout << c << " " << i << endl;
        }
    }
}


Measured memory_bytes: 3092
a = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
n = int(input())
for i in range(n) :
    b, f, r, v = [int(x) for x in input().split()]
    a[b-1][f-1][r-1] += v
for i, b in enumerate(a) :
    for f in b :
        for r in f :
            print(' %d' % r, end = '')
        print()
    if i < 3 :
        print('#'*20)


Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
    ll N, P;
    string S;
    cin >> N >> P >> S;
    if (P == 2 || P == 5) {
        ll ans = 0;
        for (int i = 0; i < S.size(); i++) {
            if ((S[i]-'0') % P == 0) {
                ans += i+1;
            }
        }
        cout << ans << endl;
        return 0;
    }
    int k[200010] = {};
    for (int i = S.size()-1, e = 1; i >= 0; i--, e = (e*10)%P) {
        k[i] = k[i+1] + e*(S[i]-'0');
        k[i] %= P;
    }
    ll ans = 0;
    map<int, ll> mp;
    for (int i = 0; i <= S.size(); i++) {
        mp[k[i]]++;
    }
    for (auto x: mp) {
        ans += (x.second)*(x.second-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1796
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

min = abs(-60 - 10 ** 5)
for i in range(n):
    temperature = t - h[i] * 0.006
    diff = abs(a - temperature)
    if diff < min:
        min = diff
        index = i + 1

print(index)


Measured memory_bytes: 38256
program main
    integer:: n, k, i, ret
    integer, allocatable:: h(:)
    read*, n, k
    ret=0
    allocate(h(n))
    read*, h(1:n)
    do i = 1, n
        if (h(i) >= k) then
            ret=ret+1
        end if
    end do
    print*, ret

end program

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

int main() {
  string s;
  cin >> s;
  int n = s.length();
  vector<int> e(n, 0);
  vector<int> r(n, 0);
  int p = 0;
  for (int i = 1; i < n; i++) {
    if (s[i - 1] == 'R' && s[i] == 'L') {
      p = i;
    }
    if (s[i] == 'L') {
      int m = i - p;
      m %= 2;
      if (m) r[p - 1]++;
      else r[p]++;
    }
  }
  p = 0;
  for (int i = n - 2; i >= 0; i--) {
    if (s[i] == 'R' && s[i + 1] == 'L') {
      p = i;
    }
    if (s[i] =='R') {
      int m = p - i;
      m %= 2;
      if (m) r[p + 1]++;
      else r[p]++;
    }
  }

  for (int i = 0; i < n; i++) {
    cout << r[i] << " ";
  }
  cout << endl;
  return 0; 
}

Measured memory_bytes: 1408
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;

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

    ll ans = 0;
    for(ll p=1; p*p<N; p++){
        if(N%p==0) {
            ll q = N/p;
            //cout << p << " " << q << endl;
            ll m = p-1;
            ll y = q;
            if(y < m) ans += m;
            m = q-1;
            y = p;
            if(y < m) ans += m;
        }
    }

    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
# cook your dish here
n=int(input())	
a = list(map(int,input().split()))

if n %2 !=0:
    a.append(0)
    n = n+1
    
a.sort()
b = a[::-1]

c=0
d=0


k = 0
while k != n:
   c += b[k]
   d += b[k+1]
   k = k +2
print(c-d)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#define llint long long
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int n, m;
llint x[1001][3];
llint d[1001];
int sg;
llint ans = 0;

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> x[i][0] >> x[i][1] >> x[i][2];
    }

    for (int sg = 0; sg < 8; sg++) {
        for (int i = 0; i < n; i++) {
            d[i] = 0;
            for (int j = 0; j < 3; j++) {
                d[i] += x[i][j] * ((sg & (1 << j))? 1 : -1);
            }
        }
        sort(d, d + n);
        llint cnt = 0;
        for (int i = 0; i < m; i++) {
            cnt += d[n - i - 1];
        }
        ans = max(ans, cnt);
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <cstdint>
#include <vector>
#include <algorithm>

using namespace std;

struct BC{
    uint32_t B;
    uint32_t C;
};

int main()
{
    uint32_t N, M;
    cin >> N >> M;
    vector<uint32_t> A;
    uint64_t sum = 0;
    for(uint32_t i = 0; i < N; ++i){
        uint32_t t;
        cin >> t;
        A.push_back(t);
        sum += t;
    }
    sort(A.begin(), A.end());
    vector<BC> bc;

    for(uint32_t i = 0; i < M; i++){
        uint32_t B, C;
        cin >> B >> C;
        bc.push_back(BC{B, C});
    }
    sort(bc.begin(), bc.end(), [](const BC& x, const BC y){return x.C > y.C;});

    int k = 0;
    for(int i = 0; i < M; i++){
        for(int j = 0; j < bc[i].B; j++){
            if(k >= N || A[k] >= bc[i].C){
                cout << sum << endl;
                return 0;
            }
            sum += bc[i].C - A[k];
            k++;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 1784
import java.util.*;
import java.util.stream.*;
class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        long x,y;
        x = input.nextLong();
        y = input.nextLong();
        long ans;
        ans = GCD(x,y);
        System.out.println(ans);
    }
    public static long GCD(long a, long b){
        long tmp,gcd;
        while (a != 0 && b != 0){
            if (a < b){
                tmp = a;
                a = b;
                b = tmp;
            }
            tmp = a;
            a = b;
            b = tmp%b;
        }
        gcd = Math.max(a,b);
        return gcd;
    }
}


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

int main(void){
    int n; cin >> n;
    string s; cin >> s;

    int cntE=0;
    for(int i=0; i<n; i++) if(s[i]=='E') cntE++;

    int ans=n;
    int tmp=cntE;
    char preChar;
    for(int i=0; i<n; i++){
        if(i!=0 && preChar=='W') tmp++;
        if(s[i]=='E') tmp--;
        preChar=s[i];

        ans=min(ans,tmp);
    }

    cout << ans << endl;
}

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

int main(){																											
	int a, b, c, buf;
	cin >> a >> b >> c;
	if (a > b) {
		buf = a;
		a = b;
		b = buf;
	}
	if (b > c) {
		buf = b;
		b = c;
		c = buf;
	}
	if (a > b) {
		buf = a;
		a = b;
		b = buf;
	}
	cout << a << " " << b << " " << c << endl;

	return 0;
}


Measured memory_bytes: 3080
#include <cstdio>
#include <iostream>
#include <vector>
#include <cstring>
#include <cmath>
using namespace std;

#define maxn 1000005


int main(int argc, char const *argv[])
{
	
	int n,m;
	cin>>n>>m;
	cout<<(1900*m+100*(n-m))*(1<<m)<<endl;

	// int n=20;
	// double sum=2-1/(pow(2,n-1))-n/(pow(2,n));
	// cout<<sum*1900<<endl;



	return 0;
}

Measured memory_bytes: 256
import scala.collection.mutable
object Main extends App {
  import scala.io.StdIn._

  val Array(n, f) = readLine.trim.split(' ').map(_.toInt)
  val map = mutable.Map[(String, String), Int]().withDefaultValue(0)
  for (_ ← 0 until n){
    val items = readLine.trim.split(' ').tail
    items.combinations(2).foreach{
      case Array(a, b) ⇒ if (a < b) map((a, b)) += 1 else map((b, a)) += 1
    }
  }
  val tuples: Seq[((String, String), Int)] = map.toSeq.filter { case (_, c) ⇒ c >= f }
  println(tuples.length)
  if (tuples.nonEmpty) println(
    tuples.map{case (k, _) ⇒ k}.sortWith{case ((a, b), (c, d)) ⇒ if (a == c) b < d else a < c}.map{case (a, b) ⇒ s"$a $b"}.mkString("\n")
  )
}


Measured memory_bytes: 76316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
ll db[1 << 18][19];
int main() {
    init();
    ll N;
    string s;
    cin >> N >> s;
    s = '#' + s;
    ll N2 = 1 << N;
    vl A(2*N2);
    rep(i, N2) cin >> A[i];
    rep(i, N2) A[i]--, A[i + N2] = A[i];

    rep(i, N2) db[i][0] = A[i];
    rep(i,N){
        rep(j,N2){
            ll a = db[j][i], b = db[(j+(1<<i))%N2][i];
            if (a > b) swap(a, b);
            if(s[b-a]=='1'){
                db[j][i + 1] = b;
            }else{
                db[j][i + 1] = a;
            }
        }
    }
    // rep(i,N2){
    //     rep(j, N + 1) cout << db[i][j] << " ";
    //     cout << endl;
    // }
    rep(i,N2){
        cout << db[i][N]+1 << "\n";
    }
    
}


Measured memory_bytes: 46248
#include<cstdio>
#include<iostream>
#include<cmath>
const int N=1e5+5;
using namespace std;
int h[N],n,ans;

int main()
{
//	freopen("1.txt","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&h[i]);
	ans=0;
	int tmp=0;
	for(int i=n;i>=1;--i)
	{
		if(h[i]>h[i-1])	tmp=0;
		else	tmp++;
		ans=max(ans,tmp);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <stack>

using namespace std;
struct user {
    user() {};
    user(int i) : id {i}, fs {}, group {-1} {};
    int id;
    vector<int> fs;
    int group;
};

void add_friends(user *us, int x, int y){
    us[x].fs.push_back(y);
    us[y].fs.push_back(x);
}

void dfs(user* us, int id, int g){
    stack<int> ss {};
    ss.push(id);
    while(ss.size()){
        int p = ss.top();
        ss.pop();
        us[p].group = g;
        vector<int> fs = us[p].fs;
        for(auto x : fs){
            if(us[x].group == g){
                continue;
            }
            ss.push(x);
        }
    }
}

void make_group(user* us, int n){
    int g = 0;
    for(int i = 0; i < n; ++i){
        if(us[i].group < 0){
            dfs(us, i, g);
            ++g;
        }
    }
}

int main(){
    int n, m;
    cin >> n >> m;
    user us[n];
    for(int i = 0; i < n; ++i){
        us[i] = user(i);
    }
    for(int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b;
        add_friends(us, a, b);
    }
    make_group(us, n);
    int q;
    cin >> q;
    for(int i = 0; i < q; ++ i){
        int a, b;
        cin >> a >> b;
        if(us[a].group == us[b].group){
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
}

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

long long int kaijyou(int i){
    long long int answer = 0;
    while(i>0){
        answer += i;
        i--;
    }
    return answer;
}

int main(){
    int N;
    cin >> N;
    vector<string> s(N);
    for(int i=0;i<N;i++){
        cin >> s[i];
        sort(s[i].begin(),s[i].end());
    }
    sort(s.begin(),s.end());

    vector<int> k_count;
    int same;
    for(int i=0;i<N;i++){
        same = 1;
        if(i==N-1) k_count.push_back(1);

        for(int k=i+1;k<N;k++){
            if(s[i] == s[k]){
                same++;
                if(k == N-1){
                k_count.push_back(same);
                i = k;
                }
            }
            else if(s[i] != s[k]){
                k_count.push_back(same);
                i = k-1;
                break;
            }
        }
    }

    long long int answer = 0;
    for(int i=0;i<k_count.size();i++) if(k_count[i]!=1) answer += kaijyou(k_count[i]-1);

    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}


void Main()
{
    ll n, m;
    cin >> n >> m;

    vector<ll> a(n);
    rep(i, n) cin >> a[i];

  //  ll v = a[0];

    ll v = a[0] / 2;
    repi(i, n) {
        ll gcd = GCD(v, a[i]/2);
        v = v * (a[i]/2) / gcd;
    }

    ll cnt = 0;
    ll t = a[0];
    while (t % 2 == 0) {
        t /= 2;
        cnt++;
    }
    ll refCnt = cnt;
    repi(i, n) {
        ll cnt = 0;
        ll t = a[i];
        while (t % 2 == 0) {
            t /= 2;
            cnt++;
        }
        if (cnt != refCnt) {
            put(0);
            return;
        }
    }

    if (m < v) {
        put(0);
        return;
    }

    cout << ((m / v + 1) / 2) << endl;
//    put(1 + (m - v) / (2 * v));

//     ll v = a[0] / 2;
//     repi(i, n) {
//         ll gcd = GCD(v, a[i]);
//         v = v * (a[i]) / gcd;
//     }
//     v /= 2;
//     rep(i, n) {
//         if (v % a[i] != a[i] / 2) {
//             put(0);
//             return;
//         }
//     }

//    put(1 + (m - v) / (2 * v));


}
signed main(){ Main();return 0;}

Measured memory_bytes: 4044
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

struct Node {
	int key;
	Node *prev, *next;
};

Node *head = new Node;

void init() {
	head->next = head;
	head->prev = head;
}

Node* listSearch(int key) {
	Node* cur = head->next;
	while(cur != head && cur->key != key) {
		cur = cur->next;
	}
	return cur;
}

void printList() {
	Node* cur = head->next;
	int isf = 0;
	while(cur != head) {
		if(isf++ > 0)
			printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t) {
	if(t == head) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	delete t;
}

void deleteFirst() {
	deleteNode(head->next);
}

void deleteLast() {
	deleteNode(head->prev);
}

void deleteKey(int key) {
	deleteNode(listSearch(key));
}

void insert(int key) {
	Node *x = new Node;
	x->key = key;
	x->next = head->next;
	head->next->prev = x;
	head->next = x;
	x->prev = head;
}

int main() {
	int key, n, size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for(int i = 0; i < n; i++) {
		scanf("%s%d", com, &key);
		if(com[0] == 'i') {
			insert(key);
			np++;
			size++;
		} else if(com[0] == 'd') {
			if(strlen(com) > 6) {
				if(com[6] == 'F')
					deleteFirst();
				else if(com[6] == 'L')
					deleteLast();
			} else {
				deleteKey(key);
				nd++;
			}
			size--;
		}
	}

	printList();

	return 0;
}


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

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

    long long sum = 0; 
    for (int i = 1; i <= n; i++) {
        if (i % 3 != 0 && i % 5 != 0)
            sum += i;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
using namespace std;
int main(){
 int N;
 string S;
 cin>>N>>S;
 string temp="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
 for(int i=0;i<S.size();i++){
   for(int j=0;j<26;j++){
     if (S.at(i)==temp.at(j))
      cout<<temp.at(j+N);
   }
 }
 cout<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
     public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	int n = scan.nextInt();
    	boolean[][] cards = new boolean[4][13];
    	String s = null;
    	int num;
    	
    	for(int j = 0; j < 4; j++){
    		for(int i = 0; i < 13; i++){
    			cards[j][i] = false;
    		}
    	}
    	
    	for(int i = 0; i < n; i++){
    		s = scan.next();
    		num = scan.nextInt();
    		num--;
    		
    		
    		switch(s){
    			case "S":
    				cards[0][num] = true;
    				break;
    			case "H":
    				cards[1][num] = true;
    				break;
    			case "C":
    				cards[2][num] = true;
    				break;
    			case "D":
    				cards[3][num] = true;
    				break;
    		}
    	}
    	
    	for(int j = 0; j < 4; j++){
    		for(int i = 1; i < 14; i++){
    			if(cards[j][i - 1] == true){   				
    			}else{
    				switch(j){
    				  case 0:
    					  s = "S";
    					  break;
    				  case 1:
    					  s = "H";
    					  break;
    				  case 2:
    					  s = "C";
    					  break;
    				  case 3:
    					  s = "D";
    					  break;
    				}   				
    				System.out.println(s + " " + i);
    			}
    			
    		}
    	}
     }
}

Measured memory_bytes: 26140
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int n, k; scanf("%d %d", &n, &k);
	int res = 0;
	for(int i = 0; i < n; i++){
		int x; scanf("%d", &x);
		res += 2 * min(x, k - x);
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>

using namespace std;
using lli = long long int;

int main() {
	int N, K;
	string s;
	cin >> N;
	cin >> s;
	cin >> K;
	for (int i = 0; i < N; i++) {
		if (s[K - 1] != s[i]) {
			s[i] = '*';
 		}
	}
	cout << s << endl;
	return 0;
}


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

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  int ans = 0;
  if (a == 1 and b == 1) {
    ans += 400000;
  }
  if (a == 1) {
    ans += 300000;
  }
  if (a == 2) {
    ans += 200000;
  }
  if (a == 3) {
    ans += 100000;
  }
  if (b == 1) {
    ans += 300000;
  }
  if (b== 2) {
    ans += 200000;
  }
  if (b == 3) {
    ans += 100000;
  }
  cout << ans;
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列(スタックとしても使える)
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
//ソート クイックだからO(NlogN)
sort(all(list));
sort(all(list), greater<int>());

//配列の最小最大(Nは要素数)
*min_element(all(c))
*max_element(all(c))

//a[0]からa[N]を逆順にする(計算量はO(N))
reverse(all(a));
//listの末尾に要素を追加
list.push_back(10);
//listの末尾から要素を削除
list.pop_back();
//空ですか？
list.empty()



//キュー(待ち行列)
//定義
queue<int> a;
//追加
a.push(x);
//取る
a.pop();
//チェック
a.front()
//サイズ
a.size()
//空ですか
a.empty()



//優先度付きキュー※全部計算量がO(NlogN)あるので注意
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義
priority_queue<int, vector<int>, greater<int>> Q1;
// double 型の要素を持ち、最も大きい値を取り出す形の priority_queueを定義
priority_queue<double, vector<double>, less<double>> Q2;
//追加
a.push(x);
//取る
a.pop();
//一番小さいの教えて下さい
a.top()
//サイズ
a.size()
//空ですか
a.empty()



//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";



//部分文字列
//添字3から5文字
s.substr(3,5)
//添字3から全部
s.substr(3)

//入れ替え
swap(a,b);


*/


Measured memory_bytes: 256
# AtCoder Beginner Contest 122 B - ATCoder
import sys

S = str(input())
target = ['A', 'C', 'G', 'T']

ans = 0
temp_ans = 0
for s in S:
    if s in target:
        temp_ans += 1
    else:
        temp_ans = 0
    ans = max(ans, temp_ans)

print(ans)


Measured memory_bytes: 3060
/*
    Problem 35
    https://onlinejudge.u-aizu.ac.jp/problems/DPL_1_B
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    for (int i = 0; i < N; i++) cin >> v[i] >> w[i];
    vector<int> dp(W+1, 0);
    for (int i = 0; i < N; i++) {
        for (int j = W; j - w[i] >= 0; j--) {
            dp[j] = max(dp[j], dp[j-w[i]] + v[i]);
        }
    }
    cout << dp[W] << '\n';
}


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

int main(){
	int w[30];
	int a,b,tmp;
	int d,n;
	char c;
	cin>>d>>n;
	for(int i=0;i<d;i++)
		w[i]=i+1;
	for(int i=0;i<n;i++){
		cin>>a>>c>>b;
		tmp=w[a-1];w[a-1]=w[b-1];w[b-1]=tmp;
	}
	for(int i=0;i<d;i++)
		cout<<w[i]<<endl;
		
		


}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    vector<int> data(n);
    for (int i = 0; i < n; i++) {
        cin >> data[i];
    }

    int ans = pow(3, n), tmp = 1;
    rep(i, n) {
        if (data[i] & 1) {
            //
        } else {
            tmp *= 2;
        }
    }

    cout << ans - tmp << endl;


    

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define PPC(x) __builtin_popcount((x))
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
using namespace std;

const int maxN = 51;

int x[maxN], y[maxN];
map <pair <int, int>, int> M;

int main()
{
	int n;
	scanf ("%d", &n);
	
	FOR(i, 0, n)
		scanf ("%d%d", x+i, y+i);
		
	FOR(i, 0, n) FOR(j, 0, n) if (i != j)
		M[{x[i] - x[j], y[i] - y[j]}]++;
		
	int z = 0;
	for (auto it : M)
		z = max(z, it.second);
		
	printf("%d\n", n - z);
	
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n,k; cin >> n >> k;
    ll ans=0;
    for(int i=k+1;i<=n;i++){
        int x=n/i;
        int y=n%i;
        //n=i*x+y
        if(y<k) ans+=x*(i-k);
        else{
            ans+=(x+1)*(y-k+1);
            ans+=x*(i-y-1);
        }
        //cout << ans << endl;
    }
    if(k==0) ans-=n;
    cout  << ans << endl;
}



Measured memory_bytes: 256
use std::io::{BufRead, Write};
use std::io;
use std::collections::HashMap;
use std::iter;

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let _: usize = buf.trim_right().parse().unwrap();
    buf.clear();
    input.read_line(&mut buf).unwrap();
    let a: Vec<usize> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
    let mut count: HashMap<usize, usize> = HashMap::new();
    for x in a {
        *count.entry(x).or_insert(0) += 1;
    }
    let result: usize = count
        .iter()
        .map(|(&k, &v)| {
            iter::once(v)
                .chain(count.get(&k.wrapping_sub(1)).cloned())
                .chain(count.get(&(k + 1)).cloned())
                .sum()
        })
        .max()
        .unwrap();
    writeln!(output, "{}", result).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "7
3 1 4 1 5 9 2\n",
            "4\n",
        );
    }
    #[test]
    fn case2() {
        test(
            "10
0 1 2 3 4 5 6 7 8 9\n",
            "3\n",
        );
    }
    #[test]
    fn case3() {
        test(
            "1
99999\n",
            "1\n",
        );
    }
}


Measured memory_bytes: 14588
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;
using ll = long long;

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

int main()
{
    int a,b;
    
    cin >> a >> b;
    
    if ((b-1)%(a-1) == 0){
        cout << (b-1)/(a-1) << endl;
    }
    else {
        cout << (b-1)/(a-1)+1 << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int x[3000];
    int y[3000];
    int i = -1;
    do{
	    i++;
        scanf("%d %d", &x[i], &y[i]);
    }while(x[i] || y[i]);
    for(i = 0; x[i] || y[i]; i++){
        if(x[i] < y[i]) printf("%d %d\n", x[i], y[i]);
        else printf("%d %d\n", y[i], x[i]);
    }
    return (0);
}


Measured memory_bytes: 2036
#include <stdio.h>
int main(){

int x,y;

while(1){
scanf("%d %d",&x,&y);
if(x==0 && y==0)break;
if(x<=y){
printf("%d %d\n",x,y);
}else{
printf("%d %d\n",y,x);
}
}
return 0;
}


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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	int c = 1, d = 0;
	int rx = 0, ry = 0, lx = 0, ly = 0;

	int pre = 1, ppre = 0;
	
	while(1) {

		int now = pre + ppre;

		if (lx <= x && x <= rx && ly <= y && y <= ry) {
			cout << c << endl;
			return 0;
		}

		if (d == 0) {
			rx += now;
		}
		else if (d == 1) {
			ry += now;
		}
		else if (d == 2) {
			lx -= now;
		}
		else if (d == 3) {
			ly -= now;
		}

		//cout << lx << " " << ly << " : " << rx << " " << ry << endl;

		swap(pre, ppre);
		swap(now, pre);

		if (c + 1 == 4) c = 1;
		else c++;

		if (d + 1 == 4) d = 0;
		else d++;
	}
}


Measured memory_bytes: 3088
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define LL long long
using namespace std;
const int Maxn = 110;
struct node {
	int y, next;
}a[Maxn<<1]; int first[Maxn], len;
void ins(int x, int y) {
	len++;
	a[len].y = y;
	a[len].next = first[x]; first[x] = len;
}
int n;
int dep[Maxn], md, mdn, fa[Maxn];
int mxc[Maxn];
void dfs(int x) {
	if(dep[x] > md) md = dep[x], mdn = x;
	for(int k = first[x]; k; k = a[k].next){
		int y = a[k].y;
		if(y == fa[x]) continue;
		fa[y] = x; dep[y] = dep[x]+1;
		dfs(y);
	}
}
int _max(int x, int y) { return x > y ? x : y; }
void dfs1(int x) {
	int ch = 0;
	for(int k = first[x]; k; k = a[k].next){
		int y = a[k].y;
		if(y == fa[x]) continue;
		fa[y] = x; dep[y] = dep[x]+1;
		dfs1(y);
		ch++;
	}
	mxc[dep[x]] = _max(mxc[dep[x]], ch);
}
int main() {
	int i, j, k;
	scanf("%d", &n);
	for(i = 1; i < n; i++){
		int x, y;
		scanf("%d%d", &x, &y);
		ins(x, y); ins(y, x);
	}
	dep[1] = 1; md = 0; fa[1] = 0;
	dfs(1);
	int x = mdn;
	dep[x] = 1; md = 0; fa[x] = 0;
	dfs(x);
	int y = mdn;
	if(dep[y]&1){
		int p = y;
		while(dep[p] != (dep[y]+1)/2) p = fa[p];
		printf("%d ", dep[p]);
		memset(mxc, 0, sizeof(mxc));
		fa[p] = 0; dep[p] = 1;
		dfs1(p);
		LL ans = 1;
		for(i = 1; i <= n; i++){
			if(mxc[i] == 0) break;
			ans = (LL)ans*mxc[i];
		}
		for(k = first[p]; k; k = a[k].next){
			int t = a[k].y;
			memset(mxc, 0, sizeof(mxc));
			fa[p] = t; dep[p] = 1;
			dfs1(p);
			fa[t] = p; dep[t] = 1;
			dfs1(t);
			LL ret = 1;
			for(i = 1; i <= n; i++){
				if(mxc[i] == 0) break;
				ret = (LL)ret*mxc[i];
			}
			if(ret*2 < ans) ans = ret*2;
		}
		printf("%lld\n", ans); 
	} else {
		int p = y;
		while(dep[p] != dep[y]/2+1) p = fa[p];
		printf("%d ", dep[y]/2);
		memset(mxc, 0, sizeof(mxc));
		dep[p] = 1;
		dfs1(p);
		dep[fa[p]] = 1; fa[fa[p]] = p;
		dfs1(fa[p]);
		LL ans = 1;
		for(i = 1; i <= n; i++){
			if(mxc[i] == 0) break;
			ans = (LL)ans*mxc[i];
		}
		printf("%lld\n", ans*2);
	}
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>

using namespace std;

int n,q,M;
int A[20]={0};

bool solve(int i, int m){
    bool res;
    if(m==0){
        return true;
    }
    if(i>=n){
        return false;
    }
    res=solve(i+1,m)||solve(i+1,m-A[i]);
    return res;
}

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%d",&M);
        if(solve(0,M)){
            printf("%s", "yes\n");
        }else{
            printf("%s", "no\n");
        }
    }
}


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

struct node { int u, v, w; }a[70];
int L, cnt, num;

void add(int u, int v, int w) {
    a[++cnt].u = u, a[cnt].v = v, a[cnt].w = w;
}

int main() {
    scanf("%d", &L);
    int tmp = L;
    while (tmp) { num++; tmp >>= 1; }
    for (int i = 1; i < num; i++) {
        add(i, i + 1, 1 << (i - 1)); add(i, i + 1, 0);
    }
    int w = 1 << (num - 1), k = 1;
    while (L != 1) {
        if (L & 1) {
            add(k, num, w); w |= 1 << (k - 1);
        }
        k++; L >>= 1;
    }
    printf("%d %d\n", num, cnt);
    for (int i = 1; i <= cnt; i++)
        printf("%d %d %d\n", a[i].u, a[i].v, a[i].w);
    return 0;
}


Measured memory_bytes: 256