akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    // 整数の入力
    int N = sc.nextInt();
    int K = sc.nextInt();
    int X = sc.nextInt();
    int Y = sc.nextInt();
    //　宿泊費の合計を計算
    int sum = 0;
    if (N<=K) {
      sum = N * X;
    } else {
      sum = K * X + (N - K) * Y;
    }
    // 出力
    System.out.println(sum);
  }
}

Measured memory_bytes: 21972
n, m = map(int, input().split())
ss = [list(map(int, input().split())) for _ in range(n)]
ps = [list(map(int, input().split())) for _ in range(m)]

ans = []
for s in ss:
    buf = float('inf')
    c_n = -1
    for idx in range(len(ps)):
        dist = abs(s[0] - ps[idx][0]) + abs(s[1] - ps[idx][1])
        if dist < buf:
            buf = dist
            c_n = idx
    ans += [c_n+1]

for x in ans:
    print(x)

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

int main() {
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		if((int)(i * 1.08) == n){
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

ll n, m, ans;


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

	if (n - m > 1 || m - n > 1) {
		cout << 0 << endl;
		return 0;
	}

	ans = 1;

	if (n != m) {
		for (ll i = 1;i <= n;i++) {
			ans = (ans * i) % mod;
		}
		for (ll i = 1;i <= m;i++) {
			ans = (ans * i) % mod;
		}
	}
	else {
		for (ll i = 1;i <= n;i++) {
			ans = (ans * i) % mod;
		}

		for (ll i = 1;i <= n;i++) {
			ans = (ans * i) % mod;
		}

		ans = ans *2 % mod;
	}

	cout << ans << endl;

	return 0;
}


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

#define mx 100005
typedef long long int ll;

ll n;
ll dp[100009][101];
ll w[102],v[123];
ll cal(ll i,ll j)
{
    if(i<0) return LLONG_MIN;
    if(j==n+1) return 0;
    if(i==0) return 0;
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    ll res=max(cal(i,j+1),cal(i-w[j],j+1)+v[j]);
    return dp[i][j]=res;
}
int main()
{
        ll k;
        cin>>n>>k;

        for(int i=1;i<=n;i++){
            cin>>w[i]>>v[i];
        }
        ll ans=0;
        memset(dp,-1,sizeof(dp));
        ans=cal(k,1);
        cout<<ans<<endl;
}


Measured memory_bytes: 82552
#include<bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair  <int,int> ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef set   <int>     si;
typedef set   <ii>      sii;
typedef vi::iterator itt;
typedef si::iterator jtt;

#define fori(i,x) for(itt i=x.begin();i!=x.end();i++)
#define forj(j,x) for(jtt j=x.begin();j!=x.end();j++)
#define all(x)   x.begin(), x.end()
#define clr(x,v) memset(x,v,sizeof(x))

#define _ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#define pb push_back
#define endl "\n"
#define MOD int(1e9+7)
#define N 200123
double r, pi=3.14159265359;
int main(){_
    cin >> r;
    cout << 2*r*pi << endl;
}

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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef rsd511
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    #ifndef rsd511
    #define trace(...) {}
    #define cotra(...) {}
    #endif
} 

// Code Here

int main()
{
    Fast_IO();
    string s; cin >> s;
    ll n = len(s);
    ll a[n]; f(i,0,n-1) a[i] = s[i] - '0';
    ll ans = 0;
    f(i,0,n-1) ans += a[i];
    if(ans % 9 == 0) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 5304
// Simple Calculator
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_4_C
//
// Accepted

use std::io::{BufRead, stdin};

fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    loop {
        let mut buf = String::new();
        stdin.read_line(&mut buf).unwrap();

        let mut data = buf.split_whitespace();

        let a: i32 = data.next().unwrap().parse().unwrap();
        let op = data.next().unwrap();
        let b: i32 = data.next().unwrap().parse().unwrap();

        if op == "?" {
            break;
        }

        println!("{}", match op {
            "+" => a + b,
            "-" => a - b,
            "*" => a * b,
            "/" => a / b,
            _ => unreachable!()
        });
    }
}


Measured memory_bytes: 5024
import sys

str = sys.stdin.readlines()

N = int(str[0])
Hs = str[1].split()

Hnum = []
Hnum.append(int(Hs[0]))
j = 0
tmpcount = 0
maxcount = 0
for i in range(1,N+1):
    if i == N:
        Hnum.append(Hnum[N-1] + 1)
    else:
        Hnum.append(int(Hs[i]))
    if Hnum[i]>Hnum[i-1]:
        tmpcount = i - j - 1
        if tmpcount > maxcount:
            maxcount = tmpcount
        j = i

print(maxcount)


Measured memory_bytes: 15236
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include <cmath>
#include<queue>
#include<cstdio>
//#include <bits/stdc++.h>
using namespace std;

int main(){
    long long N,K,ans=0;
    cin>>N>>K;
    const long long A=1000000007;
    for (long int i=K;i<=N+1;i++){
        ans+=(N-i+1)*i+1;
        ans=ans%A;
    }
    cout<<ans<<endl;
    return 0;
}

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


int main() {
  int N;
  cin >> N;
  string c;
  cin >> c;
  int red = 0;
  for(int i = 0; i < N; i++) {
    if(c[i] == 'R') red++;
  }
  if(red == N) { cout << 0; return 0; }
  int a = 0;
  for(int i = 0; i < red; i++) {
    if(c[i] == 'R') a++;
  }

  cout << red - a;
  return 0;
}

Measured memory_bytes: 3752
#include <stdio.h>
a[110],b[110];main(i,n,f){
//srand(getpid()<<16^time(NULL));
f=0;//rand()&1;
	for(;scanf("%d",&n),n;){
		//if(n>90)exit(1);
		for(i=0;i<=n;i++){
			scanf("%d",a+i);
			//if(a[i]<1||100000000<a[i])exit(1);
		}
		if(f){
			fprintf(stderr,"%d",n);
			for(i=0;i<=n;i++)fprintf(stderr," %d",a[i]);
			fprintf(stderr,"\n");
		}
		for(i=1;i<=n;i++)b[i]=a[i]-a[i-1];
		if(b[1]==b[2]&&b[2]==b[3]&&b[3]==b[4]){
			for(i=5;i<=n;i++)if(b[i]!=b[1])break;
			//if(i>n)exit(1);
			printf("%d\n",a[i]);
		}
		else if(b[2]==b[3]&&b[3]==b[4])printf("%d\n",a[0]);
		else if(b[1]==b[2]&&b[2]==b[3])printf("%d\n",a[4]);
		else if(a[2]-a[0]==b[3]&&b[3]==b[4])printf("%d\n",a[1]);
		else if(b[1]==b[2]&&b[2]==a[4]-a[2])printf("%d\n",a[3]);
		else if(b[1]==a[3]-a[1]&&a[3]-a[1]==b[4])printf("%d\n",a[2]);
		//else exit(1);
	}
exit(0);}

Measured memory_bytes: 600
#B - Palace(ABC113)
N=int(input())
T,A=map(int, input().split())
H=list(map(int, input().split()))
s=abs(A-(T-H[0]*0.006))
m=0
ans=1
for i in range(1,N):
    m=abs(A-(T-H[i]*0.006))
    if m<s:
        s=m
        ans=i+1
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vi x(N);
    vi y(N*N), z(N*N);

    priority_queue<pii, vector<pii>, greater<pii> > Q;
    vi ans(N*N);
    rep(i, N) {
        cin >> x[i];
        y[x[i] - 1] = i + 1;
        rep(j, i)Q.push(mp(x[i] - 1, i + 1));
        ans[x[i] - 1] = i + 1;
    }

    rep(i, N*N) if(!y[i] && sz(Q)){
        int lim, val;
        tie(lim, val) = Q.top();
        if(i>=lim) {
            cout << "No" << endl;
            return 0;
        }
        Q.pop();
        ans[i] = val;
    }

    priority_queue<pii> q;


    rep(i, N) {
        rep(j, N - 1 - i)q.push(mp(x[i] - 1, i + 1));
    }

    for(int i = N*N - 1; i >= 0; --i)if(!ans[i] && sz(q)) {
        int lim, val;
        tie(lim, val) = q.top();
        if(i <= lim) {
            cout << "No" << endl;
            return 0;
        }
        ans[i] = val;
        q.pop();
    }

    if(sz(q) || sz(Q)) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    rep(i, N*N)cout << ans[i] << (i != N*N - 1 ? ' ' : '\n');
}

Measured memory_bytes: 6260
pos_in = input().split()
pos = [int(s) for s in pos_in]

if(pos[0] > pos[1]):
  if( (pos[1] < pos[2]) and (pos[2] < pos[0])):
      print("Yes")
  else:
  	print("No")
else:
  if(pos[0] < pos[2]):
    if(pos[2] < pos[1]):
      print("Yes")
    else:
      print("No")
  else:
  	print("No")

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

int main() {
  int N, L[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> L[i];
  }
  
  sort(L, L+10); int sum = 0;
  for (int i = 0; i < 9; ++i) { sum += L[i]; }
  
  if (L[9] < sum) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

const int mod=1000000007,N=25,N2=600001;
int p[N],q[N],n,m,K,trans[N2][N],f[N2],to[N2];
inline void reduce(int&x){x+=x>>31&mod;}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>K;--n;
	for(;K --> 0;){
		int x,y,z;cin>>x>>y>>z;--x;--y;
		p[x]|=1<<y;q[x]|=z<<y;
	}
	memset(to,-1,sizeof to);memset(trans,-1,sizeof trans);
	for(int i=0;i<(1<<n);++i){
		int cnt=0;
		for(int j=0;j<n;++j)
			if(i>>j&1){
				if(j&&!(i>>(j-1)&1))trans[i][cnt]=i^(1<<j)^(1<<(j-1));
				++cnt;
			}
	}
	for(int i=0;i<(1<<n);++i)
		for(int j=0;j<n;++j)
			if(!(i>>j&1))to[i]=i^(1<<j);
	f[0]=1;
	for(int i=0;i<m;++i){
		for(int j=0;j<(1<<n);++j)
			if(~to[j])reduce(f[to[j]]+=f[j]-mod);
		for(int j=0;j<n;++j)
			for(int k=(1<<n)-1;~k;--k)
				if(~trans[k][j])reduce(f[trans[k][j]]+=f[k]-mod);
		for(int j=0;j<(1<<n);++j)
			if((j&p[i])!=q[i])f[j]=0;
	}
	int ans=0;
	for(int i=0;i<(1<<n);++i)reduce(ans+=f[i]-mod);
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 63616
#include <iostream>
#include <math.h>
#include <vector>
#include <queue> 
#include <algorithm>
#include <map>


typedef long long ll;

using namespace std;



int main() 
{ 
	
	map<int, bool> problems;
	map<int, int> penss;

	int n, m;

	cin >> n >> m;

	int res = 0, pens = 0;

	for (int i = 0; i < m; i++){

		int q; string ans;

		cin >> q >> ans;

		if (problems.find(q) == problems.end() && ans == "WA"){
			penss[q]++;
		}
		else if (problems.find(q) == problems.end() && ans == "AC"){
			res++;
			problems[q] = true;
		}
	}

	int pres = 0;

	map<int, bool>::iterator it;

	for ( it = problems.begin(); it != problems.end(); it++ )
	{
		if (it->second){
			pres += penss[it->first];
		}
	}

	cout << res << " " << pres << endl;

	return 0; 
} 


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int n,k;
const int maxn=200005;
int a[maxn];
int ans;
set<int> st;
int b[maxn];
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int now=1;
    int cnt=0;
    for(int i=2;i<=n;i++)
    {
        if(a[i]<a[i-1])now=i;
        if(i-now+1>=k)b[i]=1,cnt=1;
    }
    if(!b[k])ans=1;
    for(int i=1;i<=k;i++)
    {
        st.insert(a[i]);
    }
    for(int i=k+1;i<=n;i++)
    {
        ans++;
        if(b[i]||(st.lower_bound(a[i])==st.end()&&st.lower_bound(a[i-k])==st.begin()))
        {
            ans--;
        }
        st.erase(a[i-k]);
        st.insert(a[i]);
    }
    cout<<ans+cnt<<endl;
}


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

int main() {
  int i, A, B, C, K, sum_max = 0;

  cin >> A >> B >> C >> K;

  if(A >= K) cout << K << endl;
  else if(A+B >= K) cout << A << endl;
  else cout << A - (K - A - B) << endl;
  
  return 0;
}


Measured memory_bytes: 3632
module mod_union_find
  implicit none
  type union_find
    integer :: n = 0
    integer, allocatable :: par(:), rnk(:), cnt(:)
  contains
    procedure :: find => find
    procedure :: same => same
    procedure :: unite => unite
    procedure :: size => size_of
  end type
  interface union_find
    module procedure :: newuf
  end interface
contains
  type(union_find) function newuf(n) result(res)
    integer, intent(in) :: n
    integer :: i
    res%n = n
    allocate(res%par(n), res%rnk(n), res%cnt(n))
    res%par = [(i, i = 1, n)]
    res%rnk = 0
    res%cnt = 1
  end
  recursive integer function find(this, i) result(res)
    class(union_find), intent(inout) :: this
    integer, intent(in) :: i
    if (this%par(i) /= i) this%par(i) = find(this, this%par(i))
    res = this%par(i)
  end
  logical function same(this, i, j) result(res)
    class(union_find), intent(inout) :: this
    integer, intent(in) :: i, j
    res = find(this, i) == find(this, j)
  end
  subroutine unite(this, i, j)
    class(union_find), intent(inout) :: this
    integer, intent(in) :: i, j
    integer :: x, y
    x = find(this, i)
    y = find(this, j)
    if (x == y) return
    if (this%rnk(x) < this%rnk(y)) then
      this%par(x) = y
      this%cnt(y) = this%cnt(y) + this%cnt(x)
    else
      this%par(y) = x
      this%cnt(x) = this%cnt(x) + this%cnt(y)
      if (this%rnk(x) == this%rnk(y)) this%rnk(x) = this%rnk(x) + 1
    end if
  end
  integer function size_of(this, i) result(res)
    class(union_find), intent(inout) :: this
    integer, intent(in) :: i
    res = this%cnt(find(this, i))
  end
end module mod_union_find
program connect_cities
  use mod_union_find
  implicit none
  integer :: n, m, a, b, i
  type(union_find) :: uf
  read(*,*) n, m
  uf = union_find(n)
  do i = 1, m
    read(*,*) a, b
    if (uf%same(a, b)) cycle
    call uf%unite(a, b)
    n = n - 1
  end do
  write(*,'(i0)') n - 1
end program connect_cities

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

int main()
{
   ll n;
    cin>>n;
    ll ans=0;
    if(n%2==1) cout<<0<<endl;
    else{
    n/=2;
    while(n>=5){
        n/=5;
        ans+=n;
    }
    cout<<ans;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main { 
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int line = Integer.parseInt(sc.nextLine());
    	
    	int result = line*line*line;
    	
    	
    	System.out.println(result);
    	
    }
}

Measured memory_bytes: 25300
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

//#include "All.h"

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")

using ll = long long int;

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll N, M, K;
ll A[200010], B[200010];
ll a[200010] = {}, b[200010] = {};
ll ans = 0;
ll ai = 0, bi = 0;

int main() {
    cin >> N >> M >> K;
    A[0] = 0;
    a[0] = 0;
    B[0] = 0;
    b[0] = 0;
    REP(i, 1, N + 1 + 1) {
        if (i != N + 1) {
            cin >> A[i];
            a[i] = a[i - 1] + A[i];
        }
        else a[i] = (ll)1e17;

        if (a[i] > K && a[i - 1] <= K) {
            ai = i - 1;
        }
    }
    REP(i, 1, M + 1 + 1) {
        if (i != M + 1) {
            cin >> B[i];
            b[i] = b[i - 1] + B[i];
        }
        else b[i] = (ll)1e17;

        if (b[i] > K && b[i - 1] <= K) {
            bi = i - 1;
        }
    }
    /*
    for (int i = 0; i <= N + 1; i++) {
        cout << "a:" << a[i] << endl;
    }
    for (int i = 0; i <= M + 1; i++) {
        cout << "b:" << b[i] << endl;
    }
    */
    ans = ai;
    ll bii = 0;
    int L = ai + 1;
    //bool chk = false;
    //if (A[1] > K && B[1] > K) {
    //    cout << 0 << endl;
    //    return 0;
    //}
    //std::cout << ai << " " << bi << endl;
    //cout << endl;
    for (int i = 0; i < L; i++) {
        //どんどん引いてく
        while (true) {
            //std::cout << ai - i << " " << bii << endl;
            if (K < a[ai - i] + b[0]) break;
            if ((K < a[ai - i] + b[bii] || bii == bi)) {
                if (K < a[ai - i] + b[bii]) bii--;
                if (ai - i + bii > ans) {
                    ans = ai - i + bii;
                    //std::cout << a[ai - i] + b[bii] << endl;
                }
                //if (bii == bi) chk = true;
                break;
            }
            else {
                bii++;
                //if (K >= a[ai - i] + b)
            }
        }
        //if (chk) break;
    }

    std::cout << ans << endl;

}

/*
5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1 1000000000 1000000000 1000000000

5 4 1
1 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000
*/


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

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


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

int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  for(int i=0; i<N; i++){
    cin >> P[i];
  }
  int min=P[0], ans=1;
  for(int i=1; i<N; i++){
    if(min>=P[i]){
      min=P[i];
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    sort(all(h));
    ll ans = 0;
    rep(i, n - k) {
        ans += h[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  int a, b;
  cin >> a >> b;
  int res = 1, cnt = a;
  while (cnt < b) {
    cnt += a - 1;
    res++;
  }
  if (b == 1) res = 0;

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 256
X=int(input())
flag=False
i=X
ans=0
while flag==False:
    flag_2=True
    for j in range(2,1+int(i**0.5)):
        if i%j==0:
            flag_2=False
    if flag_2==True:
        ans=i
        flag=True
    i+=1
print(ans)



Measured memory_bytes: 2940
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from itertools import permutations

    n, m, q = map(int, readline().split())
    r_ = list(map(int, readline().split()))
    r = [i-1 for i in r_]

    dist = [[10 ** 18] * n for _ in range(n)]

    for i in range(n):
        dist[i][i] = 0

    for _ in range(m):
        a, b, c = map(int, readline().split())
        a, b = a - 1, b - 1
        dist[a][b] = c
        dist[b][a] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    ans = 10 ** 18
    for per in permutations(range(q)):
        score = 0
        for i in range(q - 1):
            score += dist[r[per[i]]][r[per[i + 1]]]
        ans = min(ans, score)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 74652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

template<class Type>
Type Pow(Type a, Type n)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a;
		}
		a = a * a;
		n >>= 1;
	}
	return res;
}

int main()
{
	ll x;
	cin >> x;
	for (ll i = -500; i < 500; i++) {
		for (ll j = -500; j < 500; j++) {
			if (x == Pow(i, 5LL) - Pow(j, 5LL)) {
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 3576
n, m = map(int, input().split())
a = [list(input()) for i in range(n)]
b = [list(input()) for i in range(m)]
check = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        tmp_check = True
        for k in range(m):
            for l in range(m):
                if not (a[i + k][j + l] == b[k][l]):
                    tmp_check = False
        check = check or tmp_check
print("Yes" if check else "No")

Measured memory_bytes: 3064
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = '?' + read().rstrip().decode()[::-1]
ans = 0
cnt = 0
index = 0
for _ in range(len(s) + 1):
    if s[index] == 'C' and s[index + 1] == 'B':
        cnt += 1
        index += 1
    elif s[index] == 'A':
        ans += cnt
    else:
        cnt = 0
    index += 1
    if index >= len(s) - 1:
        break
if s[-1] == 'A':
    ans += cnt
print(ans)


Measured memory_bytes: 3444
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  ll r;
  cin >> r;
  cout << 3 * r * r << endl;

  return 0;
}


Measured memory_bytes: 256
#define n_max 20
#define max(a,b) a>b?a:b
#include <stdio.h>
int main(void){
    char n[n_max];
    for(int i=0;i<n_max;i++)
    {
        n[i] = 0;
    }
    gets(n);
    int len = getlength(n);
    
    int nonine = len-1;
    for(int i=0;i<len;i++)
    {
        if(n[i]!='9')
        {
            nonine = i;
            break;
        }
    }
    
    if(nonine==len-1)
    {
        printf("%d\n",max(9*nonine+(n[nonine]-'0'),9*(nonine-1)+(n[nonine-1]-'1')+9));
        return 0;
    }
    else if(countnine(n,len)==len-1)
    {
        printf("%d\n",9*(len-1)+n[nonine]-'0');
        return 0;
    }
    else
    {
        printf("%d\n",9*nonine+n[nonine]-'1'+9*(len-nonine-1));
        return 0;
    }
}

int getlength(char data[]){
    int i=0;
    while(data[i])
    {
        i++;
    }
    return i;
}

int countnine(char data[],int length){
    int i=0,count=0;
    while(i<length)
    {
        if(data[i]=='9')
        {
            count++;
        }
        i++;
    }
    return count;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    cin >> n;
    vint a(n);
    int total = 0;
    rep(i, n) {
        cin >> a[i];
        total ^= a[i];
    }
    
    rep(i, n) {
        cout << (total ^ a[i]) << endl;
    }
    return 0;
}

Measured memory_bytes: 3988
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector<int>a(n),b(n),c(n-1);
  rep(i,n)cin >> a[i];
  rep(i,n)cin >> b[i];
  rep(i,n-1)cin>> c[i];
  int sum=0;
  rep(i,n)sum += b[i];
  rep(i,n-1){
  	if(a[i] +1 == a[i+1])sum += c[a[i] - 1];
  }
  cout << sum <<endl;
  
  
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int N,K,X,Y,c;
    scanf("%d%d%d%d",&N,&K,&X,&Y);
    
    if(N>K)
        c = K*X + (N-K)*Y;
    else
        c = N*X;
    
    printf("%d\n",c);
    
    return 0;
    
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v){
  const char* dlm = "";
  for(const auto& x:v) os << exchange(dlm, "\n") << x;
  return os;
}
struct Graph{
  using seen_t=uint64_t; using ver_t=size_t; using edge_t=pair<size_t, ver_t>;
  const seen_t NO=1e18; vector<seen_t> seen;
  vector<vector<edge_t>> edge;
  Graph(size_t n): seen(n,NO), edge(n) {}

  void search(ver_t s){
    seen[s]=0;
    priority_queue<edge_t, vector<edge_t>, greater<edge_t>> que;
    que.push(make_pair(0,s));
    while(!que.empty()){
      auto v=que.top(); que.pop();
      for(const auto& nextv:edge[v.second]){
        auto alt=seen[v.second]+nextv.first;
        if(alt<seen[nextv.second]){
          seen[nextv.second]=alt;
          que.emplace(seen[nextv.second], nextv.second);
        }
      }
    }
  }
};
ostream& operator<<(ostream& os, const Graph& g){
  for(const auto& x:g.seen){
    if(x<g.NO) cout<<x<<'\n';
    else cout<<"INF\n";
  }
  return os;
}
int32_t main(){
  size_t v,e,r; cin>>v>>e>>r;
  Graph g(v); size_t s,t,d;
  for(size_t i=0; i<e; ++i){
    cin>>s>>t>>d;
    g.edge[s].emplace_back(d,t);
  }
  g.search(r);
  cout<<g;
}



Measured memory_bytes: 19364
#include<bits/stdc++.h>
using namespace std;
string s;
int l;
int main(){
    cin>>s;
    l=s.size();
    for( register int i=0;i<l;i++){
        if(s[i]=='C'){
            for( register int j=i+1;j<l;j++){
                if(s[j]=='F'){
                    cout<<"Yes";
                    return 0;
                }
            }
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int a,b,c,k,s=0,s1=0,s2=0,sum=0;
    cin>>a>>b>>c>>k;
    if(k>a)
    {
        s=a*1;
        s1=(k-a)*0;
        s2=(k-a-b)*-1;
        sum=s+s1+s2;
    }
    else if(k<=a)
    {
        sum=k;
    }
    cout<<sum;
    
}

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

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

typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef priority_queue<int> P_QI;
typedef priority_queue<string> P_QS;
typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector< int > :: iterator $$;

#define SET(arr) memset(arr, -1, sizeof(arr))
#define CLR(arr) memset(arr, 0, sizeof(arr))

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

#define $ vector< int > :: iterator
#define m_p make_pair
#define p_b push_back
#define rep(i, n) for(int i=0; i<(n); i++)
#define forn(i, n) for (int i = 1; i <=(int)(n); ++i)
#define forab(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define forba(i, b, a) for (int i = (int)(b); i >= (int)(a); --i)

#define forv(i,v) rep(i,SZ(v))
#define forit(i,s) for(auto i=(s).begin();i!=(s).end();++i)

#define Boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define _ <<" "<<
#define CS(i) cout<<"Case "<<(int)(i)<<": "

const int MOD = 1e9+7;
const int inf = 1e9+9;
const long long INF = 1e18+3;
const ld eps = 1e-9;
const ld PI=acos(-1.0);
const ld E=2.71828182845904523536;

int main() {
Boost;
//READ("in.txt");
//WRITE("out.txt");
    int n,d;
    cin>>n>>d;
    int x[n][d];
    int sq,root,cnt=0;

    rep(i,n) rep(j,d) cin>>x[i][j];

    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++){
            sq=0;
            for(int k=0;k<d;k++)
                sq+=((x[i][k]-x[j][k])*(x[i][k]-x[j][k]));
            root=sqrt(sq);

            if(root*root==sq) cnt++;
        }
   cout<<cnt<<endl;

return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	string s; cin >> s;
	bool flag = false;
	for(char c:s) {
		if(c == 'C') {
			flag = true;
		}
		if(c == 'F' && flag) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 666666
int n,k,l;
int f1[N],f2[N],sum1[N],sum2[N];
int getf1(int v){
	if(v==f1[v]){
		return f1[v];
	}else{
		f1[v]=getf1(f1[v]);
		return f1[v];
	}
}
void merge1(int u,int v){
	int t1=getf1(u);
	int t2=getf1(v);
	if(t1!=t2){
		f1[max(t1,t2)]=min(t1,t2);
		sum1[min(t1,t2)]+=sum1[max(t1,t2)];
	}
}


int getf2(int v){
	if(v==f2[v]){
		return f2[v];
	}else{
		f2[v]=getf2(f2[v]);
		return f2[v];
	}
}
void merge2(int u,int v){
	int t1=getf2(u);
	int t2=getf2(v);
	if(t1!=t2){
		f2[max(t1,t2)]=min(t1,t2);
		sum2[min(t1,t2)]+=sum2[max(t1,t2)];
	}
	
}
void init(){
	for(int i=0;i<=n;i++) f1[i]=i;
	for(int i=0;i<=n;i++) f2[i]=i;
	for(int i=0;i<=n;i++) sum1[i]=1,sum2[i]=1;
}
map<pair<int,int>,int> mp;
signed main(){
	cin>>n>>k>>l;
	init();
	for(int i=1;i<=k;i++){
		int a,b;cin>>a>>b;
		merge1(a,b);
	}
	for(int i=1;i<=l;i++){
		int a,b;cin>>a>>b;
		merge2(a,b);
	}
	for(int i=1;i<=n;i++){
		
		mp[make_pair(getf1(i),getf2(i))]++;
	}
	for(int i=1;i<=n;i++)
		cout<<mp[make_pair(getf1(i),getf2(i))]<<" ";
	return 0;
}

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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	
	int n;
	ll sum = 0;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		if(i % 3 && i % 5) {
			sum += i;
		}
	}
	fix;
	cout << sum << "\n";




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

Measured memory_bytes: 3604
def main():
    sc =Scan()
    n = sc.intarr()
    a = sc.intarr()
    a.sort()
    total = 1    
    for num in a:
        total = total * num
        if total > 1000000000000000000:
            print("-1")
            return
    
    print(total)
        
class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        return line.split(' ')
      
      
if __name__ == '__main__':
  main()

Measured memory_bytes: 23920
#include <iostream>

int num[100050];

int main()
{
	int n,i,ans=0,tmp;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&num[i]);
	for(i=1;i<n;i++)
		if(num[i]==i && num[i+1]==i+1) ans++,num[i]=i+1,num[i+1]=i;
	for(i=1;i<=n;i++)
		if(num[i]==i) ans++;
	printf("%d\n",ans);
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
int main()
{
    int a,b,c,d,i;
    int e[500];
    while(~scanf("%d%d%d%d",&a,&b,&c,&d))
    {
        int sum=0;
        memset(e,0,sizeof(e));
    for(i=a;i<b;i++)
        e[i]++;
    for(i=c;i<d;i++)
        e[i]++;
    if(b>d) d=b;
    for(i=0;i<d;i++)
        if(e[i]==2) sum++;
    printf("%d\n",sum);
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define cpp mp::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
	int to;
	ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
string init(int a = 0, char b = '0') {
	string res(a, b);
	return res;
}
vector<vector<int>> init(int a, int b, int c = 0) {
	vector<int> x(b, c);
	vector<vector<int>> res(a, x);
	return res;
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	int H, W;
	cin >> H >> W;
	vector<string> v(H + 2);
	v[0] = v[H + 1] = init(W + 2, '#');
	rrep(i, H) {
		string S;
		cin >> S;
		S = "#" + S + "#";
		v[i] = S;
	}
	vector<vector<int>> u = init(H + 2, W + 2, 0);
	for (int i = 0; i <= H + 1; i++) {
		bool f = 0;
		int a;
		for (int j = 0; j <= W + 1; j++) {
			if (f) {
				if (v[i][j] == '#') {
					f = 0;
					for (int k = a; k < j; k++) {
						u[i][k] += j - a;
					}
				}
			}
			else {
				if (v[i][j] == '.') {
					f = 1;
					a = j;
				}
			}
		}
	}
	for (int j = 0; j <= W + 1; j++) {
		bool f = 0;
		int a;
		for (int i = 0; i <= H + 1; i++) {
			if (f) {
				if (v[i][j] == '#') {
					f = 0;
					for (int k = a; k < i; k++) {
						u[k][j] += i - a;
					}
				}
			}
			else {
				if (v[i][j] == '.') {
					f = 1;
					a = i;
				}
			}
		}
	}
	int ans = 0;
	rrep(i, H) {
		rrep(j, W) {
			ans = max(ans, u[i][j]);
		}
	}
	ans--;
	cout << ans << endl;
}

Measured memory_bytes: 23936
#include <iostream>


using namespace std;

int main(void)
{
    int n;
    cin >> n;
    int debt = 100000;
    for(int i=0;i<n;i++){
        double tmp = (double)debt * 1.05;
        debt = (int)tmp;
        int xsen = debt / 1000;
        if( debt % 1000 != 0){
            debt = 1000 * (xsen+1);
        }
    }
    cout << debt << endl;
    return 0;
}

Measured memory_bytes: 1160
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

a,b,c,d=map(int, input().split())
cd=lcm(c, d)

cc=b//c - (a-1)//c
dc=b//d - (a-1)//d
cdc=b//cd - (a-1)//cd

print(b-(a-1)-cc-dc+cdc)



Measured memory_bytes: 5344
n,m,c=map(int,input().split())
b_list=list(map(int,input().split()))
List=[list(map(int,input().split())) for i in range(n)]

counter=0
for i in range(n):
    sum=0
    for j in range(m):
        sum+=b_list[j]*List[i][j]

    if sum+c>0:
        counter+=1

print(counter)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define lint long long int
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define arep(i,a,n) for(int i=a;i<n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define fill(a,x) fill(a.begin(),a.end(),x)
#define eb(data) emplace_back(data)
#define pb(data) emplace_back(data)
#define mp make_pair
#define ALNUM 26
#define vint vector<int>
#define vlint vector<lint>
#define F first
#define S second
#define ALL(data) data.begin(),data.end()
#define GEts(s) getline(cin,s);
#define UNIQUE(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())

using namespace std;
template<typename Rast>inline void out(Rast rast){cout<<rast<<"\n";return;}
template<typename Rast>inline void in(Rast& rast){cin>>rast;return;}
template<typename T>istream& operator >> (istream& is, vector<T>& vec){for(T& x: vec) is >> x;return is;}
template<typename First, typename... Rest>void in(First& first, Rest&... rest){cin >> first;in(rest...);return;}
template<typename First, typename... Rest>void out(First first, Rest... rest){cout << first<<" ";out(rest...);return;}
template<typename T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<typename T1,typename T2>bool chmax(T1& a,T2 b){if(a<b){a=b;return true;}else{return false;}}
template<typename T1,typename T2>bool chmin(T1& a,T2 b){if(a>b){a=b;return true;}else{return false;}}
template<typename T>T lcm(T a, T b){return a * b / gcd(a, b);}
static const double pi = 3.141592653589793;
int modpow(int a,int n,int p){if (n==0)return 1%p; if(n==1)return a%p;if(n%2==1)return (a*modpow(a,n-1,p))%p;lint t=modpow(a,n/2,p);return (t*t)%p;}//a^n%p
lint MOD=pow(10,9)+7;
//lint MOD=998244353;
lint inf=pow(2,50);
int intinf=pow(2,30);
/**int dirx[]={1,0};int diry[]={0,1};//*///右、下
/**int dirx[]={0,1,0,-1};int diry[]={-1,0,1,0};//*///四方位
/**int dirx[]={-1,0,1,1,1,0,-1,-1};int diry[]={-1,-1,-1,0,1,1,1,0};//*///八方位


class unionfind{
public:
	vector<int> table;
	void init(int size){
		table.resize(size);
		rep(i,size)table[i]=i;
	};
	int root(int index){
		if(table[index]==index)return index;
		else{
			int hoge=root(table[index]);
			table[index]=hoge;
			return hoge;
		}
	};
	bool same(int x,int y){
		return(root(x)==root(y));
	};
	int marge(int x,int y){
		int yroot=root(y);
		int xroot=root(x);
		if(xroot==yroot)return 0;
		table[yroot]=xroot;
		return 0;
	}
};


int main(){
	cin.tie(0);ios::sync_with_stdio(false);cout<<std::fixed<<std::setprecision(19);
	int a,b;
	in(a,b);
	int ans=0;
	int now=1;
	while(now<b){
		ans+=1;
		now-=1;
		now+=a;
	}
	out(ans);
	return 0;
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

typedef pair<int, int> P;

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
  int N, r;
  while( cin >> N >> r, N | r ){
    vector<P> ope( r );
    REP( i, r ){
      int p, c; cin >> p >> c;
      ope.emplace_back( p, c );
    }

    int t = 1;
    REPR( i, ope.size() - 1 ){
      if( t <= ope[i].second ){
        t += ope[i].first - 1;
      }else{
        if( t <= ope[i].first + ope[i].second - 1 ){
          t -= ope[i].second;
        }
      }
    }
    cout << N - t + 1 << endl;
  }
}


Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int N,a[3];
    cin >> N;
    for(int i = 0 ; i < N ; i++){
	for(int j = 0 ; j < 3 ; j++){
	    cin >> a[j];
	}
	sort(a, a+3);
	cout << (a[0]*a[0]+a[1]*a[1] == a[2]*a[2] ? "YES" : "NO") << endl;
    }
    return 0;
}

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

int main() {
    long n, k;
    cin >> n >> k;
    vector<long> s(n);
    rep(i, n) cin >> s[i];
    sort(s.begin(), s.end());
    long ans = 0;
    if (k < n) {
        for (int i = 0; i < n-k; i++) {
            ans += s[i];
        }
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i, s, g) for(int i = s; i < g; i++)
#define FORR(i, s, g) for(int i = s - 1; i >= g; i--)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define DMP(a) std::cerr << #a << " = " << a << "\n"
using namespace std;
typedef long long ll;
struct aaa{
    aaa(){
        std::cin.tie(0); std::ios::sync_with_stdio(0); std::cout<<std::fixed<<std::setprecision(20);
    };
}aaaaaaa;

int main() {
    int n, m;
    cin >> n >> m;
    priority_queue<int, vector<int>, greater<int>> pq;
    REP(i, n) {
        int a;
        cin >> a;
        pq.push(a);
    }

    vector<pair<int, int>> bc(m);
    REP(i, m) {
        cin >> bc[i].second >> bc[i].first;
    }
    sort(ALL(bc), greater<pair<int, int>>());

    REP(i, m) {
        for(; bc[i].second > 0; (bc[i].second)--) {
            int t = pq.top();
            if(t >= bc[i].first) goto END;
            pq.pop();
            pq.push(bc[i].first);
        }
    }

END:
    ll sum = 0;
    while(!pq.empty()) {
        sum += pq.top();
        pq.pop();
    }
    cout << sum << "\n";

    return 0;
}


Measured memory_bytes: 1528
using System;
using System.Collections.Generic;
using System.Linq;

public static class Program
{
    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var result = 0;
        for (int i = 1; i <= n; i += 2)
        {
            var cnt = 0;
            for (int j = 1; j <= i; j++)
            {
                if (i % j == 0)
                    cnt++;
                if (cnt > 8)
                    break;
            }
            if (cnt == 8)
                result++;
        }
        Console.WriteLine(result);
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include<string>
#include<deque>

using namespace std;

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

	deque<pair<string, int>> process;

	for (int i = 1; i <= n; i++) {
		pair<string, int> a;
		cin >> a.first >> a.second;
		process.push_back(a);
	}
	
	int totaltime = 0;

	while (process.size() > 0)
	{
		process[0].second -= q;

		if (process[0].second <= 0) {
			cout << process[0].first << " " << q + process[0].second + totaltime << endl;
			totaltime += q + process[0].second;
			process.pop_front();
		}
		else {
			pair<string, int> a=process[0];
			process.pop_front();
			process.push_back(a);
			totaltime += q;
		}
	}

	return 0;
}



Measured memory_bytes: 6288
#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 Would
#define you
#define please



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


	int A, B, Q;
	cin >> A >> B >> Q;
	ll s[100100], t[100100];
	s[0] = -1e12;
	t[0] = -1e12;
	s[A + 1] = 1e12;
	t[B + 1] = 1e12;
	rep1(i, A) cin >> s[i];
	rep1(i, B) cin >> t[i];

	rep(i, Q) {
		ll x;
		cin >> x;

		auto sp = lower_bound(s, s + A + 2, x);
		ll s1 = *(sp - 1);
		ll s2 = *sp;
		auto tp = lower_bound(t, t + B + 2, x);
		ll t1 = *(tp - 1);
		ll t2 = *tp;

		ll saishou = 1e13;
		saishou = min(saishou, abs(min(s1, t1) - x));
		saishou = min(saishou, abs(max(s2, t2) - x));
		ll k1 = abs(s1 - x);
		ll k2 = abs(t2 - x);
		saishou = min(saishou, k1 + k2 + min(k1, k2));
		ll k3 = abs(t1 - x);
		ll k4 = abs(s2 - x);
		saishou = min(saishou, k3 + k4 + min(k3, k4));

		co(saishou);
	}

	Would you please return 0;
}

Measured memory_bytes: 2944