akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
    int a,b,c,d;

    scanf("%d%d%d%d",&a,&b,&c,&d);

    int s,e;

    if (a < c) s = c;
    else s = a;

    if (b < d) e = b;
    else e = d;

    int ans = 0;

    ans = e - s;

    if (ans <= 0) printf("%d\n",0);
    else printf("%d\n",ans);

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

vector<int>v[26];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	string x,y;
	cin>>x>>y;
	
	int n=x.size();
	for(int i=0;i<n;i++)
	{
		int temp=x[i]-'a';
		v[temp].push_back(i);
	}
	
	int now;
	if(v[y[0]-'a'].empty()) return cout<<-1,0;
	
	now=v[y[0]-'a'][0];
	
	ll tot=0;
	
	for(int i=1;i<y.size();i++)
	{
		int temp=y[i]-'a';
		if(v[temp].empty()) return cout<<-1,0;
		
		int indx=upper_bound(v[temp].begin(),v[temp].end(),now)-v[temp].begin();
		if(indx==v[temp].size())
		{
			tot+=n;
			now=v[temp][0];
		}
		else now=v[temp][indx];
	}
	
	tot+=now+1;
	
	cout<<tot;
					                                				
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	
	return 0;
}

Measured memory_bytes: 1228
n = int(input())
A = list(map(int,input().split()))

def partition(A,p,r):

    x = A[r]

    i = p-1

    for j in range(p,r):
        if A[j] <= x:
            i += 1
            tmp = A[j]
            A[j] = A[i]
            A[i] = tmp
    tmp = A[i+1]
    A[i+1] = x
    A[r] = tmp

    return i+1


y = partition(A,0,n-1)
A = list(map(str,A))
A[y] = "["+A[y]+"]"

print(" ".join(A))




Measured memory_bytes: 16392
S = input()
KEYENCE = "keyence"
 
 
isKeyence = False
for i in range(len(S)):
    for j in range(i, len(S)):
        s = S[:i] + S[j:]
        if s == KEYENCE:
            isKeyence = True
if isKeyence:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n;
    cin >> n;
    vector<ll>h(n);
    for(ll i=0;i<n;i++) cin >> h[i];
    vector<ll>dp(n+2,0);
    dp[1]=abs(h[1]-h[0]);
    for(ll i=0;i<n-1;i++){
        dp[i+2]=min(dp[i+1]+abs(h[i+2]-h[i+1]),dp[i]+abs(h[i+2]-h[i]));
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

int main(){
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int>(m,0));
    rep(i,n){
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }
    int ans = INF;
    rep(bit,1<<n){
        int res = 0;
        vector<int> power(m);
        rep(i,n){
            if(bit>>i & 1){
                res += c[i];
                rep(j,m){
                    power[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        rep(i,m){
            if(power[i] < x){
                ok = false;
                break;
            }
        }
        if(ok) ans = min(ans,res);
    }

    if(ans==INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
string s;
ll n,m,r,c,t;
int a[105];
int sum;
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	int sum1=sum/n+1;
	sum/=n;

	ll num=0;
	ll num1=0;
	for(int i=1;i<=n;i++){
		num+=((sum-a[i])*(sum-a[i]));
		num1+=((sum1-a[i])*(sum1-a[i]));
	}
	 
	cout<<min(num,num1);
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
//1 2 3 4 100 1
/*
配列を持っているa
四こに分ける
どれぞれの総和をおんなじくらいへ
配列の総和を半分にカットする関数

1回めのカット
右に
*/


int main(void){
    int x, a, b;
    scanf("%d",&x);
    scanf("%d",&a);
    scanf("%d",&b);
    printf("%d\n",x-a-((x-a)/b)*b);


    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<numeric>
#include<limits>
#include <cstdint>
#include<stack>
#include<queue>
using namespace std;
#define ll long long int
#define rep(N) for(ll i=0;i<N;i++)
#define rep2(N1,N2) for(ll i=0;i<N1;i++)for(ll j=0;j<N2;j++)
#define rep3(N1,N2,N3)for(ll i=0;i<N1;i++)for(ll j=0;j<N2;j++)for(ll k=0;k<N3;k++)
#define For(i,N) for(ll i=0;i<N;i++)

void yn(bool b) {
	if (b)printf("yes\n");
	else printf("no\n");
}

void Yn(bool b) {
	if (b)printf("Yes\n");
	else printf("No\n");
}

void YN(bool b) {
	if (b)printf("YES\n");
	else printf("NO\n");
}

int ctoi(char c) {
	return c - '0';
}

ll kai(ll x) {
	ll a = 1;
	if (x <= 0)
		return 1;
	else {
		for (ll i = 0; i < x; i++)
			a = a * (i + 1);
		return a;
	}
}

ll rui(ll x, ll y) {
	ll a = 1;
	for (ll i = 0; i < y; i++)
		a = a * x;
	return a;
}
const int nmax = 150;
int cccc[nmax][nmax];
ll comb(ll n, ll k) {
	if (n < k) {
		cout << "error n<k" << endl;
		return -1;
	}
	if (cccc[n][k] > 0)return cccc[n][k];
	if (k == 0 || n == k)return 1;
	return cccc[n][k] = comb(n - 1, k - 1) + comb(n - 1, k);
}

ll keta(ll a) {
	ll i = 1;
	while (1) {
		if (a < pow((ll)10, i))
			return i;
		i++;
	}
}
vector<ll> v;
ll n, m;
//m進数全探索
ll inc(ll a = n - 1) {
	if (a == 0 && v[0] == m) {
		v[0] = -1;
		return v[0];
	}
	if (v[a] == m) {
		v[a] = 0;
		inc(a - 1);
		return v[a];
	}
	else {
		++v[a];
		return v[a];
	}
}

ll mod = 1000000007;

ll modpowl(ll a, ll b) {
	if (b == 0) {
		
		return 1;
	}
	if (b == 1) {
		
		return a;
	}
	if (b >= 2) {
		if (b % 2 == 0) {
			ll c = modpowl((a*a)%mod, b / 2);
			c = c % mod;
			
			return c;
		}
		else { 
			ll c = (modpowl((a*a)%mod, b / 2)%mod)*a;
			c = c % mod;
			
			return c;
		}
	}
}


int main() {
	cout.precision(20);
	string S;
	ll N, M, K;
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = modpowl((ll)2, n)-1;
	
	ll moda,modb;
	ll modac, modam, modbc, modbm;
	modac = 1;
	modbc = 1;
	modam = 1;
	modbm = 1;
	rep(a) {
		modac *= (n - i)%mod;
		modac = modac%mod;
		modam *= (i + 1)%mod;
		modam = modam % mod;
	}
	rep(b) {
		modbc *= (n - i) % mod;
		modbc = modbc % mod;
		modbm *= (i + 1)%mod;
		modbm = modbm % mod;
	}

	
	modam = modpowl(modam, mod - 2);
	modbm = modpowl(modbm, mod - 2);
	moda = (modac*modam) % mod;
	modb= (modbc*modbm) % mod;
	
	if (ans >= moda)
		ans -= moda;
	else
		ans = ans + mod - moda;
	if (ans >= modb)
		ans -= modb;
	else
		ans = ans + mod - modb;
	
	cout << ans%mod;
}




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

typedef long long ll;
int n,m;

const ll mod=1e9+7;
string grid[1005];

ll c=0;

ll dp[1005][1005];
bool vis[1005][1005];

bool valid(int x,int y)
{
    return (x>=0&&x<n&&y>=0&&y<m && grid[x][y]=='.');
}

ll solve(int x,int y)
{
    if(!valid(x,y))return 0;

    if(x==n-1 && y==m-1)return 1;

    if(vis[x][y]){
        return dp[x][y];
    }
    vis[x][y]=1;
    dp[x][y]+= (solve(x+1,y)%mod+solve(x,y+1)%mod)%mod;

    return dp[x][y];
}
int main()
{
    cin >> n>> m;

    for(int i=0;i<n;i++)cin >>grid[i];
    cout << (solve(0,0)+mod)%mod<<endl;
    
}

Measured memory_bytes: 10240
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int W[11]={0},K[11]={0},wall=0,kall=0;
    for(int i=0;i<10;i++){
        cin>>W[i];
    }
    sort(W,W+10);
    reverse(W,W+10);
    for(int i=0;i<10;i++){
            cin>>K[i];
        }
        sort(K,K+10);
        reverse(K,K+10);
    for(int i=0;i<3;i++){
        wall+=W[i];
        kall+=K[i];
    }
    cout<<wall<<" "<<kall<<endl;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int n;
    cin >> n;
    vector<bitset<64>> a(n);
    bitset<64> all(0);
    rep(i, n)
    {
        int num;
        cin >> num;
        bitset<64> tmp(num);
        all ^= tmp;
        a[i] = tmp;
    }
    rep(i, n)
    {
        if (i != 0)
        {
            cout << ' ';
        }
        bitset<64> ans = all ^ a[i];
        cout << ans.to_ullong();
    }
    cout << endl;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 4752
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) { cin >> a[i]; }
    map<ll, ll> mp;
    rep(i, N) { mp[a[i]]++; }
    ll ans = 0;
    for (auto p : mp) {
        ll x = p.first;
        ll n = p.second;
        if (n < x) {
            ans += n;
        } else {
            ans += n - x;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
int R, G, B, n;
int main() {
    cin >> R >> G >> B >> n;
    int r, g, b;
    int rmax = n/R; int gmax = n/G; int bmax = n/B;

    int cnt = 0;
    for(int i = 0; i <= rmax; ++i) {
        for(int j = 0; j <= gmax; ++j) {
            if(R*i+G*j <= n) {
                if((n - R*i - G*j) % B == 0) cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
//By : BebekJK
#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;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//Declare -> ordered_set NAMA;
//Nth smallest integer -> find_by_order(N-1)
//Number of elements less than N -> order_of_key(N)
//Delete N from the set -> erase(N)

#define endl '\n'
#define MOD 1000000007
#define PI 3.141592653
#define fi first
#define sc second
#define pb push_back
#define pbb pop_back

//#pragma GCC optimize("Ofast")
//#pragma GCC target ("string"...)
//#pragma GCC push_options
//#pragma GCC pop_options
//#pragma GCC reset_options
//#pragma GCC optimize ("O3")

typedef long long ll;
typedef long long ld;
typedef pair<int , int> pii;
typedef pair<long long , long long> pll;

void BOOST(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
}
void fcin(int &x){
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c=='-'){
		neg = true;
		c = getchar();
	}
	for(;(c>47 && c<58);c=getchar())x = (x<<1)+(x<<3)+c-48;
	if(neg)x*=-1;
}
ll pmod(ll a , ll b){
	if(b==0)return 1;
	ll temp = pmod(a , b/2);
	if(b%2==0)return(temp*temp)%MOD;
	return (((temp*temp)%MOD)*a)%MOD;
}
int main(){
//	BOOST();
	int a , b , c, d;
	cin>>a>>b>>c>>d;
	int ans = 0;
	ans+=min(a ,d);
	d-=min(a,d);
	d-=min(b,d);
	ans-=min(c,d);
	cout<<ans<<endl;

}







Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (b) - 1;i >=a;--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())

using namespace std;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}


using ll = long long;
constexpr int mod = 1'000'000'007;
constexpr int INF = 1'050'000'000;

int clamp(int n, int a, int b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

int Fib[100001];

int fib(int N) {
    if (Fib[N] > 0)return Fib[N];
    if (N == 0 || N == 1)return Fib[N] = 1;
    return Fib[N] = (fib(N - 1) + fib(N - 2)) % mod;
}

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

    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> LR(M);
    cin >> LR;

    vector<int> t(N + 1);
    REP(i, M) {
        t[LR[i].first - 1]++;
        t[LR[i].second]--;
    }

    FOR(i, 1, N) {
        t[i] += t[i - 1];
    }

    cout << count(ALL(t), M) << endl;
    return 0;

}

Measured memory_bytes: 1408
#include        "algorithm"
	#include        "iostream"
	#include        "numeric"
	#include        "iomanip"
	#include        "cstring"
	#include        "math.h"
	#include        "bitset"
	#include        "string"
	#include        "vector"
	#include        "ctime"
	#include        "queue"
	#include        "stack"
	#include        "map"
	#include        "set"

	#include        "ext/pb_ds/assoc_container.hpp" // Common file
	#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
	#include        "ext/pb_ds/detail/standard_policies.hpp"

	using namespace std;
	using namespace __gnu_pbds;


	#define          f first
	#define          lgn 25
	#define          endl '\n'
	#define          sc second
	#define          N (int)2e5+5
	#define          pb push_back
	#define          mod 1000000007
	#define          ld long double
	#define          vi vector<int>
	#define          eb emplace_back
	#define          vpii vector<pii>
	#define          mii map<int,int>
	#define          int long long 
	#define          pii pair<int,int>
	#define          pq priority_queue
	#define          BLOCK (int)sqrt(N)
	#define          test(x) while(x--)
	#define          all(x) begin(x),end(x)
	#define          allr(x) rbegin(x),rend(x)
	#define          fo(i,a,n) for(int i=a;i<n;i++)
	#define          rfo(i,n,a) for(int i=n;i>=a;i--)
	#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
	#define          PI acos(-1.0)
	#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

	typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
	OS ;

	template <typename Arg1>
	void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
	template <typename Arg1, typename... Args>
	void __f (const char* names, Arg1&& arg1, Args&&... args)
	{
	     const char* comma = strchr (names + 1, ',');
	     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
	}

	inline void INP()
	{
		#ifndef ONLINE_JUDGE
		    freopen("input.txt","r",stdin);   
		    freopen("output.txt","w",stdout);
		#endif 
	}

	const int inf = 0x3f3f3f3f;
	const int INF = 0x3f3f3f3f3f3f3f3f;

	int n,m,k,q;
	string s;
	vi adj[N];
	int vis[N],par[N],a[N];

	void go()
	{
		cin >> n >> m >> k;

		int aa = k - ( n + m );
		int free = 4*n*m;

		if( aa > 0 and free < aa*aa )
		{
			cout << "Yes\n";
		}
		else cout << "No\n";
		
	}

	int32_t main()
	{
		//INP(); 
		FAST;     
		int t=1; 
		cout << fixed << setprecision(40);
		// cin>>t;
		test(t) go();
	}

	 

Measured memory_bytes: 5504
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//省略
using vi  = vector<int>;
using vii = vector<vector<int>>;
using vl  = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

// UnionFind
struct UnionFind {
    vector< int > data;
    
    UnionFind(int sz) {
        data.assign(sz, -1);
    }
 
    bool unite(int x, int y) {//要素xとyの各々の木を併合（もともと同じ木ならfalse）
        x = find(x), y = find(y);
        if(x == y) return (false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }
    
    int find(int k) {//要素kが属する木の根を得る
        if(data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }
    
    int size(int k) {//要素kが属する木の要素数
        return (-data[find(k)]);
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = find(x);
        int ry = find(y);
        return rx == ry;
    }

};

int main(){
    ll N,M;
    cin>>N>>M;
    UnionFind tree(N);
    vl A(M),B(M);
    REP(i,M){
        cin>>A[i]>>B[i];
        A[i]--;
        B[i]--;
        tree.unite(A[i],B[i]);
    }

    ll ans=1;
    REP(i,N){
        ans=max(ans,(ll)tree.size(i));
    }
    cout<<ans<<endl;

    
}

Measured memory_bytes: 7212
#include<bits/stdc++.h>
//#include<cstdio>
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
/*
inline int read(){
	int res=0; char ch=getchar_unlocked();
	while(ch<'0'||ch>'9') ch=getchar_unlocked();
	while(ch>='0'&&ch<='9') res=(res<<3)+(res<<1)+(ch^48),ch=getchar_unlocked();
	return res;
}
*/
#define int long long
#define mp make_pair
#define pb push_back
#define S second
#define F first
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define IOS ios::sync_with_stdio(false),cin.tie(0);
#define pii pair<int,int>
#define endl cout<<'\n';
#define LINE cout << "-----------------------\n";
using namespace std;
const int maxn = 1e6+5;

signed main(){
	IOS;
	int x;
	for(int i=1 ; i<=5 ; ++i) {
		cin >> x;
		if(x == 0) {cout << i << '\n';return 0;}
	}
}

Measured memory_bytes: 3632
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
map<ll,ll> mp;
const ll mod=1000000007;
int main(){
string s;
cin>>s;
vector<bool> ch(26,true);
for(int i=0;i<s.size();i++){
    ch[s.at(i)-'a']=false;
}
if(s.size()<26){
    cout<<s;
    for(char c='a';c<='z';c++){
        if(ch[c-'a']){
            cout<<c<<endl;
            return 0;
        }
    }
}
int now=24;
while(now>=0&&s.at(now)>s.at(now+1))now--;
if(now==-1) cout<<-1<<endl;
else{
    string t=s.substr(0,now);
    int now2=now+1;
    for(int i=now;i<s.size();i++){
        if(s.at(i)<s.at(now2)&&s.at(i)>s.at(now))now2=i;
    }
    cout<<t<<s.at(now2)<<endl;
    }
}

Measured memory_bytes: 256
N=int(input())
d=list(map(int,input().split()))

dd=[d[0]]

for i in range(1,N):
    dd.append(dd[i-1]+d[i])

out=0

for i in range(N-1):
    out+=d[N-1-i]*dd[N-2-i]

print(out)


Measured memory_bytes: 3060
S = input()
if len(S) < 5:
  print('NO')
  exit()
else:
  i = 0
  while True:
    if (i+5 == len(S) and S[i:i+5]=='dream') or (i+5 == len(S) and S[i:i+5]=='erase') or (i+6 == len(S) and S[i:i+6]=='eraser') or (i+7 == len(S) and S[i:i+7]=='dreamer'):
      print('YES')
      exit()
    elif S[i:i+5]=='dream' and i+8 <= len(S):
      if S[i+5:i+8]=='erd' or S[i+5:i+8]=='ere': i+=7
      elif S[i+5:i+8]=='era' or S[i+5:i+6]=='d': i+=5
      else:
        print('NO')
        exit()
    elif S[i:i+5]=='erase'  and i+7 <= len(S):
      if S[i+5:i+6]=='e' or S[i+5:i+6]=='d': i+=5
      elif S[i+5:i+6]=='r': i+=6
      else:
        print('NO')
        exit()
    else:
        print('NO')
        exit()

Measured memory_bytes: 40944
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[100],k1=0,k2=0;
    for(int i=0;i<n;i++)
        cin>>a[i];

    for(int i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            k1++;
            if((a[i]%3==0)||(a[i]%5==0))
                k2++;
        }
    }
    if(k2==k1)  cout<<"APPROVED";
    else    cout<<"DENIED";

    return 0;
}


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)
#define N 200000
i32 a[N];
i32 x[N];
i32 x2[N];

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

  rep(i, n) { cin >> a[i]; }

  rep(i, n - 1) { x[i + 1] = a[i] ^ a[i + 1]; }

  x2[0] = a[0];
  rep(i, n - 1) { x2[i + 1] = x[i + 1] ^ x2[i]; }

  i32 x3 = 0;
  rep(i, n - 1) { x3 ^= x2[i + 1]; }

  x2[0] = x3;
  cout << x3 << ' ';
  rep(i, n - 1) {
    x2[i + 1] = x[i + 1] ^ x2[i];

    cout << x2[i + 1] << ' ';
  }

  return 0;
}


Measured memory_bytes: 5964
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [10 ** 9 + 7] * (n + k + 10)
dp[0] = 0

for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            if dp[i + j] == 10 ** 9 + 7:
                dp[i + j] = dp[i] + abs(h[i] - h[i + j])
            else:    
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
        else:
            break
        
print(dp[n - 1])


Measured memory_bytes: 52448
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(int argc, char* argv[]) {
	int x, y;

	while(1){
		cin >> x >> y;
		if((x == 0) & (y == 0)) break;
		if(x <= y){
			cout << x << " " << y << endl;
		}else{
			cout << y << " " << x << endl;
		}
	}

	return 0;
}

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

void solve()
{
    int n,k,c=0;
    cin>>n>>k;
    int a[n+1];
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<n;i++)
    if(a[i]>=k)
    c++;
    cout<<c<<endl;
    
}


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


Measured memory_bytes: 764
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll i;
    for(i=0;i<=b;i++){
        if(i>=a&&i%n==0){
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
    return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())


int main(){
  ll m,d; cin >> m >> d;
  ll ans = 0;
  FOR(i,1,m+1){
    FOR(j,1,d+1){
      if(j/10>=2&&j%10>=2&&i==((j%10)*(j/10))) ans++;
    }
  }
  cout << ans << endl;
}

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

using ll = int64_t;
ll N, M, K;

int main() {
    int x[5];
    std::cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];

    for (int i = 0; i < 5; ++i) {
        if (x[i] == 0) { 
            std::cout << i + 1 << std::endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

bool prime[100010];

void furui() {
    prime[0]=true;
    prime[1]=true;
	int i = 2;
	while (i <= 100010) {
		int j = 2;
		while (j <= sqrt(i) && !prime[i]) {
			if (i%j == 0) {
				prime[i] = true;
				break;
			}
			else j++;
		}
		int z = 2;
		while (!prime[i]) {
			if (i*z <= 100010) {
				prime[i*z] = true;
				z++;
			}
			else break;
		}
		i++;
	}
}


int main(void){
    furui();
    ll x;
    cin>>x;
    for(ll i=x;;i++){
        //cout<<i<<endl;
        if(!prime[i]){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}

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

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

    int n;
    cin >> n;

    vector<int> a;
    a.push_back(2);
    rep(i, 0, 18) a.push_back(a[i] * 2);

    if (n < 3)
    {
        cout << "No" << endl;
        return 0;
    }
    for (auto x : a)
        if (x == n)
        {
            cout << "No" << endl;
            return 0;
        }

    cout << "Yes" << endl;
    if (n % 2 == 1)
    {
        for (int i = 2; i <= 2 * n; i += 2)
        {
            if (i - 1 == n)
                continue;
            cout << 1 << ' ' << i << endl;
        }
        for (int i = 2; i <= 2 * n; i += 2)
        {
            cout << i << ' ' << i + 1 << endl;
            if (i - 1 == n)
                i--;
        }
    }
    else
    {
        n--;

        for (int i = 2; i <= 2 * n + 2; i += 2)
        {
            if (i - 1 == n)
            {
                i += 3;
            }
            cout << 1 << ' ' << i << endl;
        }
        for (int i = 2; i < 2 * n + 2; i += 2)
        {
            if (i - 1 == n)
            {
                i++;
                cout << i << ' ' << i + 1 << endl;
                i--;
                continue;
            }
            cout << i << ' ' << i + 1 << endl;
        }

        n++;

        int m = 0;
        while (a[m + 1] < n)
            m++;

        cout << n << ' ' << a[m] << endl;
        cout << 2 * n << ' ' << 2 * n - a[m] + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 2304
def is_prime2(q,k=100):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    for i in range(3,k):
        x,y = q,i
        while y:
            x, y =  y, x % y
        if x != 1: continue
        if pow(i, q-1, q) != 1:
            return False
    return True

n=int(input())
for i in range(n,10**6+100):
    if is_prime2(i) is True:
        print(i)
        exit()


Measured memory_bytes: 3060
#include <iostream>
#include <array>

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

    long int n;

    while (std::cin >> n, n) {
        long int age;
        std::array<long int, 7> arr{{}};

        while (n--) {
            std::cin >> age;
            ++arr[age < 70 ? age / 10 : 6];
        }

        for (const auto& cnt : arr) {
            std::cout << cnt << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 1196
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }


int dp[40][40][40][40];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int w, h;
	while (cin >> w >> h, w&&h) {
		memset(dp, 0x3f, sizeof(dp));
		rep(i, 0, h)rep(j, 0, w)dp[i][j][i][j] = 0;
		rep(i, 0, 2 * h - 1) {
			if (i % 2 == 0) {
				rep(j, 0, w - 1) {
					int x; cin >> x;
					// i/2 j,j+1
					dp[i / 2][j][i / 2][j + 1] = (x ? INF : 1);
					dp[i / 2][j + 1][i / 2][j] = (x ? INF : 1);
				}
			}
			else {
				rep(j, 0, w) {
					int x; cin >> x;
					// i/2 i/2+1 j
					dp[i / 2][j][i / 2 + 1][j] = (x ? INF : 1);
					dp[i / 2 + 1][j][i / 2][j] = (x ? INF : 1);
				}
			}
		}
		//rep(a, 0, h)rep(b, 0, w)rep(i, 0, h)rep(j, 0, w)rep(x, 0, h)rep(y, 0, w) {
		//	chmin(dp[i][j][x][y], dp[i][j][a][b] + dp[a][b][x][y]);
		//}
		queue<pair<int, int>>q;
		q.push(make_pair(0, 0));
		int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 };
		auto within = [&](int x, int y) {return 0 <= x&&x < h && 0 <= y&&y < w; };
		vector<vector<int>>d(h, vector<int>(w, -1));
		while (!q.empty()) {
			auto u = q.front(); q.pop();
			rep(i, 0, 4) {
				int x = u.first+dx[i], y = u.second+dy[i];
				if (within(x, y)&&dp[u.first][u.second][x][y]==1&&d[x][y]==-1) {
					q.push(make_pair(x, y));
					d[x][y] = d[u.first][u.second] + 1;
				}
			}
		}

		int ans = d[h - 1][w - 1];
		cout << (ans == -1 ? 0 : ans + 1+1) << endl;
	}
	return 0;
}

Measured memory_bytes: 13148
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>


int main(void)
{
	int x[10000], i = 0, j;

	while (1){
		scanf("%d", &x[i]);
			if (x[i] == 0){
				break;
			}
			i++;
	}

	for (j = 1; j < i+1; j++){
		printf("Case %d: %d\n", j, x[j - 1]);
	}

	return 0;
}

Measured memory_bytes: 1064
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] array = new int[num];
        for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        }
        int temp = 0, count = 0, minj = 0;
        for(int i = 0; i < num - 1; i++){
            minj = i;
            for(int j = i; j < num; j++){
                if(array[j] < array[minj]){
                    minj = j;
                }
            }
            temp = array[i];
            array[i] = array[minj];
            array[minj] = temp;
            if(i != minj){
                count++;
            }
        }
        System.out.print(array[0]);
        for(int i = 1; i < num; i++){
            System.out.print(" " + array[i]);
        }
        System.out.println("\n" + count);
    }
}


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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define fi first
#define se second
#define mp make_pair

using ll = long long; using vll = vector<ll>; using vvll = vector<vll>;

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n; 
    while (cin >> n && n) {
        string d(n, ' ');
        vector<char> x(n); rep(i, n) cin >> x[i];
        vector<char> y(n); rep(i, n) cin >> y[i];
        rep(i, n) 
            d[i] = (x[i] - y[i] + 10) % 10 + '0';

        static queue<pair<string, ll>> q;
        queue<pair<string, ll>>().swap(q);
        static set<string> s;
        s.clear();

        q.push(mp(d, 0));
        int queue_max = 0;
        while (!q.empty()) {
            queue_max = max(queue_max, (int)q.size());
            auto tmp = q.front().fi; auto d = q.front().se; q.pop();

            if (tmp == string(n, '0')) {
                cout << d << endl;
                goto next;
            }

            ll i = 0;
            while (tmp[i] == '0') i++;
            ll number = tmp[i] - '0';
            repi(j, i, n) {
                tmp[j] = '0' + ((tmp[j] - '0' - number) + 10) % 10;
                if (!s.count(tmp)) {
                    q.push(mp(tmp, d+1));
                    s.insert(tmp);
                }
            }
        }
        next:;
    }
    return 0;
}

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

using namespace std;

int conv(char c){
  if(c == 'A') return 11;
  if(c == 'T' || c == 'J' || c == 'Q' || c == 'K') return 10;
  return c - '0';
}

main(){
  int n;
  cin >> n;
  while(n--){
    char c;
    int sum = 0;
    bool ace = false;
    for(int j=0;j<2;j++){
      cin >> c;
      sum += conv(c);
      if(c == 'A') ace = true;
      if(sum > 21) sum -= 10;
    }
    string str;
    for(int i=0;i<8;i++){
      cin >> c;
      str += c;
    }

    if(sum == 21){
      cout << "blackjack" << endl;
      continue;
    }

    for(int j=0;j<8;j++){
      if(sum <= 16 || (sum == 17 && ace)){
        if(conv(str[j])) sum += conv(str[j]);
        if(str[j] == 'A'){
          if(sum > 21) sum -= 10;
          else ace = true;
        }
        if(sum > 21 && ace){
          ace = 0;
          sum -= 10;
        }
      }
    }
    if(sum > 21) cout << "bust" << endl;
    else cout << sum << endl;
  }
}

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

int main(){
    ll N,A,B; cin >> N >> A >> B;
    ll tmp1=N%(A+B);
    ll tmp2=N/(A+B);
    
    ll ans=tmp2*A;
    if (tmp1<=A) ans+=tmp1;
    else ans+=A;
    
    cout << ans;
}

Measured memory_bytes: 256
#include<stdio.h>
main(){
  int a,b,i,count=0,c=0,u[3000];
    
  for(i=0;i<3000;i++){
    if(i%4==0){
      if(i% 400 ==0){u[i]=i;
	continue;}
      else if(i%100==0){u[i]=0;
	continue;
      }
      else{u[i]=i;}
    }
    else{u[i]=0;}
  }  
  

  while(1){
    c=0;   
 scanf("%d %d",&a,&b);
    if(a==0&&b==0){break;}

    if(count++>0){printf("\n");}
    
    for(i=a;i<=b;i++){
      if(u[i]!=0){	
	c++;
	printf("%d\n",u[i]);
	c++;
      }
    }
    if(c==0){printf("NA\n");
      c=0;
    }
  }
  return 0;
}

Measured memory_bytes: 0
n=int(input())
l=list(map(int,input().split()))
if(n==1):
    print("Yes")
else:
    f=0
    for i in range(n-1,-1,-1):
        if(l[i]+1==l[i-1]):
            l[i-1]-=1
    for i in range(n-1):
        if(l[i+1]<l[i]):
            f=1
            break

    if(f==0):
        print("Yes")
    else:
        print("No")


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

int main(){
  int n;
  cin >> n;
  int ans = 0;

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

Measured memory_bytes: 256
N = int(input())
txy = []
for i in range(N):
    txy.append(list(map(int,input().split())))
ans = "Yes"
t = 0
x = 0
y = 0
for i in range(N):
    deft = txy[i][0] - t
    defx = abs(txy[i][1] - x)
    defy = abs(txy[i][2] - y)
    t = txy[i][0]
    x = txy[i][1]
    y = txy[i][2]
    if (defx + defy) > deft:
        ans = "No"
        break
    elif (deft - defx - defy)%2 != 0:
        ans = "No"
        break
print(ans)

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)

int main() {
  int r;
  cin >> r;
  cout << 3 * r * r << endl;
};


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
	"unicode/utf8"
)

func main() {
	var N int
	fmt.Scan(&N)

	inputs := scanNums(N)

	sort.Sort(sort.IntSlice(inputs))
	a := inputs[N/2-1]
	b := inputs[N/2]

	fmt.Println(b - a)

}

func scanStrings(len int) (strings []string) {
	var str string
	for i := 0; i < len; i++ {
		fmt.Scanf("%s", &str)
		strings = append(strings, str)
	}
	return
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

func spritString(input string) (res []string) {
	for i := 0; i < utf8.RuneCountInString(input); i++ {
		res = append(res, input[i:i+1])
	}
	return
}


Measured memory_bytes: 5504
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;

int main(void)
{
    int n,i,j;
    while(scanf("%d",&n)==1)
    {
        int cnt = 0;
        for(i=0;i<n;i++)
        {
            int x;
            scanf("%d",&x);
            if(x % 2 == 1)
                cnt++;
        }
        if(cnt % 2 == 0)
            printf("YES\n");
        else
            printf("NO\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
//priority_queue<int> pque;
//priority_queue<int, vector<int>, greater<int>> pque;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
ll N;
ll K;
vector<ll> A(100010);
ll cnt[41];
vector<bool> k(41);

int main(void){
    cin >> N >> K;
    for(ll i = 0; i < N; i++){
        cin >> A.at(i);
    }
    
    for(ll i = 0; i < N; i++){
        ll a = A.at(i);
        for(ll j = 0; j < 41; j++){
            cnt[j] += a % 2;
            a /= 2;
        }
    }
    
    
    K++;
    for(ll i = 0; i < 41; i++){
        k.at(i) = K % 2;
        K /= 2;
    }
    
    ll Answer = 0;
    
    for(ll i = 0; i < 41; i++){
        if(k.at(i)){
            ll ans = 0;
            for(ll j = 0; j < i; j++){
                if(cnt[j] <= N - cnt[j]){
                    ans += pow(2, j);
                }
            }
            for(ll j = i; j < 41; j++){
                if(i != j && k.at(j)){
                    ans += pow(2, j);
                }
            }
            ll Ans = 0;
            for(ll j = 0; j < N; j++){
                Ans += A.at(j) ^ ans;
            }
            Answer = max(Ans, Answer);
        }
    }
    cout << Answer << endl;
}


Measured memory_bytes: 1024
x,y,z,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
abc = []
for i in range(x):
    if i > K:
        break
    for j in range(y):
        if i*j > K:
            break
        for k in range(z):
            if i*j*k > K:
                break
            abc.append(a[i]+b[j]+c[k])
abc.sort(reverse=True)
for i in range(K):
    print(abc[i])

Measured memory_bytes: 112344
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
//#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e9;
template<typename T> void cmax(T &a, T b) {a = max(a, b);}
template<typename T> void cmin(T &a, T b) {a = min(a, b);}

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

int main(){
  int x,y;
  cin>>x>>y;
  cout<<gcd(x,y)<<endl;
 return 0;
}



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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 200111, max_c = 30, inf = 1000111222;

bool have[30];
int nxt[max_n][max_c];
int lst[max_c];
string s, t;


int main()
{
    //freopen("input.txt", "r", stdin);
    cin >> s  >> t;
    for (char c : s) {
        have[c - 'a'] = true;
    }
    for (char c : t) {
        if (have[c - 'a'] == 0) {
            cout << -1 << endl;
            return 0;
        }
    }
    int n = s.size();
    s = s + s;
    for (int i = 0; i < max_c; ++i) {
        lst[i] = -1;
    }
    for (int i = s.size() - 1; i >= 0; --i) {
        for (int j = 0; j < max_c; ++j) {
            nxt[i][j] = lst[j];
            if (nxt[i][j] >= n) {
                nxt[i][j] -= n;
            }
        }
        lst[s[i] - 'a'] = i;
    }
    int cur = n - 1;
    ll ans = 0;
    for (char c : t) {
        int sym = c - 'a';
        int to = nxt[cur][sym];
        if (to > cur) {
            ans += (to - cur);
        } else {
            ans += (to - cur + n);
        }
        cur = to;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 24192
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
#define rad2deg(a) ((a)/M_PI * 180.0)
#define deg2rad(a) ((a)/180.0 * M_PI)
const std::string yes = "Yes";
const std::string no  = "No";


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

int main(){
    std::string s;
    std::cin >> s;
    int ans=0;
    rep(i,s.size()){
        if(s[i]=='R') ans++;
    }
    if(s[0]=='R'&&s[1]=='S'&&s[2]=='R'){
        std::cout << 1 << "\n";
        return 0;
    }
    std::cout << ans << "\n";
    return 0;
}

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

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

    int n,m,c,d;
    cin >> n;
    priority_queue<int> q;
    for (int i=0;i<n;i++) {
        cin >> c;
        q.push(c);        
    }
    cin >> m;
    priority_queue<int> t;
    for (int i=0;i<m;i++) {
        cin >> c;
        t.push(c);        
    }
    if (n < m) {
        cout << "NO" << endl;
    }
    else {
        bool earl = false;
        while (!t.empty()) {
            c = t.top();
            //cout << "T pop: " << c << endl;
            t.pop();
            if (q.empty()) {earl=true;}
            else {
                while (!q.empty()){
                    d = q.top();
                    q.pop();
                    if (c < d) {}
                    else if (c==d) {
                        break;
                    }
                    else {
                        earl = true;
                        break;
                    }
                }
                if (earl) {
                    //cout << "No" << endl;
                    break;
                }
            }
        }
        cout << (earl ? "NO" : "YES") << endl;
    }
    return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define mod         (ll)1000000007
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = (ll)1e18;
ld pi = 3.141592653589;
using namespace std;

ll bpow(ll x, ll v) {	
	if (v == 0)
		return 1 % mod;
	if (v % 2 == 1)
		return (x * bpow(x, v - 1)) % mod;
	ll r = bpow(x, v / 2);
	return (r * r) % mod;	
}

ll lcm(ll a,ll b)
{
	ll ret=(a*b)/__gcd(a,b);
	return ret;
} 

ll solve(){ 
	ll a,b; cin>>a>>b;
	cout<<lcm(a,b);
}
int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
    	solve();
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int X = Integer.parseInt(sc.next());
        int Y = Integer.parseInt(sc.next());
        int Z = Integer.parseInt(sc.next());
        sc.close();

        System.out.println(Z+ " " + X + " " + Y);

    }

}

       

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)


int main(void){
  int n;
  cin>>n;
  vector<int> a(n);
  r(i,n)cin>>a.at(i);
  sort(a.begin(),a.end());
  cout<<a.at(n-1)-a.at(0)<<endl;

return 0;

}


Measured memory_bytes: 256
I = input()
if I == "SUN":
  print(7)
if I == "MON":
  print(6)
if I == "TUE":
  print(5)
if I == "WED":
  print(4)
if I == "THU":
  print(3)
if I == "FRI":
  print(2)
if I == "SAT":
  print(1)

Measured memory_bytes: 3060
n = int(input())

hon = set([2, 4, 5, 7, 9])
pon = set([0, 1, 6, 8])
bon = set([3, ])

if (n % 10) in hon:
  print("hon")
elif (n % 10) in pon:
  print("pon")
else:
  print("bon")

Measured memory_bytes: 9176
S = input()

N = len(S)
num = 0
L = [0]
R = [0]
cnt = 0

for i in range(N):
    if S[i] == "<":
        cnt += 1
    else:
        cnt = 0
    L.append(cnt)

ans = 0
S = S[::-1]
cnt = 0

for i in range(N):
    if S[i] == ">":
        cnt += 1
    else:
        cnt = 0
    R.append(cnt)

R = R[::-1]

for i in range(N+1):
    ans += max(L[i], R[i])

print(ans)


Measured memory_bytes: 37020
import java.util.Scanner;

public class Main{
    public static void main(String[] aaa){
        Scanner s = new Scanner(System.in);
        int[] count = new int[27];
        String st;
        char m;
        int i,j;
        while(s.hasNextLine()){
            st = s.nextLine();
            if("".equals(st))break;
            for(i=0;i<st.length();i++){
                j=st.charAt(i);
                if(j-'a'>=0&&j-'a'<26)count[st.charAt(i)-'a']++;
                else if(j-'A'<26&&j-'A'>=0)count[st.charAt(i)-'A']++;
            }
        }
        for(i=0;i<26;i++){
            m = (char)('a'+i);
            System.out.println(m+" : "+count[i]);
        }
    }
}


Measured memory_bytes: 26296
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a+b > c+d) {
    cout << "Left" << endl;
  } else if (a+b < c+d) {
    cout << "Right" << endl;
  } else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline 
sys.setrecursionlimit(10 ** 6) 
N,Q = map(int, input().split())

tree = [[] for _ in range(N)]

for i in range(N - 1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  tree[a].append(b)
  tree[b].append(a)

ans = [0] * N

for i in range(Q):
  p,x = map(int, input().split())
  ans[p - 1] += x
  
def dfs(cur, par):
  for chl in tree[cur]:
    if chl == par:
      continue
    ans[chl] += ans[cur]
    dfs(chl,cur)

dfs(0, -1)

print(*ans)

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

int main(void){
	long long N, A, B, C, D, E;
	cin >> N >> A >> B >> C >> D >> E;
	cout << max({ (N - 1) / A, (N - 1) / B, (N - 1) / C, (N - 1) / D, (N - 1) / E }) + 5 << endl;
	return 0;
}


Measured memory_bytes: 256
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
from collections import Counter
a=[]
for i in range(n):
 s=input()
 if s[0]=="M" or s[0]=="A" or s[0]=="R" or s[0]=="C" or s[0]=="H":
   a.append(s[0])
c= Counter(a)
cv=list(c.values())
import itertools
b=list(itertools.combinations(range(len(cv)),3))
d=0
for i in b:
 d+=cv[i[0]]*cv[i[1]]*cv[i[2]]
print(d)

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

int main(){
  int Asum = 0,Bsum = 0;
  int UpDown;   // AliceとBobの順番
  int N;  //カード枚数
  cin >> N;

  vector <int> a(N,0);  //カードに書かれた数
  for (int i=0; i<N; i++){
    cin >> a.at(i);
  }

  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  for (int i=0; i<N; i++){
    if ( i%2 == 0){
      Asum += a.at(i);  // Aliceの戦略
    } else {
      Bsum += a.at(i);  // Bobの戦略
    }
  }
  cout << Asum - Bsum << endl;
}     

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

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;

    for (int d = 0; d <= n; d++) {
        bool ok = true;
        for (int i = 0; i < n - d; i++) {
            if (s.at(i + d) != t.at(i)) ok = false;
        }
        if (ok) {
            cout << n + d << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256