akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define mod 1000000007


int main() {
    int N, T; cin >> N >> T;
    vector<int> V(N);
    for(int &i:V)
        cin >> i;

    int ans = 0;
    for(int i=0; i<N-1; i++)
        ans += min(T, V[i+1]-V[i]);
    ans += T;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

void Red_or_Blue(int N) {
  char s[N+1];
  int red, blue;
  for (scanf("%s",s), red = 0, blue = 0; red+blue < N; red++, blue++) {
    if (s[red+blue] == 'R') {
      blue -= 1;
    } else {
      red -= 1;
    }
  }
  if (red > blue) {
    printf("Yes");
  } else {
    printf("No");
  }
}

int main(void) {
  int N;
  scanf("%d",&N);
  Red_or_Blue(N);
  return 0;
}

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

#define llint long long int

using namespace std;

int main(){
    int K;
    string S;

    cin >> K >> S;

    if(S.length() <= K){
        cout << S << endl;
    }else{
        for(int i = 0; i < K; i ++){
            cout << S[i];
        }
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int n,k,ti,di;
pint p[100001];
unordered_map<int,int> cnt;
int main(){
    cin>>n>>k;
    rep(i,n){
        cin>>ti>>di;
        p[i]={di,ti};
    }
    sort(p,p+n,greater<pint>());
    ll mx=0;
    rep(i,k){
        mx+=p[i].first;
        ++cnt[p[i].second];
    }
    ll sz=cnt.size();
    mx+=sz*sz;
    ll ans=mx;
    int l=k-1,r=k;
    while(1){
        while(l>=0&&cnt[p[l].second]<=1) --l;
        while(r<n&&cnt[p[r].second]!=0) ++r;
        if(l<0||r>=n) break;
        mx-=p[l].first;--cnt[p[l].second];--l;
        mx+=p[r].first;++cnt[p[r].second];++r;
        mx+=(sz+1)*(sz+1)-sz*sz;
        ++sz;
        ans=max(ans,mx);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
	string s;
	bool st = true;
	while( cin >> s ){
		if( s[s.size()-1] == '.' or s[s.size()-1] == ',' ){
			s = s.substr(0, s.size()-1);
		}
		if( 3 <= s.size() && s.size() <= 6 ){
			if( st ){
				cout << s;
				st = false;
			}else{
				cout << " " << s;
			}
		}
	}
	cout << endl;
}

Measured memory_bytes: 1180
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    A.sort()
    M = A.pop()
    heapq.heapify(A)
    m = heapq.heappop(A)

    ans = []
    while A:
        a = heapq.heappop(A)
        if a < 0:
            ans.append((M, a))
            M -= a
        else:
            ans.append((m, a))
            m -= a

    print(M-m)
    for x, y in ans:
        print(x, y)
    print(M, m)


def main():
    N = read_int()
    A = read_int_n()
    (slv(N, A))


if __name__ == '__main__':
    main()


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

int main()
{
	int n,count=0;
	cin>>n;
	map<string,bool>m;
	
	for(int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		
		if(m.find(s) == m.end())
		{
			count++;
			m.insert(make_pair(s,true));
		}
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 19180
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

const int mod = 998244353;

int sum(int x, int y){
	if (x+y < 0) return x+y+mod;
	if (x+y >= mod) return x+y-mod;
	return x+y;
}

int mult(int x, int y){
	return ((ll) x * (ll) y) % (ll) mod;
}

int pw(int x, int y){
	if (y==0) return 1;
	if (y==1) return x%mod;
	if (y%2) return mult(x, pw(x, y-1));
	int R = pw(x, y/2);
	return mult(R, R);
}

int dp[403][403][2], dp2[403][403][2];

int fact[403], rev[403];

int C(int n, int k){
	return mult(fact[n], mult(rev[n-k], rev[k]));
}

int main(){
	#ifdef LOCAL
    freopen("H_input.txt", "r", stdin);
    //freopen("B_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	fact[0] = 1;
	for (int i=1; i < 403;++i) fact[i] = mult(i, fact[i-1]);
	for (int i=0;i<403;++i) rev[i] = pw(fact[i], mod-2);
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	for (int i=0;i<n;++i) cin >> a[i] >> b[i];
	for (int i=0; i < 403; ++i) for (int j=0; j < 403; ++j){
		dp[i][j][0] = 0, dp[i][j][1] = 0;
	}
	dp[0][0][0] = 1;
	for (int i=0; i < n; ++i){
		for (int j=0;j<403;++j) for (int k=0; k < 403; ++k) for (int e=0; e < 2; ++e){
			dp2[j][k][e] = dp[j][k][e];
		}
		int Q = 1;
		for (int j=0; j < b[i]; ++j){
			for (int staa=0; staa < 403; staa++){
				for (int stab=0; stab < 403; stab++){
					for (int take=0; take < 2; ++take){
						if (dp[staa][stab][take] == 0) continue;
						int A = staa + a[i], B = stab+j;
						dp2[A][B][1-take] = sum(dp2[A][B][1-take], mult(dp[staa][stab][take], mult(Q, C(stab+j, j))));
					}
				}
			}
			Q = mult(Q, a[i]);
		}
		for (int j=0;j<403;++j) for (int k=0; k < 403; ++k) for (int e=0; e < 2; ++e){
			dp[j][k][e] = dp2[j][k][e];
		}
	}
	int ans = 0;
	int tum = 0;
	for (int i=0;i<n;++i) tum += a[i];
	for (int i=1; i < 403; ++i){
		for (int j=0; j < 403; ++j){
			for (int take=0; take < 2; take++){
				int rv = pw(i, mod-2);
				int R = mult(dp[i][j][take], pw(rv, j));
				int W = pw(mult(i, pw(tum, mod-2)), mod-2);
				if (take==1) ans = sum(ans, mult(R, W));
				else ans = sum(ans, -mult(R, W));
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 2816
from itertools import combinations

N = int(input())
S = [list(input()) for _ in range(N)]

cand = ['M', 'A', 'R', 'C', 'H']
count = [0 for _ in range(5)]
for s in S:
    for i, c in enumerate(cand):
        if c == s[0]:
            count[i] += 1

if count.count(0) < 3:
    for i in list(range(5))[::-1]:
        if count[i] == 0:
            del count[i]
    P = list(combinations(count, 3))
    result = 0
    for p in P:
        result += p[0] * p[1] * p[2]
else:
    result = 0

print(int(result))


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

inline int check(int time) {
	int s=0;
	for (int gap=time;gap>=1;--gap) {
		if (s+gap<=x)
			s+=gap;
	}
	return s==x;
}

int main() {
	scanf("%d",&x);
	int l=0,r=x;
	while (l<r) {
		int mid=(l+r)/2;
		if (!check(mid)) l=mid+1;
		else r=mid;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M =1000000007;
//MOD??
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}
ll mpow(ll x, ll n){ //x^n(mod M) ????pow(x,n)?????????????mod??
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
int main (){
  ll i,n,j,f=0,c=0;
  cin>>n;
  map<string,int> s;
  string x;
  for(i=0;i<n;i++){
    cin>>x;
    s[x]++;
  }
  cout<<s.size()<<endl;
  return 0;
}

Measured memory_bytes: 19176
// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>

#define ll long long
#define Int ll
#define loop(__x, __start, __end) for(Int __x = __start; __x < __end; __x++)
#define loopdown(__x, __start, __end) for(Int __x = __start; __x > __end; __x--)
#define rep(__n) for(Int __x = 0; __x < __n; __x++)
#define span(__a,__x,__y) __a.begin()+__x,__a.begin()+__y
#define span_all(__a) __a.begin(),__a.end()
#define len(__x) (__x.size())
#define last(__x) (__x[__x.size()-1])

using namespace std;

struct Point {
  Int x, y;
  Point(Int x, Int y): x(x), y(y) {}
  Point(): x(0), y(0) {}

  bool operator< (const Point &p1) const {
    return x < p1.x && y < p1.y;
  }
};
ostream & operator << (ostream & out, Point const & v) {
  out << "Point(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Point & v) {
  Int x, y;
  in >> x; in >> y; v.x = x; v.y = y;
  return in;
}

// Geometry

#define EPS 0.0000000001

class Vector2 {
public:
  double x, y;
  
  Vector2(double x = 0, double y = 0): x(x), y(y) {}
  
  Vector2 operator + (Vector2 v) { return Vector2(x + v.x, y + v.y); }
  Vector2 operator - (Vector2 v) { return Vector2(x - v.x, y - v.y); }
  Vector2 operator * (double k) { return Vector2(x * k, y * k); }
  Vector2 operator / (double k) { return Vector2(x / k, y / k); }
  
  double length() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  double dot (Vector2 v) { return x * v.x + y * v.y; }
  double cross (Vector2 v) { return x * v.y - y * v.x; }
  
  bool operator < (const Vector2 &v) const {
    return x != v.x ? x < v.x : y < v.y;
  }
  
  bool operator == (const Vector2 &v) const {
    return fabs(x - v.x) < EPS && fabs(y - v.y) < EPS;
  }
};

ostream & operator << (ostream & out, Vector2 const & v) { 
  out<< "Vector2(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Vector2 & v) { 
  double x, y;
  in >> x;
  in >> y;
  v.x = x;
  v.y = y;
  return in;
}

int N;
vector<int> Q(8, -1);
vector<int> A;

void input() {
  cin >> N;
  int x, y;
  rep(N) {
    cin >> y >> x;
    Q.at(y) = x;
  }
}

// O(8)
bool valid() {
  int i = 0;
  while (i < 8) {
    int y = Q.at(i);
    if (y != -1 && y != A.at(i)) return false;
    i++;
  }
  return true;
}

bool safe() {
  int x,x2;
  for (int y=0; y<7; y++) {
    for (int y2=y+1; y2<8; y2++) {
      x = A.at(y), x2 = A.at(y2);
      if (abs(x2-x) == y2-y) return false;
    }
  }
  return true;
}

void solve() {
  loop(n,0,8) A.push_back(n);
  do {
    if (!valid()) continue;
    if (safe()) break;
  } while (next_permutation(span_all(A)));

  loop(y,0,8) {
    loop(x,0,8) {
      if (x == A.at(y)) cout << "Q";
      else cout << ".";
    }
    cout << endl;
  }
}

int main() {
  input();
  solve();
  return 0;
}



Measured memory_bytes: 3160
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;\

//ll mod = 1000000007 ;
//ll INF = 10000000000 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}


int main(){
	ll n ; cin >> n ;
	vll a(n) ;
	for(auto &i:a) cin >> i ;
	bool ok = true ;
	ll cnt = 0 ;
	while(ok){
		ok = false ;
		ll sum = 0 ;
		for(int i=0;i<n;i++){
			if(a.at(i)>=n){
				sum += a.at(i)/n ;
			}
		}
		ok = (sum!=0) ;
		if(ok){
			cnt += sum ;
			for(int i=0;i<n;i++){
				a.at(i) += (sum-a.at(i)/n)-a.at(i)/n*n ;
			}
		}
	}
	cout << cnt << endl ;
}


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

int main() {
    long long Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;
    Q *= 4;
    H *= 2;

    long long min1 = min(min(Q, H), S);
    long long min2 = min(min1 * 2, D);
    if (N % 2 == 0) {
        cout << N / 2 * min2 << endl;
    }
    else {
        cout << N / 2 * min2 + min1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[500];
int ans;
int main(void){
	string s; cin>>s;
	for(int i=0;i<4;i++){
		int k=s[i];
		a[k]++;
	}
	for(int i=0;i<500;i++){
		if(a[i]==2){
			ans++;
		}
	}
	if(ans==2){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	
}


Measured memory_bytes: 764
#include<set>
#include<cmath>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<numeric>
#include<vector>
#include<ctime>
#include<queue>
#include<list>
#include<map>
#define pi acos(-1)
#define INF 0x7fffffff
#define clr(x)  memset(x,0,sizeof(x));
#define clrto(x,siz,y)  for(int xx=0;xx<=siz;xx++)  x[xx]=y;
#define clrset(x,siz)  for(int xx=0;xx<=siz;xx++)  x[xx]=xx;
#define clrvec(x,siz) for(int xx=0;x<=siz;xx++)  x[xx].clear();
#define fop   freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define myprogram By_135678942570
#define clrcpy(x,siz,y)  for(int xx=0;xx<siz;xx++)  x[xx]=y[xx];
using namespace std;
map<string,int>mp;
main()
{
     string tt;
     string maxstr=" ";
     string maxstr2=" ";
     int maxn=0;
     while(cin>>tt)
     {
         mp[tt]++;
         if(mp[tt]>mp[maxstr])
            maxstr=tt;
         if(tt.size()>maxn)
            maxn=tt.size(),maxstr2=tt;
     }
     cout<<maxstr<<" "<<maxstr2<<endl;
     return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int,int> P;

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

int main(){
	long j,yakusuu,prime[10000],k=0,i=1;
		while(k<1000){
			yakusuu=0;
			for(j=1;j<=i;j++)
			{
				if(i%j==0) yakusuu++;
			}

			if(yakusuu==2){
				prime[k]=i;
				k++;
			}
			i++;
		}
	int N;
	cin>>N;
	int first=2;

	cout<<first<<" ";
	int l=4;
	int c=0;
	while(c<N-1){
		if(prime[l]%5==1){
			cout<<prime[l]<<" ";
			c++;
		}
		l++;
		}
}

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

using namespace std;

double mem[3000][3000];
int vis[3000][3000];
int n;
double arr[3000];

double go(int x,int y)
{
	if(x>=n) return (y>n-y);
	if(vis[x][y]) return mem[x][y];
	vis[x][y]=1;
	return mem[x][y]=(arr[x]*go(x+1,y+1)+(1-arr[x])*go(x+1,y));
}

int main()
{
	cin >> n;
	for(int i=0;i<n;i++)
		cin >> arr[i];
	cout << fixed << setprecision(15) << go(0,0) << endl;
}

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

namespace ConsoleApp121 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split().ToArray();
            string N = st[0];
            int n = int.Parse(N);
            var N_array = N.ToCharArray();
            int keta = N.Length;
            int K = int.Parse(st[1]);

            List<char> D = Console.ReadLine().Split().Select(x => x[0]).ToList();

            //全ての文字のリスト
            var allNumList = new List<char> { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
            //使える文字のリスト
            List<char> usableNumList = allNumList.Except(D).ToList();

            int ans = n;

            while (true) {
                if (n.ToString().ToCharArray().ToList().Except(usableNumList).ToList().Count() == 0) {
                    ans = n;
                    break;
                }





                n++;
            }

            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 17572
#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

typedef std::vector<int> TInts;
void Input(TInts& Numbers)
{
	int Count = 0;
	std::cin >> Count;
	Numbers.resize(Count);
	for(int i=0;i<Count;i++)
	{
		std::cin >> Numbers[i];
	}
}

bool Search(const TInts& Data,int Target,int Buffer,TInts::iterator It)
{
	if(Buffer == Target) return true;
	if(It == Data.end()) return false;
	int Now = *It;
	It++;
	return Search(Data,Target,Buffer + Now,It) || Search(Data,Target,Buffer,It);
}

int main()
{
	TInts Inputs;
	Input(Inputs);
	TInts Targets;
	Input(Targets);
	std::sort(Inputs.begin(),Inputs.end(),std::greater<int>());
	
	for(unsigned int i=0;i<Targets.size();i++)
	{
		std::string Result = Search(Inputs,Targets[i],0,Inputs.begin()) ? "yes" : "no";
		std::cout << Result << std::endl;
	}
	
	return 0;
}

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

int main() {
 string S; cin >> S;
 int ans = 0;
 rep(i,3) if(S.find(string(i+1,'R')) != string::npos) ans=i+1;
 cout<<ans<<endl;
 return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <math.h>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

map<ll, ll> mp;
int main() {
	ll n, k; cin >> n >> k;

	rep(i, 0, n) {
		ll a, b; cin >> a >> b;
		mp[a] += b;
	}

	for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
		k -= it->second;
		if (k <= 0) {
			cout << it->first << endl;
			return 0;
		}
	}

	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 2000000000;
constexpr auto MOD = 1000000007;

ll gcd(ll p, ll q) {
	if (p % q == 0)return q;
	return gcd(q, p % q);
}

int main() {
	ll a, b;
	cin >> a >> b;
	if (a < b)swap(a, b);

	ll gc = gcd(a, b);

	vector<ll> div = {};
	
	rep1(i, sqrt(gc)) {
		if (gc % i == 0) {
			if (gc == i * i)div.push_back(i);
			else {
				div.push_back(i);
				div.push_back(gc/i);
			}
		}
	}

	ll ans = 0;

	rep(i, div.size()) {
		ll k = div[i];

		if (k == 1) {
			ans++;
			continue;
		}

		bool prime = true;

		rep1(j, sqrt(k)) {
			if (j == 1)continue;
			if (k % j == 0)prime = false;
		}

		if (prime)ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
long int a[1000000];
//insertionSort
void insertion_sort(long int *a, long int g, long int n, long long int *cnt)
{
    int i, j;
    long int v;

    for(i=g;i<n;i++)
    {
        v=a[i];
        j=i-g;
        while(j>=0 && a[j]>v)
        {
            a[j+g]=a[j];
            j=j-g;
            (*cnt)++;
        }
        a[j+g]=v;
    }
}
int main(void)
{
    long int n;
    long int g[100], h;
    int i, j, m=0;
    long long int cnt=0;

    scanf("%ld", &n);
    for(i=0; i<n; i++)
        scanf("%ld", &a[i]);

    //shellSort
    h=1;
    for(i=0; h<=n; i++)
    {
        g[i]=h;
        m++;
        h=h*3+1;
    }
    for(j=m-1; j>=0; j--)
        insertion_sort(a, g[j], n, &cnt);

    printf("%d\n", m);
    for(i=m-1;i>0;i--)
        printf("%ld ", g[i]);
    printf("%ld\n", g[i]);
    printf("%lld\n", cnt);
    for(i=0;i<n;i++)
        printf("%ld\n", a[i]);

    return 0;
}

Measured memory_bytes: 8412
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>
 
  using namespace std;
   

//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ
  typedef long long ll;
  typedef long double lld;
//   typedef string str;
//   typedef unsigned long long ull;
//   ll INF = INT_MAX;
  // ll mod = 998244353;
  lld PI = 3.141592653;

// const int N = 2e5 + 5;

// int a[N];
// int n,k;
  



 


vector<vector<int> > a;
vector<int> b;
queue<int> q;
vector<bool> visited;



  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     

   int n,m;
   cin>>n>>m;
   a = vector<vector<int> > (n+1);
   b = vector<int > (n+1);
   visited = vector<bool> (n+1);
   while (m--){
    int x,y;
    cin>>x>>y;
    a[x].push_back(y);
    a[y].push_back(x);
   }
   q.push(1);
   visited[1] = true;

   while (!q.empty()){
    int v = q.front();
    q.pop();
    for (int i = 0;i<a[v].size();i++){
      int u = a[v][i];
      if (!visited[u]){
        q.push(u);
        visited[u] = true;
        b[u] = v;
      }
    }
   }
   bool ok =true;
   for (int i = 2;i<=n;i++){
    if (b[i]==0) ok = false;
   }
   if (ok){
    cout<<"Yes\n";
    for (int i = 2;i<=n;i++){
    cout<<b[i]<<"\n";
   }

   }else{
    cout<<"No\n";
   }
   
   
   

}
  

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

typedef long long int lli;

using namespace std;

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

	vector<int> N(3);
	int res; 
	cin >> N[0] >> N[1] >> N[2];
	sort(N.begin(), N.end());
	cout << N[0] + N[1] << endl;
}

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


int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
    
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  if (s[0] == '2' || s[0] == '4' || s[0] == '5' || s[0] == '7' || s[0] == '9')
  cout << "hon" << endl;
  else if (s[0] == '0' || s[0] == '1' || s[0] == '6' || s[0] == '8')
    cout << "pon" << endl;
  else if (s[0] == '3')
    cout << "bon" << endl;
}
 

Measured memory_bytes: 3652
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)
	ans := 0
	s := func(x int) (sum int) {
		xStr := strconv.Itoa(x)
		for _, str := range xStr {
			ret, _ := strconv.Atoi(string(str))
			sum += ret
		}
		return
	}
	for i := 0; i <= n; i++ {
		if ret := s(i); a <= ret && ret <= b {
			ans += i
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1808
#include <iostream>

using namespace std;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

int main()
{
    const int F(cin2var<int>());
    const int C = (F - 30) / 2;
    cout << C << endl;
    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
#include <chrono>
#include <thread>

using namespace std;


const bool debug = false;

#ifndef M_PI
    const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
//#define ll long long
const int mod = int(1e9) + 7;
const int inf = 1e9;
//const long long infLL = 1e11;
//const int MX2 = 10100500; //  e7
//const long long INF = 1e18 + 0.5;
const int MX = 200500; //       e5
const int SZ = 1100;
//const int delta = 1 << 19;

int a[MX];

int main()
{
    ios_base::sync_with_stdio(false);
    //if(debug)
    //freopen("/Users/ozzy/Documents/in.txt","r", stdin);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        a[x]++;
        a[y]++;
    }
    for(int i = 1; i <= n; i++){
        if(a[i] & 1){cout << "NO\n"; return 0;}
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <time.h>
#include <deque>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 3030000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
//const int mod = 1e9 + 7;
//const int mod = 998244353;
int mod;

ll dp[6010][3010];

int main(){
	int n; cin >> n >> mod;
	int N = 3*n;
	dp[0][0] = 1;
	rep(i,N){
		rep(j,n+1){
			(dp[i+1][j] += dp[i][j]) %= mod;
			(dp[i+2][j+1] += dp[i][j] * (i+1)) %= mod;
			(dp[i+3][j+1] += dp[i][j] * (i+1) * (i+2)) %= mod;
		}
	}
	ll ans = 0;
	rep(j,n+1) ans += dp[N][j];
	ans %= mod;
	cout << ans << "\n";
}

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

using namespace std;
typedef long long ll;
const int MAXN = 22, mod = 1e9 + 7;
int N, a[MAXN][MAXN];
ll dp[MAXN][1 << MAXN];

ll rec(int m, int w)
{
	if (m == N)
	{
		if (w == 0)
			return 1;
		return 0;
	}
	if (dp[m][w] != -1)
		return dp[m][w];
	ll tot = 0;
	for (int i = 0; i < N; i++)
	{
		int woman = 1 << i;
		bool available = ((woman & w) != 0);
		if (available && a[m][i])
			tot = (tot + rec(m + 1, w ^ woman)) % mod;
	}
	return dp[m][w] = tot;
}

int main()
{
	ios_base::sync_with_stdio(0);

	cin >> N;
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			cin >> a[i][j];
	memset(dp, -1, sizeof(dp));
	ll ans = rec(0, (1 << N) - 1);
	cout << ans;

	return 0;
}

Measured memory_bytes: 724540
def odds_of_oddness():
	
	N = int(input())
	
	tmp = 0 
	for i in range(1,N+1):
		if i % 2 == 1:
			tmp += 1
				
	print(float(tmp)/N)
	
	return 

if __name__=='__main__':
	
	odds_of_oddness()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
  int n=100005;
  int dp[100005];
   vector<int> v(n);

int main()
{
  int k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {cin>>v[i];}
    dp[0]=0;
    for(int i=1;i<k;i++)
    {
dp[i]=abs(v[i]-v[0]);
//cout<<dp[i]<<" ";
    }
    for(int i=k;i<n;i++)
    {dp[i]=INT_MAX;
    	for(int j=1;j<=k;j++)
	dp[i]=min(dp[i-j]+abs(v[i]-v[i-j]),dp[i]);
    }
cout<<dp[n-1];

}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int a[100010], b[100010];
signed main(void)
{
  int n, k;
  cin >> n >> k;
  REP(i, n) cin >> a[i] >> b[i];

  // a[j]でbitが立っていてcでbitが立っていない → だめ
  int ret = 0;
  REP(j, n) {
    bool flag = true;
    REP(l, 30) {
      if((a[j]>>l)&1 && !((k>>l)&1)) {flag = false; break;}
    }
    if(flag) ret += b[j];
  }
  int ans = ret;
  // cout << ans << endl;
  REP(i, 30) {
    // kの上位ibit目が1 → そこを0にしてそこより下位のbitを1に
    // cout << (k>>i) << endl;
    if(k>>i&1) {
      // cout << "i:" << i << " ";
      int c = k&~(1LL<<i);
      c |= (1LL<<i)-1;
      // cout << "c:" << c << " ";
      // a[j]でbitが立っていてcでbitが立っていない → だめ
      int ret = 0;
      REP(j, n) {
        bool flag = true;
        REP(l, 30) {
          if((a[j]>>l)&1 && !((c>>l)&1)) {flag = false; break;}
        }
        if(flag) ret += b[j];
      }
      chmax(ans, ret);
      // cout << ret << endl;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
//#define 200000 MAXN
using namespace std;
//char dp[MAXN];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //int temp, counter = 0;
    string s;
    cin >> s;

    for( int i=0;i<s.length();i++){
        if( s[i] == '?') s[i] = 'D';
    }
    cout << s;

    return 0;
}


Measured memory_bytes: 3740
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
first = 0
for i in range(n+1):
  first += abs(a[i+1] - a[i])
for i in range(1,n+1):
  print(first-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]))
  

Measured memory_bytes: 14048
package main

import (
        "bufio"
        "os"
        "strconv"
)

func main() {
        scanner := bufio.NewScanner(os.Stdin)
        scanner.Split(bufio.ScanWords)

        scanner.Scan()
        N, _ := strconv.Atoi(scanner.Text())
        scanner.Scan()
        Q, _ := strconv.Atoi(scanner.Text())

        edges := make([][]int, N+1)
        for i := 0; i < len(edges); i++ {
                edges[i] = make([]int, 0)
        }
        for i := 1; i <= N-1; i++ {
                scanner.Scan()
                a, _ := strconv.Atoi(scanner.Text())
                scanner.Scan()
                b, _ := strconv.Atoi(scanner.Text())
                edges[a] = append(edges[a], b)
        }

        counts := make([]int, N+1)
        for j := 1; j <= Q; j++ {
                scanner.Scan()
                p, _ := strconv.Atoi(scanner.Text())
                scanner.Scan()
                x, _ := strconv.Atoi(scanner.Text())
                counts[p] += x
        }

        for i := 1; i <= N; i++ {
                if counts[i] == 0 {
                        continue
                }
                edges := edges[i]
                for k := 0; k < len(edges); k++ {
                        counts[edges[k]] += counts[i]
                }
        }

        w := bufio.NewWriter(os.Stdout)
        for i := 1; i <= N-1; i++ {
                w.WriteString(strconv.Itoa(counts[i]) + " ")
        }
        w.WriteString(strconv.Itoa(counts[N]) + "\n")
        w.Flush()
}


Measured memory_bytes: 17536
N = int(input())
A = list(map(int,input().split()))
print(*A)
for i in range(1,N):
    v = A[i]
    j=i-1
    while(j>=0 and A[j] > v):
        A[j+1] = A[j]
        j-=1
    A[j+1]=v
    print(*A)

Measured memory_bytes: 5984
s = gets.chomp.chars
s.delete_at(s.size - 1)
while true
  if s[0..((s.size - 1)/2)] == s[((s.size + 1)/2)..(s.size - 1)]
    break
  end
  s.delete_at(s.size - 1)
end
puts s.size

Measured memory_bytes: 14220
import numpy as np
N, T = (int(_) for _ in input().split())
e = [[int(i) for i in input().split()] for i in range(N)]
T_list=[]
for j in range(N):
  if e[j][1]<=T:
    T_list.append(e[j][0])
if len(T_list)==0:
  print ("TLE")
else:
  print (np.min(T_list))
  

Measured memory_bytes: 12776
#include<bits/stdc++.h>
using namespace std;
#define MN 1000000
#define mod 1000000007
inline int read()
{
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int f[MN+5],p[MN+5],inv[MN+5],Inv[MN+5],n,ans;
inline int C(int n,int m){return 1LL*p[n]*Inv[m]%mod*Inv[n-m]%mod;}
int main()
{
    n=read();p[0]=inv[0]=f[0]=Inv[0]=p[1]=inv[1]=1;
    for(int i=2;i<=n;++i) p[i]=1LL*p[i-1]*i%mod,inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
    for(int i=1;i<=n;++i) Inv[i]=1LL*inv[i]*Inv[i-1]%mod;
    for(int i=1,j=2;i<=n;++i,j=j*2%mod) f[i]=(j+mod-f[i-1])%mod;
    int pp=1LL*(mod+1)/3*inv[n]%mod;
    for(int i=2;i<=n+1;++i)  // G(n+1-i,i) -> C(n+1-i+i,i-1)
        ans=(ans+1LL*f[i-2]*C(n,i-1)%mod*pp%mod*inv[i-1])%mod;
    for(int i=1;i<n;++i) ans=1LL*ans*(mod+1)/3%mod;
    cout<<ans;
    return 0;
}
//tot -> k part
//E(min) = sum s=0-tot/k (tot-ks)^(k-1) / tot^(k-1)
// sum -> -1/k^2 (tot-ks)^k
//E(min) = 0 - (-1/k^2 * tot^k / tot^(k-1))
//       = tot / k^2

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
class binary_indexed_tree {
  public:
    int n;
    vector<int> tr;
    binary_indexed_tree (int size) {
      n = size;
      tr.resize(n, 0);
    }
    int size () {
      return n;
    }
    int acm (int i) {
      int ret = 0;
      for (; i >= 0; i &= i + 1, i--){
        ret += tr[i];
      }
      return ret;
    }
    void add (int i, int x) {
      for (; i < n; i |= i + 1) {
        tr[i] += x;
      }
    }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  binary_indexed_tree bit(m + 1);
  vector<vector<pair<int, int>>> itv(m + 1);
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    int d = ++r - l;
    bit.add(l, 1);
    bit.add(r, -1);
    itv[d].push_back({l, r});
  }
  vector<int> ret(m + 1, 0);
  int base = 0;
  for (int d = m; d >= 1; d--) {
    ret[d] = base;
    for (int i = 0; i <= m; i += d) {
      ret[d] += bit.acm(i);
    }
    for (auto &nxt : itv[d]) {
      int l = nxt.first;
      int r = nxt.second;
      bit.add(l, -1);
      bit.add(r, 1);
      base++;
    }
  }
  for (int d = 1; d <= m; d++) {
    cout << ret[d] << '\n';
  }
  return 0;
}

Measured memory_bytes: 8448
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define ls k<<1
#define rs k<<1|1
using namespace std;
const int N=200005;
struct node
{
    int u,v,nxt;
}edge[2*N];
struct Tree
{
    int l,r,w,siz,f;
}T[2*N];
int n,m,cnt=0,num=1,root=1,a[N],b[N],head[N];
int deep[N],fa[N],son[N],tot[N],top[N],idx[N];
void AddEdge(int x,int y)
{
    edge[num].u=x;
    edge[num].v=y;
    edge[num].nxt=head[x];
    head[x]=num++;
}
int dfs1(int now,int f,int dep)
{
    deep[now]=dep;
    fa[now]=f;
    tot[now]=1;
    int maxson=-1;
    for(int i=head[now];i!=-1;i=edge[i].nxt)
    {
        if(edge[i].v==f) continue;
        tot[now]+=dfs1(edge[i].v,now,dep+1);
        if(tot[edge[i].v]>maxson) maxson=tot[edge[i].v],son[now]=edge[i].v;
    }
    return tot[now];
}
void update(int k)
{
    T[k].w=T[ls].w+T[rs].w;
}
void Build(int k,int ll,int rr)
{
    T[k].l=ll;T[k].r=rr;T[k].siz=rr-ll+1;
    if(ll==rr)
    {
        T[k].w=a[ll];
        return;
    }
    int mid=(ll+rr)>>1;
    Build(ls,ll,mid);
    Build(rs,mid+1,rr);
    update(k);
}
void dfs2(int now,int topf)
{
    idx[now]=++cnt;
    a[cnt]=b[now];
    top[now]=topf;
    if(!son[now]) return;
    dfs2(son[now],topf);
    for(int i=head[now];i!=-1;i=edge[i].nxt)
      if(!idx[edge[i].v]) dfs2(edge[i].v,edge[i].v);
}
void pushdown(int k)
{
    if(!T[k].f) return ;
    T[ls].w=T[ls].w+T[ls].siz*T[k].f;
    T[rs].w=T[rs].w+T[rs].siz*T[k].f;
    T[ls].f=T[ls].f+T[k].f;
    T[rs].f=T[rs].f+T[k].f;
    T[k].f=0;
}
void IntervalAdd(int k,int ll,int rr,int val)
{
    if(ll<=T[k].l&&T[k].r<=rr)
    {
        T[k].w+=T[k].siz*val;
        T[k].f+=val;
        return;
    }
    pushdown(k);
    int mid=(T[k].l+T[k].r)>>1;
    if(ll<=mid) IntervalAdd(ls,ll,rr,val);
    if(rr>mid) IntervalAdd(rs,ll,rr,val);
    update(k);
}
int IntervalSum(int k,int ll,int rr)
{
    int ans=0;
    if(ll<=T[k].l&&T[k].r<=rr)
        return T[k].w;
    pushdown(k);
    int mid=(T[k].l+T[k].r)>>1;
    if(ll<=mid) ans=ans+IntervalSum(ls,ll,rr);
    if(rr>mid)  ans=ans+IntervalSum(rs,ll,rr);
    return ans;
}
void TreeSum(int x,int y)
{
    int ans=0;
    while(top[x]!=top[y])
    {
        if(deep[top[x]]<deep[top[y]]) swap(x,y);
        ans=ans+IntervalSum(1,idx[top[x]],idx[x]);
        x=fa[top[x]];
    }
    if(deep[x]>deep[y]) swap(x,y);
    ans=ans+IntervalSum(1,idx[x],idx[y]);
    cout<<ans<<" ";
}
int main()
{
    cin>>n>>m;
    memset(head,-1,sizeof(head));
    for(int i=1;i<=n-1;i++)
    {
    	int x,y;
    	cin>>x>>y;
        AddEdge(x,y);
		AddEdge(y,x);
    }
    dfs1(root,0,1);
    dfs2(root,root);
    Build(1,1,n);
    while(m--)
    {
    	int x,y;
    	cin>>x>>y;
        IntervalAdd(1,idx[x],idx[x]+tot[x]-1,y);
    }
    for(int i=1;i<=n;i++) TreeSum(i,i);
    cout<<endl;
    return 0;
}

Measured memory_bytes: 37504
//#pragma optimization_level 3
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset;
*/

#define fr first
#define sc second
#define vec vector
#define pb push_back
#define pii pair<int, int>
#define fo(x,y) for(int x = 1 ; x <= y ; ++x)
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;

typedef long long ll;
typedef unsigned int uint;
const int nmax = 200005;
const ll linf = LLONG_MAX;
const int mod = 1e9+7;
const int inf = INT_MAX;
#define pll pair<ll,ll>


ll n , range , a;
pll mon[nmax];
queue < pll > take;

int main(){
    cin >> n >> range >> a;
    range = 2*range + 1;
    fo(i,n){
        cin >> mon[i].fr >> mon[i].sc;
    }
    ll rez = 0 , delta = 0;
    sort(mon+1,mon+n+1);
    for(int m = 1 ; m <= n ;m ++){
        while(!take.empty() && take.front().fr <= mon[m].fr){
            delta += take.front().sc;
            take.pop();
        }
        while(mon[m].sc + delta > 0){
            take.push(make_pair(mon[m].fr + range, a*((mon[m].sc + delta + a - 1)/a)));
            rez += (mon[m].sc + delta + a - 1)/a;
            delta -= a*((mon[m].sc + delta + a - 1)/a);

        }
    }
    cout << rez << '\n';
}


Measured memory_bytes: 4992
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)
#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    int mx=0, mn=INF;
    
    cin>>N;
    rep(i,N){
        int x;cin>>x;
        if(x>mx)mx=x;
        if(x<mn)mn=x;
    }
    cout1(mx-mn);
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());

    while(n-- > 0){
      System.out.println(sc.nextLine().replaceAll("Hoshino","Hoshina"));
    }
  }
}

Measured memory_bytes: 12000
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct q{
char name[100];
int t;
} P;

P Q[LEN];
int head,tail,n;

void enqueue(P x){
Q[tail]=x;
tail=(tail+1) % LEN;
}

P dequeue(){
P x=Q[head];
head=(head+1) % LEN;
return x;
}

int min(int a,int b){
return a < b ? a : b;
}

int main(){
int lap=0,c;
int i,q;
P a;
scanf("%d%d",&n,&q);

for(i=1;i <= n; i++){
scanf("%s",Q[i].name);
scanf("%d",&Q[i].t);
}
head=1;
tail=n+1;

while(head != tail){
a=dequeue();
c=min(q,a.t);
a.t-=c;
lap+=c;
if(a.t > 0) enqueue(a);
else{
printf("%s %d\n",a.name,lap);
}
}
return 0;
}

Measured memory_bytes: 10756
#include<stdio.h>
 
int main()
{
  int N, i, boss;
  int num[200000] = {0};
 
  scanf("%d", &N);
  
  for(i = 1; i < N; i++)
  {
    scanf("%d", &boss);
    num[boss - 1] += 1;
  }
 
  for(i = 0; i < N; i++)
  {
    printf("%d\n", num[i]);
  }
 
  return 0;
}

Measured memory_bytes: 2492
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=998244353;

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

int n,a[200010],b[200010],ans = 0;

bool isBig(int x){
	return (b[(x + n - 1) % n] < b[x] && b[x] > b[(x + 1) % n]);
}

signed main(){
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 0;i < n;i++) cin >> b[i];
	queue<int> que;
	for(int i = 0;i < n;i++){
		if(isBig(i)) que.push(i);
	}
	while(!que.empty()){
		int v = que.front();que.pop();
		int dist = b[v] - max(a[v],max(b[(v + n - 1) % n],b[(v + 1) % n]));
		int dec = b[(v + n - 1) % n] + b[(v + 1) % n];
		if(dist % dec == 0) {
			b[v] -= dist;
			ans += dist / dec;
		}
		else{
			b[v] -= dec * (dist / dec + 1);
			ans += dist / dec + 1;
		}
		if(isBig((v + n - 1) % n) && b[(v + n - 1) % n] > a[(v + n - 1) % n]) que.push((v + n - 1) % n);
		if(isBig((v + 1) % n) && b[(v + 1) % n] > a[(v + 1) % n]) que.push((v + 1) % n);
	}
	bool isOK = true;
	for(int i = 0;i < n;i++){
		if(a[i] != b[i]) isOK = false;
	}
	if(isOK) cout << ans << endl;
	else cout << -1 << endl;
}

Measured memory_bytes: 4224
/*
ID: thanhvq1
LANG: C++14
PROB: namenum
*/

#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;

// defines
#define int long long
typedef long long ll;
#define double long double
#define vec vector
#define vi vector<int>
#define vvi vector<vector<int>>
#define FZ(n) memset((n),0,sizeof())
#define FMO(n) memset((n),-1,sizeof(n))
#define unset unordered_set
#define ii pair<int, int>
#define vii vector<ii>
#define F first
#define S second
#define mp make_pair
#define PB push_back
#define ALL(x) begin(x),end(x)
#define SZ(x) ((int)(x).size())
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define debug(x) cout << #x << " = " << (x) << endl
#define debug2(x, y) cout<<#x<<" = "<<(x)<<", "<<#y<<" = "<<(y)<< endl
#define debug3(x, y, z) cout<<#x<<" = "<<(x)<<", "<<#y<<" = "<<(y)<<", "<<#z<<" = "<<(z)<<endl
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
#define max3(a, b, c) max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c) min(a, b) < min(b, c) ? min(a, b) : min(b, c)

//permanent constants
const long long INF64 = 1e18; const int INF32 = 1e9; const int BIG = (int)(1e9 + 239);
const int MOD = 998244353; //1e9 + 7;  const ll MOD2 = (ll)MOD * (ll)MOD;
const double PI = 2.0*acos(0.0); //acos(-1.0L);
const double EPS = static_cast<double>(1e-10);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0};
//const ll INF = (ll)(1e18 + 239);

//random
mt19937 rnd(239); //(chrono::high_resolution_clock::now().time_since_epoch().count());

void FILEIO() {  freopen("in.txt", "r", stdin);  freopen("out.txt", "w", stdout); }
//void FILEIO()   {freopen("in.txt", "w", stdout);}
//void FILEIO() {  freopen("namenum.in", "r", stdin);  freopen("namenum.out", "w", stdout); }
void input() {   }

void solve() {
	int a, b, c; cin >> a >> b >> c;
	cout <<  max(0LL, c - (a - b)) << endl;
}

signed main() {
  ios_base::sync_with_stdio(false); cin.tie();
//  FILEIO();
//auto beginProgram = chrono::steady_clock::now();

//  int test = 0;
//  int t; cin >> t;
//  while(t--)
  {
//	  cout << "Case " << ++test << ": ";
	  solve();
  }

//  auto endProgram = chrono::steady_clock::now();
//  cout << chrono::duration_cast<chrono::milliseconds>(endProgram - beginProgram).count() << " ms" << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    bool red[100001];
    int balls[100001];
    int n,m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        red[i] = false;
        balls[i] = 1;
    }
    red[1] = true;
    for(int i = 0; i < m; i++){
        int x,y;
        cin >> x >> y;
        if(red[x] == true){
            red[y] = true;
            if(balls[x] == 1)red[x] = false;
        }
        balls[x]--;
        balls[y]++;
    }
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        if(red[i] == true)cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 768
#include <stdio.h>

int main(void) {
    int n, a[100005] = {0};
    int t[100005] = {0};
    long long int dist[100005] = {0};

    scanf("%d", &n);
    for(int i=1; i<=n; i++) {
        scanf("%d", a+i);
        t[i] = a[i]>a[i-1] ? a[i]-a[i-1] : a[i-1]-a[i];
        dist[i] = dist[i-1] + t[i];
    }
    t[n+1] = a[n]>0 ? a[n] : -a[n];
    dist[n+1] = dist[n] + t[n+1];

    for(int i=1; i<=n; i++) {
        long long int temp = dist[i-1] + (a[i-1] > a[i+1] ? a[i-1] - a[i+1] : a[i+1] - a[i-1]) + dist[n+1]-dist[i+1];
        printf("%lld\n", temp);
    }
    return 0;
}


Measured memory_bytes: 2304