akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define iterator IT
#define SIZ(V) V.size()
#define FS(a) fixed<<setprecision(a)
using namespace std;
namespace STARTER {
	int MAX(int a,int b) {return a>b?a:b;}
	int MIN(int a,int b) {return a<b?a:b;}
	int ABS(int a) {return a<0?-a:a;}
	int GCD(int a,int b) {return !b?a:GCD(b,a%b);}
	int LCM(int a,int b) {return a/GCD(a,b)*b;}
	int QSM(int a,int b,int p) {int ret=1;while (b) (b&1)&&(ret=ret*a%p),a=a*a%p,b>>=1;return ret;}
	int ROUND(double a) {return a+0.5;}
}
using STARTER::MAX;
using STARTER::MIN;
using STARTER::ABS;
using STARTER::GCD;
using STARTER::LCM;
using STARTER::QSM;
using STARTER::ROUND;
const int maxN=2005;int n,x,y,/*dis[maxN][maxN],*/s[maxN][maxN],ans[maxN],t[maxN*maxN];
int main() {
	cin>>n>>x>>y/*,dis[x][y]=1*/;
	//for (int i=1;i<n;i++) dis[i][i+1]=1; 
	//for (int i=1;i<n;i++)
	//	for (int j=i+1;j<=n;j++) dis[i][j]=1;
	for (int i=1;i<n;i++)
		for (int j=i+1;j<=n;j++) //{
			//if (i<=x&&j>=y) s[i][j]=x-i+1+j-y;
			//else s[i][j]=j-i;
			s[i][j]=min(j-i,ABS(x-i)+1+ABS(j-y));
		//}
	//for (int i=1;i<n;i++) {
	//	for (int j=i+1;j<=n;j++) printf("s[%d][%d]=%d ",i,j,s[i][j]);
	//	puts("");
	//}
	for (int i=1;i<n;i++)
		for (int j=i+1;j<=n;j++) t[s[i][j]]++;
	for (int k=1;k<n;k++) cout<<t[k]<<'\n';
}

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

using namespace std;

int main(){
  using ll = int64_t;
  int n;
  cin >> n;
  vector<ll> a(n);
  for(auto&& x:a)cin >> x;
  sort(a.begin(), a.end());
  vector<ll> b(a);
  for(int i=0;i<n-1;i++)
    b[i+1] += b[i];
  int f = 0;
  for(int i=0;i<n-1;i++){
    cerr << i << " " << b[i] << " " << a[i+1] << endl;
    if(2 * b[i] < a[i+1])f = i + 1;
  }
  cout << n-f << endl;
}


Measured memory_bytes: 1792
while true
  m = gets.to_i
  if m == 0
    break
  end

  u = 1
  n = 5
  s = 2
  e = 3
  w = 4
  d = 6

  sum = 1
  i = 0
  while i < m
    x = gets.chomp
    case x
    when "North"
      t = u
      u = s
      s = d
      d = n
      n = t

    when "East"
      t = u
      u = w
      w = d
      d = e
      e = t

    when "West"
      t = u
      u = e
      e = d
      d = w
      w = t

    when "South"
      t = u
      u = n
      n = d
      d = s
      s = t

    when "Right"
      t = s
      s = e
      e = n
      n = w
      w = t

    when "Left"
      t = s
      s = w
      w = n
      n = e
      e = t
    end
    sum += u
    i += 1
  end

  puts sum
end

Measured memory_bytes: 6096
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int main(){
  int n, k;cin>>n>>k;
  vector<int> h(n);
  rep(i, n)cin>>h[i];
  sort(h.begin(), h.end());
  if(n<=k)cout<<0<<endl;
  else{
  	ll ans=0LL;
    rep(i, n-k){
      ans+=h[i];
    }
    cout<<ans<<endl;
  }
}



Measured memory_bytes: 1024
program main
   implicit none
   INTEGER :: n, x, i, j, k
   READ(*, *) n, x
   do i = 0, n
      do j = 0, n - i
        k = n - i - j
        if(10000 * i + 5000 * j + 1000 * k == x) then
            WRITE(*, *) i, j, k
            goto 100
        endif
        enddo
    enddo 
    WRITE(*, *) -1, -1, -1
    100 end
!end program main

Measured memory_bytes: 2856
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 



int main(){
    int N;
    cin >> N;
    int num;
    if(N%2==0){
        num=N/2;
    }
    else{
        num=N/2+1;
    }
    cout << num;
} 


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		String ans = "NG";
		for(int i = a; i <= b; i++) {
			if(i%k==0) {
				ans = "OK";
				break;
			}
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 35800
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

string nextConvert(string s) {
	transform(s.begin(), s.end(), s.begin(), [](char c)->char{
			if (islower(c)) return (c - 'a' + 1) % 26 + 'a';
			else 			return c;
		});
	return s;
}

bool check(string s) {
	vector<string> targets({"the", "this", "that"});

	for (auto &target : targets) {
		if (s.find(target) != string::npos) {
			return true;
		}
	}

	return false;
}

int main(void) {
	string s;

	while (getline(cin, s)) {
		for (int i = 0; i < 26; i++) {
			s = nextConvert(s);
			if (check(s)) {
				cout << s << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
typedef pair<int,int> P;
typedef long long ll;
ll n,m,k,ans;
string s;

int main(){
  int h,w; cin >> h >> w;
  int n; cin >> n;
  int a[n]; rep(i,n) cin >> a[i];
  int ans[h][w];
  int i = 0;
  rep(hi,h){
    rep(wi,w){
      if(hi%2){
        if(a[i] == 0) i++;
        ans[hi][w-1-wi] = i+1;
        a[i]--;
      }else{
        if(a[i] == 0) i++;
        ans[hi][wi] = i+1;
        a[i]--;
      }
    }
  }
  rep(i,h){
    rep(j,w){
      cout << ans[i][j];
      if(j < w-1) cout << " ";
    }
    cout << "\n";
  }
}

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

int main(){
    ll n, m;    cin >> n >> m;
    vector<vector<ll>> island(n);
    for(int i=0; i<m; i++){
        ll a, b;    cin >> a >> b;
        a--;    b--;
        island.at(a).push_back(b);
        island.at(b).push_back(a);
    }
    string ans="IMPOSSIBLE";
    for(auto x: island.at(0)){
        auto itr = find(island.at(x).begin(), island.at(x).end(), n-1);
        if(itr!=island.at(x).end()) ans = "POSSIBLE";
    }
    cout << ans << endl;

}

Measured memory_bytes: 12776
#include <bits/stdc++.h>
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;
#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif


namespace Solver{
using namespace std;

struct Problem{
    LL s;
    vector<LL> dig;
    Problem(LL s):s(s){};

    long long modpow(long long a, long long n,long long mod=MOD){
        long long i=1,ret=1,p=a;
        while(i<=n){
            if(i&n) ret=(ret*p)%mod;
            i=(i<<1);
            p=(p*p)%mod;
        }
        return ret;
    }
    LL calc(LL dl, LL dr, LL sum){
        //calculates the number of possible l, such that len(l)=dl,len(r)=dr.
        for(LL i=dl+1; i<dr; ++i){
            sum-=dig[i-1]*9*i;
        }
        LL g = __gcd(dl,dr);
        if(sum<0 or sum%g!=0)return 0;
        LL lb =1,ub = 9*dig[dl-1];
        while((sum-lb*dl)%dr)lb++;
        while((sum-ub*dl)%dr)ub--;
        if((sum-ub*dl)/dr<1){
            LL diff =1- (sum-ub*dl)/dr;
            diff = (diff+(dl/g)-1)/(dl/g)*(dr/g);
            ub-=diff;
        }
        if((sum-lb*dl)/dr>9*dig[dr-1]){
            LL diff = (sum-lb*dl)/dr-9*dig[dr-1];
            diff = (diff+(dl/g)-1)/(dl/g)*(dr/g);
            lb+=diff;
        }
        return max((ub-lb)/(dr/g)+1,0ll);
    }
    void solve(){
        for(LL i=0,j=1; i<10; ++i,j*=10){
            dig.push_back(j);
        }
        LL ans =0;
        for(int i=1; i<=10; ++i){
            for(int j=i+1; j<=10; ++j){
                ans+=calc(i,j,s);
            }
        }
        ans%=MOD;
        for(int i=1; i<=10; ++i){
            if(s%i==0){
                ans+=max(0ll,9*dig[i-1]-s/i+1);
            }
        }
        ans%=MOD;
        vector<LL> divisors;
        for(int i=1; i*i<=s; ++i){
            if(s%i==0){
                divisors.push_back(i);
                divisors.push_back(s/i);
            }
        }
        sort(divisors.begin(),divisors.end());
        divisors.erase(unique(divisors.begin(),divisors.end()),divisors.end());
        LL ub = (s-1)/10;
        ans+=ub;
        for(auto i :divisors){
            if(i>ub)break;
            int k = s/i;
            ans+= modpow(10,k-1)*9-i;
            ans%=MOD;
            ans=(ans+MOD)%MOD;
        }
        cout << ans << "\n";
    }
};
}

int main(){
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    long long s=0;
    std::cin >> s;
    Solver::Problem p(s);
    p.solve();
    return 0;
}



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

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

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

  vector<pair<ll, ll>> p;
  rep(i,n){
    ll x,y;
    cin >> x >> y;
    p.push_back(make_pair(x,y));
  }

  ll summin=p.at(0).first+p.at(0).second;
  ll summax=p.at(0).first+p.at(0).second;
  rep(i,n){
    ll sum = p.at(i).first+p.at(i).second;
    summin = min(summin, sum);
    summax = max(summax, sum);
  }
  ll dmin=p.at(0).first-p.at(0).second;
  ll dmax=p.at(0).first-p.at(0).second;
  rep(i,n){
    ll sum = p.at(i).first-p.at(i).second;
    dmin = min(dmin, sum);
    dmax = max(dmax, sum);
  }
  
  ll ans1 = summax-summin; 
  ll ans2 = dmax-dmin; 
  cout << max(ans1, ans2);
}

Measured memory_bytes: 7456
def trained(N: int, A: list)->int:
    lightning = 1
    for i in range(N):
        if lightning == 2:
            return i
        lightning = A[lightning-1]
    return -1


if __name__ == "__main__":
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ans = trained(N, A)
    print(ans)


Measured memory_bytes: 7084
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    int h, w; cin>>h>>w;
    vector<string> s(h);
    for(int i=0; i<h; i++) cin>>s[i];

    vector<vector<int>> dp(h, vector<int>(w, inf));
    if(s[0][0] == '#') dp[0][0] = 1;
    else dp[0][0] = 0;

    queue<P> que;
    que.emplace(0, 0);
    while(que.size()){
        int cy, cx; tie(cy, cx) = que.front(); que.pop();
        
        // した
        int ny = cy + 1, nx = cx;
        if(ny < h){
            if(s[cy][cx] == '#'){
                if(dp[ny][nx] > dp[cy][cx]){
                    dp[ny][nx] = dp[cy][cx];
                    que.emplace(ny, nx);
                }
            }
            else{
                if(s[ny][nx] == '.'){
                    if(dp[ny][nx] > dp[cy][cx]){
                        dp[ny][nx] = dp[cy][cx];
                        que.emplace(ny, nx);
                    }
                }
                else{
                    if(dp[ny][nx] > dp[cy][cx] + 1){
                        dp[ny][nx] = dp[cy][cx] + 1;
                        que.emplace(ny, nx);
                    }
                }
            }
        }

        // みぎ
        ny = cy, nx = cx + 1;
        if(nx < w){
            if(s[cy][cx] == '#'){
                if(dp[ny][nx] > dp[cy][cx]){
                    dp[ny][nx] = dp[cy][cx];
                    que.emplace(ny, nx);
                }
            }
            else{
                if(s[ny][nx] == '.'){
                    if(dp[ny][nx] > dp[cy][cx]){
                        dp[ny][nx] = dp[cy][cx];
                        que.emplace(ny, nx);
                    }
                }
                else{
                    if(dp[ny][nx] > dp[cy][cx] + 1){
                        dp[ny][nx] = dp[cy][cx] + 1;
                        que.emplace(ny, nx);
                    }
                }
            }
        }
    }

    cout << dp[h-1][w-1] << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
    #include <filesystem>
    namespace fs = std::filesystem;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

string s;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path __p = __FILE__;
        fs::path __input, __output;
        __input = __output = __p.parent_path();
        __input += string("/input/") + string(__p.stem()) + string(".txt");
        __output += string("/output/") + string(__p.stem()) + string(".txt");
        freopen(__input.c_str(), "r", stdin);
        freopen(__output.c_str(), "w", stdout);
    #endif
    cin >> s;
}

bool solve(){
    string t;
    while(s!=t){
        t = s;
        if(s.substr(max(0,(int)s.length()-7),s.length())=="dreamer") s = t.substr(0,max(0,(int)s.length()-7));
        else if(s.substr(max(0,(int)s.length()-6),s.length())=="eraser") s = t.substr(0,max(0,(int)s.length()-6));
        else if(s.substr(max(0,(int)s.length()-5),s.length())=="dream") s = t.substr(0,max(0,(int)s.length()-5));
        else if(s.substr(max(0,(int)s.length()-5),s.length())=="erase") s = t.substr(0,max(0,(int)s.length()-5));

        // else if(s.substr(0,6)=="eraser") s = t.substr(6);
        // else if(s.substr(0,5)=="dream") s = t.substr(5);
        // else if(s.substr(0,5)=="erase") s = t.substr(5);
    }
    if(s.length()==0) return true;
    return false;
}   

int main()
{
    input();
    cout << (solve()?"YES":"NO") << endl;
    return 0;
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()
l = inputIL()

count = [0]*(N+1)

for i in l:
  count[i] += 1

res = 0
for i in count:
  res += i*(i-1)//2

for i in l:
  print(res-(count[i]-1))

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

  #define vi vector<int>
  #define all(v) v.begin(),v.end()
  #define ll long long int
  #define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define D1(x) {cerr<<" [" <<#x<<": "<<x<<"]";cout << endl;}
  #define D2(x) {cerr<<" [" <<#x<<": ";for(auto it:x)cerr<<it<< " ";cerr<<"] ";cout << endl;}
  const ll inf = 1e18;
  const ll MOD=1e9+7;
  const int maxn=1e5+10;
  vector<int> graph[maxn];
  vector<int> vis(maxn,0);
  void solve(){
     int n;
     cin >> n;
     map<pair<int,int>,ll> mp;
     for(int i=0;i<n-1;i++){
       int a,b,c;
       cin >> a >> b >> c;
       graph[a].push_back(b);
       graph[b].push_back(a);
       mp[{a,b}]=c;
       mp[{b,a}]=c;
     }
     int k,q;
     cin >> q >> k;
     vector<ll> d(n+1,inf);
     d[k]=0;
     set<pair<ll,int>> s;
     s.insert({0LL,k});
     while(!s.empty()){
        int v = s.begin()->second;
        s.erase(s.begin());
        for(int x:graph[v]){
          ll len = mp[{v,x}];
           if(d[v]+ len< d[x]){
             s.erase({d[x],x});
             d[x]=d[v]+len;
             s.insert({d[x],x});
           }
        }
     }
     while(q--){
        int a,b;
        cin >> a >> b;
        ll ans =  d[a]+d[b];
        cout << ans << '\n';
     }

  }


  int main(){
    IOS
       solve();
       cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 27128
#include<iostream>
#include<boost/format.hpp>
#include<string>

using namespace std;

int main(){
  string  str;
  
  cin >> str;

  bool sw=true; 
  std::for_each(str.begin(), str.end(), [&](char ch){
      if( sw ){ cout <<  ch; sw=false; cout.flush(); }
      else    {              sw=true;  }
    } );

  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int GetMinIndex(int *a, int start, int len) {
  int min = a[start], minIndex = start;
  for (int i = start + 1; i < len; i++) {
    if (min > a[i]) {
      min = a[i];
      minIndex = i;
    }
  }
  return minIndex;
}

void Swap(int *a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

void ReadArray(int *a, int len) {
  for (int i = 0; i < len; i++) {
    scanf("%d", &a[i]);
  }
}

void PrintArray(int *a, int len) {
  for (int i = 0; i < len; i++) {
    printf("%d%c", a[i], i + 1 == len ? '\n' : ' ');
  }
}

void InsertionSort(int *a, int len) {
  // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A
  PrintArray(a, len);
  for (int i = 1; i < len; i++) {
    int v = a[i];
    int j = i - 1;
    while (j >= 0 && a[j] > v) {
      a[j + 1] = a[j];
      j--;
      a[j + 1] = v;
    }
    PrintArray(a, len);
  }
}

int main(int argc, char *argv[]) {
  int N;
  scanf("%d", &N);
  int a[N];
  ReadArray(a, N);
  InsertionSort(a, N);

  return 0;
}

Measured memory_bytes: 1828
#include <bits/stdc++.h>
using namespace std;
int a, b, c, x, y;

int main() {
    cin >> a >> b >> c >> x >> y;
    c *= 2;
    int ans = a * x + b * y;
    for (int i = min(x, y); i <= max(x, y); i++) {
        int tmpa = a * max(0, x - i);
        int tmpb = b * max(0, y - i);
        ans = min(ans, c * i + tmpa + tmpb);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>

#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>

#include <list>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF 1<<29
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back
#define _DEBUG(x) cout<<#x<<": "<<x<<endl
#define _DDEBUG(x,y) cout<<#x<<": "<<x<<", "<<#y<<": "<<y<<endl
#define ll long long
#define ull unsigned long long
#define MOD 1000000007

// topological sort p345
// ??????????????°??£?????????
// bfs 

static const int MAX = 100000;

vector<int> G[MAX];
vector<int> out;
bool V[MAX];
int N;

void dfs(int u) {
	V[u] = true;
	for(auto &v : G[u]) {
		if( !V[v] ) {
			dfs(v);
		}
	}
	out.push_back(u);
}


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

	int s, t, M;
	cin >> N >> M;

	REP(i, N) {
		V[i] = false;
	}

	REP(i, M) {
		cin >> s >> t;
		G[s].push_back(t);
	}

	REP(i, N) {
		if( !V[i] ) {
			dfs(i);
		}
	}

#if DEBUG
	cout << "** RESULT **" << endl; // debug
#endif

	reverse(out.begin(), out.end());
	REP(i, N) {
		cout << out[i] << endl;
	}
	return 0;
}

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

using namespace std;
#define ll long long

int K;
ll vals[100010];

ll check(ll m) {
	for (int i = 0; i < K; i++) {
		m = m - (m%vals[i]);
	}
	return m;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// int K;
	cin >> K;
	// ll vals[K];
	for (int i = 0; i < K; i++) {
		cin >> vals[i];
	}
	ll low = 2LL;
	ll high = 1000000000000000000LL;
	while (low < high) {
		ll cur = (low+high+1LL)/2LL;
		if (check(cur) > 2LL) {
			high = cur-1;
		}
		else {
			low = cur;
		}
	}
	// cout << "low   " << low << endl;
	if (check(low) != 2LL) {
		cout << -1 << endl;
		cin >> K;
		return 0;
	}
	ll l1 = 2LL;
	ll h1 = low;
	while (l1 < h1) {
		ll mid = (l1+h1)/2LL;
		// cout << "mid   " << mid << endl;
		if (check(mid) == 2LL) {
			h1 = mid;
		}
		else {
			l1 = mid+1LL;
		}
	}
	ll l2 = low;
	ll h2 = 1000000000000000000LL;
	while (l2 < h2) {
		ll mid = (l2+h2+1LL)/2LL;
		if (check(mid) == 2LL) {
			l2 = mid;
		}
		else h2 = mid-1LL;
	}
	cout << l1 << " " << l2 << endl;
	cin >> K;
}

Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }

    #[allow(dead_code)]
    pub fn get3<S: FromStr, T: FromStr, U: FromStr>() -> (S, T, U)
    where
        <S as FromStr>::Err: Debug,
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}

#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn main() {
    let mut abc: Vec<usize> = util::gets();
    let mut count = 0;

    while abc.iter().all(|&x| x % 2 == 0) && !abc.iter().all(|&x| x == 0) {
        abc.sort();

        let a0 = abc[0];
        for i in 0..3 {
            abc[i] -= a0;
        }

        let a = abc[0];
        let b = abc[1];
        let c = abc[2];

        abc[0] = (b + c) / 2;
        abc[1] = (a + c) / 2;
        abc[2] = (a + b) / 2;

        count += 1;
    }

    if abc.iter().all(|&x| x == 0) {
        println!("-1");
    } else {
        println!("{}", count);
    }
}


Measured memory_bytes: 4352
import sys
def input():
    return sys.stdin.readline()[:-1]

import math

def pos(k, l):
    r = math.radians(k)
    x = l * math.cos(r)
    y = l * math.sin(r)
    return(x,y)

def test():
    # n,m,q = map(int, input().split())
    a,b,h,m = [int(i) for i in input().split()]
    hx, hy = pos(((h*60+m)%720)/2, a)
    mx, my = pos((m % 60)*6, b)
    return(math.sqrt((hx-mx)**2 + (hy-my)**2))


print(test())

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    string S;
    string T;
    ll index = -1;
    cin >> S;
    cin >> T;
    rep(i, S.size() - T.size() + 1) {
        bool flag = true;
        string temp = string(S.begin() + i, S.begin() + i + T.size());
        rep(j, T.size()) {
            if(temp[j] != T[j] && temp[j] != '?') flag = false;
        }
        if(flag) index = i;
    }
    if(index == -1) {
        cout << "UNRESTORABLE";
    } else {
        rep(i, T.size()) S[index + i] = T[i];
        iter(c, S) if(c == '?') c = 'a';
        cout << S;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
Ts = list(map(int,input().split()))
M = int(input())
Ps =[list(map(int,input().split())) for i in range(M)]
s = sum(Ts)
for i in range(M):
  index = Ps[i][0]-1
  diff = Ps[i][1] - Ts[index]
  print(s+diff)
  


Measured memory_bytes: 8996
#include <cstdio>
int main() {
  int n[4];
  for (int i = 0; i < 4; i++) scanf("%d", n + i);
  int c[4] = {0, 0, 0, 0};
  for (int i = 0; i < 4; i++) {
    if (n[i] == 1) c[0]++;
    else if (n[i] == 9) c[1]++;
    else if (n[i] == 7) c[2]++;
    else if (n[i] == 4) c[3]++;
  }
  bool flag = true;
  for (int i = 0; i < 4; i++) {
    if (c[i] == 0) flag = false;
  }
  if (flag) puts("YES");
  else puts("NO");
}

Measured memory_bytes: 128
M,D = map(int,input().split())
cnt = 0
lists = []
for i in range(1,M+1):
    for j in range(10,D+1):
        if i == j:
            pass
        else:
            m = str(i)
            d = str(j)
            d10 = int(d[0])
            d1 = int(d[-1])
            
            if d1 >= 2 and d10 >= 2 and  int((d1*d10)) == int(m):
                cnt += 1

        
print(cnt)


Measured memory_bytes: 3060
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long int
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(),v.rend() //reverse
#define vl vector<long long>v(n);
#define mii unordered_map<ll,ll>
#define pb push_back
double pi = 2*acos(0.0);
//ll power(ll a,ll b){ ll res=1;while(b){if(b&1)res=res*a;b=b/2; a=(a*a); }return res;}

      
 int main()
 {
       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
       ll tst;
       tst=1;
       //cin>>tst;
    
       while(tst--)
       {
ll n;
cin>>n;
map<string,int>mp;
while(n--)
{
string s;
cin>>s;
mp[s]++;
}
cout<<"AC"<<" "<<"x"<<" "<<mp["AC"]<<endl;
cout<<"WA"<<" "<<"x"<<" "<<mp["WA"]<<endl;
cout<<"TLE"<<" "<<"x"<<" "<<mp["TLE"]<<endl;
cout<<"RE"<<" "<<"x"<<" "<<mp["RE"]<<endl;


     
       }
 }

Measured memory_bytes: 3572
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			solveA();
			//			 solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int n = nextInt();
		int k = nextInt();

		if (k==1) {
			out.println(0);
			return;
		}
		int tmp = (n-(k-1)) -1;
		out.println(tmp);
	}

	private void solveB() {
		int n = nextInt();

		out.println("");
	}

	private void solveC() {
		int n = nextInt();

		out.println("");
	}

	private void solveD() {
		int n = nextInt();

		out.println("");
	}

	private void solveE() {
		int n = nextInt();

		out.println("");
	}

	private void solveF() {
		int n = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

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

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

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

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

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

int main()
{
	vector<int> k(10), w(10);
	for (int i = 0; i < 10; ++i) cin >> w[i]; 
	for (int i = 0; i < 10; ++i) cin >> k[i];
	sort(k.begin(), k.end());
	sort(w.begin(), w.end());
	cout << w[9]+w[8]+w[7] << " " << k[9]+k[8]+k[7] << endl;
	return 0;
}

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

const int maxn = 2e5 + 5;
char str[maxn];
int a[maxn], b[maxn];
int n, k, c, cnt = 0, tot = 0;
int main(){
	scanf("%d%d%d",&n,&k,&c);
	scanf("%s", str+1);
	for(int i=1;i<=n;i++){
		if(str[i] == 'o' && cnt == 0){
			a[++tot] = i; cnt = c+1;
		}
		if(tot == k) break;
		if(cnt) cnt --;
	}
	tot = k, cnt = 0;
	for(int i=n;i;i--){
		if(str[i] == 'o' && cnt == 0){
			b[tot--] = i; cnt = c+1;
		}
		if(tot == 0) break;
		if(cnt) cnt --;
	}
	for(int i=1;i<=k;i++){
		if(a[i] == b[i]) printf("%d\n", a[i]);
	}
	return 0;
}

Measured memory_bytes: 3200
import sys

def lcm(c, d):
    c, d = max(c, d), min(c, d)
    cd = c * d
    while c % d > 0:
        c, d = d, c % d
    return cd // d

def solve():
    A, B, C, D = map(int, input().split())
    cd = lcm(C, D)
    divC = B // C - (A - 1) // C
    divD = B // D - (A - 1) // D
    divCD = B // cd - (A - 1) // cd
    print((B - A + 1) - (divC + divD - divCD))

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (int &x : a) cin >> x;
  using T = tuple<int, int, int>;
  vector<T> b(q);
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    b[i] = {l - 1, r - 1, i};
  }
  sort(b.begin(), b.end(), [](const T &x, const T &y) {
    int xl, xr, xi;
    int yl, yr, yi;
    tie(xl, xr, xi) = x;
    tie(yl, yr, yi) = y;
    xl /= 708;
    yl /= 708;
    if (xl != yl) return xl < yl;
    else return xr < yr;
  });

  int l = 0, r = 0;

  vector<int> cnt(n + 1);
  int ta = 0;
  auto add = [&](int i) {
    if (++cnt[a[i]] == 1) {
      ++ta;
    }
  };
  auto del = [&](int i) {
    if (--cnt[a[i]] == 0) {
      --ta;
    }
  };

  add(0);

  vector<int> ans(q);
  for (auto &x : b) {
    int ql, qr, qi;
    tie(ql, qr, qi) = x;
    while (ql < l) add(--l);
    while (qr > r) add(++r);
    while (ql > l) del(l++);
    while (qr < r) del(r--);
    ans[qi] = ta;
  }

  for (int x : ans) {
    cout << x << endl;
  }
  return 0;
}



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

using namespace std;

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

    vector<int> A(N);
    vector<long long> B(N + 1);  // 累積和用
    int mod = 1000000007;        // 10億7

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

    long ans = 0;
    for(int i = 0; i < N; i++) {
        long long sum = (B[N] - B[i + 1]) % mod;
        ans += A[i] * sum;
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5568
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) #x << "=" << x << "  " <<
using namespace std;
using ll = long long;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MXN = 1e5 + 5;
const int MOD = 1e9 + 7;
int add(int x, int y) { return (x += y) < MOD ? x : x - MOD; }
int sub(int x, int y) { return (x -= y) >= 00 ? x : x + MOD; }
int mul(int x, int y) { return (ll) x * y % MOD; }
int pwr(int x, int p) {
  if (p == 0) return 1;
  if (p % 2) return mul(x, pwr(x, p - 1));
  return pwr(mul(x, x), p / 2);
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  vector<int> list;
  for (int i = 0; i < n; ++i) {
    int num;
    cin >> num;
    if (num - 1 > (int) list.size()) {
      cout << "-1\n";
      return 0;
    }
    list.insert(list.begin() + num - 1, num);
  }
  for (int it : list) {
    cout << it << ' ';
  }
}


Measured memory_bytes: 256
from sys import stdin
n = int(stdin.readline().rstrip())
a = [0]*n
for x in range(n):
   a[x] = int(stdin.readline().rstrip())

a.sort(reverse = True)

sum = 1

for x in range(n-1):
   if a[x] > a[x+1]:
      sum += 1
print(sum)

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using ll = long double ;
using namespace std;
int main()
{
    ll a , b, c; cin >> a >> b >> c;
   ll d = c - a - b; ll e = 4 * a * b ; ll f = d * d;
   if(d > 0 && (e < f))
   {
       cout << "Yes";
   }
   else
   {
       cout << "No";
   }

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;
int n,k,q,a[20005],b[20005],c[20005],tmp[20005],tot,ans;
void clr(int l,int r)
{
	int i;
	int len=(r-l+1);
	for(i=l;i<=r;++i) tmp[i]=a[i];
	sort(tmp+l,tmp+r+1);
	while(len>=k)
	{
		c[++tot]=tmp[l];
		++l,--len;
	}
}
void work(int x)
{
	tot=0;
	int i;
	for(i=1;i<=2000;++i) c[i]=2e9+7;
	int l=1,r=1;
	while(l<=n)
	{
		while(a[r]>=x&&r<=n) ++r;
		--r;
		if(r<l)
		{
			++l,r=l;
			continue;
		}
		clr(l,r);
		l=r+1;
		++r;
	}
	sort(c+1,c+tot+1);
	ans=min(ans,c[q]-x);
}
int main()
{
	int i;
	ans=1e9+7;
	scanf("%d%d%d",&n,&k,&q);
	for(i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	for(i=1;i<=n;++i) work(b[i]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
fun main(args:Array<String>) {
    val (n,d) = readLine()!!.split(" ").map { it.toInt() }
    pointList.addAll((1..n).map { readLine()!!.split(" ").map { it.toInt() } })
    var ans = 0
    for(i in (0 until pointList.size - 1)) {
        for(j in (i+1 until pointList.size)) {
            if(dist(pointList[i], pointList[j])) {
                ans++
            }
        }
    }
    println(ans)
}

val pointList = mutableListOf<List<Int>>()
fun dist(pos1:List<Int>, pos2:List<Int>):Boolean {
    var dist = 0
    for(i in pos1.indices) {
        dist += (pos1[i]-pos2[i])*(pos1[i]-pos2[i])
    }
    val tmp = Math.sqrt(dist.toDouble()).toInt()
    return tmp*tmp == dist
}


Measured memory_bytes: 37812
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	int *h = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	sort(h, h + n, greater<int>());
	int deltaMin = 1e9 + 1;
	for (int i = 0; i <= (n - k); i++) {
		deltaMin = min(deltaMin, h[i] - h[i + k-1]);
	}
	cout << deltaMin << endl;
	return 0;
}

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

using namespace std;

using ll = long long;

#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()

int main()
{
    int A,B,C;
    cin >> A >> B >> C;
    cout << max(0,B+C-A) << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  int n, m;
  readf("%d %d\n", &n, &m);

  auto que = BinaryHeap!(int[], "a < b")(new int[100000], 0);

  auto a = readln.chomp.split.to!(int[]);
  foreach (i; 0..n) {
    que.insert(a[i]);
  }

  while (m--) {
    auto x = que.front;
    que.popFront;
    que.insert(x/2);
  }

  long sum;
  while (!que.empty) {
    sum += que.front;
    que.popFront;
  }
  sum.writeln;
}


Measured memory_bytes: 4376
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>

#define INF 1e9
#define nmax 400010
#define fst first
#define snd second
#define pb push_back
#define SZ(x) ((int)(x.size()))

#define MOD 1000000007

#define MOD1 998244353
#define MOD2 666013
#define P1 255
#define P2 2059

using namespace std;

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

int n, k;
int pw1[nmax], iv1[nmax];

int my_pow(int x, int p)
{
    int sol = 1;

    while (p > 0) {

        if (p % 2 == 1) sol = (1LL * sol * x) % MOD;

        p /= 2;
        x = (1LL * x * x) % MOD;
    }

    return sol;
}

int comb(int n, int k)
{
    return (1LL * ((1LL * pw1[n] * iv1[k]) % MOD) * iv1[n - k]) % MOD;
}

int main()
{
    scanf("%d %d", &n, &k);

    pw1[0] = iv1[0] = 1;

    for (int i = 1; i <= 2 * n; i++) {

        pw1[i] = (1LL * pw1[i - 1] * i) % MOD;

        iv1[i] = my_pow(pw1[i], MOD - 2);
    }

    int answer = comb(2 * n - 1, n - 1);

    for (int i = k + 1; i < n; i++) {

        // we have i zeroes
        // n - i rooms left

        int f = comb(n, i);
        
        int x = n - i;

        int n1 = n - 1; // the sum is the same
        int k1 = x - 1;

        int s = comb(n1, k1);

        answer = (answer + MOD - (1LL * f * s) % MOD) % MOD;
    }

    printf("%d", answer);

    // IMPORTANT!!!!!
    // Are you missing something????
    // check limits, int or ll

    return 0;
}

Measured memory_bytes: 3328
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int N;
int A[1234567];
string S;

int twoc(int x) {
	int res = 0;
	while (x >= 1) {
		x /= 2;
		res += x;
	}
	return res;
}

bool isodd(int n, int r) {
	if (r == 0 || r == n)return true;
	int ow = twoc(n) - twoc(r) - twoc(n - r);
	if (ow > 0) {
		return false;
	}
	else {
		return true;
	}
}

int solve() {
	int res = 0;
	for (int i = 0; i < N; ++i) {
		if (isodd(N - 1, i)) {
			res += A[i];
		}
	}
	return res % 2;
}

int main() {
	cin >> N;
	cin >> S;
	bool one = false;
	for (int i = 0; i < N; ++i) {
		A[i] = S[i] - '1';
		if (A[i] == 1)one = true;
	}
	if (!one) {
		for (int i = 0; i < N; ++i) {
			A[i] /= 2;
		}
	}
	int ans = solve();
	if (one) {
		cout << ans << endl;
	}
	else {
		cout << ans * 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 5380
num_of_cities, start = gets.split.map(&:to_i)
cities = (gets.split.map(&:to_i) << start).sort

answer = cities[1] - cities[0]

for i in 1 .. num_of_cities - 1

  answer = answer.gcd(cities[i + 1] - cities[i])

end

puts answer


Measured memory_bytes: 10096
class SegmentTree:
    def __init__(self, iterable, op, e):
        n = len(iterable)
        self._op = op
        self._e = e
        self._size = n
        t = 1 << (n - 1).bit_length()
        self._offset = t - 1
        self._data = [e] * (t * 2 - 1)
        self._data[self._offset:self._offset + self._size] = iterable
        for i in range(self._offset - 1, -1, -1):
            self._data[i] = op(self._data[i * 2 + 1], self._data[i * 2 + 2])
 
    def __getitem__(self, key):
        return self._data[self._offset + key]
 
    def __setitem__(self, key, value):
        op = self._op
        data = self._data
        i = self._offset + key
        data[i] = value
        while i >= 1:
            i = (i - 1) // 2
            data[i] = op(data[i * 2 + 1], data[i * 2 + 2])
 
    def query(self, start, end):
        op = self._op
        res = self._e
        l = self._offset + start
        r = self._offset + end
        while l < r:
            if l & 1 == 0:
                res = op(res, self._data[l])
            if r & 1 == 0:
                r -= 1
                res = op(res, self._data[r])
            l = l // 2
            r = r // 2
        return res
    
    def getTop(self):
        return self._data[0]
 
N,K=map(int,input().split())
A = []
for i in range(N):
  a = int(input())
  A.append(a)
 
A_MAX = 300000
dp = [0]*(A_MAX+5)
 
st = SegmentTree(dp,max,0)

for i in range(N):
  s = max(A[i]-K, 0)
  e = min(A[i]+K+1, A_MAX+1)
  st[A[i]] = st.query(s, e) + 1
print(st.getTop())


Measured memory_bytes: 143308