akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

#define PT pair<ll,ll>

unordered_map<ll, ll> MP;
//map<ll, ll> MP;
priority_queue<PT> PQ;

void keisan(ll n, ll k) {
	if (k > MP[n]) {
		MP[n] = k;
		PQ.push(mp(k, n));
	}
}

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


	int T;
	cin >> T;

	rep(t, T) {
		ll N, A, B, C, D;
		cin >> N >> A >> B >> C >> D;

		MP.clear();
		MP[N] = 1e18;
		PQ.push(mp(ll(1e18), N));

		while (PQ.size()) {
			auto p = PQ.top();
			PQ.pop();

			ll n = p.second;
			ll k = p.first;

			if (n > 1 && k - __int128(n - 1) * D >= 0) {
				ll tmp = k - (n - 1) * D;
				if (tmp > MP[1]) {
					MP[1] = tmp;
				}
			}

			ll k2 = k - A;
			keisan(n / 2, k2 - D * (n % 2));
			if (n % 2) {
				keisan(n / 2 + 1, k2 - D * (n % 2));
			}

			k2 = k - B;
			int r = n % 3;
			keisan(n / 3, k2 - D * r);
			if (r) {
				keisan(n / 3 + 1, k2 - D * (3 - r));
			}

			k2 = k - C;
			r = n % 5;
			keisan(n / 5, k2 - D * r);
			if (r) {
				keisan(n / 5 + 1, k2 - D * (5 - r));
			}

		}

		co(ll(1e18) - MP[1] + D);



	}




	Would you please return 0;
}

Measured memory_bytes: 4160
'use strict';
function main(input) {
    var rinput = input.trim().split('').reverse().join('')
    var words = ['dream', 'dreamer', 'erase' ,'eraser']
    var rwords = words.map(a=>a.split('').reverse().join(''))
    let index = 0
	while (true) {
      const f = rwords.find(a=>rinput.startsWith(a,index))
      if(!f) break
      index = index + f.length
    }
  	//console.log(index, rwords, rinput, index === rinput.length)
    if(index === rinput.length) {
      console.log('YES')
    }else{
      console.log('NO')
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(void) {
    int n;
    while (cin >> n, n) {
        vector<int> scores(n);
        for (int i = 0; i < n; i++) {
            cin >> scores[i];
        }
        sort(scores.begin(), scores.end());

        cout << accumulate(scores.begin()+1, scores.end()-1, 0) / (scores.size()-2) << endl;
    }

    return 0;
}

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

int main(){
	int n,a[52];double ans;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	ans=(a[1]+a[2])/2.0;
	for(int i=3;i<=n;i++)ans=(ans+a[i])/2.0;
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 256
import sys
input =sys.stdin.readline
def solve():
  s = input().rstrip()
  n = len(s)
  dp = [[float("Inf")]*2 for _ in range(n+1)]
  dp[0][0] = 0
  dp[0][1] = 1

  for i in range(0,n):
    number = int(s[i])

    dp[i+1][0] = min([dp[i][0]+number,dp[i][0]+(10-number)+1,dp[i+1][0]])
    if number != 9:
      dp[i+1][1] = min([dp[i][0]+number+1,dp[i][0]+(10-number),dp[i+1][1]])
     
    dp[i+1][0] = min(dp[i][1] +(10-number),dp[i+1][0])
    dp[i+1][1] = min(dp[i][1] + (10-number-1),dp[i+1][1])
        
  #print(dp)
  print(min(dp[n][0],dp[n][1]+1))
solve()

Measured memory_bytes: 199240
import sys
def S(): return sys.stdin.readline().rstrip()
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    n,a,b = IL()
    s = S()
    count = 0
    fs = 1
    for rep in s:
        if rep=='a':
            if count < a+b:
                count += 1
                print('Yes')
            else:
                print('No')
        elif rep=='b':
            if count<a+b and fs<=b:
                count += 1
                fs += 1
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    return

if __name__=='__main__':
    solve()

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

int main()
{
  set<int> v;
  int x;
  cin>>x;
  v.insert(x);
  cin>>x;
  v.insert(x);
  
  if(v.count(1)==0)
    cout<<1;
  else if(v.count(2)==0)
    cout<<2;
  else
     cout<<3;
  
  return 0;
           
           
           }

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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define for1(i, a, b) for (int i = (int)a; i < (int)(b); ++i)
#define rfor1(i, a, b) for (int i=(int)b-1;i>=(int)a;i--)
#define for2(i, a, b) for (int i = (int)a; i <= (int)(b); ++i)
#define for3(i, a, b) for (int i = (int)a; i < (int)(b); i=i+2)
#define for4(i, a, b) for (int i = (int)a; i <= (int)(b); i=i+2)
#define tc(t) int t; cin>>t; while(t--)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c;
    cin >> a >> b >> c;
    cout <<(c >= a && c<= b ?"Yes":"No")<<"\n";

}









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

int main(void) {
  long long s;
  cin >> s;
  vector<int> ss;

  long long t = s;
  while(t != 0) {
    ss.push_back(t % 10);
    t /= 10;
  }

  reverse(ss.begin(), ss.end());

  // for (int i = 0; i < ss.size(); i++)
  //   cout << ss[i] << " ";
  // cout << endl;

  int m = 100000;
  for (int i = 0; i < ss.size() - 2; i++) {
    m = min(abs(753 - ss[i + 2] - ss[i + 1] * 10 - ss[i] * 100), m);
  }

  cout << m << endl;

  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc126/tasks/abc126_c

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 1e5;
const int K_MAX = 1e5;

int N, K;

void solve() {
  K--;
  double ans = max(N - K, 0);
  int c = 0;
  while (K > 0) {
    int k2 = K / 2;
    ans += (min(K, N) - min(k2, N)) * pow(0.5, (double)++c);
    K = k2;
  }
  printf("%.12lf\n", ans / N);
}

void input() {
  scanf("%d%d", &N, &K);
}

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


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  
  int N,a[100],i,j,counter=0,alternative,minj;
  
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  
  for(i=0;i<=N-1;i++){
    minj=i;
    for(j=i;j<=N-1;j++){
      if(a[j]<a[minj]){
	minj=j;
      }
    }
    alternative=a[i];
    a[i]=a[minj];
    a[minj]=alternative;
    if(i!=minj){
      counter=counter+1;
    }
  }
  
  for(i=0;i<N-1;i++){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[N-1]);
  printf("%d\n",counter);

  return 0;
}

Measured memory_bytes: 600
/*
 * src.cpp
 *
 *  Created on: 2016/08/04
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

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

const int MAX_SIZE=50;

int X,Y;
int tx,ty,kx,ky;
int de[MAX_SIZE][MAX_SIZE];

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

bool flg[50][50][50][50];

struct P{
	int x1,y1,x2,y2;
	int t;
	P(int x1=0,int y1=0,int x2=0,int y2=0,int t=0):x1(x1),y1(y1),x2(x2),y2(y2),t(t){};
};

int bfs(){
	queue<P> q;
	memset(flg,0,sizeof(flg));
	q.push(P(tx,ty,kx,ky,0));
	flg[tx][ty][kx][ky]=true;
	while (!q.empty()){
		P p=q.front();
		q.pop();
		if (p.t>=100){
			return -1;
		}
		if (p.x1==p.x2 && p.y1==p.y2){
			return p.t;
		}
		REP(i,4){
			int x1,y1,x2,y2;
			x1=p.x1+dx[i];
			y1=p.y1+dy[i];
			x2=p.x2+dx[(i+2)%4];
			y2=p.y2+dy[(i+2)%4];
			if (x1<0 || x1>=X || y1<0 || y1>=Y || de[y1][x1]==1){
				x1=p.x1;
				y1=p.y1;
			}
			if (x2<0 || x2>=X || y2<0 || y2>=Y || de[y2][x2]==1){
				x2=p.x2;
				y2=p.y2;
			}
			if (!flg[x1][y1][x2][y2]){
				q.push(P(x1,y1,x2,y2,p.t+1));
				flg[x1][y1][x2][y2]=true;
			}
		}
	}
	return -1;
}

int main(){
	do{
		scanf("%d %d",&X,&Y);
		if (X || Y){
			scanf("%d %d",&tx,&ty);
			scanf("%d %d",&kx,&ky);
			tx--;
			ty--;
			kx--;
			ky--;
			REP(i,Y){
				REP(j,X){
					scanf("%d",&de[i][j]);
				}
			}
			int ans=bfs();
			if (ans!=-1){
				printf("%d\n",ans);
			}else{
				printf("NA\n");
			}
		}
	}while(X || Y);
	return 0;
}

Measured memory_bytes: 7532
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define MOD 1000000007
using namespace std;

int main() {
    string s;
    int ans = 0;
    cin >> s;
    for (int i = 0; i < 4; i++) {
        if (s[i] == '+')ans++;
        else ans--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <utility>
#include <cstdlib>
using namespace std;

int main(){
	double x[3],y[3],xp,yp;
	while(cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> xp >> yp){
		//??????
		double gaiseki[3];
		for(int i=0;i<3;i++){
			double vx,vy,vxp,vyp;
			vx = x[(i+1)%3]-x[i];
			vy = y[(i+1)%3]-y[i];
			vxp = xp-x[i];
			vyp = yp-y[i];
			gaiseki[i] = vx*vyp-vy*vxp;
		}
		if((gaiseki[0]>0&&gaiseki[1]>0&&gaiseki[2]>0)||(gaiseki[0]<0&&gaiseki[1]<0&&gaiseki[2]<0)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1216
n = input()
t, a = map(int, input().strip().split())
x = (t - a) / 0.006
answer = 0
minimum = float("inf")
for i, h in enumerate(map(int, input().strip().split())):
    d = abs(h - x)

    if d < minimum:
        minimum = d
        answer = i


print(answer + 1)


Measured memory_bytes: 3060
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
def main(n, a):
    s=[0]*(n+1)
    for i in range(n):
        s[i+1]=s[i]+a[i]
    c=Counter(s)
    ans=0
    for value in c.items():
        if value[0]==0:
            ans+=value[1]-1
            if value[1]>2:
                ans+=(value[1]-1)*(value[1]-2)//2
        elif value[1]>1:
            ans+=value[1]*(value[1]-1)//2
    return ans
print(main(n, a))

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

a = []
b = []
c = []

tmpa, tmpb, tmpc = map(int, input().split())
a.append(tmpa)
b.append(tmpb)
c.append(tmpc)

for _ in range(N-1):
    tmpa, tmpb, tmpc = map(int, input().split())
    tmpa += max(b[-1], c[-1])
    tmpb += max(a[-1], c[-1])
    tmpc += max(b[-1], a[-1])
    
    a.append(tmpa)
    b.append(tmpb)
    c.append(tmpc)

    
print(max(a[-1], b[-1], c[-1]))
    


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

#define ll long long

int main(){
    ll n;
    string s="";
    cin >> n;
    while(n>0){
        n-=1;
        s+=char('a'+(n)%26);
        n/=26;
    }
    reverse(s.begin(),s.end());
    cout << s;
}

Measured memory_bytes: 3608
sp = list(input())
t = list(input())
n = len(sp)
for i in range(len(t), n + 1):
    flag = True
    for j in range(len(t)):
        if sp[n - i + j] != t[j] and sp[n - i + j] != '?':
            flag = False
            break
    if flag:
        s = ''
        sp[n - i:n - i + len(t)] = t
        for j in range(n):
            if sp[j] == '?':
                s += 'a'
            else:
                s += sp[j]
        print(s)
        exit()
print('UNRESTORABLE')


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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string S; cin >> S;
    int ans = INF;

    int c = 0;
    for(int i = 1; i < (int)S.length(); i++) if(S[i] != S[i-1]) c++;
    chmin(ans, c);

    c = 0;
    for(int i = (int)S.length()-2; i >= 0; i--) if(S[i] != S[i+1]) c++;
    chmin(ans, c);

    cout << ans << endl;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
const int N=1010;
int n,m,Px[N],Py[N],Pr[N];
double f[N];
bool vis[N];
inline long long sqr(int x){return 1ll*x*x;}
inline double dis(int x,int y){return sqrt(sqr(Px[x]-Px[y])+sqr(Py[x]-Py[y]));}
inline double Dij(int s,int t){
	for (int i=1;i<=n;++i) f[i]=1e15,vis[i]=0;f[s]=0;
	for (int tim=n;tim--;){
		int nd=0;double nf=1e15;
		for (int i=1;i<=n;++i) if (!vis[i]&&f[i]<nf) nd=i,nf=f[i];
		vis[nd]=1;
		for (int nv=1;nv<=n;++nv) f[nv]=min(f[nv],nf+max(double(0),dis(nv,nd)-Pr[nv]-Pr[nd]));
	}
	return f[t];
}
int main(){
	scanf("%d%d%d%d%d",Px+1,Py+1,Px+2,Py+2,&n);
	n+=2;
	for (int i=3;i<=n;++i) scanf("%d%d%d",Px+i,Py+i,Pr+i);
	printf("%.10lf",Dij(1,2));
	return 0;
}

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

const ll p = 1e9+7;

int n, a, b;
vector<int> ans;

int get(int i, int j) {
	if ((i&(1<<j)) == 0)
		return 0;
	return 1;
}

vector<int> go(int a, int b, int k, int open) {
	//cout << a << ' ' << b << ' ' << k << ' ' << open << endl;
	if (k == 1)
		return {a, b};
	int ind = -1;
	for (int i = 0; i < n; ++i)
		if ((get(a, i) != get(b, i)) && get(open, i))
			ind = i;
	assert(ind != -1);
	int ind2 = -1;
	for (int i = 0; i < n; ++i)
		if (get(open, i) && (i != ind))
			ind2 = i;
	assert(ind2 != -1);
	vector<int> ans1 = go(a, a^(1<<ind2), k-1, open^(1<<ind));
	vector<int> ans2 = go(a^(1<<ind2)^(1<<ind), b, k-1, open^(1<<ind));
	for (int j : ans2)
		ans1.push_back(j);
	return ans1;
}

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

	cin >> n >> a >> b;
	int sa = __builtin_popcount(a), sb = __builtin_popcount(b);
	if (sa%2 == sb%2) {
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;
	ans = go(a, b, n, (1<<n)-1);
	for (int i : ans)
		cout << i << ' ';
	cout << endl;
}

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

int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if(a+b > c+d){
	cout << "Left" << endl;
}
else if(a+b < c+d){
	cout << "Right" << endl;
}
else{
	cout << "Balanced" << endl;
}
}

Measured memory_bytes: 256
import java.util.*;

class Main{            
     
   public static void main(String[] args){
       Scanner sc = new Scanner(System.in);  
       
       int N = sc.nextInt();
       int count = 0;
       
       int a[] = new int[N+1];
       
       for(int i = 1;i <= N;i++){
           a[i] = sc.nextInt();
       }
       
       for(int i = 1;i <= N;i++){
           if(i == a[i]){
               count++;
               i++;
           }           
       }
       
       System.out.println(count);
    
       
       
   }
}
               
        
        
        
        

Measured memory_bytes: 51464
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n=1):n(n), f(n+1) {
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; ++i) {
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (ll j = i*i; j <= n; j += i) {
                if (!f[j]) f[j] = i;
            }
        }
    }
    bool isPrime(int x) { return f[x] == x;}
    vector<int> factorList(int x) {
        vector<int> res;
        while (x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<P> factor(int x) {
        vector<int> fl = factorList(x);
        if (fl.size() == 0) return {};
        vector<P> res(1, P(fl[0], 0));
        for (int p : fl) {
            if (res.back().first == p) {
                res.back().second++;
            } else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n; cin>>n;
    Sieve s(n + 10);

    ll ans = 0;
    rrep(i, 1, n + 1) {
        ll cnt = 1;
        for (auto a : s.factor(i)) cnt *= (a.se + 1);
        ans += i * cnt;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 46484
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT false
#define ALL(x) (x).begin(),(x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int N,C; cin>>N; cin>>C; 
  vector<int> X (N,0);
  vector<int> V (N,0);
  for (int i = 0; i < N; i++)
  {
    cin>>X[i]>>V[i];
  }
  vector<int> VL(N+1,0),VR(N+1,0);
  for (int i = 0; i < N; i++)
  {
    VL[i+1] += VL[i] + V[i];
  }
  // reverse(ALL(V));
  for (int i = 0; i < N; i++)
  {
    VR[i+1] += VR[i] + V[N - 1 -i];
  }
  DEBUG(VL,VR);
  int ANS = 0;
  auto VL2 = VR;
  auto VR2 = VL;

  for (int i = 0; i < N; i++)
  {
    VL2[i+1] -= C - X[N-1 -i ];
    chmax(VL2[i+1],VL2[i]);
  }
  for (int i = 0; i < N; i++)
  {
    VR2[i+1] -= X[i];
    chmax(VR2[i+1],VR2[i]);
  }
  DEBUG(VL2);
  DEBUG(VR2);
  //L
  reverse(ALL(X));
  X.push_back(0);
  reverse(ALL(X));
  X.push_back(C);
  DEBUG(X);
  for (int i = 0; i < N + 1; i++)
  {
    int score = 0;
    score += VL[i] - X[i]*2;
    score += VL2[N-i];
    chmax(ANS,score);
    DEBUG("L",i,score,"\n");
  }
  for (int i = 0; i < N + 1; i++)
  {
    int score = 0;
    score += VR[i] - (C - X[N + 1  -i])*2;
    score += VR2[N-i];
    chmax(ANS,score);
    DEBUG("R",i,score,X[N+1-i],"\n");

  }
  cout<<ANS<<endl;
  
  
  



  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);

std::cout << std::fixed;
std::cout << std::setprecision(9);
solve();

return 0;
}


Measured memory_bytes: 5728
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

struct Graph {
  vector<vector<int>> edge;
  Graph(int n = 0) { resize(n); }
  void resize(int n) {
    edge.resize(n, vector<int>());
  }
  void addEdge(int from, int to, bool directed = false) {
    edge[from].push_back(to);
    if (!directed)
      edge[to].push_back(from);
  }
  vector<int>& operator[](int from) { return edge[from]; }
};

int main() {
  int in(N); int in(M);

  Graph G(N);
  rep(i, M) {
    int in(a); int in(b);
    --a, --b;
    G.addEdge(a, b);
  }

  vector<int> before(N, 1e6);
  before[0] = -1;
  queue<int> q;
  q.push(0);

  while (!q.empty()) {
    int from = q.front(); q.pop();
    for (auto& to:G[from]) {
      if (before[to] != 1e6)
        continue;
      before[to] = from;
      q.push(to);
    }
  }

  cout << "Yes\n";
  rep(i, N-1)
    cout << before[i+1] + 1 << endl;

  return 0;
}


Measured memory_bytes: 10272
#include <iostream>
#include <vector>

using namespace std;

using p = pair<int, int>;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl
const int MOD = 1000000007;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  IN(N); IN(M);
  ll ans = 1;
  for (ll i = 2; i <= M && M > 1; ++i) {
    int count = 0;
    ll sum = 0;
    while (M % i == 0) {
      // i=Mの因数
      ++count; // Mはi^countで割れる
      M /= i;
    }
    FOR(j, 1, count+1) {
      // N箇所のうちj箇所を選び、そこにcount個を振り分ける
      sum += comb(N, j) // j箇所の選び方
        * comb(count-1, j-1); // j箇所それぞれに1個以上振り分ける
      sum %= MOD;
    }
    if (sum > 0) {
      ans *= sum;
      ans %= MOD;
    }
  }
  OUT(ans%MOD);

  return 0;
}


Measured memory_bytes: 12160
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
#include <algorithm>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
//#define cocount cout << count << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define Cinint(n) int n;\
cin >> n;
#define Cinvecint(a, n) vector<int> a(n);\
for (int i = 0; i < (int)(n); i++) {\
  int num;\
  cin >> num;\
  a.at(i) = num;\
}
#define Cinstring(s) string s;\
cin >>s;

  

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >>d;
  cout << max(max(a*c, a*d), max(b*c, b*d)) << endl;
}


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

using namespace std;
typedef long long LL;
typedef pair<int,int> P;
const int Max_Num=1e5+10;

int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	map<int,int> odd, even;
	rep(i,n){
		if(i%2==0) odd[v[i]]++;
		else even[v[i]]++;
	}
	vector<P> o, e;
	for(auto itr:odd) o.emplace_back(P(itr.second,itr.first));
	for(auto itr:even) e.emplace_back(P(itr.second,itr.first));
	o.emplace_back(0,0), e.emplace_back(0,0);
	sort(o.begin(),o.end(),greater<P>());
	sort(e.begin(),e.end(),greater<P>());
	if(o[0].second==e[0].second){
		cout << min(n-o[0].first-e[1].first,n-o[1].first-e[0].first) << endl;
	}
	else cout << n-o[0].first-e[0].first << endl;

	return 0;
}

Measured memory_bytes: 6520
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
map<string,int> mp;
int main()
{
    int n;cin>>n;
    string s;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        mp[s]++;
    }
    cout<<mp.size()<<endl;

}


Measured memory_bytes: 19224
#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 <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    int x, y;
    while(cin >> x >> y, x+y){
        if(x < y) swap(x ,y);
        int count = 0;
        while(y != 0){
            x = x % y;
            swap(x, y);
            count++;
        }
        cout << x << " " << count << endl;
    }
}

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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ld n, k; cin >> n >> k;
  vi a(n);
  rep(i, n) cin >> a[i];

  int ans = ceil((n - 1) / (k - 1));
  cout << ans << endl;
}


Measured memory_bytes: 3808
#include <stdio.h>
#include <math.h>

int main(void)
{
    int h1, m1, h2, m2, k, diff;

    scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
    diff = abs((60*h2 + m2) - (60*h1 + m1)) - k;

    if(diff < 0)
        diff = 0;

    printf("%d", diff);

    return 0;
}


Measured memory_bytes: 1732
n,k=map(int,input().split())
answer=0
tree=[]
def tree_keisan(x,y): #最大の木と最小の木の差を出す
    ans=tree[x+y-1]-tree[x]
    return ans
for i in range(n):
    tree.append(int(input()))
tree.sort()
answer=tree_keisan(0,k)
for i in range(n-k+1):
    sa=tree_keisan(i,k)
    if answer>sa:
        answer=sa
print(answer)


Measured memory_bytes: 7388
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N+1);
    A[0] = 0;
    repi(i,1, N+1) cin >> A[i];
    vector<ll> dp[2][2];
    rep(i, 2){
        rep(j, 2) {
            dp[i][j].resize(N + 1);
            rep(k, N + 1) dp[i][j][k] = -1e18;
        }
    }
    dp[0][0][0] = 0;
    dp[1][0][0] = 0;
    dp[0][1][1] = A[1];
    dp[1][1][0] = 0;
    repi(i, 2, N + 1) {
        int j = (i - 1) / 2;
        if (j > 0) {
            dp[0][i % 2][j] = dp[1][(i - 1) % 2][j - 1] + A[i];
            dp[1][i % 2][j] = max(dp[0][(i - 1) % 2][j], dp[1][(i - 1) % 2][j]);
        }
        ++j;
        dp[0][i % 2][j] = dp[1][(i - 1) % 2][j - 1] + A[i];
        dp[1][i % 2][j] = max(dp[0][(i - 1) % 2][j], dp[1][(i - 1) % 2][j]);
    }
    cout << max(dp[0][N%2][N / 2], dp[1][N%2][N / 2]) << endl;
    return 0;
}



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

int main()
{
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    mp[t]++;
  }
  int ans(0);
  for (auto&& e : mp) {
    ans += e.first <= e.second ? e.second - e.first : e.second;
  }
  cout << ans << endl;
}


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

using namespace std;

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

    int a, b; cin >> a >> b;

    for(int i = a; i <= b; i++)
    {
        if(i % k == 0)
        {
            cout << "OK\n";
            return 0;
        }
    }

    cout << "NG\n";
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;

    int info[4][3][10]{};

    int n;
    cin >> n;
    while (n--) {
        int b, f, r, v;
        cin >> b >> f >> r >> v;

        info[b - 1][f - 1][r - 1] += v;
        if (info[b - 1][f - 1][r - 1] < 0)
            info[b - 1][f - 1][r - 1] = 0;
        else if (info[b - 1][f - 1][r - 1] > 9) {
            info[b - 1][f - 1][r - 1] = 9;
        }
    }

    rep(i, 4) {
        rep(j, 3) {
            rep(k, 10) cout << " " << info[i][j][k];
            cout << endl;
        }
        if (i != 3)
            cout << "####################" << endl;
    }
}




Measured memory_bytes: 3212
//CazadorDivino
#include "bits/stdc++.h"
#include <cmath>
using namespace std;

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)


#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pii;
typedef pair<int,int> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

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

//~ struct no{
	//~ int x, y;
	//~ int cust;
	//~ no(int x ,int y, int cust):x(x),y(y),cust(cust){
	//~ }
//~ };
//~ vector<no> g;
//~ bool vis[N];
//~ int v[N];
//~ void dfs(int u){
    //~ vis[u] = true;
    //~ rep(i,0,sz(g[u].x)-1){
        //~ if(!vis[g[u]])
            //~ dfs(g[u][i]);
    //~ }
    //~ return;
//~ }

//~ void add(int x, int y, int z){
	//~ no a(x,y,z);
	//~ g[x].pb(a);
	//~ g[y].pb(a);
//~ }

int main(){	
	string s;
	cin>> s;
	if(sz(s) == 2)
		cout<<s;
	else
		per(i,sz(s)-1,0)
			cout<<s[i];
	return 0;
}
	


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

int main() {
  
  int a,b;
  cin >> a >> b;
  
  int i,hantei = 0;
  
  for ( i = 1; i <= 10000; i++){
    if ( int(i * 0.08) == a && int(i * 0.1) == b ){
      hantei = 1;
      break;
    }
  }
  
  if ( hantei == 1 ){
    cout << i << endl;
  }else{
    cout << -1 << endl;
  }
  
}

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

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

    long long n;
    cin >> n;

    long long f = n * (n - 1) / 2;
    if(n == 1){
        cout << 0 << endl;
    }else{
        cout << f << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, n) for(int i = 0; i<(int)(n); i++)
ll int n,m;
ll int x[1001],y[1001],z[1001];
int main(){
    int d,n;
    cin >> d >> n;
    if(n == 100) n = 101;
    	cout << n;
    	REP(i, d) cout << "00";
    	cout << endl;
    

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool Calcable(int n) 
{
  for (int i = 1; i < 10; i++) {
  	for (int j = 1; j < 10; j++) {
  		if (n == i * j) {
        	return 1;
        }
    }
  }
  return 0;
}

int main() {
	int n;
  	cin >> n;
  	
  	if (Calcable(n)) {
    	cout << "Yes" << endl;
    } else {
    	cout << "No" << endl;
    }
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  vector<int> l(n);
  for(int i=0;i<n;i++) cin>>l.at(i);
  int cnt=0;
  int tmp;
  for(int i = 0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      if(l.at(i)>l.at(j)){
        tmp=l.at(i);
        l.at(i)=l.at(j);
        l.at(j) = tmp;
      }
    }
  }

  for(int i = 0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      for(int k=j+1;k<n;k++){
        if(l.at(k) >= l.at(i)+l.at(j)) break;
        cnt++;
      }
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 384
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>

using namespace std;

double EPS = 1e-10;

double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}

  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }

  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }

  point operator * (double d){
    return point(x*d,y*d);
  }

  point operator / (double d){
    return point(x/d,y/d);
  }
  
  bool operator == ( const point &p ) const {
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};

double dot(point a, point b) {
  return (a.x * b.x + a.y * b.y);
}

double cross(point a, point b) {
  return (a.x * b.y - a.y * b.x);
}

int is_point_on_line(point a, point b, point c) {
  return cross(b-a, c-a)==0.0 &&
         (dot(b-a, c-a) > -EPS) &&
         (dot(a-b, c-b) > -EPS);
}

int is_intersected_ls(point a1, point a2, point b1, point b2) {

  if(cross(a1-a2,b1-b2)==0){
    return is_point_on_line(a1,a2,b1) || is_point_on_line(a1,a2,b2) 
        || is_point_on_line(b1,b2,a1) || is_point_on_line(b1,b2,a2);
  }
  else {
    return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
           ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
  }
}

int inside(point p, vector<point> ps){
  point a,b;
  a=b=p;

  b.x=1000000;

  int n=ps.size();
  ps.push_back(ps[0]);

  double ymx=-DBL_MAX,ymn=DBL_MAX;
  for(int i=0;i<n;i++){
    ymx=max(ymx,ps[i].y);
    ymn=min(ymn,ps[i].y);
  }
  if(a.y<=ymn||a.y>=ymx)return 0;
  
  for(int i=0;i<n;i++){
    if(is_point_on_line(ps[i],ps[i+1],p))return 0;
  }
  
  int cnt1=0;
  for(int i=0;i<n;i++)
    if(is_point_on_line(a,b,ps[i]))cnt1++;
  
  int cnt=0;
  for(int i=0;i<n;i++)
    if(is_intersected_ls(ps[i],ps[i+1],a,b))cnt++;
  
  return (cnt-cnt1)%2;
}

int main(void){
 
  point in[4],p;
  vector<point>ps;

  while(cin>>in[1].x>>in[1].y>>in[2].x>>in[2].y>>in[3].x>>in[3].y>>p.x>>p.y){

    ps.clear();

    for(int i=1;i<4;i++)
    ps.push_back(in[i]);

    if(inside(p,ps))cout << "YES" << endl;
    else cout << "NO" << endl;
  }
 
  return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>

int main()
{
	int c[20], s,n=3 , i, ans = 0;
	scanf("%d", &s);
	for (i = 0; i < s; i++)
	{
		scanf("%d", &c[i]);
	}
	for (i = 0; i < s; i++)
	{
		if (c[i] > c[i - 1] && i > 0)
		{
			if (n == 1 || n == 2)
			{
				ans++;
			}
			n = 1;
		}
		if (c[i] < c[i - 1] && i>0)
		{
			if (n == 0)
			{
				ans++;
			}
			n = 0;
		}
		if (c[i] == c[i - 1] && i > 0)
		{
			if (n == 0)
			{
				ans++;
			}
			n = 2;
		}
	}
	printf("%d", ans);
}

Measured memory_bytes: 128
import math
n=int(input())
a=list(map(int,input().split()))
m=(10**6+1)
b=[-1]*m
g=a[0]
for i in a:
    g=math.gcd(g,i)
for i in range(2,m):
    tmp=i
    while tmp<m:
        if b[tmp]==-1:
            b[tmp]=i
        tmp+=i
def factorize(k):
    l=[]
    while k>1:
        l.append(b[k])
        k//=b[k]
    return l
p=set()
for i in a:
    l=factorize(i)
    for j in l:
        if j in p:
            if g==1:
                print('setwise coprime')
            else:
                print('not coprime')
            exit()
    for j in l:
        p.add(j)
print('pairwise coprime')

Measured memory_bytes: 204792
import java.io.*;
import java.util.*;

class MyScanner {
    private final InputStream in = System.in;
    private final byte[] buf = new byte[1024];
    private int p = 0;
    private int len = 0;
    private boolean hasNextByte() {
        if (p >= len) {
            p = 0;
            try {
                len = in.read(buf);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return len >= 1;
    }
    private int readByte() {
        if (hasNextByte()) {
            return buf[p++];
        }
        else {
            return -1;
        }
    }
    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buf[p])) p++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b;
        while (isPrintableChar(b = readByte())) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }
}

public class Main {
    public static void main(String[] args){
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = Integer.parseInt(sc.next());
        long k = Long.parseLong(sc.next());
        Integer[][] a = new Integer[62][n + 1];
        int t = 1;
        for (int i = 1; i <= n; i++) a[0][i] = Integer.parseInt(sc.next());
        for (int i = 0; i < 61; i++) {
            for (int j = 1; j <= n; j++) {
                a[i + 1][j] = a[i][a[i][j]];
            }
            if ((k >> i & 1) == 1) t = a[i][t];
        }
        out.println(t);
        out.flush();
    }
}

Measured memory_bytes: 104792
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
B = [int(input()) for _ in range(N)]
A = [
    A1,
    A2,
    A3,
    [A1[0],A2[0],A3[0]],
    [A1[1],A2[1],A3[1]],
    [A1[2],A2[2],A3[2]],
    [A1[0],A2[1],A3[2]],
    [A1[2],A2[1],A3[0]],
]

for al in A:
    res = True
    for a in al:
        if not a in B:
            res = False
    if res:
        print('Yes')
        exit()

print('No')

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main(){
	int i,n=0,ans=0;
	string s;
	cin>>s;
	for(i=1;i<=s.size();i++){
		if(s[i-1]=='R')n++;
		else{
			if(n>ans)ans=n;
			n=0;
		}
	}
	if(n>ans)ans=n;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve(){
	int n;
	cin>>n;
	vector<string> dp={"a"};
	for(int i=0;i<n-1;i++){
		vector<string> tdp;
		for(auto &item:dp){
			char mx = 0;
			for(auto c:item){
				mx = max(mx,c);
			}
			for(int j=0;j<=(i+1);j++){
				string temp = item;
				if((j+'a'-mx)>1) break;
				temp.push_back(j+'a');
				tdp.push_back(temp);
			}
		}
		dp = tdp;
	}
	for(auto &item:dp){
		cout<<item<<endl;
	}
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll N,ans,j,s,z;
  vl A,B;
  cin >> N;
  REP(i,N+1){
		int x;
		cin >> x;
		A.push_back(x);
	}
  REP(i,N){
		int x;
		cin >> x;
		B.push_back(x);
	}
  ans = 0;
  z=0;
  for(j=N-1;j>=0;j--){
    if(B[j]>=A[j+1]){
      ans = ans+A[j+1];
      B[j] = B[j]-A[j+1];
      A[j+1]=0;
      if(A[j]-B[j]>=0){
        s = A[j]-B[j];
      }else{
        s = 0;
      }
      ans = ans + A[j] - s; 
      A[j] = s;
    }else{
      ans = ans + B[j];
    }
  }
  cout << ans<< endl;
  return 0;
}

Measured memory_bytes: 2548
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[inline]
#[allow(dead_code)]
fn gcd(mut m: u64, mut n: u64) -> u64 {
    if m < n {
        std::mem::swap(&mut m, &mut n);
    }

    loop {
        let k = m % n;
        if k == 0 {
            return n;
        }

        m = n;
        n = k;
    }
}

#[inline]
#[allow(dead_code)]
fn lcm(m: u64, n: u64) -> u64 {
    m / gcd(m, n) * n
}

macro_rules! eprint(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = write!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! eprintln(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! dbg {
    ($val:expr) => {
        // Use of `match` here is intentional because it affects the lifetimes
        // of temporaries - https://stackoverflow.com/a/48732525/1063961
        match $val {
            tmp => {
                eprintln!("[{}:{}] {} = {:#?}",
                          file!(), line!(), stringify!($val), &tmp);
                tmp
            }
        }
    }
}

fn main() {
    input!{
        n: usize,
        a_v: [usize; n],
    }

    let mut counts = [0u64; 100010];
    for &a in &a_v {
        counts[a] += 1;
        counts[a+1] += 1;
        counts[a+2] += 1;
    }

    let answer = counts.iter().max().unwrap();
    println!("{}", answer);
}


Measured memory_bytes: 5116
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n,x;
  cin >> n >> x;
  vector<int> m(n);
  int sum=0,min=1001;
  for(int  i=0;i<n;i++){
    cin >> m[i];
    sum += m[i];
    if(m[i]<min) min=m[i];
  }
  cout << n+(x-sum)/min << "\n";
  
  return 0;
}


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

typedef long long ll;

const ll N = 101;
const ll MAX = 104206969;

ll graph[N][N];

struct edge {
	int u, v, w;
	edge(int _u = -1, int _v = -1, int _w = -1): u(_u), v(_v), w(_w) {}
};

istream& operator>>(istream& i, edge& e) {
	i >> e.u >> e.v >> e.w;
	return i;
}

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, m; cin >> n >> m;
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			graph[i][j] = (i == j ? 0 : MAX);
	edge e[m];
	for (int i = 0; i < m; i++) {
		cin >> e[i];
		graph[e[i].u][e[i].v] = e[i].w;
		graph[e[i].v][e[i].u] = e[i].w;
	}

	for (int k = 1; k <= n; k++)
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				if (graph[i][k]+graph[k][j] < graph[i][j])
					graph[i][j] = graph[i][k]+graph[k][j];

	int ans = m;
	for (int i = 0; i < m; i++) {
		edge temp = e[i];
		// Find the number of the edges that are not contained in _any_ shortest path between any pair of different vertices. 
		bool ok = 0;
		for (int j = 1; j <= n; j++)
			if (graph[j][temp.u]+temp.w == graph[j][temp.v]) 
				ok = 1;
		ans -= ok;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> void re(T& x) { cin >> x; }
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "/home/o_o/MyCodes/pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  

void solve(){
	int a , b ;
	re(a,b);
	int cnt = 1 ; 
	cout << (a + b - 3) / (a-1) ;
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3624