akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
//#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
#define ll long long
#define mp make_pair
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
int a[100+10][100+10];
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
int main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	ll n;
	cin>>n;
	cout<<50<<endl;
	for(int i=1;i<=50;i++)
        a[0][i]=i-1;
    for(int i=1;i<50;i++)
    {
        ll minn=inf;
        ll mi=0;
        for(int j=1;j<=50;j++)
        {
            if(a[i-1][j]<minn)
                minn=a[i-1][j],mi=j;
        }
        for(int j=1;j<=50;j++)
        {
            if(j!=mi)
                a[i][j]=a[i-1][j]-1;
            else
                a[i][j]=a[i-1][j]+50;
         //   cerr<<a[i][j]<<" ";
        }
       // int t;
      //  cin>>t;
    }
    for(int i=1;i<=50;i++)
        cout<<a[n%50][i]+n/50<<" ";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;

int main(){

	int Q,c_num,a_num,n_num,tmp,maximum;

	scanf("%d",&Q);

	for(int loop = 0; loop < Q; loop++){
		scanf("%d %d %d",&c_num,&a_num,&n_num);

		maximum = 0;

		for(int x = 0,z = 0;3*x <= c_num ; x++){
			for(int y = 0; 2*y <= c_num ;y++){
				if(3*x + 2*y <= c_num && y <= a_num){
					tmp = 0;
					z = c_num - (3*x + 2*y);
					tmp = x + y + min(z,min(a_num-y,n_num));
					maximum = max(maximum,tmp);
				}else{
					break;
				}
			}
		}
		printf("%d\n",maximum);

	}
	return 0;
}

Measured memory_bytes: 2752
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

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

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

// ---------------------
#define INF 922337203685477580
typedef long long ll;

int main() {
  int a, b, c;
  cin >> a >> b >> c;


  if ((a * 100 + b * 10 + c) % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int N, K;
    string S;
    cin >> N >> K >> S;
 
    int ans = 0;
    for (int i = 1; i < N; i++)
    {
        if (S[i - 1] == S[i])
        {
            ans++;
        }
    }
    ans = min(N - 1, ans + 2 * K);
    cout << ans << endl;
}

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

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    int n, m;
    cin >> n >> m;
    int sum = (n-m)*100 + 1900*m;
    while(m--) sum *= 2;
    cout << sum;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
 
  int n, k;
  int x;
  int ans = 0;
  
  cin >> n >> k;
  
  rep(i, n){
    cin >> x;
    ans += ((x > k - x) ? (k - x) : x) * 2;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
N = int(input())
T, A = list(map(int, input().split(' ')))
HS = list(map(int, input().split(' ')))
diff = 999999999
ans = 0
for i in range(N):
    H = HS[i]
    t = T - H * 0.006
    if abs(A - t) < diff:
        diff = abs(A - t)
        ans = i + 1
print(ans)

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int s;
	int l,r;
	scanf("%d",&s);
	l = s / 100;	r = s % 100;
	if(1 <= l && l <= 12){
		if(1 <= r && r <= 12)	puts("AMBIGUOUS");
		else puts("MMYY");
	}
	else{
		if(1 <= r && r <= 12)	puts("YYMM");
		else puts("NA");
	}
	return 0;
}

Measured memory_bytes: 128
h, w = map(int, input().split())
S = [list(input()) for i in range(h)]

for i in range(h):
    l = ''
    for j in range(w):
        if S[i][j] == '#':
            l += '#'
        else:
            l += str(sum([T[max(0, j-1):min(w, j+2)].count('#') for T in S[max(0, i-1):min(h, i+2)]]))
    print(l)

Measured memory_bytes: 3064
X = int(input())

v = int(X ** 0.5)
m = X
ans = 1

for b in range(2, v + 1):
    p = 2
    j = b ** p
    while j <= X:
        if j <= X and X - j <= m:
            m = X - j
            ans = j
        p += 1
        j = b ** p      
            
print(ans)

Measured memory_bytes: 3188
# coding: utf-8
n=int(input())
a=list(map(int,input().split()))
dic={}
mx=[0,0]
for x in a:
    if x in dic:
        dic[x]+=1
    else:
        dic[x]=1
    if dic[x]==2:
        dic[x]=0
        for i in range(2):
            mx.sort()
            if mx[i]<x:
                mx[i]=x
                break
print(mx[0]*mx[1])


Measured memory_bytes: 18060
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define D(x) cerr << #x << " = " << (x) << '\n'
using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<ll> a(n);
	vector<vector<ll>> dp(n, vector<ll>(n, 1e18));
	for(int i = 0; i < n; ++ i) cin >> a[i];
	vector<ll> pref(1,0);
	for(auto x:a) pref.push_back(pref.back() + x);
	auto query = [pref](int l, int r) {
		return pref[r] - pref[l];
	};
	for(int i = n - 1; i >= 0; --i) {
		dp[i][i] = 0;
		for(int j = i + 1; j < n; ++j) {
			dp[i][j] = query(i, j + 1);
			ll cost = 1e18;
			for(int k = i; k < j; ++ k) {
				cost = min(cost, dp[i][k] + dp[k + 1][j]);
			}
			dp[i][j] += cost;
		}
	}
	cout << dp[0][n - 1] << '\n';
}


Measured memory_bytes: 1536
N = int(input())
values = [[int(i) for i in input().split()] for _ in  range(N)]
dp = [values[0]]
for i in range(N-1):
  dp.append([max(dp[i][1],dp[i][2])+values[i+1][0],max(dp[i][2],dp[i][0])+values[i+1][1],max(dp[i][0],dp[i][1])+values[i+1][2]])

print(max(dp[-1]))
  
  
  

Measured memory_bytes: 44020
e, y = map(int, input().split())
if e == 0:
    if y < 1912:print("M" + str(y - 1867))
    elif y < 1926:print("T" + str(y - 1911))
    elif y < 1989:print("S" + str(y - 1925))
    else:print("H" + str(y - 1988))
else:print(y + (1867,1911,1925,1988)[e - 1])


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

  string s;
  cin >> s;
  vector<char> alf(26, 0);
  REP(i, 26){
    alf[s[i]%26]++;
  }
  int ct = 0;
  REP(i, 26){
    if(alf[i] > 0) ct++;
  }
  if(ct >= 3){
    int mv = s.size();
    if(s[0] == s[s.size()-1]) mv -= 3;
    else mv -= 2;
    cout << (mv%2 ? "First" : "Second") << "\n";
  }else{
    cout << "Second" << "\n";
  }
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for1(i, a, b) for (int i = (int)a; i < (int)(b); ++i)
#define rfor1(i, a, b) for (int i=b-1;i>=a;i--)
#define for2(i, a, b) for (int i = (int)a; i <= (int)(b); ++i)
#define for3(i, a, b) for (int i = (int)a; i < (int)(b); i=i+2)
#define for4(i, a, b) for (int i = (int)a; i <= (int)(b); i=i+2)
#define tc(t) int t; cin>>t; while(t--)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
//==================================================================//

int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
//=================================================================//
	int n;
	cin >> n;
	if (n >= 400 && n <= 599) cout << "8" << endl;
	else if (n >= 600 && n < 800) cout << "7" << endl;
	else if (n >= 800 && n < 1000) cout << "6" << endl;
	else if (n >= 1000 && n < 1200) cout << "5" << endl;
	else if (n >= 1200 && n < 1400) cout << "4" << endl;
	else if (n >= 1400 && n < 1600) cout << "3" << endl;
	else if (n >= 1600 && n < 1800) cout << "2" << endl;
	else if (n >= 1800 && n < 2000) cout << "1" << endl;



}








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

int main(){
  int a[4];
  string s;
  cin >> s;
  rep(i, 4){
    a[i] = s[i] - 0x30;
  }
  char op[3];
  rep(i, 2){
    rep(j, 2){
      rep(k, 2){
        int ans = a[0];
        if(i == 0){
          ans += a[1];
          op[0] = '+';
        }else{
          ans -= a[1];
          op[0] = '-';
        }
        if(j == 0){
          ans += a[2];
          op[1] = '+';
        }else{
          ans -= a[2];
          op[1] = '-';
        }
        if(k == 0){
          ans += a[3];
          op[2] = '+';
        }else{
          ans -= a[3];
          op[2] = '-';
        }
        if(ans == 7){
          cout << a[0];
          rep(i, 3){
            cout << op[i] << a[i+1];
          }
          cout << "=7" << endl;
          return 0;
        }
      }
    }
  }

}


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

int main() {
  
  int N,add,b=1;
  
  cin>>N>>add;
  
  
  for(int i=0;i<N;i++){ 
    if(b*2<b+add)
      b*=2;
    
      else
        b+=add;

  }
   cout<<b;
  
  

  
    
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, k;
  cin >> n >> k;
  vector<int>x(n),d(n);
  for(int i=0;i<n;i++){
    cin >> x[i];
  }
  int ans=400000001;
  for(int i=0;i<=n-k;i++){
    d[i]=abs(x[i+k-1]-x[i])+min(abs(x[i+k-1]),abs(x[i]));
    ans=min(ans,d[i]);
  }
  cout << ans << endl;
}



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N;
	cin >> N;
	vector<string> S(N);
	REP(i, N) cin >> S[i];
	int64 B = 0, A = 0, AB = 0;
	int64 res = 0;
	REP(i, N) {
		if (S[i][0] == 'B' && S[i].back() == 'A') AB++;
		else if (S[i][0] == 'B') B++;
		else if (S[i].back() == 'A') A++;
		REP(j, S[i].size()-1) {
			if (S[i][j] == 'A' && S[i][j+1] == 'B') res++;
		}
	}
	int64 last = 0;
	while (AB + A + last) {
		if (A || last) {
			if (AB) {
				res++;
				A -= 1 - last;
				AB--;
				last = 1;
			} else if (B) {
				res++;
				A -= 1 - last;
				B--;
				last = 0;
			} else {
				last = 0;
				break;
			}
		} else {
			if (AB - (1 - last) > 0) {
				res++;
				AB -= 2 - last;
				last = 1;
			} else if (B) {
				res++;
				AB -= 1 - last;
				B--;
				last = 0;
			} else {
				last = 0;
				break;
			}
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 768
n = int(input())
a = list(map(int,input().split()))

m = 1000
cnt = 0
have = False
for i in range(n-1):
    if cnt:
        if a[i] >= a[i+1]:
            m += cnt * a[i]
            cnt = 0
    else:
        if a[i] < a[i+1]:
            cnt += m // a[i]
            m -= a[i] * cnt
m += cnt * a[n-1]

print(m)

Measured memory_bytes: 61936
#include<iostream>
#include<string>

using namespace std;


int calc(int x,string op,int y){
  if(op=="+")return x+y;
  else if(op=="-")return x-y;
  else if(op=="*")return x*y;
  else if(op=="/")return x/y;
}

int main(void){

  int x,y;
  string op;

  cin >> x;

  while(true){

    cin >> op;

    if(op=="="){
      cout << x << endl;
      break;
    }

    cin >> y;
   x=calc(x,op,y);
  }

  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

int n, m, d;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n >> m >> d;
    

    if(d == 0){
        printf("%.9f\n", (double)(m-1)/n);
    }else{
        int x = (n-1) * 2;
        x -= (d - 1) * 2;
        x *= (m - 1);
        double ans = (double)x / (n*n);
        
        printf("%.9f\n", ans);
    }

}


Measured memory_bytes: 256
#include <iostream>


int main(){
    int64_t r, D, x2k;
    std::cin >> r >> D >> x2k;

    int64_t res;
    for(int32_t i = 1; i <= 10; i++){
        res = r * x2k -D;
        std::cout << res << std::endl;
        x2k = res;
    }
    return 0;
}


Measured memory_bytes: 256
void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
using namespace std;

int N, M;
class edge {
public:
	long long a, b, c;
};
vector<edge> Edges;
vector<long long> dp;

void solve() {
	cin >> N >> M;
	Edges.resize(M);
	for (int m = 0; m < M; m++) {
		cin >> Edges[m].a >> Edges[m].b >> Edges[m].c;
		Edges[m].a--; Edges[m].b--;
		Edges[m].c =  - Edges[m].c;
	}
	dp.resize(N, LLONG_MAX);
	dp[0] = 0;
	for (int time = 0;time < N; time++) {
		for (auto itr = Edges.begin(); itr != Edges.end(); itr++) {
			if (dp[itr->a] == LLONG_MAX)continue;
			if (dp[itr->b] > dp[itr->a] + itr->c) {
				dp[itr->b] = dp[itr->a] + itr->c;
			}
		}
	}
	vector<bool> negcheck;
	negcheck.resize(N,false);
	for (int time = 0; time < N; time++) {
		for (auto itr = Edges.begin(); itr != Edges.end(); itr++) {
			if (dp[itr->a] == LLONG_MAX)continue;
			if (dp[itr->b] > dp[itr->a] + itr->c) {
				dp[itr->b] = dp[itr->a] + itr->c;
				negcheck[itr->b] = true;
			}
			if (negcheck[itr->a])negcheck[itr->b] = true;
		}
	}
	if (negcheck[N - 1])cout << "inf" << endl;
	else cout << -dp[N - 1] << endl;
	return;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list()
c = list()
for i in range(n):
    if(i==0):
        b.append(a[i])
    elif(i%2==1):
        b.append(a[i])
    else:
        c.append(a[i])
c.reverse()
c = c + b
if(i%2==1):
    c.reverse()
for i in c:
    print(i,end=' ')

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

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] = abs(a[i] - x);
  }
  if (n == 1) {
    cout << a[0] << '\n';
  } else {
    int ans = a[0];
    for (int i = 1; i < n; i++) {
      ans = __gcd(ans, a[i]);
    }
    cout << ans << '\n';
  }
  return 0;
}

Measured memory_bytes: 3724
#include <iostream>
#include <vector>
#include <algorithm>

void ToOctalNumber(int n){
	if(!n)return;
	ToOctalNumber(n >> 3);
	std::cout << ((n&7)<4?n&7:(n&7)==4?5:(n&7)+2);
}

int main(){
	int n;
	while(std::cin >> n, n){
		ToOctalNumber(n);
		std::cout << "\n";
	}
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(void){
int A, B, C, sum=0;
scanf("%d%d%d", &A, &B, &C);
sum=10*A+B+C;
if(10*B+A+C>sum){
    sum=10*B+A+C;
}else if(10*C+A+B>=sum){
    sum=10*C+A+B;
}
printf("%d\n",sum);
return 0;
}

Measured memory_bytes: 128
/// Author: Sarfaraz Alam
# include <bits/stdc++.h>
# define pb push_back
# define ll long long

# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG
typedef unsigned long long int ull;
using namespace std;
#include<string>

const int N = 1e5 + 7;
const int mod = 1e9 + 7;

int n, a[N], ans = 1, x;

int main()
{
    speed;
    #ifdef DEBUGfd
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG

    //Code begins
    string str;
    cin>>str;


    ull start = 0, end  =0 ;
    ull s_max, e_max;
    ull size_g = 0, size_l = 0;

      int flag = 0;
      for(ull j = 0; j<str.size(); j++){

      if(str[j] == 'A' && flag == 0)
      {
        start = j;
        flag = 1;
      }
      else if(str[j] == 'Z')
      {end = j;

      if(end-start+1 > size_g)
      size_g = end-start+1;}

    }
    cout<<size_g<<"\n";






    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); i++)
#define rrep(i, to) for (int i = (to) - 1; i >= 0; i--)
#define repf(i, from, to) for (int i = (from); i < (to); i++)
#define all(v) v.begin(), v.end()
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int n;
  int a, b;
  cin >> n >> a >> b;

  int ans = 0;
  repf(i, 1, n + 1) {
    int sum = 0;
    int left = i;

    while(left / 10 > 0) {
      sum += left % 10;

      left /= 10;
    }
    sum += left % 10;

    if(sum >= a && sum <= b) {
      ans += i;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3560
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

LL N;
vector<pair<LL, int>>A, B;
map<int, LL>G;

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		LL v;
		cin >> v;
		A.push_back({ v,i });
	}
	for (int i = 0; i < N; ++i) {
		LL v;
		cin >> v;
		B.push_back({ v,i });
	}
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	for (int i = 0; i < N; ++i) {
		if (A[i].first > B[i].first) {
			cout << "No" << endl;
			return 0;
		}
		G[A[i].second] = B[i].second;
	}
	for (int i = 1; i < N; ++i) {
		if (A[i].first <= B[i - 1].first) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	int now = 0;
	int cnt = 0;
	do {
		now = G[now];
		++cnt;
	} while (now != 0);
	if (cnt == N) {
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

ll x;

int main(int argc, char const *argv[]) {
    std::cin >> x;
    ll b_left, b_right;
    FOR(a,0,1e5) {
        ll A = pow(a,5);
        // Aがxよりも大きい時普通の二分探索をすれば良い
        if (A > x) {
            b_left = -1; b_right = 1e3+1;
            while (b_left + 1 < b_right)
            {
                ll b = (b_left + b_right) / 2;
                ll B = pow(b,5);
                if (A - B <= x) b_right = b;
                else b_left = b;
            }
        } else {
            b_left = -1 * 1e3 -1; b_right = 1;
            while (b_left + 1 < b_right)
            {
                ll b = (b_left + b_right) / 2;
                ll B = pow(b,5);
                // std::cout << B << "\n";
                if (A - B <= x) b_right = b;
                else b_left = b;
            }
        }
        // std::cout << a << " " << b_left << " " << b_right << "\n";
        if (A - pow(b_right,5) == x) {
            std::cout << a << " " << b_right << "\n";
            return 0;
        }
        else if (A - pow(b_left,5) == x) {
            std::cout << a << " " << b_left << "\n";
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define F first
#define S second
int main()
{
    vector<string> arr = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string tmp;
    cin >> tmp;
    int i;
    for (i = 0; i < arr.size(); i++)
        if (tmp == arr[i])
            break;
    cout << 7 - i << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    _, _, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = min(a) + min(b)
    for _ in range(m):
        x, y, c = map(int, input().split())
        ans = min(ans, a[x - 1] + b[y - 1] - c)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 18740
#include "bits/stdc++.h"
using namespace std;
     
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
     
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll, ll>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

#define N 1010

int n;
vi p(N), childnum(N);
vii child(N, vi());
vi x(N);
vector<pii> bw(N);


bool solve(int k) {
  if (child[k].size() == 0) {
    bw[k] = pii(x[k], 0);
    return true;
  }
  for (int i = 0; i < child[k].size(); i++) {
    if (!solve(child[k][i])) {
      return false;
    }
  }
  vector<vector<bool> > dp(child[k].size() + 1, vector<bool>(5010, false));
  dp[0][0] = true;
  for (int i = 0; i < child[k].size(); i++) {
    for (int j = 5005; j >= 0; j--) {
      if (dp[i][j]) {
	dp[i + 1][min(5009, j + bw[child[k][i]].first)] = true;
	dp[i + 1][min(5009, j + bw[child[k][i]].second)] = true;
      }
    }
  }
  int sum = 0;
  for (int i = 0; i < child[k].size(); i++) {
    sum += bw[child[k][i]].first + bw[child[k][i]].second;
  }
  int m = inf;
  for (int i = 0; i <= 5000; i++) {
    if (dp[child[k].size()][i]) {
      int aikata = sum - i;
      if (i <= x[k]) {
	m = min(m, aikata);
      }
      if (aikata <= x[k]) {
	m = min(m, i);
      }
    }
  }
  if (m == inf) {
    return false;
  }
  else {
    bw[k] = pii(x[k], m);
    return true;
  }
      
  
}


int main () {
  int i;
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> p[i];
    p[i]--;
    child[p[i]].push_back(i);
    childnum[p[i]]++;
  }
  for (i = 0; i < n; i++) {
    cin >> x[i];
  }
  if(solve(0)) {
    cout << "POSSIBLE" << endl;
  }
  else {
    cout << "IMPOSSIBLE" << endl;
  }
}


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

int n, q;
map<int, string> mp;

int main() {
  int i, x;
  string s;
  cin >> n >> q;
  mp[0] = "kogakubu10gokan";
  for(i = 0; i < n; ++i) {
    cin >> x >> s;
    mp[x] = s;
  }
  i = q;
  while(1) {
    if(mp.find(i) != mp.end()) {
      cout << mp[i] << endl;
      break;
    }
    --i;
  }
  return 0;
}


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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int X;
    cin >> X;
    if (X >= 30) cout << "Yes" << "\n";
    else cout << "No" << "\n";
}

Measured memory_bytes: 3644
import java.util.*;

public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        int a = scan.nextInt();
        int b = scan.nextInt();
        
        String cnt;
        
        if(a == 1)a = 14;
        if(b == 1)b = 14;
        
        if( a>b )cnt = "Alice";
        else if( a<b )cnt = "Bob";
        else cnt = "Draw";
            
        System.out.println(cnt);
	  }
}

Measured memory_bytes: 22996
n=int(input())
sp=[list(input().split()) for _ in range(n)]
for i in range(n):
    sp[i][1]=int(sp[i][1])
    sp[i].append(i+1)
# print(sp)
sp.sort(key=lambda x:(x[0],-x[1]))
# print(sp)
for i in range(n):
    print(sp[i][2])


Measured memory_bytes: 3060
from heapq import heappush, heappop

class City(object):
    def __init__(self, i, year):
        self.i = i
        self.year = year
        self.id = None

    def __lt__(self, other):
        return self.year < other.year

    def __eq__(self, other):
        return self.year == other.year

    def __gt__(self, other):
        return self.year > other.year


class Solver(object):
    def __init__(self):
        self.n, self.m = list(map(int, input().split(" ")))
        self.prefectures = [[] for _ in range(self.n)]
        self.cities = []
        for i in range(self.m):
            p, y = list(map(int, input().split(" ")))
            city = City(i+1, y)
            self.cities.append(city)
            heappush(self.prefectures[p-1], city)

    def solve(self):
        for i in range(self.n):  # For each prefecture Pi
            for j in range(len(self.prefectures[i])):  # For each Cj in Pi
                city = heappop(self.prefectures[i])
                city.id = "{:06d}{:06d}".format(i+1, j+1)
        for city in self.cities:
            print(city.id)


if __name__ == "__main__":
    s = Solver()
    s.solve()

Measured memory_bytes: 48556
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

// 復習場所

int main(){
    int n, k;
    cin >> n >> k;
	vector<int> d(k);
	rep(i, k) cin >> d[i];
	while(1){
      	int s = log10(n)+1;
		bool flag = true;
		rep(i, s){
			rep(j, d.size()){
				if(to_string(n)[i] - '0' == d[j]){
					flag = false;
					break;
				}
			}
			if (!flag) break;
		}
		if(flag){
			cout << n << endl;
			return 0;
		}
		n++;
	}
	
	
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] a = new int[M];
    int[] b = new int[M];
    Set<Integer> setA = new HashSet<Integer>();
    Set<Integer> setB = new HashSet<Integer>();
    for (int i =0; i<M; i++) {
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
      if (a[i] == 1) {
        setA.add(b[i]);
      }
      if (b[i] == N) {
        setB.add(a[i]);
      }
    }
    boolean OK = false;
    for (int x : setA) {
      if (setB.contains(x) ) {
        OK = true;
        break;
      }
    }
    if (OK) {
      System.out.print("POSSIBLE");
    } else {
      System.out.print("IMPOSSIBLE");
    }
  }
}

Measured memory_bytes: 114276
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
#define pii pair<ll int, ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define repi(i, n) for(ll i=0; i<n; i++)
#define rep(i, a, b) for(ll i=a; i<=b; i++)
#define M 1000000007
 
using namespace std;
 
int main() {
    ios
    ll n; cin>>n;
    vector <ll> v[3];
    repi(i, 3) v[i].resize(n);
    repi(i, n){
        repi(j, 3) cin>>v[j][i];
    }
    vector <ll> dp[3];
    repi(i, 3) dp[i].resize(n);
    repi(i, n){
        if(i==0) repi(j, 3) dp[j][i] = v[j][i];
        else repi(j, 3) {
            dp[j][i] = 0;
            repi(k, 3) if(j!=k) dp[j][i] = max(dp[j][i], dp[k][i-1] + v[j][i]);
        }
    }
    ll ans = 0;
    repi(i, 3) ans = max(ans, dp[i][n-1]);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 7932
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;

int main(){
  string S;
  cin>>S;
  int L=S.size();

  vi num(L, 1);
  vb R2L(L, false);
  for(int i=0; i<L-1; i++){
    if(S[i]=='R'){
      if(S[i+1]=='L'){
        R2L[i]=true;
      }else{
        num[i+1]+=num[i];
        num[i]=0;
      }
    }
  }

  for(int i=L-1; i>0; i--){
    if(S[i]=='L'){
      if(S[i-1]=='L'){
        num[i-1]+=num[i];
        num[i]=0;
      }
    }
  }
/*
  for(int x: num){
    cout<<x<<",";
  }cout<<endl;

  for(bool x: R2L){
    cout<<x<<",";
  }cout<<endl;
*/
  for(int i=0; i<L; i++){
    if(R2L[i]){
      int sum = num[i]+num[i+1];
      if(sum%2==0){
        num[i] = num[i+1] = sum/2;
      }else{
        if(num[i]%2==1){
          num[i] = sum/2+1;
          num[i+1] = sum/2;
        }else{
          num[i] = sum/2;
          num[i+1] = sum/2+1;
        }
      }
    }
  }

  for(int x: num){
    cout<<x<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 1024
N=int(input())
list=[1]
i=1
while(6**i<=N):
    list.append(6**i)
    i+=1
i=1
while(9**i<=N):
    list.append(9**i)
    i+=1
dp=[0 for i in range(N+1)]
#dp[i] i円引き出すのにかかる操作
for i in range(N):
    kouho=10**9
    for k in list:
        if i+1-k>=0:
            kouho=min(kouho,dp[i+1-k]+1)
    dp[i+1]=kouho
print(dp[N])


Measured memory_bytes: 44912
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define loop(i,a,n) for (int i = (a); (i) < (n); ++ (i))
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF (int)1e9
#define MOD 0
//#define int ll
using namespace std;
typedef vector<int> vi;

signed main(){
    int a[5],b[5],count = 0;
    cin.tie(0);
    ios::sync_with_stdio(false);
    rep(i,5) {
        cin >> a[i];
    }
    rep(i,10) {
        rep(j,5) {
            if( (a[j] + i)%10 == 0) {
                if(count < 4) {
                    b[j] = a[j] + i;
                    count++;
                } else {
                    b[j] = a[j];
                    break;
                }
            }
        }
    }
    int sum = 0;
    rep(i,5){
        sum += b[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		String t = sc.next();
		boolean flag = false;

		for (int i = 0; i < s.length(); i++) {

			flag = s.equals(t);
			if (flag)
				break;

			char e;
			String tmp;
			e = s.charAt(s.length() - 1);
			tmp = s.substring(0, s.length() - 1);
			s = e + tmp;

		}

		if (flag)
			System.out.println("Yes");
		else
			System.out.println("No");
		sc.close();
	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

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

  long long suma = 0,sumb = 0;
  vector<long long> a(N),b(N);
  for(int i = 0;i < N;i++) {
    cin >> a.at(i);
    suma += a.at(i);
  }

  for(int i = 0;i < N;i++) {
    cin >> b.at(i);
    sumb += b.at(i);
  }

  long long resta = max(0LL,sumb-suma),restb = resta;

  for(int i = 0;i < N;i++) {
    if(resta == 0 && restb == 0) break;

    if(a.at(i) < b.at(i)) {
      long long dis = b.at(i)-a.at(i);
      a.at(i) += 2*min(resta,(dis+1)/2);
      resta -= min(resta,(dis+1)/2);
      if(a.at(i)!=b.at(i) && restb > 0) {
        b.at(i)++;
        restb--;
      }
    }else if(a.at(i) > b.at(i)){
      long long dis = a.at(i)-b.at(i);
      b.at(i) += min(restb,dis);
      restb -= min(restb,dis);
    }
  }

  bool can = true;
  for(int i = 0;i < N;i++) {
    if(a.at(i) != b.at(i)) can = false;
  }

  if(resta*2 != restb) can = false;

  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;


}



Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;

#define n_max pow(10,5)

int main(){
    int n;
    vector<long long int> A;
    cin >>n;
    long long int tmp;
    for(int i=0;i<n;i++){
        scanf("%lld",&tmp);
        A.push_back(tmp);
    }
    if(n==1){
        if(A[0]==1) printf("0\n");
        else printf("1\n");
        return 0;
    }
    sort(A.begin(),A.end());
    int ans=0;
    int index=1;
    long long int now=A[0];
    int tmp_count=1;
    while(1){
        if(now!=A[index]){
            if(now<=tmp_count) ans+=tmp_count - now;
            else ans+=tmp_count; 
            tmp_count=1;
            now=A[index];
        }
        else tmp_count+=1;
        index+=1;
        if(index >=n){
            if(now<=tmp_count) ans+=tmp_count - now;
            else ans+=tmp_count;
            break;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 1400
def solve(result,rows,cols):
    MOD=10**9+7

    t={"#":1,".":0}
    dp=[[1]*cols for i in range(rows)]
    dp[0][0]=1
    for j in range(1,cols):
        dp[0][j]=dp[0][j-1]*(1-t[result[0][j]])
    for i in range(1,rows):
        dp[i][0]=dp[i-1][0]*(1-t[result[i][0]])
        
    for i in range(1,rows):
        for j in range(1,cols):
            if result[i][j]=="#":
                dp[i][j]=0
            else:
                dp[i][j]=dp[i-1][j]+dp[i][j-1]
            
            
    return dp[-1][-1]%MOD

        
    


value=[int(i) for i in input().split()]
rows,cols=value[0],value[1]
result=[]
for i in range(rows):
    t=input()
    result.append(t)
#result=[[str(i) for i in input().split()]for j in range(rows)]
print(solve(result,rows,cols))

Measured memory_bytes: 208636
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGreatOceanView solver = new BGreatOceanView();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGreatOceanView {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int h[] = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = in.nextInt();
            }
            int max = 0;
            int ans = 0;
            for (int i = 0; i < n; i++) {
                if (h[i] >= max) {
                    max = h[i];
                    ans++;
                }
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21328
#include <iostream>
#include <string>
#include <unordered_map>
 
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
  string S;
  cin >> S;
 
  auto const n = S.length();
  unordered_map<int, ull> U{{ 0, 1 }}; // Tn を先に追加
  
  ll Tk = 0, d = 1;
  for(int k = n-1; k >= 0; --k) {
    Tk = (Tk + d * (S[k] - '0')) % 2019;
    d = (10 * d) % 2019;
    ++U[Tk];
  }

  ll ans = 0;
  for(auto& p: U) {
    ans += p.second * (p.second - 1) / 2;
  }

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

Measured memory_bytes: 3372
#include<bits/stdc++.h>
using namespace std;
template<typename T>
inline void read(T &x)
{
	x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	x*=f;
	return;
}
template<typename T>
void write(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
	return;
}
int n;
string s[55];
int t[55];
string x;
int ans=0;
int main()
{
	bool flag=0;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>s[i]>>t[i];
	cin>>x;
	for(int i=1;i<=n;i++)
	{
		if(flag) ans+=t[i];
		if(s[i]==x) flag=1;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int A,B,K;cin>>A>>B>>K;
  for(int i=0;i<K;i++){
    if(i%2==0){B+=A/2;A/=2;}
    else{A+=B/2;B/=2;}
  }
  cout<<A<<" "<<B<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int t, sum, last;
int main(){
	//ios::sync_with_stdio(0), cin.tie(0);
	//cout<< fixed<< setprecision(10) << x << endl;
	cin>>t;
	vector<int> y(t);
	for(auto &x : y)cin>>x;
	vector<int> a(t);
	for(auto &x : a)cin>>x;
	t--;
	vector<int> b(t);
	for(auto &x : b)cin>>x;
    last = -2;
	for(auto x : y){
        if(last + 1 == x && x - 2 < t)sum += b[x - 2];
        sum += a[x - 1];
        last = x;
	}
	cout<<sum<<"\n";
}


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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct FenwickTree{
	vector<ll> data;
	FenwickTree(int n):data(n+1){}
	void Add(int i,int x){
		for(i++;i<data.size();i+=i&-i)
			data[i]+=x;
	}
	ll Sum(int i){
		ll res=0;
		for(;i;i-=i&-i)
			res+=data[i];
		return res;
	}
	ll Sum(int i,int j){
		return Sum(j)-Sum(i);
	}
};

int main()
{
	for(int a,b,p;cin>>a>>b>>p && a|b|p;){
		int n=b-a+1;
		vi xs;
		{
			vs ss;
			rep(i,n){
				char s[11];
				sprintf(s,"%d",a+i);
				ss.push_back(s);
			}
			sort(all(ss));
			for(auto s:ss) xs.push_back(atoi(s.c_str()));
		}
		
		FenwickTree ft(n);
		for(int x:xs){
			ll sum=ft.Sum(x-a);
			ft.Add(x-a,(sum+1)%p);
		}
		cout<<ft.Sum(n)%p<<endl;
	}
}

Measured memory_bytes: 7484
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int k,a,b,flag=0;
	cin>>k>>a>>b;
	
	for(int i=a;i<=b;i++)
	{
		if(i%k==0){flag=1;break;}
	}
	if(flag==1)cout<<"OK";
	else cout<<"NG";
	return 0;
}


Measured memory_bytes: 3592
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N;
	cin >> N;
	long long Y;
	cin >> Y;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			int k = max(N - i - j, 0);
				if (i + j + k == N) {
					if (10000 * i + 5000 * j + 1000 * k == Y) {
						cout << i << ' ' << j << ' ' << k << endl;
						return 0;
					}
				}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}

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

a.sort()
l=[]
sum=-a[0]+a[n-1]
for i in range(n-2):
    sum+=abs(a[i+1])
print(sum)

x=a[n-1]-a[0]
for i in range(n-1):
    if i==0:
        l.append([a[n-1],a[0]])
    else:
        if a[i]<0:
            l.append([x,a[i]])
            x+=abs(a[i])
        else:
            s=l[i-1][0]
            t=l[i-1][1]
            l[i-1][0]=t
            l[i-1][1]=s
            l.append([a[i],-x])
            x+=a[i]

for y in l:
    print(y[0],y[1])

Measured memory_bytes: 22452
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,ans;
	cin>>n;
	ans=n;
	vl x(n),y(n);
	rep(i,n)cin>>x[i]>>y[i];
	rep(i,n){
		rep(j,i){
			int tmp=n;
			ll p=x[i]-x[j];
			ll q=y[i]-y[j];
			rep(k,n){
				rep(l,n){
					if(k==l)continue;
					if(((x[l]-x[k])==p&&(y[l]-y[k])==q)){
						tmp--;
						l=n;
					}
				}
			}
			chmin(ans,tmp);
		}
	}
	if(n==1)ans=1;
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a,b;
	double f;
	scanf("%d%d",&a,&b);
	
	f = (double)a / b;
	
	printf("%d %d %.5lf\n",a/b,a%b,f);
	
	return 0;	
	
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 100005
#define MOD 20190823
#define eps 1e-8
#define bl bool
#define INF 1e+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
template<class T> inline void read(T &f){
	f=0;
    T x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
ll n;
int main(){
	read(n);
	if(n==1){
		cout<<"1.0000000000"<<endl;
		return 0;
	}
	if(n%2==0){
		cout<<"0.5000000000"<<endl;
		return 0;
	}
	if(n%2==1){
		ll p=(n+1)/2;
		db ans=(db)p/(db)n;
		printf("%.10lf\n",ans);
	}
	return 0;
}

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

#define sz(s) (int)(s).size()
#define re(i, n) for (int i = 1; i <= n; i ++)
#define pb push_back
#define finish(x) return cout << x << endl, 0
#define MP make_mair
#define trav(x, a) for(auto& x: a)
#define all(x) (x).begin,(x).end()
#define Sor(x) sort(all(x))
#define REV(x) reverse(all(x))
#define F first
#define S second
#define I insert
#define N 222222
#define MOD 1000000007

using namespace std;

typedef long long ll;
vector <ll> vll;
template <class T> bool umin(T& a, T b) {if(a>b){a = b; return 1;}return 0;}
template <class T> bool umax(T& a, T b) {if(a<b){a=b; return 1;}return 0;}
template <class T, class TT> bool pal(T a, TT n){int k = 0; for(int i =0; i <= n / 2; i ++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

ll powmod(ll a, ll b, ll m = MOD){ll r = 1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	ll n, k;
	cin >> n >> k;
	if(n < k)
		{
			ll l = abs(n - k);
			cout << min(l, n);
			return 0;
		}
	ll q = n % k;
	ll p = abs (k - q);
	cout << min(p, q);
    
    
    
    
    
    
    
    
    
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
count = 0
if n < 3:
  pass
else:
  for i in range(n-2):
    for j in range(i+1,n-1):
      for k in range(j+1,n):
        a,b,c = l[i],l[j],l[k]
        if abs(a-c)<b<a+c and a!=b and b!=c and c!=a:
          count += 1
print(count)

Measured memory_bytes: 9204
#include <iostream>
using namespace std;
int main() {
    int n,i=0,x=0;
    string s;

    cin >> n >> s;

    while (1) {
        x=s.find("ABC");
        if (x == string::npos) {
            break;
        }
        i++;
        s.erase(x,3);
        x = 0;
    }
    cout << i;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


int n, m, k[11], s[11][11];
bool b[11];

int main(){
	cin >> n >> m;
	int ans = 0;
	for(int i = 0; i < m; i++){
		cin >> k[i];
		for(int j = 0; j < k[i]; j++){
			cin >> s[i][j];
		}
	}
	for(int i = 0; i < m; i++){
		cin >> b[i];
	}
	
	for(int i = 0; i < (1 << n); i++){
		bool ok = 1;
		for(int j = 0; j < m; j++){
			int cnt = 0;
			for(int x = 0; x < k[j]; x++){
				if((i >> (s[j][x]-1)) & 1) cnt++;
			}
			if(cnt%2 != b[j]) ok = 0;
		}
		if(ok) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
require 'prime'

class Integer
  def divisors
    return [1] if self == 1
    Prime.prime_division(self).map do |e|
      Array.new(e[1]+1).map.with_index do |element, i|
        e[0]**i
      end
    end.inject{|p,q| p.product(q)}.map do |a|
      [a].flatten.inject(&:*)
    end.sort
  end
end

n = gets.chomp.to_i
min = n
divisors = n.divisors
divisors.each do |a|
  b = n / a
  min = [min, a + b - 2].min
end
puts min

Measured memory_bytes: 3708