akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
int main()
{

  int time=0,i,head=0,tail,n,kuontamu,x[100000];
  char name[100000][10];

  scanf("%d %d",&n,&kuontamu);
  tail = n;
  for(i = 0; i < n; i++) {
    scanf("%s %d",name[i],&x[i]);
  }


  while(tail != head) {
    if(x[head] > kuontamu) {
      time += kuontamu;
      x[head] -= kuontamu;

      strcpy(name[tail],name[head]);
      x[tail] = x[head];
      tail++;
      if(tail == 100000) {
        tail = 0;
      }
    }
    else{
      time += x[head];
      printf("%s %d\n",name[head],time);
    }
    head++;
    if(head == 100000) {
      head = 0;
    }
  }
  return 0;
}

Measured memory_bytes: 1980
#include <bits/stdc++.h>
#include<unordered_map>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;

int main() {
	cin >> N;
	vector<int>a(N);
	for (int i = 0; i < N; i++)cin >> a[i];
	sort(a.begin(), a.end());
	ll mx = a[N - 1];
	ll diff = 1e9;
	for (int i = 0; i < N-1; i++) {
		if (diff >= abs(2 * a[i] - mx)) {
			ans = a[i];
			diff = abs(2 * a[i] - mx);
		}
	}
	cout << mx << " " << ans << endl;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  for (int i = 0; i < 4; i++) {
    if (A * B * i % 2 == 1) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
li = [int(input()) for _ in range(5)]
time = 0
min1 = 10
for i in range(5):
    a = li[i]
    if a % 10 != 0:
        time += (int(a/10) + 1) * 10
        if a % 10 < min1 :
            min1 = a % 10
    else:
        time += a
print(time - 10 + min1)


Measured memory_bytes: 3060
#include <stdio.h>
#define N 3
int suretu[N][N] = {
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 0}};
int dx[] = { 0, 1, 0, -1 };
int dy[] = { -1, 0, 1, 0 };
int keisan(int f[N][N]) {
  int i,j;
    for (i=0;i<N;++i) {
        for (j=0;j<N;++j) {
            if(f[i][j] != suretu[i][j])
                return 0;
        }
    }
    return 1;
}
int jeep(int f[N][N], int x, int y, int v, int d, int l) {
  int i,j,res,nx,ny;
    if (keisan(f)) return d;
    if (d > l)return -1;
    for (i=0;i<4;++i) {
        nx=x+dx[i]; ny=y+dy[i];
        if (nx<0||nx>2||ny<0||ny>2||(i+2)%4==v)
            continue;
        f[y][x]=f[ny][nx]; f[ny][nx]=0;
        if((res=jeep(f, nx, ny, i, d + 1, l)) > 0)return res;
        f[ny][nx] = f[y][x];  f[y][x] = 0;
    }
    return -1;
}
int main() {
  int f[N][N], x, y,i,j,res;
    for (i=0; i< N; ++i) {
        for (j=0; j<N;++j) {
            scanf("%d",&f[i][j]);
            if(f[i][j]==0) {
                y=i;x=j;
            }
        }
    }
        for (i=1;i<50;++i) {
        if ((res=jeep(f,x,y,-1,0,i))>=0){
            break;
        }
    }
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 2124
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,k;
    cin>>n>>k;
    int res=1;
    for(int i=0;i<n;i++){
        if(res<k)res*=2;
        else res+=k;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=5000;
string s;
string ans[10],tmp[10];
int n,len;
void work(string s)
{
    ans[++len]=s;
    sort(ans+1,ans+len+1);
    int now=1;
    tmp[1]=ans[1];
    for(int i=2;i<=len;++i)
        if(ans[i]!=ans[i-1]) tmp[++now]=ans[i];
    len=now;
    for(int i=1;i<=len;++i) ans[i]=tmp[i];
    if(len>5) --len;
}
int main()
{

    cin>>s;
    n=s.length();
    for(int i=0;i<n;++i)
    {
        string t="";
        for(int j=i;j<min(n,i+5);++j)
        {
            t+=s[j];
            work(t);
        }
    }
    int k;
    cin>>k;
    cout<<ans[k];
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

vector<vector<int>> g;
int ans = 0;
int n, m;

void dfs(int v, int c, vector<int> visited) {
  visited[v] = 1;
  c++;
  if (c == n){
    bool ok = true;
    rep(i, n) if (!visited[i]) ok = false;
    if (ok) ans++;
    return;
  } 
  rep(i, g[v].size()) {
    int u = g[v][i];
    if (visited[u]) continue;
    dfs(u, c, visited);
  }
}

int main(){
  cin >> n >> m;
  g.resize(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> x(n, 0);
  dfs(0, 0, x);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
const int MAXN = 10;
int F[MAXN];
int X[MAXN];
int Y[MAXN];
int N;

void init() {
    F[0] = 1;
    for (int i = 1; i <= N; ++i) {
        F[i] = F[i-1] * i;
    }
}

int main() {
    scanf("%d", &N);
    init();
    for (int i = 1; i <= N; ++i) {
        scanf(" %d%d", &X[i], &Y[i]);
    }
    double sum = 0;
    for (int i = 1; i < N; ++i) {
        for (int j = i+1; j <= N; ++j) {
            double D = hypot(X[i] - X[j], Y[i] - Y[j]);
            sum += 2 * D * F[N-1];
        }
    }
    sum /= F[N];
    printf("%.9f\n", sum);
    return 0;
}

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

int main(){
  int n,m,ans=-1;
  cin >> n >> m;
  for(int i=0;i<=1262;i++){
    if(floor(i*0.08)==n&&floor(i*0.1)==m){
      ans=i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int a,b,c,d; cin>>a>>b>>c>>d;
    bool ok=false;
    if(abs(a-c)<=d) ok =true;
    if(abs(a-b)<=d && abs(b-c)<=d) ok=true;
    cout<<(ok?"Yes": "No")<<endl;
}

Measured memory_bytes: 3516
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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

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

	cout << (n-k)+1 << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

using ll = long long;
using Graph = vector<vector<int>>;

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(s);
  bool nf=false,sf=false,ef=false,wf=false;
  REP(i,s.size()){
    if(s[i]=='N') nf=true;
    if(s[i]=='S') sf=true;
    if(s[i]=='E') ef=true;
    if(s[i]=='W') wf=true;
  }
  Yes((nf == sf) && (ef == wf));
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

ll h, w, h1, h2, h3, w1, w2, w3, mx, mn, ans = INF, m1, m2, m3;

ll f(ll h, ll w) {
    for (ll h1 = 1; h1 < h; ++h1) {
    m1 = h1 * w;

    h2 = ceil((h - h1) / 2.0);

    m2 = h2 * w;
    h3 = (h - h1 - h2);
    m3 = h * w - m1 - m2;
    mx = max({m1, m2, m3});
    mn = min({m1, m2, m3});
    ans = min(ans, mx - mn);

    h2 = h - h1;
    w2 = ceil(w / 2.0);
    m2 = h2 * w2;
    w3 = w - w2;
    m3 = h * w - m1 - m2;
    mx = max({m1, m2, m3});
    mn = min({m1, m2, m3});
    ans = min(ans, mx - mn);
  }
  return ans;
}


int main() {
  int H, W;
  cin >> H >> W;
  ans = min(f(H, W), f(W, H));

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


Measured memory_bytes: 256
from sys import stdin
input = stdin.readline
def main():
  num_list = list(map(int, input().split()))
  A=num_list[0]
  B=num_list[1]
  C=num_list[2]
  K=num_list[3]
  sum_count=0
  sFlag=True
  i=0
  if(A>=K):
    sum_count=K
    sNum=0
  else:
    sNum=K-A
    sum_count=sum_count+A
  if(B>=sNum):
    sNum=0
  else:
    sNum=sNum-B
  if(sNum!=0):
    sum_count=sum_count-sNum
  else:
    if(C>=sNum):
      sum_count=sum_count-sNum
    else:
      sum_count=sum_count-C
  print(sum_count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 61944
//BadWaper gg
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define N 100010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
ll a[N];ll ans;
ll n;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	for(register ll i=1;i<=n;i++)a[i]=read();
	for(register ll i=1;i<=n;i++)
	{
		ans+=a[i]/2;a[i]%=2;
		if(a[i]&&a[i+1]>=1)
		{
			ans++;a[i+1]--;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n, k; cin >> n >> k;
	vector<int> neg, pos;

	rep(i, 0, n) {
		int t; cin >> t;
		if (t >= 0) pos.push_back(t);
		else neg.push_back(t);
	}
	reverse(all(neg));

	int ans = 0x3f3f3f3f;
	rep(i, 0, min(k, sz(neg)) + 1) {
		int ll = i, rr = k - i;
		if (rr > pos.size()) continue;
		int distl = ll > 0 ? -neg[ll - 1] : 0;
		int distr = rr > 0 ? pos[rr - 1] : 0;
		ans = min(ans, distl * 2 + distr);
		ans = min(ans, distl + distr * 2);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1020
#include<iostream>
#include<utility>
#include<vector>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(v) v.begin(),v.end()
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
int parent[10010];

int find(int a){
	if(parent[a]==a)return a;
	else return parent[a]=find(parent[a]);
}

void unite(int a,int b){
	parent[find(a)]=find(b);
	find(a);find(b);
}

int main(){
	int n,m,a,b,c;
	cin>>n>>m;
	vector<piii> edge;
	rep(i,m){
		cin>>a>>b>>c;
		edge.pb(piii(c,pii(a,b)));
	}
	rep(i,n)parent[i]=i;
	sort(all(edge));
	int ans=0;
	rep(i,edge.size()){
		int a=edge[i].second.first,b=edge[i].second.second;
		if(find(a)==find(b))continue;
		ans+=edge[i].first;
		unite(a,b);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4500
#include<stdio.h>
#include<math.h>
int main()
{
  double x1, x2, y1, y2,n;
  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
  n = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
  printf("%lf",n);
  
  return 0;
}



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

using namespace std;
typedef long long ll;

#define size1 1001001001
int n,a[100005],k;
ll dp[100005];
ll jump(int i)
{
    if(i>=n)
        return size1;

    if(i==n-1)
        return 0;

    if(dp[i]!=-1)
        return dp[i];

    ll temp=size1;
    for(int j=1;j<=k;j++)
    {
        temp=min(temp,abs(a[i]-a[i+j])+jump(i+j));
    }
    dp[i]=temp;
    return dp[i];
}

int main()
{
    memset(dp,-1,sizeof(dp));
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    cout<<jump(0);
    return 0;
}


Measured memory_bytes: 12540
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

int main(){
  std::string s;
  int p;
  std::map<std::string,std::vector<int> > m;
  while(std::cin>>s>>p,!std::cin.eof()){
    m[s].push_back(p);
  }
  std::map<std::string,std::vector<int> >::iterator m_it = m.begin();
  while(m_it!=m.end()){
    std::cout<<(*m_it).first<<std::endl;
    std::sort((*m_it).second.begin(),(*m_it).second.end());
    std::vector<int>::iterator v_it = (*m_it).second.begin();
    while(v_it!=(*m_it).second.end()){
      std::cout<<*v_it;
      v_it++;
      (v_it==(*m_it).second.end())?std::cout<<std::endl:std::cout<<" ";
    }
    m_it++;
  }
  return 0;
}
/*
Sample Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output for the Sample Input
document
13
easy
9
even
18 25
introduction
3
style
7 12 21
*/

Measured memory_bytes: 0
from fractions import gcd

A, B, C, D = map(int, input().split())
l = C * D // gcd(C, D)
x = (A - 1) - (A - 1) // C - (A - 1) // D + (A - 1) // l
y = B - B // C - B // D + B // l
print(y - x)


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

int main(){
  int K,N,Ans;
  cin >> K >> N;
  vector<int> A(N);
  vector<int> btw(N);
  vector<int> lgst(2);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
    if(i != 0){
      btw.at(i) = (A.at(i-1) - A.at(i))*(-1);
      if(i == N-1)
        btw.at(0) = K - A.at(i) + A.at(0);
    }
  }
  lgst.at(0) = btw.at(0); lgst.at(1) = 0;
  for(int i=0; i<N; i++){
    if(lgst.at(0) <= btw.at(i)){
      lgst.at(0) = btw.at(i);
      lgst.at(1) = i;
    }
  }
  
  for(int i=0; i<N; i++){
    Ans += btw.at(i);
  }
  cout << Ans-lgst.at(0) << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <set>
#include <string>
using namespace std;


int main() {

	string S;
	cin >> S;
	int bucket[30] = {};
	char result = ' ';

	for (int i = 0; i < S.size(); i++) {
		bucket[(S[i] - 'a')]++;
	}


	for (int i = 0; i <= 25; i++) {
		if (bucket[i] == 0) {
			result = i + 'a';
			break;
		}
	}
	
	if (result == ' ') {
		cout << "None";
	}
	else {
		cout << result;
	}
	

}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first 
#define s second
int32_t main(){
     int n , k;
     cin>>n>>k;
     int arr[n];
     for(int i = 0 ; i < n ;i++)cin>>arr[i];
     sort(arr , arr+n);
     int sum = 0;
     for(int i = 0 ; i < k ;i++){
          sum += arr[i];
     }
     cout<<sum<<endl;
}

Measured memory_bytes: 3648
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [[int(i) for i in input().split()] for i in range(m)]
l = [1] * n
for i in range(m):
    if h[ab[i][0] - 1] < h[ab[i][1] - 1]:
        l[ab[i][0] - 1] = 0
    elif h[ab[i][0] - 1] > h[ab[i][1] - 1]:
        l[ab[i][1] - 1] = 0
    else:
        l[ab[i][0] - 1] = 0
        l[ab[i][1] - 1] = 0
ans = sum(l)
print(ans)
        


Measured memory_bytes: 30360
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

//Code Short
#define REP(i,n) for(int i = 0;i < n;++i)
#define PB(s) push_back(s)
#define DSORT(n) sort(n.begin(),n.end())
#define QECHO(n) cout << n
#define QECHOS(n) cout << n << " "

//Define Math
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;
typedef long long ll;
/* prototype */
int EDSum(ll);//各桁の和
vector<int> SOE(int,int);//素数 (Min,Max)
int MinCM(int,int);//最小公倍数(num1,num2)
int MaxCD(int,int);//最大公約数(num1,num2)
vector<int> igets(int);//cin * N
ll nPr(ll,ll); //(n,r)
ll nE(ll); //(n)
ll nCr(ll,ll); //(n,r)

void solve(){
    //START
  int a,b;
  cin >> a >> b;
  a++;
  cout << a - b << endl;
}

int main(void){cin.tie(0);ios::sync_with_stdio(false);solve();}
int EDSum(ll number) {
  int ans = 0;
  while (1) {
    ans += number % 10;
    number /= 10;
    if (number == 0) break;
  }
  return ans;
}

vector < int > SOE(int min, int max) {
  if (min < 2) min = 2;
  vector < int > int_array;
  for (int i = min; i <= max; i++) int_array.push_back(i);
  vector < int > sosu;
  double stop = sqrt(max);
  while (true) {
    sosu.push_back(int_array.front());
    int_array.erase(int_array.begin());
    if (stop < (double)(sosu.back())) break;
    for (int i = 0; i < (int) int_array.size(); i++) {
      if (int_array[i] % sosu.back() == 0)
        int_array.erase(int_array.begin() + i);
    }
  }
  sosu.insert(sosu.end(), int_array.begin(), int_array.end());
  return sosu;
}

int MinCM(int a, int b) {
  int c = a * b;
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return c / b;
}

int MaxCD(int a, int b) {
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
vector < int > igets(int N) {
  vector < int > A;
  int temp;
  for (int i = 0; i < N; ++i) {
    cin >> temp;
    A.push_back(temp);
  }
  return A;
}

ll nPr(ll n, ll r) {
  ll ans = 1;
  r = n - r;
  while (n != r) {
    ans *= n;
    --n;
  }
  return ans;
}

ll nE(ll n) {
  return nPr(n, n);
}

ll nCr(ll n, ll r) {
  if (r == 0) return -1;
  else {
    if (0 != n - r && n - r < r) r = n - r;
    return nPr(n, r) / nE(r);
  }
}

Measured memory_bytes: 256
n,k = map(int,input().split())

ans = 0

if k == 0:
    print(n**2)
    exit()

for i in range(k+1,n+1):
    a = n // i
    b = n % i
    tmp = a * (i - k) + max(0, b - k + 1)
    ans += tmp

print(ans)


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

int main()
{
  int n;
  cin >> n;
  int a,ans=0;
  for(int i=0;i<n;i++){
    cin >> a;
    while(a%2==0){
      a/=2; ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<tuple<ll, ll, ll> > arr(N);
  ll A, B;
  for(int i=0;i<N;++i) {
    cin>>A>>B;
    arr[i] = make_tuple(A-B, A, B);
  }
  sort(arr.begin(), arr.end());
  if(get<0>(arr[0])==0) {
    cout<<0<<endl;
    return 0;
  }
  ll sum = 0;
  ll h = big;
  for(int i=0;i<N;++i) {
    sum += get<2>(arr[i]);
    if(get<0>(arr[i])>0) {
      h = min(h, get<2>(arr[i]));
    }
  }
  cout<<sum-h<<endl;
}


Measured memory_bytes: 3788
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

const MOD = 998244353;
long[] f; // 階乗
long[] finv; // 階乗の逆元

long modPow(long x, long k, long m) {
    if (k == 0) return 1;
    if (k % 2 == 0) return modPow(x * x % m, k / 2, m);
    return x * modPow(x, k - 1, m) % m;
}

void init(long n) {
    f = new long[n + 1];
    f[0] = 1;
    for (int i = 1; i <= n; i++) {
        f[i] = (i * f[i - 1]) % MOD;
    }

    finv = new long[n + 1];
    finv[n] = modPow(f[n], MOD - 2, MOD);
    for (long i = n - 1; i >= 0; i--) {
        finv[i] = (finv[i + 1] * (i + 1)) % MOD;
    }
}

long calc(long n, long a, long b, long k) {

    long nck(long n, long k) {
        return (f[n] * finv[k] % MOD) * finv[n - k] % MOD;
    }

    // ax + by = k
    long ans = 0;
    for (int x = 0; x <= n; x++) {
        if (k - a * x < 0) break;
        if ((k - a * x) % b != 0) continue;

        long y = (k - a * x) / b;
        if (y > n) continue;
        ans += nck(n, x) * nck(n, y) % MOD;
        ans %= MOD;
    }

    return ans;
}

void main() {
    auto xs = reads!long;
    long n = xs[0], a = xs[1], b = xs[2], k = xs[3];

    init(n);
    auto ans = calc(n, a, b, k);
    writeln(ans);
}

Measured memory_bytes: 7932
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
  int r, D, x;
  cin >> r >> D >> x;
  int x_out = x;
  REP(i, 10) {
    x_out = r * x_out - D;
    cout << x_out << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int N=200010;
int n;
vector<vector<int>> g(N); 
vector<int> b,w;

void dfs(int v,int pre,int c){
	if(c==1) b.push_back(v);
	if(c==-1) w.push_back(v);
	for(auto itr:g[v]){
		if(itr==pre) continue;
		dfs(itr,v,-c);
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>n;
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--,b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0,-1,1);
	vector<int> p(n),cnt(3,0),now(3); 
	cnt[0]=cnt[1]=cnt[2]=n/3;
	if(n%3==1) cnt[1]++;
	if(n%3==2) cnt[1]++,cnt[2]++;
	now[0]=3,now[1]=1,now[2]=2;
	if(b.size()>w.size()) swap(b,w);
	int x=b.size(),y=w.size();
	if(x<=n/3){
		for(auto v:b){
			cnt[0]--;
			p[v]=now[0];
			now[0]+=3;
		}
		for(auto v:w){
			rep(i,3){
				if(cnt[i]){
					cnt[i]--;
					p[v]=now[i];
					now[i]+=3;
					break;
				}
			}
		}
	}else{
		for(auto v:b){
			if(cnt[1]){
				cnt[1]--;
				p[v]=now[1];
				now[1]+=3;
			}else{
				cnt[0]--;
				p[v]=now[0];
				now[0]+=3;
			}
		}
		for(auto v:w){
			rep(i,3){
				if(cnt[i]){
					cnt[i]--;
					p[v]=now[i];
					now[i]+=3;
					break;
				}
			}
		}
	}
	cout<<p<<endl;
}

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

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

int main() {
	int w, h, c;
	cin >> w >> h >> c;
	int g = gcd(w, h);
	cout << w / g * h / g * c << endl;
	return 0;
}


Measured memory_bytes: 3064
/*
 * @Author: Luisvacson
 * @LastEditors: Luisvacson
 * @Descriptions: None
 * @Date: 2020-09-05 19:39:07
 * @LastEditTime: 2020-09-05 19:57:47
 * @FilePath: \VSC\C++\Public\Bomber.cpp
 */
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>

int n, m;
int bn;
pii bomb[300005];
int row[300005];
int col[300005];
set<pii> st;
signed main()
{
    scanf("%d%d", &n, &m);
    scanf("%d", &bn);
    register int i;

    for (i = 1; i <= bn; ++i) {
        scanf("%d%d", &bomb[i].first, &bomb[i].second);
        ++row[bomb[i].first];
        ++col[bomb[i].second];
        st.insert(make_pair(bomb[i].first, bomb[i].second));
    }

    int maxr = -1 << 30, maxc = -1 << 30;
    for (i = 1; i <= n; ++i)
        maxr = max(maxr, row[i]);
    for (i = 1; i <= m; ++i)
        maxc = max(maxc, col[i]);

    vector<int> Qr, Qc;
    for (i = 1; i <= n; ++i)
        if (row[i] == maxr)
            Qr.push_back(i);
    for (i = 1; i <= m; ++i)
        if (col[i] == maxc)
            Qc.push_back(i);

    for (vector<int>::iterator it = Qr.begin(); it != Qr.end(); ++it) {
        for (vector<int>::iterator jt = Qc.begin(); jt != Qc.end(); ++jt) {
            int r = *it;
            int c = *jt;
            if (st.find(make_pair(r, c)) == st.end()) {
                printf("%d\n", maxr + maxc);
                return 0;
            }
        }
    }

    printf("%d\n", maxr + maxc - 1);
    return 0;
}

Measured memory_bytes: 26192
let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let xs = Array.init m @@ fun _ -> Scanf.scanf " %d" (+) 0
let ds = if n >= m then (print_endline "0"; exit 0); Array.(sort (-) xs; init (m - 1) @@ fun i -> xs.(i + 1) - xs.(i))
let _ = Array.(sort (fun x y -> y - x) ds; sub ds 0 @@ n - 1 |> fold_left (+) 0 |> (-) @@ xs.(m - 1) - xs.(0) |> Printf.printf "%d\n")

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    int n,r;cin >> n >> r;
    if(n < 10){
        r += 100*(10 - n);
    }
    cout << r;
    return 0;
}

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

int main() {
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    int bgn,end;
    bgn = max(A,C);
    end = min(B,D);
    int t;
    t = end - bgn;
    if (t < 0) t = 0;
    cout << t << endl;
    return 0;
}

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

using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
    int N;
    ll l = 0, ans = 1;
    string S;
    cin >> N >> S;
    rep(i, N * 2) {
        if ((S[i] == 'B') ^ (i % 2)) {
            l++;
        } else {
            if (l < 1) {
                cout << 0 << endl;
                return 0;
            }
            ans = (ans * l) % MOD;
            //cout << i << " " << ans << endl;
            l--;
        }
    }
    if (l != 0) {
        cout << 0 << endl;
        return 0;
    }
    rep(i, N) {
        ans = (ans * (i + 1)) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl "\n"
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
   int a,b,t;
   cin>>a>>b>>t;
   cout<<(t/a)*b<<endl;
}
int32_t main(){
  IOS;
  solve();
  //debug();
 #ifdef LOCAL_DEFINE
 cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
 #endif	
}


Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

using ll = long long;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)


/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) (LL((v).size()))
#define each(itr,v) for(auto (itr):(v))

#define FIND(v, k) (v).find(k) != (v).end()
#define VFIND(v, k) find(ALL(v), k) != (v).end()

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
	os << "[";
	for (auto vv : v)
		os << vv << ",";
	return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
	os << "[";
	for (auto vv : v)
		os << vv << ",";
	return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
	return os << "(" << p.fst << "," << p.snd << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
T sq(T a) {
	return a * a;
}

template <typename T>
T gcd(T a, T b) {
	if (a > b) return gcd(b, a);
	return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
	if (n == 0) return 1;
	if (n == 1) return b /* % MOD */;
	if (n % 2 == 0) {
		return mypow(b * b /* % MOD */, n / 2);
	}
	else {
		return mypow(b, n - 1) * b /* % MOD */;
	}
}

ll pcnt(ll b) {
	return __builtin_popcountll(b);
}



// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	cin >> N;
	ll group_A = 0, group_B = 0, group_C = 0;
	REP(i, N) {
		ll a;
		cin >> a;
		if (a % 4 == 0) {
			group_C++;
			continue;
		}
		if (a % 2 == 0) {
			group_B++;
			continue;
		}
		group_A++;
	}
	if (group_B != 0) group_A++;

	if ((group_A - 1) <= group_C) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {
	
	static long A, B, C, D;
	static Map<Long, Long> memo;
	
	static long calc(long n) {
		Long ret = memo.get(n);
		if (ret != null) return ret;
		if (n == 1) return D;
		if (n == 0) return 0;
		long tmp = Long.MAX_VALUE;
		if (tmp / n > D) {
			tmp = n * D;
		}
		for (int i = -2; i <= 2; i++) {
			if (Math.abs(i) <= 1 && (n + i) % 2 == 0 && n + i != 0) {
				tmp = Math.min(tmp, A + Math.abs(i) * D + calc((n + i) / 2));
			}
			if (Math.abs(i) <= 1 && (n + i) % 3 == 0 && n + i != 0) {
				tmp = Math.min(tmp, B + Math.abs(i) * D + calc((n + i) / 3));
			}
			if ((n + i) % 5 == 0 && n + i != 0) {
				tmp = Math.min(tmp, C + Math.abs(i) * D + calc((n + i) / 5));
			}
		}
		memo.put(n, tmp);
		return tmp;
	}
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int T = sc.nextInt();
		for (int i = 0; i < T; i++) {
			memo = new HashMap<>();
			long N = sc.nextLong();
			A = sc.nextLong();
			B = sc.nextLong();
			C = sc.nextLong();
			D = sc.nextLong();
			out.println(calc(N));
		}
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 60348
import java.util.*;
import java.lang.*;

public class Main {
    static boolean canBeMonth(int m){
        return m>0 && m<=12;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String S = sc.next();

        int A = Integer.valueOf(S.substring(0,2));
        int B = Integer.valueOf(S.substring(2,4));

        if(canBeMonth(A)){
            if(canBeMonth(B)) System.out.println("AMBIGUOUS");
            else System.out.println("MMYY");
        }else{
            if(canBeMonth(B)) System.out.println("YYMM");
            else System.out.println("NA");
        }

    }
}


Measured memory_bytes: 23764
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<map>
#include<cmath>
using namespace std;

int a[5010];
int n, k;

int check(int m) {
    int s = 0, t = 0, sum = 0, f = 0;
    for(;;) {
        while(t < n && sum + m < k) {
            if(a[t] == m && f == 0) { f = 1; t++; continue; }
            sum += a[t++];
        }
        if(sum + m < k) break;
        if(sum < k) return 1;
        if(a[s] == m && f == 1) { f = 2; s++; }
        sum -= a[s++];
    }
    return 0;
}

int sreach() {
    int l = 0, h = n - 1, mid;
    if(check(a[0])) return -1;
    if(!check(a[n - 1])) return n - 1;
    for(int i = 0; i < 30; i++) {
        mid = (l + h) / 2;
        if(!check(a[mid])) l = max(mid, l);
        else h = min(h, mid);
    }
    return mid;
}

int main()
{
    while(~scanf("%d %d", &n, &k)) {
        int sum = 0;
        for(int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        sort(a, a + n);
        printf("%d\n", sreach() + 1);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    ll a, b, c, n;
    cin >> a >> b >> c >> n;
    ll ans = 2*(a*b+b*c+c*a);
    map<tuple<int, int, int>, int> v;
    array<int, 6> dx{1, -1, 0, 0, 0, 0}, dy{0, 0, -1, 1, 0, 0}, dz{0, 0, 0, 0, 1, -1};
    for (int i = 0; i < n; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        int cnt = 6 - (x == 0) - (x == a-1) - (y == 0) - (y == b-1) - (z == 0) - (z == c-1);
        for (int k = 0; k < 6; ++k) {
            if(v.count(make_tuple(x+dx[k], y+dy[k], z+dz[k]))) cnt--;
        }
        v[make_tuple(x, y, z)]++;
        ans += 2*cnt-6;
    }
    cout << ans << "\n";
    return 0;
}


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

int main(){
  int N,ans;
  cin>>N;
  vector<int> B(N-1);
  
  for(int i=0;i<N-1;i++){
    cin>>B.at(i);
  }
  
  ans=B.at(0)+B.at(N-2);
  
  for(int i=0;i<N-2;i++){
    if(B.at(i)>=B.at(i+1)){
      ans+=B.at(i+1);
    }
    if(B.at(i)<B.at(i+1)){
      ans+=B.at(i);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




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

    double pi = 3.1415926535;




    cout << N * 2 * pi << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<typename A, size_t N, typename T>void Fill(A (&a)[N], const T &v){fill((T*)a,(T*)(a+N),v);}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD=1e9+7;
const int N=1e5+1;
P<int, int> A[9][9], B[9][9][9];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  FOR(i, 1, 10)FOR(j, 1, 10){
    int k=i, l=0, m=0;
    do{
      B[i-1][j-1][l] = mp(k-1, m);
      l++;
      m++;
      k += j;
      if(k>9){
        m++;
        k = k%10+1;
      }
    }while(k != i);
    A[i-1][j-1] = mp(l, m);
  }
  int m, p;
  cin >> m;
  ll ans = 0;
  FOR(i, 0, m){
    int d;
    ll c;
    cin >> d >> c;
    if(!d){
      ans += c;
      continue;
    }
    d--;
    if(!i){
      p = d;
      c--;
    }
    P<int, int> t = A[p][d];
    ans += c/t.fi*t.se;
    c %= t.fi;
    ans += B[p][d][c].se;
    p = B[p][d][c].fi;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons,std.numeric,std.math;
const dx = [1,0,-1,0], dy = [0,1,0,-1];
const readMixin = q{ auto line = readln().split();foreach(i,ref arg; args){ if (i >= line.length) return;arg = line[i].to!(typeof(arg));}};
void read(T...)  (auto ref T args){ mixin(readMixin);}
void readArray(T)(auto ref T args){ mixin(readMixin);}
void times(int n,void delegate() stmt){foreach(i;iota(n))stmt();}

auto sieve(){
	const primeMax = 200000;
	bool[primeMax] notPrime;
	notPrime[0] = notPrime[1] = true; 
	for(int i = 2; i * i < primeMax; i++){
		if (notPrime[i]) continue;
		for(int j = i; i * j < primeMax; j++){
			notPrime[i * j] = true;
		}
	}
	return notPrime;
}
void main(){
	int[] primes_;
	foreach(int i,np;sieve()){if(!np)primes_ ~= i;}
	auto primes = primes_.assumeSorted;
	int n,p;
	while(read(n,p),n!=-1 && p != -1){
		auto starts = primes.upperBound(n)[0..p].array;
		int[] m ;
		foreach(i,s1;starts){
			foreach(s2;starts[i..$]){
				m ~= s1 + s2;
			}
		}
		m.sort[p-1].writeln;
	}
}

Measured memory_bytes: 6164
#include<iostream>
#include<string.h>
using namespace std;
int main(void){
    int n,tstr,bstr,ans=0,cnt,tf;
    char t[100];
    char b[100];
    cin>>n;
    cin>>t;
    tstr=strlen(t);
    for(int I=0;I<n;I++){
        cin>>b;
        bstr=strlen(b);
        for(int kan=1;kan<=(bstr-(tstr-1));kan++){
            for(int start=0;start<bstr-kan*(tstr-1);start++){
                tf=1;
                cnt=0;
                for(int i=start;i<bstr&&cnt<tstr;i+=kan){
                    //cout<<"??£???="<<I+1<<" start="<<start<<" kan="<<kan<<" t["<<cnt<<"]="<<t[cnt]<<" b["<<i<<"]="<<b[i]<<endl;
                    if(t[cnt]!=b[i]){
                        tf=0;
                        //cout<<"----------"<<endl;
                        break;
                    }
                    cnt++;
                }
                if(tf==1){
                    //cout<<"----------"<<endl;
                    ans++;
                    break;
                }
            }
            if(tf==1)break;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <map>
#include <stack>
 
using namespace std;

void construct_tree(vector<vector<int>> &graph, map<pair<int, int>, int> &memo,vector<vector<int>> &tree)
{
    vector<bool> flag(graph.size(), false);
    stack<int> s;
    flag[0] = true;
    s.push(0);
    while (!s.empty())
    {
        int current = s.top();
        bool no = true;
        for (int i = 0; i < graph[current].size(); i++)
        {
            int next = graph[current][i];
            if (!flag[next])
            {
                flag[next] = true;
                s.push(next);
                tree[current].push_back(next);
                memo[{min(current, next), max(current, next)}] = 0;
                no = false;
                break;
            }
        }
        if (no)
        {
            s.pop();
        }
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> edge(m);
    vector<int> outd(n, 0);
    vector<vector<int>> graph(n, vector<int>());
    map<pair<int, int>, int> memo;
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        int minn = min(a, b) - 1;
        int maxn = max(a, b) - 1;
        edge[i] = {minn, maxn};
        graph[minn].push_back(maxn);
        graph[maxn].push_back(minn);
    }
    if(m % 2 == 1){
        cout << -1 << endl;
    }else{
        vector<vector<int>> tree(n, vector<int>());
        construct_tree(graph, memo, tree);
        for(int i = 0; i < m; i++)
        {
            if(memo.count({edge[i]}) == 0)
            {
                memo[edge[i]] = 1;
                outd[edge[i].first]++;
                //cout << edge[i].first + 1 << " " << edge[i].second + 1 << endl;
            }
        }
        //cout << endl;
        stack<int> s;
        vector<bool> flag(n, false);
        flag[0] = true;
        s.push(0);
        while(!s.empty())
        {
            int current = s.top();
            bool no = true;
            for(int i = 0; i < tree[current].size(); i++)
            {
                int next = tree[current][i];
                if(!flag[next]){
                    flag[next] = true;
                    s.push(next);
                    no = false;
                    break;
                }
            }
            if(no)
            {
                s.pop();
                if(s.empty()) break;
                int parent = s.top();
                if(outd[current] % 2 != 0){
                    memo[{current, parent}] =  1;
                    //cout << "add " << current + 1 << " " << parent + 1 << endl;
                }else{
                    memo[{parent, current}] = 1;
                    //cout << "add " << parent + 1 << " " << current + 1 << endl;
                    outd[parent]++;
                }
            }
        }
        for(auto e : memo){
            if(e.second == 0) continue;
            cout << e.first.first + 1 << " " << e.first.second + 1 << endl;
        }
    }
}

Measured memory_bytes: 22912
n=gets.split.map(&:to_i)
if n[0]==n[1]
    result=2
    for i in 1..n[0]
        result*=i
        result*=i
        result%=10**9+7
    end
    result%=10**9+7
    p result
elsif (n[0]-n[1]).abs==1
    result=1
    v=[n[0],n[1]].min
       for i in 1..v
           result*=i
           result*=i+1
           result%=10**9+7
       end
       result%=10**9+7
       p result
elsif (n[0]-n[1]).abs>1
    p 0
end

Measured memory_bytes: 14392
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

bool isAnagram(string &txt,string &pat){
    vector<int> f1(256,0);
    vector<int> f2(256,0);
    for(int i=0;i<txt.l();i++){
        f1[txt[i]]++;
        f2[pat[i]]++;
    }
    for(int i=0;i<256;i++){
        if(f1[i]!=f2[i]){return false;}
    }
    return true;
}
bool check(string &txt,string &pat){
    if(txt.l()!=pat.l()){return false;}
    if(txt==pat){return 1;}
    if(!isAnagram(txt,pat)){return false;}
    
    for(int l=1;l<=txt.l();l++){
        string a="";
        string b="";
        a=txt.substr(0,l);
        if(l<txt.l()){
            b=txt.substr(l);
        }
        // cout<<b<<" "<<a<<" : "<<b+a<<endl;
        if(b+a==pat){return 1;}
    }
    return false;
}

void solve(){
    string txt,pat;
    cin>>txt>>pat;
    
    if(check(txt,pat)){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}





int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
int main(void)
{
	int N, T, A,bango = 0,saisyo= 10000001;
	cin >> N >> T >> A;
	T *= 1000;
	A *= 1000;
	for (int i = 0; i < N; i++)
	{
		int a; cin >> a;
		if (saisyo > abs(A-(T-6*a)))
		{
			bango = i + 1;
			saisyo = abs(A - (T - 6*a));
		}
	}
	cout << bango << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main() {
    int n;
    cin>>n;
    int x=n%10;

    if(x==0 || x==1 || x==6 || x==8) cout<<"pon"<<endl;
    else if(x==3) cout<<"bon"<<endl;
    else cout<<"hon"<<endl;
}



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

int main()
{
	int l, r, d;
	cin >> l >> r >> d;
	int ans = 0;
	for(int i = l; i <= r; i++){
		if(i % d == 0) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3640