akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>


long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


long long stair(int N){
long long i=1;
for(int k=2;k<=N;k++){
    i*=k;
    if(i>mod){
        i%=mod;
    }
}
return i;

}

int main(){
int N;
cin>>N;
string s;
cin>>s;
char white='W';
char black='B';
if(s[0]==white || s[2*N-1]==white){
    cout<<"0"<<endl;
    return 0;
}


bool LorR[2*N];

LorR[0]=false;//L=false,R=trueとする


for(int i=1;i<2*N;i++){
    if(s[i-1]==s[i]){
        LorR[i]=!LorR[i-1];
    }
    else{
        LorR[i]=LorR[i-1];
    }
}
int countL[2*N+1];//Lの個数の累積和
int countR[2*N+1];//Lの個数の累積和
countL[0]=0;
countR[0]=0;
for(int i=0;i<2*N;i++){
    if(LorR[i]){
        countR[i+1]=countR[i]+1;
        countL[i+1]=countL[i];
    }
    else{
        countR[i+1]=countR[i];
        countL[i+1]=countL[i]+1;   
    }
}

if(countL[2*N]!=countR[2*N]){
    cout<<"0"<<endl;
    return 0;
}
long long ans=1;
for(int i=1;i<=2*N;i++){
    if(LorR[i-1]){
        if(countL[i]<countR[i]){
           cout<<"0"<<endl;
            return 0;
        }
        ans*=(countL[i]-countR[i-1]);
    }

    if(ans>mod){
        ans%=mod;
    }
}
//順列なのでnの階乗をかける
ans=(ans*stair(N))%mod;

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

Measured memory_bytes: 2308
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;

int main()
{
  ll x;cin>>x;
  
  ll a=0;
  ll b=0;
  while (500*a<=x)
  {
    a++; 
  }
  a--;
  while (5*b<=x-500*a)
  {
    b++; 
  }
  b--;
  cout<<1000*a+5*b<<endl;
}

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

void swap(int *p1, int *p2){
	int tmp;

	tmp = *p1;
	*p1 = *p2;
	*p2 = tmp;
}

int select_sort(int *data, int size){
	int swap_count = 0;
	int i,j,minj;

	for(i=0;i<size;i++){
		minj = i;
		for(j=i;j<size;j++){
			if( data[j] < data[minj] ){
				minj = j;
			}
		}
		if( i != minj ){
			swap(data+i,data+minj);
			swap_count++;
		}
	}

	return swap_count;
}

int main(int argc, char** argv){
	int n,*data,i,swap_count;

	// Input
	scanf("%d",&n);
	data = malloc(sizeof(int)*n);
	for(i=0;i<n;i++){
		scanf("%d",data+i);
	}

	// Sort
	swap_count = select_sort(data,n);

	// Output
	printf("%d",data[0]);
	for(i=1;i<n;i++){
		printf(" %d",data[i]);
	}
	putchar('\n');
	printf("%d\n",swap_count);

	// Reset
	free(data);

	return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;

double x, h;

double pyramid() {
	return (x * x + 4 * sqrt(h * h + x * x / 4) * x / 2);
}

int main() {
	while (true) {
		cin >> x;
		cin >> h;
		if (x == 0 && h == 0) {
			break;
		}
		printf("%.6lf\n", pyramid());
	}
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int x=(c/b);
  if(c%b)
    x++;
  int y=(a/d);
  if(a%d)
    y++;
  if(x<=y)
    cout<<"Yes";
  else cout<<"No";
  return 0;
}

Measured memory_bytes: 3624
n = int(input())
b = list(map(int, input().split()))

a = [0 for i in range(n)]

a[0] = b[0]

for ii in range(max(0,n-2)):
    i = ii+1
    a[i] = min(b[i-1],b[i])

a[n-1] = b[n-2]
print(sum(a))

Measured memory_bytes: 38384
from fractions import gcd as bltin_gcd

def coprime2(a, b):
    return bltin_gcd(a, b) == 1

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


def main():
	[a,b]=[int(x) for x in input().split()]
	kouyakusuu=list(set(make_divisors(a))&set(make_divisors(b)))
	kouyakusuu.sort()
	ans=[1,]
	for item in kouyakusuu[1:]:
		if all([coprime2(item,x) for x in ans])==True:
			ans.append(item)
	#print(ans)
	print(len(ans))
    

if __name__ == '__main__':
	main()

Measured memory_bytes: 68200
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
const ll waru=1e9;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

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

    ll x[3]={0ll},y[3]={0ll};

    ll amari=S%waru;
    if(amari==0){
        x[1]=0; y[2]=0;
    }else{
        x[1]=1; y[2]=1000000000-amari;
    }

    x[2]=1000000000;
    S+=x[1]*y[2];
    y[1]=S/x[2];

    cout<<x[0]<<" "<<y[0]<<" "<<x[1]<<" "<<y[1]<<" "<<x[2]<<" "<<y[2]<<endl;
    //cout<<abs(x[2]*y[1]-x[1]*y[2])<<endl;
    /*
    bool flag= false;
    for(int i=0;i<3;i++){
        if(x[i]>1e9||y[i]>1e9){
            flag=true;
        }
    }
    if(flag) cout<<"out"<<endl;
     */

    return 0;
}



Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<deque>
#include<cstdlib>
#include<algorithm>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define rep(n) for(int i=0;i<(n);i++)

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

Measured memory_bytes: 3620
/**
 *    Author:   ElProfesor
 *	       
**/

#include<bits/stdc++.h>

using namespace std;
 
// Competetive Template:
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
typedef vector <lli> vl;
typedef vector <string> vs;
typedef vector < pair <long, long> > vll;

// Debugging :
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ba  back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define gcd __gcd
#define maxe *max_element
#define mine *min_element
#define deb debug
 
#define forz(i,n) for(lli i=0; i<n; i++)
#define rep(i,k,n) for (lli i = k; i < n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)

// Printing Data :
#define pvec(v) forz(i,v.si) cout<<v[i]<<" "; cout<<endl;
#define parr(arr, n) forz(i,n) cout<<arr[i]<<" "; cout<<endl;
#define p1(i) cout<<i<<endl;
#define p2(i, j) cout<<i<<" "<<j<<endl;
#define p3(i, j, k) cout<<i<<" "<<j<<" "<<k<<endl;
#define p4(i, j, k, l) cout<<i<<" "<<j<<" "<<k<<" "<<l<<endl;
#define pc(b, s1, s2) cout << (b ? s1 : s2) << endl;

typedef pair <lli,lli> pll;
 
// CODE BEGINS :

int main()
{
    kira; 

    lli a, b, c, k; cin>>a>>b>>c>>k;

    lli res=0;
    if(k>0)
    {
        lli key = min(a, k);
        res += key;
        k-=key;
    }

    if(k>0)
    {
        lli key = min(b, k);
        k-=key;
    }

    if(k>0)
    {
        lli key = min(c, k);
        k-=key;
        res-=key;
    }

    p1(res);
    

    return 0;
}




















































Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int ridge[40];
int floor[30];
int room[100];
int menber[90];
int resident[40][30][100];
int main(){
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> ridge[i] >> floor[i] >> room[i] >> menber[i];
        
        resident[ridge[i]][floor[i]][room[i]] += menber[i];
    }
    for(int i=1;i<=4;i++){
        for(int j=1;j<=3;j++){
            for(int k=1;k<=10;k++){
                cout << " " << resident[i][j][k];
            }
            cout << endl;
        }
        if(i <= 3){
            cout << "####################" << endl;
        }
        
    }
    return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int x;
    cin>>x;
    int to = x / 500;
    x %= 500;
    cout<<to * 1000 + (x/5) * 5;
    return 0;
}

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

int main(void){
int n;
  cin >> n;
  int pi[n];
  for(int i=0;i<n;i++){
     cin >> pi[i];
  }
  int count = n;
  int mini=pi[0];
  for(int i=0;i<n;i++){
      if(mini < pi[i]){
         count--;
        continue;
      }
    mini = min(mini,pi[i]);
  }
  cout << count;
return 0;
}


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

const int mod = (int) (1e9)+7;
using ll = long long;

int parent[300000];
int n;

void make_set() 
{
    for(int i = 0; i <= n; i++) parent[i] = i;
}

int find_par(int v) 
{
    if(parent[v] == v) return v;
    else return parent[v] = find_par(parent[v]);
}

void union_set(int u, int v)
{
    int pu = find_par(u);
    int pv = find_par(v);
    if(pu != pv) {
        parent[find_par(u)] = find_par(v);
    }
}


int main()
{
    int m;
    scanf("%d%d", &n, &m);
    int u, v;
    int mx = 1;
    make_set();
    for(int i = 0; i < m; i++) {
        scanf("%d%d", &u, &v);
        union_set(u, v);
    }
    map<int, int> cnt;
    for(int i = 1; i <= n; i++) {
        cnt[find_par(i)]++;
        mx = max(mx, cnt[find_par(i)]);
    }
    printf("%d\n", mx);
}


Measured memory_bytes: 13936
N=int(input())
A=list(map(int,input().split()))
A.sort()
A+=[10**9+1]
ans,memo,counter=0,0,0
for a in A:
    if a!=memo:
        if memo>counter:ans+=counter
        memo,counter=a,0
    counter+=1
    if counter>memo:ans+=1
print(ans)

Measured memory_bytes: 15260
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
string s,t;
int main(){
    cin>>s>>t;
    t+=s;
    cout<<t<<endl;
}

Measured memory_bytes: 256
if __name__ == "__main__":
    height, width = list(map(int, input().split()))
    input = [input() for i in range(height)]

    sharps = "#" + "#" * width + "#"
    print(sharps)
    for i in range(height):
        print("#", end="")
        print(input[i], end="")
        print("#")
    print(sharps)

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

int main(){
    int N,a, nega = 0;
    long long ans = 0;
    cin >> N;
    //vector<int> A(N);
    vector<long long> A_abs(N);
    for(int i = 0;i<N;i++) {
        cin >> a;
        if (a < 0) {
            nega++;
            A_abs[i] = -a;
        }else A_abs[i] = a;
    }

    
    for(int i= 0;i<N;i++) ans += A_abs[i];
    if (nega%2 == 1) {
        long long minA = *min_element(A_abs.begin(),A_abs.end());
        ans -= 2*minA;
    }
    cout << ans << endl;

}

Measured memory_bytes: 1024
#include <stdio.h>
#include<string.h>
 
int main(void){
    char number[1001];
    int i, sum=0;
     
    while(1){
        scanf("%s", number);
        if(number[0] == '0'){
            break;
        }
        for(i=0; i<strlen(number); i++){
            sum += number[i] - '0';
        }
        printf("%d\n", sum);
        sum = 0;
    }   
    return 0;
}

Measured memory_bytes: 536
#include <iostream>

using namespace std;

int S[2000][2000];
int cnt_eh[2000][2000];
int cnt_ev[2000][2000];
int cnt_v[2000][2000];

int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            char s;
            cin >> s;
            S[i][j] = s-'0';
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            if(i == 0){
                if(j == 0){
                    cnt_v[i][j] = S[i][j];
                    cnt_eh[i][j] = 0;
                    cnt_ev[i][j] = 0;
                }else{
                    cnt_v[i][j] = cnt_v[i][j-1]+S[i][j];
                    cnt_eh[i][j] = cnt_eh[i][j-1];
                    cnt_ev[i][j] = 0;
                    if(S[i][j-1] == 1 && S[i][j] == 1) cnt_eh[i][j]++;
                }
            }else{
                if(j == 0){
                    cnt_v[i][j] = cnt_v[i-1][j]+S[i][j];
                    cnt_eh[i][j] = 0;
                    cnt_ev[i][j] = cnt_ev[i-1][j];
                    if(S[i][j] == 1 && S[i-1][j] == 1) cnt_ev[i][j] += 1;
                }else{
                    cnt_v[i][j] = cnt_v[i-1][j]+cnt_v[i][j-1]+S[i][j]-cnt_v[i-1][j-1];
                    //cnt_e[i][j] = cnt_e[i-1][j]+cnt_e[i][j-1]-cnt_e[i-1][j-1];
                    cnt_eh[i][j] = cnt_eh[i][j-1]+cnt_eh[i-1][j]-cnt_eh[i-1][j-1];
                    cnt_ev[i][j] = cnt_ev[i-1][j]+cnt_ev[i][j-1]-cnt_ev[i-1][j-1];
                    if(S[i-1][j] == 1 && S[i][j] == 1) cnt_ev[i][j]++;
                    if(S[i][j-1] == 1 && S[i][j] == 1) cnt_eh[i][j]++;
                }
            }
            //cout << i << ' ' << j << endl;
            //cout << cnt_v[i][j] << ' ' << cnt_ev[i][j]  << ' ' << cnt_eh[i][j] << endl;
        }
    }
    for(int i = 0; i < Q; i++){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        int e, v;
        x1--;x2--;y1--;y2--;
        //x1--;y1--;
        e = cnt_ev[x2][y2]+cnt_eh[x2][y2]-cnt_ev[x1][y2]-cnt_eh[x2][y1];
        v = cnt_v[x2][y2];
        //cout << x1 << ' ' << y1 << endl;
        //cout << e << ' ' << v << endl;
        if(x1 != 0){
            //cout << "u:";
            v -= cnt_v[x1-1][y2];
            e -= cnt_eh[x1-1][y2];
            //cout << cnt_e[x1-1][y2] << ' ' << cnt_v[x1-1][y2] << endl;
        }
        if(y1 != 0){
            //cout << "v:";
            v -= cnt_v[x2][y1-1];
            e -= cnt_ev[x2][y1-1];
            //cout << cnt_e[x2][y1-1] << ' ' << cnt_v[x2][y1-1] << endl;
        }
        if(x1 != 0 && y1 != 0){
            //cout << "x:";
            v += cnt_v[x1-1][y1-1];
            e += (cnt_eh[x1-1][y1] + cnt_ev[x1][y1-1]);
            //cout << cnt_e[x1-1][y1-1] << ' ' << cnt_v[x1-1][y1-1] << endl;
        }
        //cout << e << ' ' << v << endl;
        cout << v-e << endl;
    }
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

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

    if((c >= a && c <= b) || (c <= a && c >= b)) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


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

int main() {
	int n;
	cin >> n;
	for(int t = 0; t < n; t++) {
		int s;
		cin >> s;
		cout << "Case " << t + 1 << ":" << endl;
		for(int i = 0; i < 10; i++) {
			s = s * s;
			s = (s / 100) % 10000;
			cout << s << endl;
		}
	}
}

Measured memory_bytes: 1160
x, k, d = gets.chomp.split(" ").map(&:to_i)
min = 0
x = x.abs

if x > k*d
    min = x - k*d
    if x < 0
        min *= -1
    end
else
    if (k - x/d).even?
        #偶数の場合
        min = x - d * (x / d)
    elsif
        #奇数の場合
        min = (x - d * (x / d + 1)).abs
    end
end

puts min

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

#define double long double
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
} 
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;

int norm(int a) {
  return ((a % MOD) + MOD) % MOD;
}

int mul(int a, int b) {
  return int(a * 1LL * b % MOD);
}

int binPow(int a, int k) {
  int ans = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1) {
      ans = mul(ans, a);
    }
    a = mul(a, a);
  }
  return ans;
}

// If I need to find (x / a) % MOD, I need to use this function:
//    (x / a) % MOD = (x * inv(a)) % MOD
int inv(int a) {
  int b = binPow(a, MOD - 2);
  assert(mul(a, b) == 1);
  return b;
}

// Init variables here
const int N = 1e6 + 7;

void init() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);

}

void solve() {
  int a, b;
  cin >> a >> b;
  int c = 1;
  int cnt = 0;
  while (c < b) {
    c = c - 1 + a;
    cnt++;
  }
  cout << cnt << "\n";

  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

int main() {
  //ios_base::sync_with_stdio(false); cin.tie();
  //auto beginProgram = chrono::steady_clock::now();
  //int t; scanf("%d", &t); while (t--) 
  {
    init();
    solve();
  }
  //auto endProgram = chrono::steady_clock::now();

  return 0;
}



Measured memory_bytes: 256
/*input
6 15
6 5
5 6
6 4
6 6
3 5
7 2
*/
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ll long long int
#define vll vector<ll>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 9000000000000001
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--) 
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define sz(x)  ((ll)x.size())
#define DEBUG
#ifdef DEBUG
#define dbg(x) cout << (#x) << " is " << (x) << endl
#else 
#define dbg(x)
#endif
#define N 200002

using namespace std;
ll dp[100][N];

int main()
{
	fastio
	ll T=1,n,m;string str;
	// cin>>T;
	// cin.ignore(); put after cin, just b4 a getline(cin, s) to avoid getline() directly getting \n
	while(T--)
	{
		ll p=0,q=0,tmp=0,sum=0,count=0; //tmp variable
		int flag=0;
		ll W;
		cin>>n>>W;

		ll val[n],w[n];
		ll col_size = 0;
		for (int i = 0; i < n; ++i)
		{
			cin >> w[i] >> val[i];
			col_size = max(col_size,val[i]);
		}
		col_size *= n+1;
		// dbg("hel");
		
		// dbg("hel2");
		// memset(dp,-1,sizeof(dp));
		rep(i,0,n) rep(j,0,col_size) dp[i][j] = inf;
		for (int i = 0; i < n; ++i)
		{
			dp[i][0] = 0;
		}
		dp[0][val[0]] = w[0];
		for (int i = 1; i < n; ++i)
		{
			for (int j = 1; j < N; ++j)
			{
				
				dp[i][j] = dp[i-1][j];
				if(val[i]<=j) dp[i][j] = min(dp[i][j],dp[i-1][j-val[i]]+w[i]);

				// if(dp[i][j]!=-1)
				// {
				// 	dbg(i); dbg(j);
				// }
			}
		}
		ll mx = 0;
		for (int i = 0; i < col_size; ++i)
		{
			if(dp[n-1][i]<=W) mx = i;
		}

		cout << mx << endl;
		
	}
	return 0;
}

Measured memory_bytes: 159116
#include<stdio.h>

int main(void){
  long long int N , M , sum =0 ;

  scanf("%lld %lld" , &N , &M);

  if( N >= M / 2){
    sum = M / 2;
  }else{
    sum += N;
    M -= 2*N;
    sum += M/4;
  }

  printf("%lld" , sum);

  return 0;



}

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

int main(){
  long long int x,a,b;
  map<long long int, long long int> st;
  cin >> x;
  for(int i = 0; 1000 > i; i++){
  	st[1LL*i * i * i * i * i] = i; 
  }
  for(auto i : st){
    if(st.count(x - i.first)){
      cout << i.second << " " << -st[x-i.first];
      return 0;
    }
    if(st.count(-x + i.first)){
      cout << i.second << " " << st[-x+i.first];
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3188
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

bool is_palindromic(int n){
  string s = to_string(n);
  return s[0]==s[4]&&s[1]==s[3];
}

int main(){
  int a,b;
  cin >> a >> b;
  int ans = 0;
  for(int i = a; i <= b; i++){
    if(is_palindromic(i)) ans++;
  }
  cout << ans << endl;
}


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

int main() {
	int n;
    cin >> n;
    map<int64_t, int64_t> data;
    for (int i = 0; i < n; i++){
        int64_t len;
        cin >> len;
        data[len]++;
    }

    int64_t status = 0;
    int64_t max = 0;
    for (auto it = data.end() ; it != data.begin(); it--){
        if (next(it, -1)->second > 1 && status == 0){
            status = next(it, -1)->first;
        }else if (next(it, -1)->second > 1 && status != 0){
            max = status * next(it, -1)->first;
            break;
        }
    }

    for (auto it = data.end() ; it != data.begin(); it--){
        if (next(it, -1)->second > 3){
            int64_t squ = next(it, -1)->first * next(it, -1)->first;
            if (max < squ){
                max = squ;
            }
        }
    }

    cout << max << endl;
}

Measured memory_bytes: 6528
#include <stack>
#include <vector>
#include <cassert>
#include <cstdio>
//---------------------------------//

struct SlidingWindowAggregation {
public:
	void push(const int &x) {
		push(x, sback, vback);
	}
	
	int pop() {
		assert(!empty());
		if (sfront.empty()) {
			while (!sback.empty()) {
				push(sback.top(), sfront, vfront);
				sback.pop();
			}
			vback.clear();
		}
		sfront.pop();
		vfront.pop_back();
	}
	
	bool empty() {
		return sfront.empty() && sback.empty();
	}
	
	int fold_all() {
		assert(!empty());
		if (vfront.empty()) return vback.back();
		if (vback.empty()) return vfront.back();
		return func(vfront.back(), vback.back());
	}
	
private:
	std::stack<int> sfront, sback;
	std::vector<int> vfront, vback;
	
	void push(const int &x, std::stack<int> &st, std::vector<int> &v) {
		st.push(x);
		if (v.empty()) v.push_back(x);
		else {
			int addval = func(v.back(), x);
			v.push_back(addval);
		}
	}
	
	int func(const int &x, const int &y) {
		return std::min(x, y);
	}
};

int main() {
	int N, L;
	scanf("%d %d", &N, &L);
	std::vector<int> A(N);
	for (int i = 0; i < N; ++i) scanf("%d", &A[i]);
	
	SlidingWindowAggregation swag;
	for (int i = 0; i < L - 1; ++i) swag.push(A[i]);
	
	for (int i = L - 1; i < N; ++i) {
		swag.push(A[i]);
		printf("%d%c", swag.fold_all(), i == N - 1 ? '\n' : ' ');
		swag.pop();
	}
	
	return 0;
}



Measured memory_bytes: 7856
#define _CRT_SECURE_NO_WARNINGS
#include "iostream"
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main(void)
{
	int x;
	cin >> x;
	if (x < 1200)
		cout << "ABC" << endl;
	else
		cout << "ARC" << endl;
}

Measured memory_bytes: 256
x = int(input())
lst = list(map(int, input().split()))
i = 1
cnt = 0
a = lst[0]
if x == 1:
    print(0)
else:
    while True:
        b = lst[i]
        if b < a:
            cnt += abs(b - a)
            a = a
        else:
            a = b
        if i >= x - 1:
            break
        i += 1
    print(cnt)

Measured memory_bytes: 32200
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll n; cin>>n;
	ll m; cin>>m;
	vector<ll> a(m);
	REP(i,m) cin>>a[i];
	ll ans=0;
	REP(i,m)ans+=a[i];
	ans=n-ans;
	if(ans>=0){
		cout<<ans<<endl;
	}else{
		cout<<-1<<endl;
	}
	return 0;
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 1024
queue<int> a[N], que;
set<int> s;
int b[N][N] = {};

void op(int i){
	if(a[i].empty()) return;
	int j = a[i].front();
	// DEBUG("%d => %d\n", i+1, j+1);
	if(i > j) swap(i, j);
	if(b[i][j]) que.emplace(i);
	else b[i][j]++;
}

int main(){
	int n; scanf("%d", &n);
	REP(i, n){
		REP(j, n-1){
			int x; scanf("%d", &x); x--;
			a[i].emplace(x);
		}
	}
	REP(i, n) op(i);
	int x = 1, y = 0;
	while(que.size()){
		int i = que.front(); que.pop();
		int j = a[i].front(); a[i].pop();
		DEBUG("%d %d\n", i+1, j+1);
		assert(a[j].front() == i); a[j].pop();
		if(s.find(i) != s.end() || s.find(j) != s.end()){
			s.clear();
			x++;
		}
		y++;
		s.emplace(i);
		s.emplace(j);
		op(i); op(j);
	}
	if(y < n*(n-1)/2) x = -1;
	printf("%d\n", x);
}




Measured memory_bytes: 8832
#include<stdio.h>
int main()
{
    int n, i, a=0, b=0;
    char s[100];
 
    scanf("%d", &n);
    scanf("%s", s);
 
    for(i=0; i<n; i++){
        if(s[i] =='(') a++;
        else if(a>0) a--;
        else b++;
    }
 
    for(i=0; i<b; i++){
            printf("(");
    }
    printf("%s",s);
    for(i=0;i<a;i++){
        printf(")");
    }
 
    return 0;
}


Measured memory_bytes: 128
N = int(input())
now,nowx,nowy=0,0,0
out = "Yes"
for i in range(N):
    t,x,y = list(map(int,input().split()))
    D = abs(x-nowx)+abs(y-nowy)
    T = t-now
    if D<=T and T%2==D%2:
        now,nowx,nowy = t,x,y
        continue
    else:
        now,nowx,nowy = t,x,y
        out="No"
print(out)


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

void chmax(int &a,int b){	a=max(a,b);	return;	}

int main(){
	int n;
	string s;
	cin>>n>>s;
	int l=0,r=0,d=0;
	for(int i=0;i<s.size();++i){
		if(s[i]=='(') ++l;
		else ++r;
		chmax(d,r-l);
	}
	string ans(d,'(');
	ans+=s;
	ans.append(l+d-r,')');
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ldb;
typedef pair<ll,ll> pll;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define V vector
#define endl "\n"
#define CLEAR(a) memset(a,0,sizeof(a))
#define all(x) x.begin(),x.end()
#define sz(x) ((ll)x.size())
#define rep0(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define ios_tie() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(nullptr)
#define trace1(a)             cout <<#a<<":"<<a<< endl;
#define trace2(a,b)           cout <<#a<<":"<<a<<" | "<<#b<<":"<<b<< endl;
#define trace3(a,b,c)         cout <<#a<<":"<<a<<" | "<<#b<<":"<<b<<" | "<<#c<<":"<<c<<endl;
#define trace4(a,b,c,d)       cout <<#a<<":"<<a<<" | "<<#b<<":"<<b<<" | "<<#c<<":"<<c<<" | "<<#d<<":"<<d<<endl;

const ll inf = (ll)1e18;
const ll maxn = 1e9+1;
const ldb PI = acos(-1);

void lol(ll s) {cerr<<"check........................................... "<<s<<endl;}
ll power(ll x, ll y, ll mod) {ll res=1; x%=mod; while(y) {if(y&1) res=(res*x)%mod; y>>=1LL; x=(x*x)%mod; }return res;}
ll inv(ll x, ll mod) {return power(x,mod-2,mod);}//(1/x)%y = x^(y-2) % y;   // pow(x,y)%m = pow(x,y%(m-1))%m
mt19937 rng((ll)chrono::steady_clock::now().time_since_epoch().count());

// I can solve mirror cube in 2 mins but can't solve div2 C in 1hr.
void solve()
{
    ll n, k;
    cin>>n>>k;
    ll a[n];
    rep0(i,n) {
        cin>>a[i];
    }
    sort(a,a+n);
    ll sum = 0;
    rep0(i,k) {
        sum += a[i];
    }
    cout<<sum<<endl;
}
int main()
{
    ios_tie();
    // freopen("input.txt", "r", stdin);
    // freopen("myOut.txt", "w", stdout);
    ll _ = 1;
    // cin>>_;
    rep1(i,_)
    {
        // cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define Test ll t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define rep(i, a, b) for(ll i=a;i<b;i++)
#define repR(i,a,b) for(ll i=a;i>=b;i--)
#define loopS(i,a,b,step) for(ll i=a;i<b;i+=step)
#define loopRS(i,a,b,step) for(ll i=a;i>=b;i-=step)
#define ull unsigned long long int
#define pll pair<ll,ll>
#define puu pair<ull, ull>
#define V vector
#define M map
#define UM unordered_map
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define inf INT_MAX
#define S3(a,b,c) cin >> a >> b >> c
#define S2(a,b) cin >> a >> b
#define debug(x) cerr << #x << " = " << x << endl;
#define debug2(x,y) cerr << #x << " = " << x << " " << #y << " = " << y << endl;
#define debug3(x,y,z) cerr << #x << " = " << x << " " << #y << " = " << y <<  " " << #z << " = " << z << endl;
using namespace std;

void input(ll n, ll arr[]) {
	rep(i, 0, n)cin >> arr[i];
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout.tie(NULL);
	ll n, d; S2(n, d);
	ll cnt = 0;
	rep(i, 0, n) {
		ll x, y; S2(x, y);
		ll dist = x * x + y * y;
		double val = sqrt(dist);
		if (val <= double(d))cnt++;

	}
	cout << cnt << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <queue>
#include <map>
using namespace std;

int main()
{
	map<string, int> time;
	queue<string> nums;
	int n, t; scanf("%d%d",&n,&t);
	for(int i = 0; i < n; ++i) {
		string s; int v; cin>>s>>v;
		time[s] = v;
		nums.push(s);
	}
	int ms = 0;
	while(!nums.empty()) {
		string f = nums.front(); nums.pop();
		int f_t = time[f];
		if(f_t <= t) {
			ms += f_t;
			time[f] = 0;
			cout<<f<<" "<<ms<<endl;
		} else {
			ms += t;
			time[f] -= t;
			nums.push(f);
		}
	}
	return 0;
}



Measured memory_bytes: 9156
#include <cstdio>
#include <iostream>

int T;
int input[10];
int B[10], C[10];
int Bcnt, Ccnt;
int flag = 1;

void dfs(int i);
void clear();


int main(void) {
    scanf("%d", &T);
    for (int i = 0; i<T; i++) {
        for (int j = 0; j<10; j++)
            scanf("%d", &input[j]);
        
        dfs(0);
        if (flag) puts("YES");
        else puts("NO");
        clear();
    }
}

void dfs(int i) {
    if (i>9) return;
    
    if (input[i]>B[Bcnt-1]) {
        B[Bcnt++] = input[i];
        dfs(i+1);
    } else if (input[i]>C[Ccnt-1]) {
        C[Ccnt++] = input[i];
        dfs(i+1);
    } else flag = 0;
}

void clear() {
    for (int i = 0; i<10; i++) {
        input[i] = 0;
        B[i] = 0;
        C[i] = 0;
    }
    Bcnt = Ccnt = 0;
}

Measured memory_bytes: 1168
s=input()
p=input()
l1=s.split()
l2=p.split()
N=int(l1[0])
M=int(l1[1])
A=[int(l2[n]) for n in range(0,N)]
count=0
for i in range(0,N):
    if A[i]>=sum(A)/(4*M):
        count+=1
if count>=M:
    print('Yes')
else:
    print('No')

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

int main() {
	int n;
	cin >> n;
	vector<int> x(n), y(n);
	for (int i = 0; i < n; i++)
		cin >> x[i];
	y = x;
	sort(y.begin(), y.end());
	for (int i = 0; i < n; i++) {
		if (x[i] <= y[n / 2 - 1])
			x[i] = y[n / 2];
		else
			x[i] = y[n / 2 - 1];
	}
	for (int i = 0; i < n; i++)
		cout << x[i] << endl;
	return 0;
}

Measured memory_bytes: 3712
#include <cstdio>
#include <iostream>
#include <cmath>
#include <map>
#include <queue>

using namespace std;
#define N 4
#define NN N*N

static const int dx[4] = {0,-1,0,1};
static const int dy[4] = {1,0,-1,0};
int H[NN][NN];

struct Puzzle
{
  int field[NN],space,MD;
  int cost;

    bool operator < (const Puzzle& p) const {
    for(int i=0; i<NN; i++) {
        if( field[i] == p.field[i] ) continue;
        return field[i] < p.field[i];
    }
    return false;
    }
};

struct State
{
  Puzzle puzzle;
  int f_value;
  bool operator < (const State &s) const{
    return f_value > s.f_value;
  }
};

int getTotalMD(Puzzle pz){
    int sum=0;
    for(int i=0; i<NN; i++) {
    if( pz.field[i] == NN ) continue;
    sum += H[i][pz.field[i]-1];
    }
    return sum;
}

int astar(Puzzle pz){
  priority_queue<State> q;
  pz.MD = getTotalMD(pz);
  pz.cost = 0;
  map<Puzzle,bool> V;
  Puzzle u,v;
  State initial;
  initial.puzzle = pz;
  initial.f_value= getTotalMD(pz);
  q.push(initial);

  while(!q.empty()){
    State st = q.top(); q.pop();
    u = st.puzzle;
    if( u.MD == 0 ) return u.cost;
    V[u] = true;

    int sx = u.space / N;
    int sy = u.space % N;

    for(int r=0; r<4; r++) {
        int tx = sx + dx[r];
        int ty = sy + dy[r];
        if( tx<0 || ty<0 || tx>=N || ty>=N ) continue;
        v = u;

        v.MD -= H[tx*N+ty][v.field[tx*N+ty]-1];
        v.MD += H[sx*N+sy][v.field[tx*N+ty]-1];

        swap(v.field[sx*N+sy], v.field[tx*N+ty]);
        v.space = tx*N+ty;
        if( !V[v] ) {
        v.cost++;
        State news;
        news.puzzle = v;
        news.f_value = v.cost + v.MD;
        q.push(news);
        }
    }
    }
    return -1;
}

int main(){
for(int i = 0; i<NN; i++)
  for(int j =0;j < NN;j++)
    H[i][j] = abs(i / N - j / N) + abs(i % N - j % N);

  Puzzle in;

  for(int i=0;i<NN;i++){
    cin >> in.field[i];
    if(in.field[i] == 0){
      in.field[i] = NN;
      in.space = i;
    }
  }

  cout << astar(in) << endl;
  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N; cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; ++i) {
        int s = to_string(i).size();
        if (s % 2) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
ll int N,T;
struct st{ ll A,B; }arr[3001];
map<ll,ll> jido;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>N>>T;
	for(int i=1;i<=N;i++){
		cin>>arr[i].A>>arr[i].B;
	}
	sort(arr+1,arr+N+1,[&](st a,st b){
		return a.A<b.A;
	});
	for(int i=1;i<=N;i++){
		for(ll j=T-1;j>=0;j--){
			if((jido[j] || j==0)){
				jido[j+arr[i].A] = max(jido[j+arr[i].A], jido[j]+arr[i].B);
			}
		}
	}
	ll ans=0;
	for(ll int i=0;i<=T+3000;i++) if(jido[i]) ans=max(ans,jido[i]);
	cout<<ans;
}

Measured memory_bytes: 640
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
using vvc = vector<vector<char> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
 //各位の和　
int wa(ll x)
{
ll sum = 0;
while(x!=0){
  sum += x% 10;
  x /= 10;
}
return sum;
}
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()
//文字→数字　'0' アルファベット→数字　'a'　'A'が65番,'a'が97番だわ
//型キャスト　char('a'+1)
//reverse 回文
//if(isupper('A'))->大なら真


//グローバル変数宣言
ll p=0,q=0,r=0;

int main()
{
  string s,t,u;
  cin>>s>>t;
  u=s;
  rep(j,s.size())
  {
    rep(i,s.size())
    {
      if(i==0)u[i]=s[s.size()-1];
      else u[i]=s[i-1];
    }
    rep(i,s.size())
    {
      s[i]=u[i];
    }
    if(s==t)
    {
      print("Yes") return 0;
    }
  }
  print("No")
}

Measured memory_bytes: 3604
# -*- coding: utf-8 -*-
"""
D - Make Them Even
https://atcoder.jp/contests/abc109/tasks/abc109_d

"""
import sys


def solve(H, W, grid):
    ans = []
    for y, row in enumerate(grid):
        row_sum = sum(row)
        can_drop = row_sum % 2
        for x, c in enumerate(row):
            if c % 2:
                if can_drop and y != H-1:
                    ans.append([y+1, x+1, y+2, x+1])
                    grid[y][x] -= 1
                    grid[y+1][x] += 1
                    can_drop = False
                elif x != W-1:
                    grid[y][x] -= 1
                    ans.append([y+1, x+1, y+1, x+2])
                    grid[y][x+1] += 1
    return len(ans), ans


def main(args):
    H, W = map(int, input().split())
    grid = [[int(a) for a in input().split()] for _ in range(H)]
    N, ans = solve(H, W, grid)
    print(N)
    for a in ans:
        print(*a)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 31432
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  int ans = 0;
  rep(i, 0, n) {
    int l, r;
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <vector>

using namespace std;

long long int dfs(string rest, long long int now, vector<string> debug){
  if (rest.length() == 0){
    //for (int i = 0; i < debug.size(); i++){
    //  cerr << debug[i] << ',';
    //}
    //cerr << now << endl;
    //cerr << endl;
    return now;
  }else{
    long long int result = 0;
    for (int i = 1; i <= rest.length(); i++){
      result += dfs(rest.substr(i, rest.length()-i), now+(long long int)(atol(rest.substr(0,i).c_str())), debug);
    }
    return result;
  }
}

int main(){
  string s;
  cin >> s;
  vector<string> debug;
  cout << dfs(s, 0, debug) << endl;
  return 0;
}


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

using namespace std;

int main(){
    int d; // dimension
    cin >> d;
    vector<int> x1(d,0);
    vector<int> x2(d,0);
    unsigned long L1_sum = 0,L2_sum = 0,L3_sum = 0;
    unsigned long M;
    double temp = 0;

    for (int i=0;i<d;i++) cin >> x1[i];
    for (int i=0;i<d;i++) cin >> x2[i];
    
    for(int i = 0;i < d;i++){
        unsigned long diff = abs(x1[i]-x2[i]);
        L1_sum += diff;
        M = max(diff,M);
        L2_sum += pow(x1[i]-x2[i],2);
        L3_sum += pow(diff,3);
    }
    double L1 = L1_sum;
    double L2 = sqrt(L2_sum);
    double L3 = pow(L3_sum,(double)1/3);
    double L_inf = M;

    printf("%.6lf\n",L1);
    printf("%.6lf\n",L2);
    printf("%.6lf\n",L3);
    printf("%.6lf\n",L_inf);
    


    
    
    return 0;   
}



Measured memory_bytes: 3356
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
    int h,w;
    while(1){
        cin >> h >> w;
        
        if(h == 0 && w == 0){
            break;
        }
        for(int i = 0;i < h;++i){
            // 始めと最初は#で
            if(i == 0 || (i + 1) >= h){
                for(int j = 0;j < w;++j){
                    cout << "#";
                }
            }
            else{
                for(int j = 0;j < w;++j){
                    if(j == 0 || (j + 1) >= w){
                        cout << "#";
                    }
                    else{
                        cout << ".";
                    }
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


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

int main() {
	int n,w;
	set<int>s;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>w;
		s.insert(w);
	}
	if(s.size()==n){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
}


Measured memory_bytes: 9600
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, M := ReadInt(), ReadInt()
	from := []int{}
	to := make(map[int]bool)
	for i := 0; i < M; i++ {
		a, b := ReadInt(), ReadInt()
		if a == 1 {
			from = append(from, b)
		}
		if b == N {
			to[a] = true
		}
	}
	for _, c := range from {
		if to[c] {
			fmt.Println("POSSIBLE")
			return
		}
	}
	fmt.Println("IMPOSSIBLE")
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

int main(){

ll n,k;
cin>>n>>k;
ll h[n+1];
ll dp[n+1];
for(int i=1;i<=n;i++){
	cin>>h[i];
	dp[i]=1e18;
}

dp[1]=0;
for(ll i=2;i<=n;i++){
	for(ll j=1;j<=k;j++){
		if(i-j<=0) break;
		dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
	}
}

cout<<dp[n]<<endl;

}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin >> n;
  int k[n+1];
  k[0]=0;
  rep(i,n){
    int a;
    cin >> a;
    k[i+1]=k[i]+a;
  }
  int mi=100000000;
  rep(i,n){
    mi=min(mi,abs(k[i+1]-(k[n]-k[i+1])));
  }
  cout << mi << endl;
}  


Measured memory_bytes: 256
# encoding:utf-8


def sub(n, values):
	cnt = 0
	tmp = -1

	for val in values:
		#print(val, tmp ,cnt)
		if val == tmp + 1:
			tmp = val
		elif val <= tmp:
			cnt += tmp
			tmp = val
		else:
			cnt = -1
			return(cnt)
	
	cnt += tmp
	return(cnt)

def main():
	n = int(input())
	values = [int(input()) for _ in range(n)]
	print(sub(n, values))

if __name__ == '__main__':
	main()

Measured memory_bytes: 11052
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  int cnt = 0;
  rep(i, n-2) if (s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C') cnt++;
  cout << cnt << endl;
  return 0;
}

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

typedef long long lll;

int A[502][502], B[502][502];

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> A[i][j];
            B[i][j] = A[i][j];
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m - 1; j++) {
            if(A[i][j] & 1) {
                A[i][j] -= 1;
                A[i][j + 1] += 1;
                ans++;
             }
        }
    }
    for(int i = 0; i < n - 1; i++) {
        if(A[i][m - 1] & 1) {
            A[i][m - 1] -= 1;
            A[i + 1][m - 1] += 1;
            ans++;
        }
    }
    cout << ans << endl;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m - 1; j++) {
            if(B[i][j] & 1) {
                B[i][j] -= 1;
                B[i][j + 1] += 1;
                cout << i + 1 << " " << j + 1 << " " << i + 1 << " " << j + 2 << endl;
             }
        }
    }
    for(int i = 0; i < n - 1; i++) {
        if(B[i][m - 1] & 1) {
            B[i][m - 1] -= 1;
            B[i + 1][m - 1] += 1;
            cout << i + 1 << " " << m << " " << i + 2 << " " << m << endl;
        }
    }
}


Measured memory_bytes: 4096
#include<stdio.h>
typedef long long LL;
LL fast(LL a,LL b){
	LL ans=1ll;
	while(b>0ll){
		if(b&1ll) ans=a*ans;
		a=a*a;
		b=b/2ll;
	}
	return ans;
}
int main(){
	LL x;
	LL a=-100ll,b=-100ll;
	scanf("%lld",&x);
	for(a=-120ll;a<=120ll;a++){
		for(b=-120ll;b<=120ll;b++){
			LL y=fast(a,5ll)-fast(b,5ll);
			if(y==x) goto l;
		}
	}
	l:;
	printf("%lld %lld",a,b);//*/
	return 0;
}

Measured memory_bytes: 1692
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;

vector<int> b;

int main(){
  int n,bin;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>bin;
    b.push_back(bin);
    if(bin>i+1){
      cout<<-1<<endl;
      return 0;
    }
  }
  vector<int> ans;
  while(b.size()>0){
    for(int i=b.size()-1;i>=0;i--){
      if(b.at(i)==i+1){
        ans.push_back(b.at(i));
        b.erase(b.begin()+i);
        break;
      }
    }
  }
  reverse(ans.begin(),ans.end());
  for(int i=0;i<n;i++) cout<<ans.at(i)<<endl;
}

Measured memory_bytes: 256