akhauriyash/Code-Regression huggingface dataset:
// AOJ 1221 Numoeba
// 2018.2.16 bal4u

#include <stdio.h>
#include <string.h>

#define MAGIC 20

typedef struct { int val; short w, node[MAGIC]; int mk; } T;
T cell[5000]; int top;

int root;
int tm, maxval, maxid, cells, maxcells;

int new(int val, int par)
{
	T *t = cell + top++;
	cells++;
	t->val = val, t->w = 1, t->node[0] = par, t->mk = tm;
	return top-1;
}

int numbosome(int val, int mode)
{
	int k = (val+1)>>1;

	if (!mode) {
		val += k;
		while (!(val & 1)) val >>= 1;
		if (val > 12345678) val -= 12345678;
	} else {
		val = k;
		if (!(val & 1)) val += mode;
	}
	return val;
}

int child(int par, int id)
{
	int i, chi, n = 0;
	for (i = 0; i < cell[id].w; i++) {
		int x = cell[id].node[i];
		if (x == par || cell[x].val == 0) continue;
		n++, chi = x;
	}
	if (n == 0) return 0;
	if (n == 1) return chi;
	return -1;
}

void set_child(int id, int chi)
{
	int i;
	for (i = 0; i < cell[id].w; i++) {
		if (cell[cell[id].node[i]].val == 0) {
			cell[id].node[i] = chi;
			return;
		}
	}
	cell[id].node[cell[id].w++] = chi;
}

void update(int par, int id)
{
	int i, val, chi, leaf_bonus;

	if (cell[id].val == 0 || cell[id].mk == tm) return;
	cell[id].mk = tm;

	chi = child(par, id);

	val = numbosome(cell[id].val, 0);
	if (val > maxval) maxid = id, maxval = val;
	else if (val == maxval) maxid = 0;

	if (val > cell[id].val && chi == 0) {
		leaf_bonus = new(numbosome(val, 1), id);
		set_child(id, leaf_bonus);
	}

	if (val > 1) {
		cell[id].val = val;
		cells++;
		for (i = 0; i < cell[id].w; i++) update(id, cell[id].node[i]);
	} else {
		if (par == 0) return;

		cell[id].val = 0;
		if (chi <= 0) return;

		for (i = 0; ; i++) {
			if (cell[par].node[i] == id) { cell[par].node[i] = chi;	break; }
		}
		for (i = 0; ; i++) {
			if (cell[chi].node[i] == id) { cell[chi].node[i] = par;	break; }
		}
		update(par, chi);
	}
}

int main() 
{
	int k;

	while (scanf("%d", &k) && k) {
		memset(cell, 0, sizeof(cell));
		top = 1, root = top++, maxcells = 1;
		cell[root].val = k;
		for (tm = 1; ; tm++) {
			maxval = 0, maxid = 0, cells = 0;
			update(0, root);
			if (cells == 0) break;
			if (maxid > 0) {
				int leader_bonus;
				root = maxid;
				leader_bonus = new(numbosome(cell[root].val, -1), root);
				set_child(root, leader_bonus);
			}
			if (cells > maxcells) maxcells = cells;
		}
		printf("%d %d\n", tm, maxcells);
	}
	return 0;
}



Measured memory_bytes: 1984
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		int k = sc.nextInt();
		if (k == 0)
			System.out.println(2);
		else if (k == 1)
			System.out.println(1);
		else{
		long a = 2, b = 1;

		for (int i = 2; i <= k; i++) {
			long tmp = a + b;
			a = b;
			b = tmp;
		}
		System.out.println(b);
		}
	}

}

Measured memory_bytes: 23764
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
    for (T &in : v) is >> in;
    return is;
}

int main(void) {
    using std::cin;
    using std::cout;
    using std::endl;
    using std::size_t;
    using std::sort;
    using std::vector;

    int n, m;  // <=1e5
    cin >> n >> m;
    vector<int> a(n);
    cin >> a;

    sort(a.begin(), a.end());

    long long removed_sum = 0LL;
    for (int i = 1; i <= m; ++i) {
        int ab = a.back() / 2;
        a.pop_back();

        decltype(a)::iterator it = std::lower_bound(a.begin(), a.end(), ab);
        if (a.end() - it < m - i) {
            ++i;
            ab /= 2;
            it = std::lower_bound(a.begin(), a.end(), ab);
        }
        a.insert(it, ab);  // a.end()-itの時間計算量(線形)
    }

    long long sum = std::accumulate(a.begin(), a.end(), 0LL);

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

// #include <unordered_set>
// #include <unordered_map>

#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

#define pb push_back
#define mp make_pair

int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}

typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;

#define int long long

const int MAX_V=1000;
int dist[MAX_V][MAX_V];
int n,m;
bool out=false;
bool use[MAX_V][MAX_V];


void init(int n){
	REP(i,n){
		REP(j,n){
			use[i][j]=true;
		}
	}
}
 
void hoge_warshall_floyd(int V){
    for(int k=0;k<V;k++){
        for(int i=0;i<V;i++){
            for(int j=0;j<V;j++){
            	// dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            	if(dist[i][j]>dist[i][k]+dist[k][j]){
            		out=true;
            	}
            }
        }
    }
}
 
 
signed main(){



	
    
    cin>>n;
    init(n);
    int hoge;
 
//init
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j==i)dist[i][j]=0;
            else dist[i][j]=INF;
        }
    }
 
    for(int i=0;i<n;i++){
    	for(int j=0;j<n;j++){
    		cin>>hoge;
    		dist[i][j]=hoge;
    	}  
    }

 
    hoge_warshall_floyd(n);

    if(out){
    	cout<<-1<<endl;
    	return 0;
    }


    int sum=0;

    REP(i,n){
    	REP(j,n){
    		sum+=dist[i][j];
    	}
    }


    REP(i,n){
    	REP(j,n){
    		REP(k,n){

    			if(k==i||k==j)continue;
    			if(dist[i][j]<dist[i][k]+dist[k][j])continue;
    			use[i][j]=false;
    			break;
    		}
    	}
    }

   // REP(i,n){
   // 		REP(j,n){
			// cout<<use[i][j]<<" ";
   // 		}cout<<endl;
   // }


   REP(i,n){
   	REP(j,n){
   		if(!use[i][j]){
   			sum-=dist[i][j];
   		}
   	}
   }
    cout<<sum/2<<endl;
      
    return 0;
}

Measured memory_bytes: 3456
#include<stdio.h>
#include<stdlib.h>

typedef struct node{
  struct node *p;
  struct node *l;
  struct node *r;
  int key; 
}Node;

Node *Root;
Node *NIL;

void insert(int in){
  Node *N=NIL;
  Node *r=Root;
  Node *z;

  z=(Node*)malloc(sizeof(Node));

  z->key=in;
  z->l=NIL;
  z->r=NIL;

  while(r!=NIL){
    N=r;
    if(in < r->key) r=r->l; 
    else r=r->r;
  }
  z->p=N;

  if(N==NIL)Root=z;
  else{
    if(in < N->key) N->l=z;  
    else N->r=z;  
  } 
}

void iO(Node *r1){
  if(r1==NIL)return;
  iO(r1->l);
  printf(" %d",r1->key);
  iO(r1->r);
}

void pO(Node *r2){
  if(r2==NIL)return;
  printf(" %d",r2->key);
  pO(r2->l);
  pO(r2->r);
}

int main(){
  int i,n,x;	scanf("%d",&n);
  char com[10];

  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);

    }else{
      iO(Root);
      printf("\n");
      pO(Root);
      printf("\n");
    }
  }

  return 0;
}







Measured memory_bytes: 25140
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <set>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long ll;

#define forn(i, n) for(int i = 0; i < (int)(n);++i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define fi first
#define se second
#define pb push_back
#define pll pair<ll,ll>
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vb vector<bool>
#define vvi vector<vi>
#define vpll vector<pll>
#define vll vector<ll>
#define vvll vector<vll>
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

ll n;

void fastik() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

//ifstream &cin
void solve(){

}

ll get(ll x){
    return (n+x-1)/x;
}

bool check(char c){
    return c == 'A' || c == 'C' || c == 'G' || c =='T';
}

int main() {
    fastik();
    ll n,q;cin>>n>>q;
    string s; cin >> s;
    vpll ac;
    vll a(sz(s),0);
    fore(i,1,n-1){
        if(s[i] == 'C' && s[i-1] == 'A'){
            a[i] = a[i-1] + 1;

        }
        a[i+1] = a[i];
    }
    forn(i,q){
        ll l,r;cin >> l >>r;
        l--;r--;

        cout <<a[r] - a[l] << "\n";
    }


}

Measured memory_bytes: 1872
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

//nCr mod m
#define MOD 998244353
#define M 220000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
vi dp(1000,-1);
int f(int a){
	if(dp[a]+1)return dp[a];
	return dp[a]=powmod(fact[a],MOD-2,MOD);
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin>>n;
	vi a(n),b(n),c(n);
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	rep(i,n)c[i]=i+1;
	int x,y,i=0;
	do{
		i++;
		if(a==c)x=i;
		if(b==c)y=i;
	}while(next_permutation(all(c)));
	cout<<abs(y-x)<<endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i=0;i<N;i++){
    cin >> d[i];
  }
  
  sort(d.begin(), d.end());
  d.erase(unique(d.begin(), d.end()), d.end());
  
  int count = 0;
  for(int i=0;i<d.size();i++){
    count++;
  }
  cout << count << endl;  
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,j,k;
  while(scanf("%d",&i)!=EOF){
    for(j=0,k=i;j<10;j++){
      k>>=1;
      if((i>>j)&1){
	printf("%d",1<<j);
	if(k==0) printf("\n");
	else printf(" ");
      }
    }
  }
  return 0;
}

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

ll solve(vector<ll>& A) {
    int n = A.size();
    vector<ll> C(n+1);
    for ( int i = 0; i < n; i++ ) {
        C[i+1] = C[i] + A[i];
    }

    auto diff = [](ll m1, ll m2) {
        return max(m1,m2) - min(m1,m2);
    };

    int i1,i2,i3;
    ll ans = 1LL<<60;
    for ( i2 = 2; i2 <= n-2 ; i2++ ) {
        i1 = lower_bound(C.begin(), C.end(), (C[i2]+1)/2) - C.begin();
        if ( i1 >= 2 ) {
            if ( diff(C[i2]-C[i1-1],C[i1-1]-C[0]) < diff(C[i2]-C[i1],C[i1]-C[0]) ) i1--;
        }
        if ( i1 <= 0 ) i1 = 1;
        if ( i1 >= i2 ) i1 = i2-1;

        i3 = lower_bound(C.begin(), C.end(), C[i2] + ((C[n]-C[i2])+1)/2 ) - C.begin();
        if ( i3 > n ) i3 = n;
        if ( i3 >= i2+2 ) {
            if ( diff(C[n]-C[i3-1],C[i3-1]-C[i2]) < diff(C[n]-C[i3],C[i3]-C[i2]) ) i3--;
        }
        if ( i3 <= i2 ) i3 = i2+1;
        if ( i3 >= n ) i3 = n-1;

        ll x = max({C[i1],C[i2]-C[i1],C[i3]-C[i2],C[n]-C[i3]}) - min({C[i1],C[i2]-C[i1],C[i3]-C[i2],C[n]-C[i3]});
        if ( ans > x ) ans = x;
    }

    return ans;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }    
    auto ans = solve(A);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3328
#!/usr/local/gnu/bin/bash
n=`sed -r "s/^0+//"`
n1=$((n/100))
n2=$((n%100))
if((1<=n1&&n1<=12))
then
    ((1<=n2&&n2<=12)) && echo AMBIGUOUS || echo MMYY
else
    ((1<=n2&&n2<=12)) && echo YYMM || echo NA
fi


Measured memory_bytes: 548
import sys
input=sys.stdin.readline
sx,sy,tx,ty=map(int,input().split())
n=int(input())
p=[(sx,sy,0)]
for _ in range(n):
  x,y,r=map(int,input().split())
  p.append((x,y,r))
p.append((tx,ty,0))
n+=2
edge=[[]for _ in range(n)]
for i in range(n-1):
  for j in range(i+1,n):
    sx,sy,sr=p[i]
    tx,ty,tr=p[j]
    t=(abs(sx-tx)**2+abs(sy-ty)**2)**0.5
    c=max(0,t-(sr+tr))
    edge[i].append((j,c))
    edge[j].append((i,c))
from heapq import heappop,heappush
inf=10**20
ans=[inf]*n
ans[0]=0
root=[-1]*n
h=[(0,0)]
while h:
  c,v=heappop(h)
  if ans[v]<c:continue
  for u,t in edge[v]:
    if c+t<ans[u]:
      ans[u]=c+t
      root[u]=v
      heappush(h,(c+t,u))
print(ans[n-1])


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

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

//Union Find
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> cnt;

    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); cnt.resize(n);
        for (int i = 0; i < n; ++i) {
          par[i] = i;
          rank[i] = 0;
          cnt[i] = 1;}
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        cnt[x] += cnt[y];
        return true;
    }
};


int main() {
  ll N,M;
  cin >> N >> M;
  
  vector<vector<int>> ab(M,vector<int> (2));
  rep(i,M) {
    cin >> ab[i][0] >> ab[i][1];
    ab[i][0]--;ab[i][1]--;}
  reverse(ab.begin(),ab.end());

  UnionFind uf = UnionFind(N);
  vector<ll> ans(M);
  ans[0] = N*(N-1)/2;

  // for (auto k:uf.par) cout << uf.cnt[uf.root(k)] << ' ';

  rep(i,M-1) {
    ans[i+1] = ans[i];
    if (uf.issame(ab[i][0],ab[i][1])) continue;
    ll t1,t2;
    t1 = uf.cnt[uf.root(ab[i][0])];
    t2 = uf.cnt[uf.root(ab[i][1])];
    ans[i+1] -= t1*t2;
    uf.merge(ab[i][0],ab[i][1]);
  }
  reverse(ans.begin(),ans.end());
  rep(i,M) cout << ans[i] << endl;
}

Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
int main (void)
{
    long long int a,b,v,w,t;
    cin>>a>>v;
    cin>>b>>w;
    cin>>t;
    long long int temp=llabs(a-b);
    if(temp<=t*(v-w))
    cout<<"YES";
    else
    cout<<"NO";
}


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

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;

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

  vector<ll> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  vector<ll> p2 = p;
  sort(p2.begin(), p2.end());

  int cnt = 0;

  for (int i = 0; i < N; i++) {
    if (p[i] != p2[i]) cnt++;
  }

  if (cnt <= 2) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V  = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class H> void rsz(V<T> &v, H h) { v.resize(h); }
template<class T, class H, class... R> void rsz(V<T> &v, H h, R... r) { v.resize(h); for (auto&& i : v) rsz(i, r...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  string s; cin >> s;
  bool ok = true;
  if (s[0] != 'A') ok = false; else s = s.substr(1, 10);
  string t = s.substr(1, s.size() - 2);
  if (count(t.begin(), t.end(), 'C') != 1) ok = false;
  for (auto&& c : s) {
    if (!('a' <= c and c <= 'z' or c == 'C')) ok = false;
  }
  cout << (ok ? "AC" : "WA") << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		int min = Math.min(a, b);
		int max = Math.max(a, b);
		for (int i = 0; i < max; i++) {
			System.out.print(min);
		}
		System.out.println();
	}
}


Measured memory_bytes: 21844
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

LL N, K;

int main(){
    INIT;
    cin >> N >> K;
    if(K == 0) {
        cout << N*N << "\n";
        return 0;
    }
    LL ans = 0;
    for(LL b = K+1; b <= N; b++) {
        LL y = N / b;
        LL an = (b-K)*y;
        ans += an;
        LL r = N-y*b;
        if(r >= K) ans += r-K+1;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <cstring>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
//#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
const int INF = (int)2e9 + 1;
const long long LINF = (long long)9e18 + 1;

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

  int N, K;
  cin >> N >> K;
  vector<char> seq(N);
  for (auto &v : seq) {
    cin >> v;
  }
  int now = 0;
  for (int i = 0; i < N; i++) {
    if (seq[i] == 'L') {
      if (i != 0) {
        if (seq[i - 1] == 'L') now++;
      }
    } else {
      if (i != N - 1) {
        if (seq[i + 1] == 'R') now++;
      }
    }
  }

  int ans = min(N - 1, now + 2 * K);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
	 
using namespace std;
	 
typedef long long LL;
typedef double db;
	 
const int L = 8005;
const int N = 8005;
const int mo = 998244353;
 
bitset<L>a[N],Lim;
int n;
int key[N];
LL mi[L];
 
void getbit(bitset<L> &a){
	char s[L];
	scanf("%s",s+1);
	int len=strlen(s+1);
	fo(i,0,len-1)a[i]=s[len-i]-'0';
}
 
bitset<L> trs(bitset<L> a,bitset<L> b){
	int wa,wb;
	fd(i,4000,0)if (a[i]){wa=i;break;}
	fd(i,4000,0)if (b[i]){wb=i;break;}
	if (wa<wb)swap(a,b),swap(wa,wb);
	while(wb>-1){
	a=a^(b<<(wa-wb));
		bool fd=0;
		fd(i,wa,0)if (a[i]){wa=i;fd=1;break;}
		if (!fd)wa=-1;
		if (wa<wb)swap(a,b),swap(wa,wb);
	}
	return a;
}
	 
int main(){
	mi[0]=1;
	fo(i,1,4000)mi[i]=mi[i-1]*2%mo;
	scanf("%d",&n);
	getbit(Lim);
	fo(i,1,n)getbit(a[i]);
	int n_=0;
	fo(i,1,n){
		fo(j,1,i-1)
		if (a[i][key[j]])a[i]=a[i]^a[j];
		if (a[i].count()==0)continue;
		int w=-1;
		fd(x,4000,0)if (a[i][x]){w=x;break;}
		key[i]=w;
		if (w!=-1){
			key[++n_]=w;
			a[n_]=a[i];
		}
	}
	n=n_;
	int pre=0;
	for(bool pd=1;pd;){
		int pn=n;
		pd=0;
		int w=(pre==0)?n:pre;
		fo(i,1,w)
			fo(j,pre+1,pn)
			if (i!=j){
				bitset<L> now=trs(a[i],a[j]);
				fo(p,1,n)
				if (now[key[p]])now=now^a[p];
				if (now.count()>0){
					a[++n]=now;
					key[n]=0;
					fd(x,4000,0)if (now[x]){key[n]=x;break;}
				}
			}
		pre=pn;
	}
	int keyw=1;
	fo(i,2,n)
	if (key[i]<key[keyw])keyw=i;
	int w=0;
	fd(i,4000,0)
	if (Lim[i]){w=i;break;}
	LL ans=0;
	fd(i,w,key[keyw])
	if (Lim[i])ans=(ans+mi[i-key[keyw]])%mo;
	bitset<L>now;
	fo(i,0,4000)now=0;
	fd(i,w,key[keyw])
	if (Lim[i]!=now[i])now=now^(a[keyw]<<(i-key[keyw]));
	int prefer=1;
	fd(i,key[keyw],0)
	if (Lim[i]!=now[i]){
		if (now[i]>Lim[i])prefer=0;
		break;
	}
	ans=(ans+prefer)%mo;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int NUM = 1000000;
  bool prime[NUM];
  prime[0] = false;prime[1] = false;
  for(int i=2;i<NUM;i++)prime[i] = true;
  for(int i=2;i*i<NUM;i++)
    for(int k=2;i*k<NUM;k++)
      prime[i*k]=false;

	int primeNum[NUM];
	for(int i=0,c=0;i<NUM;i++){
		prime[i]&&c++;
		primeNum[i] = c;
	}
	for(int n;cin>>n;cout<<primeNum[n]<<endl);
}

Measured memory_bytes: 0
import java.io.IOException;
import java.util.Scanner;

public class Main {

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

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			double n = scanner.nextDouble();
			if (n < 0)
				break;
			int val = (int) n;
			if (Integer.toBinaryString(val).length() > 8)
				System.out.println("NA");
			else {
				double syousu = (n - val) * 16;
				int syousuInt = (int) syousu;
				if (syousu != syousuInt)
					System.out.println("NA");
				else {
					int a = Integer.parseInt(Integer.toBinaryString(val));
					int b = Integer.parseInt(Integer.toBinaryString(syousuInt));
					System.out.printf("%08d.%04d\n", a, b);
				}
			}

		}
	}
}

Measured memory_bytes: 25816
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
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; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}
ll MOD=1000000007;

int main(){
  vector<vector<int>> a(3,vector<int>(3));
  rep(i,3){
    rep(j,3){
      cin >> a.at(i).at(j);
    }
  }
  int n; cin >> n;
  vi b(n);
  rep(i,n) cin >> b.at(i);
 
  rep(i,n){
    rep(j,3){
      rep(k,3){
        if(a.at(j).at(k) == b.at(i)){
          a.at(j).at(k) = 0;
        }
      }
    }
  }
  string ans = "No";
  if(a[0][0] == 0){
    if(a[0][1] == 0 and a[0][2] == 0) ans = "Yes";
    if(a[1][0] == 0 and a[2][0] == 0) ans = "Yes";
    if(a[1][1] == 0 and a[2][2] == 0) ans = "Yes";
  }
  if(a[0][1] == 0){
    if(a[1][1] == 0 and a[2][1] == 0) ans = "Yes";
  }
  if(a[0][2] == 0){
    if(a[1][2] == 0 and a[2][2] == 0) ans = "Yes";
    if(a[1][1] == 0 and a[2][0] == 0) ans = "Yes";
  }
  if(a[1][0] == 0){
    if(a[1][1] == 0 and a[1][2] == 0) ans = "Yes";
  }
  if(a[2][0] == 0){
    if(a[2][1] == 0 and a[2][2] == 0) ans = "Yes";
  }
  cout << ans << endl;
}


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

import numpy as np
l = list(map(int, input().split()))
l = list(map(lambda x: -1 * x, l))

import heapq

heapq.heapify(l)

for _ in range(M):
	max_value = -1 * heapq.heappop(l)
	heapq.heappush(l, (max_value // 2) * (-1))

print(-1 * sum(l))

Measured memory_bytes: 23148
// https://atcoder.jp/contests/abc126/tasks/abc126_b

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  int S, l, b;
  cin >> S;

  l = S % 100;
  b = S / 100;

  if (l == 0 || 12 < l)
  {
    if (0 < b && b <= 12)
      cout << "MMYY" << '\n';
    else
      cout << "NA" << '\n';
  }
  else
  {
    if (0 < b && b <= 12)
      cout << "AMBIGUOUS" << '\n';
    else
      cout << "YYMM" << '\n';
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int a, b, x;
    cin >> a >> b >> x;
    const double PI = acos(-1);
    double ok = 0, ng = PI / 2;
    REP (i, 100) {
        double m = (ok + ng) / 2, V;
        if (m >= atan(1.0 * b / a)) V = a * b * b / (2 * tan(m));
        else V = (2 * b - a * tan(m)) * a * a / 2;
        if (V >= x) ok = m;
        else ng = m;
    }
    cout << ok / PI * 180 << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S1 = input()
S2 = input()
dominos = []
yokoflag = 0
for u, l in zip(S1, S2):
    if u == l:
        dominos.append(1)
    else:
        if yokoflag == 0:
            yokoflag = 1
            continue
        else:
            dominos.append(2)
            yokoflag = 0
combi = 1
if dominos[0] == 1:
    combi = 3
else: combi = 6
for i in range(1, len(dominos)):
    if dominos[i-1] == 1 and dominos[i] == 1:
        combi *= 2
    elif dominos[i-1] == 1 and dominos[i] == 2:
        combi *= 2
    elif dominos[i-1] == 2 and dominos[i] == 1:
        combi *= 1
    elif dominos[i-1] == 2 and dominos[i] == 2:
        combi *= 3
    combi = combi % 1000000007
print(combi)

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	cin >> N;

	rep(h, 0, 3501)rep(n, 0, 3501)
	{
		int u = N * h*n;
		int d = 4 * h*n - N * n - N * h;
		if (d > 0 && u%d == 0)
		{
			cout << h <<" "<< n <<" "<< u / d << endl;
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3660
N=int(input())
A=list(map(int,input().split()))
def bubbleSort(A,N):
    flg=1
    global ct
    ct = 0
    while flg:
        flg = 0
        for j in range(N-1,0,-1):
            if A[j] < A[j-1]:
                A[j-1],A[j]=A[j],A[j-1]
                flg=1
                ct+=1

    return ' '.join(map(str,A))

print(bubbleSort(A,N))
print(ct)


Measured memory_bytes: 5600
#include <stdio.h>

int main ( ) {
    int x , a , b ;

    while ( ~scanf ( "%d%d%d" , &x , &a , &b ) ) {

        if ( a >= b ) {
            printf ( "delicious\n" ) ;
        }
        if ( b - a > x ) {
            printf ( "dangerous\n" ) ;
        }
        if ( b > a && b -a <= x ) {
            printf ( "safe\n") ;
        }
    }

    return 0 ;
}


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

using namespace std;

using LL = long long;
const LL infLL = (LL)1e18 + 123;
const int N = (int)1e5 + 5, SEEHT = (int)sqrt(N);

int n, s[N];
LL prefSum[SEEHT][N], suffSum[SEEHT][N], ans;

int main() {
    scanf(" %d", &n);
    for (int i = 0; i < n; ++i) scanf(" %d", s + i);

    for (int i = 0; i < n; ++i) {
        for (int j = 1; j < SEEHT; ++j) if (i % j == 0) {
            prefSum[j][i] = s[i] + (i >= j ? prefSum[j][i - j] : 0);
        }
    }
    for (int i = n - 1; i >= 0; --i) {
        for (int j = 1; j < SEEHT; ++j) if (i % j == (n - 1) % j) {
            suffSum[j][i] = s[i] + (i + j <= n - 1 ? suffSum[j][i + j] : 0);
        }
    }

    for (int j = 1; j < SEEHT; ++j) {
        for (int i = 1; i * j < n; ++i) {
            int lstSuff = i * j + (n - 1) % j,
                lstPref = (n - 1) - i * j - (n - 1) % j;
            if ( (n - 1) % j == 0 && lstPref >= lstSuff) continue ;
            LL ret = prefSum[j][lstPref] + suffSum[j][lstSuff];
            ans = max(ans, ret);
        }
    }

    for (int j = SEEHT; j < n; ++j) {
        vector<int> pref, suff;
        for (int i = 0; i < n; i += j) pref.push_back(s[i] + (pref.size() ? pref.back() : 0) );
        for (int i = n - 1; i >= 0; i -= j) suff.push_back(s[i] + (suff.size() ? suff.back() : 0) );
        for (int i = 1; i * j < n; ++i) {
            int lstSuff = i * j + (n - 1) % j,
                lstPref = (n - 1) - i * j - (n - 1) % j;
            if ( (n - 1) % j == 0 && lstPref >= lstSuff) continue ;
            LL ret = suff[(int)suff.size() - i - 1] + pref[(int)pref.size() - i - 1];
            ans = max(ans, ret);
        }
    }

    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 493696
void main()
{
    long n = rdElem;

    long[] divisor;
    for (long i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            divisor ~= i;
            if (i != n / i) divisor ~= n / i;
        }
    }

    long[] list;
    foreach (d; divisor)
    {
        if (d == 1) continue;
        long num = n;
        while (num % d == 0)
        {
            num /= d;
        }
        if (num % d == 1) list ~= d;
    }

    long m = n - 1;
    for (long i = 1; i * i <= m; ++i)
    {
        if (m % i == 0)
        {
            if (i != 1) list ~= i;
            if (i != m / i) list ~= m / i;
        }
    }

    list.sort!"a < b";
    uniq(list);

    list.length.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 380
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
const int inf = 1e9;

struct road{
    int dist;
    int cost;
    int to;
    road(int d, int c, int t): dist(d), cost(c), to(t){}
    bool operator < (const road &a) const{
        return (dist==a.dist)? cost > a.cost : dist > a.dist;
    }
};

int main(){
    while(1){
        int n,m;
        cin >> n >> m;
        if(n==0) break;

        vector<vector<road> > adj(n);
        for(int i=0; i<m; i++){
            int u,v,d,c;
            cin >> u >> v >> d >> c;
            u--; v--;
            adj[u].push_back(road(d, c, v));
            adj[v].push_back(road(d, c, u));
        }

        priority_queue<road> wait;
        wait.push(road(0, 0, 0));
        vector<int> mindist(n, inf);
        vector<bool> used(n, false);
        mindist[0] = 0;
        int ans=0;
        while(!wait.empty()){
            int dist = wait.top().dist;
            int cost = wait.top().cost;
            int pos = wait.top().to;
            wait.pop();
            if(dist > mindist[pos] || used[pos]) continue;
            used[pos] = true;
            ans += cost;
            for(int i=0; i<(int)adj[pos].size(); i++){
                int ndist = dist + adj[pos][i].dist;
                int ncost = adj[pos][i].cost;
                int to = adj[pos][i].to;
                if(ndist <= mindist[to] && !used[to]){
                    wait.push(road(ndist, ncost, to));
                    mindist[to] = ndist;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4068
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  vector<int> q(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];
  vector<int> a(n);
  rep(i, n) a[i] = i+1;
  map<vector<int>, int> mp;
  do{
    mp[a]=mp.size();
  } while(next_permutation(a.begin(), a.end()));

  int ans = abs(mp[p] - mp[q]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8680
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
 
  while( true ) {
    long long int n, input;
    cin >> n;
 
    if ( n == 0 ) break;
 
    vector< long long int > s;
 
    for ( long long int i = 0; i < n; i++ ) {
 
      cin >> input;
      s.push_back( input );
 
    }
 
    sort( s.begin(), s.end() );
 
    long long int ans = 0;
 
    for ( long long int i = 1; i < n - 1; i++ ) {
 
      ans += s[i];
 
    }
 
    cout << ans / ( n - 2 ) << endl;
 
  }
 
  return 0;
 
}

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

int main() {
  int K;
  cin >> K;
  string S;
  cin >> S;
  if(S.size() <= K){
    cout << S << endl;
  } else {
    rep(i, K){
      cout << S.at(i);
    }
    cout << "..." << endl;
  }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

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

    vector<ll> w;
    ll count = 0;
    for(ll i=0;i<s.size();++i){
        if(s[i] == 'W'){
            w.push_back(i);
            count++;
        }
    }

    ll ans = 0;
    ll left = 0;
    for(ll i=0;i<count;++i){
        ans += w[i] - left;
        left++;
    }
    cout<<ans<<endl;

    return 0;
}

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

void solve();

typedef long long ll;
typedef pair<ll, ll> pll; // first to
typedef pair<int, pll > pipll;
typedef pair<ll, pll> plpll;

ll N,M,X;
ll H[100010];
bool visited[100010] = {0};
ll D[100010] = {0};

vector<pll> G[100010];

int main()
{
    scanf("%lld%lld%lld",&N,&M,&X);
    for(int i = 1; i < N + 1; i++)
    {
        scanf("%lld",&H[i]);
    }
    for(int i = 0; i < M; i++)
    {
        ll A,B,T;
        scanf("%lld%lld%lld",&A,&B,&T);
        pll mem;
        mem.second = T;
        mem.first = B;
        G[A].push_back(mem);
        mem.first = A;
        G[B].push_back(mem);
    }
    solve();
    return 0;
}

void solve()
{
    ll mem;
    priority_queue<plpll, vector<plpll> ,greater<plpll> > Q;
    plpll fir;
    fir.first = 0;
    fir.second.first = 1;
    fir.second.second = X;
    Q.push(fir);
    while(Q.size())
    {
        plpll now = Q.top();
        Q.pop();
        if(!visited[now.second.first])
        {
            if(now.second.first == N)
            {
                mem = now.second.second;
            }
            D[now.second.first] = now.first;
            visited[now.second.first] = true;
            for(int i = 0; i < G[now.second.first].size(); i++)
            {
                if(H[now.second.first] >= G[now.second.first][i].second)
                {
                    if(now.second.second > H[G[now.second.first][i].first] + G[now.second.first][i].second)
                    {
                        Q.push(make_pair(now.first + G[now.second.first][i].second + now.second.second - H[G[now.second.first][i].first] - G[now.second.first][i].second,make_pair(G[now.second.first][i].first,H[G[now.second.first][i].first])));
                    }
                    else if(now.second.second >= G[now.second.first][i].second)
                    {
                        Q.push(make_pair(now.first + G[now.second.first][i].second,make_pair(G[now.second.first][i].first,now.second.second - G[now.second.first][i].second)));
                    }
                    else
                    {
                        Q.push(make_pair(now.first + 2 * G[now.second.first][i].second - now.second.second,make_pair(G[now.second.first][i].first,0)));
                    }
                }
            }
        }
    }
    if(D[N])
    {
        printf("%lld\n",D[N] + H[N] - mem);
    }
    else
    {
        printf("-1\n");
    }
    return;
}

Measured memory_bytes: 45540
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	rep(i, N) {
		cin >> A[i];
	}

	int l = 1;
	int r = 1e9;
	int ans = 0;
	while (l < r)  {
		int m = (l + r) / 2;
		int t = 0;
		rep(i, N) {
			t += (A[i] - 1) / m;
		}
 
		if (t <= K) {
			ans = r = m;
		}
		else {
			ans = l = m + 1;
		}
	}
 
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3964
#include <iostream>
#include <math.h>
using namespace std;

int main(void){
    int n;
    int weight[10];
    bool flag;
    while(cin>>n){
        for(int i=0;i<10;i++){
            weight[i]=0;
        }
        flag=false;
        for(int i=9;i>=0;i--){
            if(pow(2,i)<=n){
                weight[i]=1;
                n-=pow(2,i);
            }
        }
        for(int i=0;i<10;i++){
            if(flag==false and weight[i]==1){
                flag=true;
                cout<<pow(2,i);
            }
            else if(weight[i]==1){
                cout<<" "<<pow(2,i);
            }
        }
        cout<<endl;
    }
}



Measured memory_bytes: 3404
n = int(input())
h = list(map(int, input().split()))
a = [0]
ans = 0
for i in range(1,n):
    if h[i-1]>=h[i]:
        ans+=1
    else:
        a.append(ans)
        ans=0
    if i==n-1:
        a.append(ans)
a.sort(reverse=True)
print(a[0])

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

int main() {
  int N, K;
  int C = 0;
  cin >> N;

  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  bool f;
  f = true;
  while (f) {
    f = false;
    for (int j = N - 1; j > 0; j--) {
      if (vec.at(j) < vec.at(j - 1)) {
        int t = vec.at(j);
        vec.at(j) = vec.at(j - 1);
        vec.at(j - 1) = t;
        f = true;
        C++;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (i > 0) cout << " ";
    cout << vec.at(i);
  }

  cout << endl <<  C << endl;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int x;
	int i;
	double sum,ans;
	cin>>n;
	sum=0.0;
	for(i=0;i<n;i++){
		cin>>x;
		sum+=(double)1/x;
	}
	ans=1.0/sum;
	printf("%.5lf\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define BE(x) x.begin(), x.end()

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

    vector<pair<int,int>> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i].first;
        x[i].second = i;
    }
    sort (BE(x));

    vector<pair<int,int>> y(n);
    for (int i = 0; i < n; i++) {
        y[i].first = x[i].second;
        y[i].second = i;
    }
    sort (BE(y));

    for (int i = 0; i < n; i++) {
        if (y[i].second < n/2) cout << x[n/2].first << endl;
        else cout << x[n/2-1].first << endl;
    }
}

Measured memory_bytes: 6312
#include<bits/stdc++.h>
using namespace std;
#define int long long

int32_t main(){
   int n,m;
   cin>>n>>m;
   int arr[n],sm=0;
   for(int i=0;i<n;i++){
      cin>>arr[i];
      sm += arr[i];
   }
   int f= 1;
   sort(arr,arr+n,greater<int>());
   int t = sm/(4*m) + ((sm%(4*m))!=0);

   for(int i=0;i<m;i++){
      if(arr[i]<t){
         f=0;
         break;
      }
   }
   puts(f?"Yes":"No");
}

Measured memory_bytes: 256
import sys
import random
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# 文字列アルゴリズム
# RollingHash
# ローリングハッシュ

# 64bit 溢れないように
class RollingHash:
    MASK30 = (1 << 30) - 1
    MASK31 = (1 << 31) - 1
    MOD = (1 << 61) - 1
    POSITVIZER = MOD * ((1 << 3) - 1)

    def __init__(self, S):
        # 事前計算
        Base = random.randrange(129, (1 << 61) - 1)
        self.Base = Base

        L = len(S)
        powMemo = [0] * (L + 1)
        rhash = [0] * (L + 1)

        powMemo[0] = 1
        for i in range(1, L + 1):
            powMemo[i] = self.calcMod(self.Mul(powMemo[i - 1], Base))

        for i in range(L):
            rhash[i + 1] = self.calcMod(self.Mul(rhash[i], Base) + ord(S[i]))

        self.powMemo = powMemo
        self.rhash = rhash

    def getHash(self, begin, length):
        r = self.calcMod(
            self.rhash[begin + length]
            + self.POSITVIZER
            - self.Mul(self.rhash[begin], self.powMemo[length])
        )

        return r

    def Mul(self, l, r):
        lu = l >> 31
        ld = l & self.MASK31
        ru = r >> 31
        rd = r & self.MASK31
        middle = ld * ru + lu * rd

        return (
            ((lu * ru) << 1) + ld * rd + ((middle & self.MASK30) << 31) + (middle >> 30)
        )

    def calcMod(self, val):
        val = (val & self.MOD) + (val >> 61)
        if self.MOD <= val:
            val -= self.MOD
        return val


N = int(input())
S = input()

RH = RollingHash(S)


def check(n, RH):
    ret = False
    cnt = defaultdict(int)
    for i in range(0, N - n + 1):
        h = RH.getHash(i, n)

        if not cnt[h]:
            cnt[h] = i + 1
        else:
            f = cnt[h]
            if f + n <= i + 1:
                ret = True
                break

    return ret


l = 0  # OK
r = (N // 2) + 1  # NG

while (r - l) != 1:
    mid = (l + r) // 2
    if check(mid, RH):
        l = mid
    else:
        r = mid

print(l)


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

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef TurnRed
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	ll a;
	cin >> a;
	cout << a * (a-1)/2;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
int k,s;
cin>>k>>s;

int ret=0;
for(int i=0;i<=k;++i){
for(int j=0;j<=k;++j){
if (i+j<=s && i+j+k>=s)++ret;
}
}
cout<<ret<<endl;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int n,ans,a[200005],dp[200005];
int main(){
cin>>n;
for(int k=1;k<=n;k++){
   cin>>a[k];
}
dp[1]=0;
dp[2]=abs(a[2]-a[1]);
for(int k=3;k<=n;k++){
   int t=abs(a[k-2]-a[k])+dp[k-2];
   int c=abs(a[k-1]-a[k])+dp[k-1];
   dp[k]=min(c,t);
}
cout<<dp[n];
return 0;
}


Measured memory_bytes: 1024
#include <iostream>
 
int main() {
	int summer_days {};
  	std::cin >> summer_days;
  	
  	int num_of_assignments {};
  	std::cin >> num_of_assignments;
  
  	while(num_of_assignments > 0) {
    	int days_for_assignment {};
      	std::cin >> days_for_assignment;
      	summer_days -= days_for_assignment;
      	
      	num_of_assignments -= 1;
    }
  
  	if(summer_days < 0) {
    	std::cout << -1 << std::endl;
    }else {
    	std::cout << summer_days << std::endl;
    }
 
}

Measured memory_bytes: 3604