akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//is(string &s) {int c;for(;;){c=gcu();if(c=='\n'||c==' ')return true;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
template <typename T>
void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

typedef vector<int> v;

struct deck {
	v d;
	int t = 0;

	deck(int n) {
		d = v(n);
		for (int &x: d)
			x = in(), t += x;
		sort(d.begin(), d.end());
		d.erase(unique(d.begin(), d.end()), d.end());
	}

	v cmp(deck &b, size_t i, size_t j) {
		if (i >= d.size() || j >= b.d.size())
			return {-1};

		int a = d[i], c = b.d[j], diff = (t - a + c) - (b.t - c + a);
		if (!diff)
			return {a, c};
		if (diff > 0)
			return cmp(b, i + 1, j);
		else
			return cmp(b, i, j + 1);
	}
};

int main() {
	int n, m;
	while (n = in(), m = in(), n || m) {
		deck a(n), b(m);
		v r = a.cmp(b, 0, 0);
		out(r);
	}
}


Measured memory_bytes: 2448
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
//#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repm(i, a, n) for (int i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vs vector<string>
#define vii vector<vector<int>>
#define vll vector<ll>
#define vllll vector<vector<ll>>
#define vd vector<double>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define reverse_v(a) reverse(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    (c) ? (cout << "Yes" << endl) : (cout << "No" << endl);
}

void Print(bool c)
{
    (c) ? (cout << "YES" << endl) : (cout << "NO" << endl);
}

template <typename T>
T gcd(T a, T b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

template <typename T>
T lcm(T a, T b)
{
    return a * b / gcd(a, b);
}

bool cmp(const pii &a, const pii &b) //セカンドキー->ファーストキーの順ソート
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

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

int main(void)
{
    int n;
    cin >> n;
    vll a(n), sum_p(n, 0);
    ll sum = 0;
    rep(i, 0, n)
    {
        cin >> a[i];
        //cout << a[i] << " ";
        sum += a[i];
    }
    sum_p[0] = a[0];
    rep(i, 1, n)
    {
        sum_p[i] = sum_p[i - 1] + a[i];
    }
    ll ans = LINF;
    rep(i, 0, n - 1)
    {
        ans = min(ans, abs(sum_p[i] - (sum - sum_p[i])));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	vector<int> vec;
	for (int i = 1; i * i <= sum; ++i) {
		if (sum % i == 0) {
			vec.push_back(i);
			vec.push_back(sum / i);
		}
	}
	int answer = 0;
	for (int div : vec) {
		int rem = 0;
		for (int i = 0; i < n; ++i) {
			rem += a[i] % div;
		}
		rem /= div;
		vector<int> b = a;
		sort(b.begin(), b.end(), [&](int x, int y) {
			return x % div > y % div;
		});
		int moves = 0;
		for (int i = 0; i < rem; ++i) {
			moves += div - b[i] % div;
		}
		if (moves <= k) {
			answer = max(answer, div);
		}
	}
	cout << answer << '\n';
 	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999

int main(){
    int n,t,l,b;
    while(cin>>n>>t>>l>>b&&(n||t||l||b)){
        bool L[110]={};
        bool B[110]={};
        rep(i,l){
            int a;
            cin>>a;
            L[a]=true;
        }
        rep(i,b){
            int a;
            cin>>a;
            B[a]=true;
        }
        
        double dp[110][110];
        rep(i,110)rep(j,110) dp[i][j]= 0;
        dp[0][0]=1;
        
        for(int i=0;i<t;i++){
            rep(j,n){
                for(int dice = 1;dice<=6;dice++){
                    int pos = j+dice;
                    if(pos>n)pos = n-(pos-n);
                    if(B[pos])  pos=0;
                    if(L[pos])  dp[i+2][pos] += dp[i][j]/6.0;
                    else        dp[i+1][pos] += dp[i][j]/6.0;

                }
            }
        }
        rep(i,t)dp[t][n]+=dp[i][n];
        printf("%.10lf\n",dp[t][n]);
    }
}

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

al = list(map(int,input().split()))

import itertools

al_ac = [0] + list(itertools.accumulate(al))


from collections import defaultdict
dic = defaultdict(int)

for a in al_ac:
    dic[a] += 1

ans = 0
for i in dic.values():
    ans += i * (i-1) // 2

print(ans)

Measured memory_bytes: 42252
#include<bits/stdc++.h>
using namespace std;
int n;
long long he[2000010];
long long yh[2000010];
int x;
long long res;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		he[i]=he[i-1]+x;
		yh[i]=yh[i-1]^x;
	}
	int le=1;
	for(int ri=1;ri<=n;ri++){
		while((he[ri]-he[le-1])!=(yh[ri]^yh[le-1]))
			le++;
		res+=(long long)(ri-le+1);
	}
	cout<<res<<endl;
	return 0;
}
//two pointers

Measured memory_bytes: 5888
n = int(input())
a = list(map(int, input().split()))
num = [0 for _ in range(n)]
c = [0 for _ in range(n)]
for i in a:
    num[i - 1] += 1

for i in range(n):
    if num[i] == 0:
        continue
    c[i] = num[i] * (num[i] - 1) // 2
# print(c)
ans = sum(c)
# print(num)
for i in a:
    tmp = (num[i - 1] - 2) * (num[i - 1] - 1) // 2 - num[i - 1] * (num[i - 1] - 1) // 2
    print(ans + tmp, )

Measured memory_bytes: 89000
#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;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

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



Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N,M;cin>>N>>M;
	for(int i=M/N;i>0;i--){
		if(M%i==0){ cout<<i<<endl; break; }
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        

fast();
//ll t;cin>>t;while(t--)
{
    string s;
    cin>>s;
    //cerr<<s<<endl;
    string f="";
     f=s[0];
     
    //cerr<<f<<endl;
    ll n=s.length(),c=1;
    for(int i=1;i<n;i++)
    {
      string sd="";
        sd=s[i];
       if(f==sd)
       {
        
        while(f==sd&&i<n)
        {
          i++;
          string t="";
          t=s[i];
          sd.append(t);
        }
        if(i<n)
         { c++;
        //cout<<"Ajit = "<<f<<" "<<sd<<endl;
        f=sd;
      }
      else
      {
        break;
      }

       }
       else
       {
        c++;
        //cout<<"Trivedi = "<<f<<" "<<sd<<endl;
        f=sd;
       }

    }
    cout<<c<<endl;
}
return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, cur = 1, ans = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
    if (a[i] != cur)
      ans++;
    else cur++;
  }
  cout << (ans != n ? ans : -1)<< '\n';
  return 0;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < n; i++) {
        cout << s[i] <<t[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<int> X(N);
  for (auto& xi: X) scanf("%d", &xi);

  std::vector<int> Y = X;
  std::sort(Y.begin(), Y.end());
  int small = Y[N/2-1];
  int large = Y[N/2];
  for (auto xi: X) {
    if (small < xi) {
      printf("%d\n", small);
    } else {
      printf("%d\n", large);
    }
  }
}


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

string divide[4] = {"dream","dreamer","erase","eraser"};

int main(){
  string s; cin >> s;
  reverse(s.begin(), s.end());
  for(int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

  bool can = true;
  for(int i = 0; i < s.size();){
    bool can2 = false;
    for(int j = 0; j < 4; ++j){
      string d = divide[j];
      if(s.substr(i, d.size()) == d){
        can2 = true;
        i += d.size();
      }
    }
    if(!can2){
      can = false;
      break;
    }
  }
  if(can) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int n,cnt[1000005],i,x;
long long ans;
int main()
{
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>x;
		cnt[x]++;
	}
	if (n&1)
	{
		for (i=2;i<=n;i+=2)
		{
			if (cnt[i]!=2)
			{
				cout<<0;
				return 0;
			}
		}
		if (cnt[0]!=1)
		{
			cout<<0;
			return 0;
		}
	}
	else
	{
		for (i=1;i<=n;i+=2)
		{
			if (cnt[i]!=2)
			{
				cout<<0;
				return 0;
			}
		}
	}
	ans=1;
	for (i=1;i<=n/2;i++) (ans*=2)%=((long long)1e9+7);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 888
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const gojo=(a:number,b:number):number=>{if(a%b===0)return b;return gojo(b,a%b)};
const main=()=>{
  let n=tn(),ans='No'
  for(let i=0;i*4<=n;i++){
    for(let j=0;i*4+j*7<=n;j++){
      if(4*i+7*j===n)ans='Yes'
    }
  }
  to(ans)
}
main()

Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    string s;cin>>s;
    int Q;cin>>Q;
    int rev=0;
    deque<char> d;
    REP(i,s.size()) d.push_back(s[i]);
    REP(_,Q){
        int T;cin>>T;
        if(T==1){
            rev=1-rev;
        }
        else{
            int f;
            char c;
            cin>>f>>c;
            if(f==1){
                if(!rev) d.push_front(c);
                else d.push_back(c); 
            }
            else{
                if(!rev) d.push_back(c);
                else d.push_front(c);
            }
        }
    }
    if(rev) reverse(All(d));
    REP(i,d.size()) cout<<d[i];
    cout<<endl;
}


Measured memory_bytes: 896
#include<stdio.h>
int main()
{
    long long n, m, a, s = 0;
    scanf("%lld%lld", &n, &m);

    a = m/2;
    if(a <= n)
        s = a;
    else
        s = n + (m - n*2)/4;
    printf("%lld", s);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

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

ll powMod(ll n, ll p, ll m) {
	if (p == 0) return 1;
	if (p == 1) return n % m;
	ll e = powMod(n, p / 2, m);
	e = (e * e) % m;
	if (p & 1)
		e = (e * n) % m;
	return e;
}

int main() {FIN
    
    ll n, m = 0, i, p, d;
    string s;
    cin >> n;
    vll ns(n + 1, -1);
    vvll md(n + 1, vll(2));
    cin >> s;
    for (i = 0; i < n; i++)
		if (s[i] == '1') m++;
	
	ns[0] = 0;
	for (i = 1; i <= n; i++)
		ns[i] = 1 + ns[i % __builtin_popcount(i)];
	
	if (m - 1 > 0) {
		p = 1;
		for (i = n - 1; i >= 0; i--) {
			if (s[i] == '1')
				md[i][0] = (md[i + 1][0] + p) % (m-1); 
			else
				md[i][0] = md[i + 1][0];
			p = (2 * p) % (m-1);
		}
	}
	if (m + 1 <= n) {
		p = 1;
		for (i = n - 1; i >= 0; i--) {
			if (s[i] == '1')
				md[i][1] = (md[i + 1][1] + p) % (m+1); 
			else
				md[i][1] = md[i + 1][1];
			p = (2 * p) % (m+1);
		}
	}
	
	for (i = 0; i < n; i++) {
		if (s[i] == '1') {
			d = m > 1 ? (1 + ns[((md[i + 1][0] + (((md[0][0] - md[i][0]) + (m-1)) % (m-1))) % (m-1))]) : 0;
		} else {
			d = 1 + ns[((((md[i + 1][1] + (((md[0][1] - md[i][1]) + (m+1)) % (m+1))) % (m+1)) + powMod(2, n-i-1, m+1)) % (m+1))];
		}
		cout << d << "\n";
	}
    
    return 0;
}


Measured memory_bytes: 16080
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, j, n) for (int i = j; i < (n); ++i)
#define SORT(a) sort(a.begin(), a.end())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = 1001001001;

bool greater_second(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return a.first > b.first;
    }
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<pair<ll,ll>> new_cards;
    rep(i,m){
        ll b,c;
        cin >> b >> c;
        pair<ll,ll> new_card;
        new_card.first = b;
        new_card.second = c;
        new_cards.push_back(new_card);
    }
    sort(a.begin(), a.end(),greater<ll>());
    sort(new_cards.begin(), new_cards.end(),greater_second);
    //rep(i,m)cout<<new_cards[i].first << ":" <<new_cards[i].second<<endl;
    
    ll ans =0;
    int p = 0;
    int q = 0;
    rep(i,n){
        if(new_cards[p].second > a[q]){
            ans+=new_cards[p].second;
            new_cards[p].first--;
            if(new_cards[p].first<=0) p++;
        }else{
            ans+=a[q];
            q++;
        }
    }
    cout<<ans<<endl;
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n; cin >> n;
    vector<vector<int>> cnt(26, vector<int>(n));
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        for (int j = 0; j < (int)s.length(); j++) {
            cnt[s[j] - 'a'][i]++;
        }
    }
    for (int i = 0; i < 26; i++) {
        int num = *min_element(cnt[i].begin(), cnt[i].end());
        for (int j = 0; j < num; j++) cout << (char)('a' + i);
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

bool dp[100010];

signed main()
{
    string s; cin>>s;
    int N=s.length();

    dp[0]=true;
    REP(i,N){
        if(dp[i]){
            if(s.substr(i,5)=="dream") dp[i+5]=true;
            if(s.substr(i,7)=="dreamer") dp[i+7]=true;
            if(s.substr(i,5)=="erase") dp[i+5]=true;
            if(s.substr(i,6)=="eraser") dp[i+6]=true;
        }
    }
    cout<<(dp[N]? "YES":"NO")<<endl;
}


Measured memory_bytes: 512
/*

Author: Ayush Shah :)
Institution: BIT Mesra :)

*/


#include<bits/stdc++.h>
using namespace std;


/*
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;  //find_by_order(), order_of_key() 
*/


#define deb(x) cout << #x << " " << x << endl
#define fast  ios_base::sync_with_stdio(false), cin.tie(NULL) , cout.tie(NULL)
#define ll long long int 
#define ld long double
#define pb  push_back
#define mp  make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define forn(i,a,n) for(ll (i) = a;(i) <= (n); (i)++)
#define vi vector<int >
#define vl vector<ll >
#define pi pair<int , int>
#define pl pair<ll , ll>
#define vpi vector< pi >
#define vpl vector< pl >
#define bigint int64_t
#define mod 1000000007
#define endl '\n'
const ll INF = 1e9 + 5;

//template<typename T>
// typedef tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


ll power(ll x, ll n){
    if(n==0)
    return 1;
    
    if(n%2)
    return (x*power((x*x)%mod, (n-1)/2))%mod;
    else
    return power((x*x)%mod, n/2);
}



int main()
{
  
      fast;

	 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    
    int n, k;
    cin >> n >> k ;
    ll h[n];
    ll dp[n];
    dp[0] = 0;
    for(int i=1; i<n; i++)
    dp[i] = INF;
    for(int i=0; i<n; i++){
    	cin >> h[i];
    }
    for(int i=0; i<n; i++){
    	for(int j =1; j<=k; j++){
    		if(i+j < n)
    		dp[i+j] = min(dp[i+j], dp[i]+abs(h[i] - h[i+j])); 
    	}
    }
    
    cout << dp[n-1] << endl;
    



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




    return 0;

}

Measured memory_bytes: 1792
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 ? "Possible" : "Impossible");
	}
}

Measured memory_bytes: 23892
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		while(true){
			boolean noFlg = false;
			int n = sc.nextInt();
			if(n == 0) break;
			map = new HashMap< String, ArrayList<Edge> >();

			while(n-- > 0){
				sc.next();
				String from = sc.next();
				sc.next();
				int cost = Integer.parseInt(sc.next().split("\\^")[1]);
				String to = sc.next();

				if(noFlg) continue;

				int res = calCost(from,to,0,new HashSet<String>());
				if(res != Integer.MAX_VALUE && res != cost){
					noFlg = true;
					continue;
				}

				if(map.get(from) == null) map.put(from,new ArrayList<Edge>());
				if(map.get(to) == null) map.put(to,new ArrayList<Edge>());
				map.get(from).add(new Edge(from,to,cost));
				map.get(to).add(new Edge(to,from,-cost));
			}

			System.out.println(noFlg ? "No" : "Yes");
		}
	}

	private static HashMap<String,ArrayList<Edge>> map;

	private static int calCost(String from,String to,int cost,HashSet<String> used){
		if(from.equals(to)) return cost;
		if(used.contains(from) || map.get(from) == null) return Integer.MAX_VALUE;

		used.add(from);
		for(Edge e : map.get(from)){
			int res = calCost(e.to,to,cost+e.cost,used);
			if(res != Integer.MAX_VALUE) return res;
		}

		return Integer.MAX_VALUE;
	}
}

class Edge{
	String from,to;
	int cost;

	public Edge(String from,String to,int cost){
		this.from = from;
		this.to = to;
		this.cost = cost;
	}

	public String toString(){
		return String.format("[%s->%s,%d]",from,to,cost);
	}
}

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

int main() {
  long long x;
  cin >> x;
  int year = 0;
  long long yokin = 100;
  while(1){
    long long rishi = yokin*0.01;
    yokin += rishi;
    year++;
    if(yokin >= x){
      cout << year << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3636
def lcs(m,n):
	N=len(n)
	dp=[0]*(N+1)
	for x in m:
		dp_kari=dp[:]
		for j, y in enumerate(n):
			if x==y:
				dp[j+1]=dp_kari[j]+1
			elif dp[j+1]<dp[j]:
				dp[j+1]=dp[j]
	return dp[N]
import sys
for _ in range(int(input())):
	m=sys.stdin.readline().rstrip()
	n=sys.stdin.readline().rstrip()
	print(lcs(m,n))


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

pair<int, int> popStack(stack<string>* s) {
    int s2 = stoi((*s).top());
    (*s).pop();
    int s1 = stoi((*s).top());
    (*s).pop();
    return make_pair(s1, s2);
}

int main() {
    stack<string> s;

    string str, v;
    getline(cin, str);

    stringstream ss{str};
    while (getline(ss, v, ' ')) {
        pair<int, int> op;
        if (v[0] == '+') {
            op = popStack(&s);
            s.push(to_string(op.first + op.second));
        } else if (v[0] == '-') {
            op = popStack(&s);
            s.push(to_string(op.first - op.second));
        } else if (v[0] == '*') {
            op = popStack(&s);
            s.push(to_string(op.first * op.second));
        } else {
            s.push(v);
        }
    }

    cout << s.top() << endl;
    return 0;
}



Measured memory_bytes: 3308
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin>>K;
  cout<<A[K-1]<<endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
s = 0
temp = -100
for i in a:
    s += b[i - 1]
    if temp + 1 == i:
        s += c[temp - 1]
    temp = i
print(s)


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

int main()
{
    int m, n;
    int a[100000];

    std::cin >> n >> m;

    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    uint64_t b[100001];
    b[0] = 0;
    for (int i = 1; i <= n; i++) {
        b[i] = b[i - 1] + a[i - 1];
    }

    std::unordered_map<int, uint64_t> map;
    for (int i = 1; i <= n; i++) {
        int mod = b[i] % m;
        map[mod] += 1;
    }

    uint64_t count_sum = 0;
    for (auto& e : map) {
        count_sum += (e.second * (e.second - 1)) / 2;
    }
    if (map.count(0) != 0) {
        count_sum += map[0];
    }

    std::cout << count_sum << std::endl;

    return 0;
}


Measured memory_bytes: 5152
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 1000000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define eps 0.000001
#define endl '\n'
#define mo 998244353
 
using namespace std ;
 
#define MAXN 10000000 + 2
 
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

int main()
{
////////////////////////////////////////////
    fastio;
    
    lli a,b;
    cin>>a>>b;

    if(a>=13)
        cout<<b<<endl;

    else if(a<=12 && a>=6)
        cout<<b/2<<endl;

    else cout<<0<<endl;


}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int H=in.nextInt(),W=in.nextInt();
		int field[][]=new int[H][W];
		
		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				field[i][j]=Integer.parseInt(in.next())==1 ? 0 : 1;
			}
		}
		
		int max=0;
		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				if(field[i][j]>=1 && isBS(field,i,j)) {
					field[i][j]=Math.min(field[i-1][j], Math.min(field[i][j-1],field[i-1][j-1]))+1;
				}
				max=Math.max(max, field[i][j]);
			}
		}

		System.out.println(max*max);
	}
	
	static boolean isBS(int A[][],int y,int x) {
		if(y-1<0 || x-1<0)return false;
		if(A[y-1][x]>=1 && A[y][x-1]>=1 && A[y-1][x-1]>=1){
			return true;
		}
		else return false;
	}

}



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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll inf = LONG_LONG_MAX / 2 - 1;
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll mx = -inf, mn = inf;
    map<ll, ll> cnt;
    rep(i, n) {
        cin >> a[i];
        mx = max(mx, a[i]);
        mn = min(mn, a[i]);
        cnt[a[i]]++;
    }
    bool ans = true;
    if (mx % 2 == 0) {
        if (mn != (mx / 2)) ans = false;
        if (cnt[mn] != 1) ans = false;
    }
    else {
        if (mn != ((mx + 1) / 2)) ans = false;
        if (cnt[mn] != 2) ans = false;
    }
    reps(i, mn + 1, mx + 1) {
        if (cnt[i] < 2) ans = false;
    }
    cout << (ans ? "Possible" : "Impossible") << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
int C[100010]={0};
int blmn(int v,int e,int s,int *fr,int *to,int *co){
  int i,j,f;
  for(i=0;i<v;i++)C[i]=1000000000;
  for(i=C[s]=0;i<v;i++){
    for(j=0;j<e;j++){
      if(C[fr[j]]-1000000000&&C[to[j]]>C[fr[j]]+co[j]){
	C[to[j]]=C[fr[j]]+co[j];
	if(i==v-1)return 1;
      }
    }
  }
  return 0;
}
int main(){
  int n,m,s,i,a[100010],b[100010],c[100010];
  scanf("%d %d %d",&n,&m,&s);
  for(i=0;i<m;i++)scanf("%d %d %d",&a[i],&b[i],&c[i]);
  if(blmn(n,m,s,a,b,c))printf("NEGATIVE CYCLE\n");
  else{
    for(i=0;i<n;i++){
      C[i]-1000000000?printf("%d\n",C[i]):printf("INF\n");
    }
  }
  return 0;
}

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

int main() {
	int a,b,c,x;
    scanf("%d%d%d%d",&a,&b,&c,&x);
	int co=0;
	for(int i=0;i<=a;i++){
	    for(int j=0;j<=b;j++){
	        for(int k=0;k<=c;k++){
	            if(500*i+100*j+50*k==x)
	            co++;
	        }
	    }
	}
	printf("%d",co);
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "sstream"
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const int N=1e5+1;
bool isprime[N]; vector<int>like; int ans;
void sieve(int n) {
memset(isprime,1, sizeof(isprime));
isprime[0]=isprime[1]=0;
    for (int i = 2; i*i <=n ; i++)
        if (isprime[i])
            for (int j = i * i; j <= n; j += i)
                isprime[j] = 0;
for(int i=1;i<=n;i+=2)
    if(isprime[i]&&isprime[(i+1)/2])
      like.push_back(i);
}
int main() {
    quick
sieve(1e5);
    int q,l,r; scanf("%d",&q);
   while(q--){
       scanf("%d %d",&l,&r); ans=0;
       for(auto i:like){
           if(i>=l&&i<=r){ans++;}
       if(i>r){break;}
       }
       printf("%d\n",ans);
   }
}

Measured memory_bytes: 768
#include<stdio.h>
int main(){
  int n,i;
  long long m=0,a=0,r=0,c=0,h=0,count=0;
  scanf("%d",&n);
  char s[n+1][11];
  for(i=0;i<n;i++){
    scanf("%*c%s",s[i]);
    if(s[i][0]=='M')
      m++;
    else if(s[i][0]=='A')
      a++;
    else if(s[i][0]=='R')
      r++;
    else if(s[i][0]=='C')
      c++;
    else if(s[i][0]=='H')
      h++;
  }
  count=m*a*(r+c+h)+m*r*(c+h)+m*c*h+a*r*(c+h)+a*c*h+r*c*h;
  printf("%lld\n",count);
  return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
using namespace std;
const int N=1e5+10;
int sm,n,t,q,a,r[N],v[N];
int main(){
	scanf("%d%d",&sm,&n);
	for (int i=1;i<=n;++i) scanf("%d",r+i);
	for (int i=n;i;--i) v[i]=r[i]-r[i-1];
	int low=0,lh=0;
	int up=sm,uh=sm;
	int pos=0;r[n+1]=2e9;
	scanf("%d",&q);
	while (q--){
		scanf("%d%d",&t,&a);
		while (r[pos+1]<=t){
			++pos;
			if (pos&1){//ÏòÏÂv[pos] 
				if (lh<v[pos]) low+=v[pos]-lh;
				lh=max(lh-v[pos],0);
				uh=max(uh-v[pos],0);
			}else{//ÏòÉÏ 
				if (uh+v[pos]>sm) up-=uh+v[pos]-sm;
				lh=min(lh+v[pos],sm);
				uh=min(uh+v[pos],sm);
			}
			low=min(low,sm);
			up=max(up,0);
		}
		t-=r[pos];
		if (a<=low) a=lh;
		else if (a>=up) a=uh;
		else a=lh+a-low;
		if (pos&1) printf("%d\n",min(a+t,sm));else printf("%d\n",max(a-t,0));
	}
	return 0;
}

Measured memory_bytes: 2048
h = Hash.new(0)
s = gets.chomp
4.times do |i|
  h[s[i]] += 1
end
if h.keys.length != 2
    puts "No"
    exit
end
h.values.each do |e|
    if e != 2
        puts "No"
        exit
    end
end
puts "Yes"

Measured memory_bytes: 1788
y,m,d = [int(i) for i in input().split('/')]

if y < 2019:
    print('Heisei')
elif y > 2019:
    print('TBD')
else:
    if m < 4:
        print('Heisei')
    elif m > 4:
        print('TBD')
    else:
        if d <= 30:
            print('Heisei')
        else:
            print('TBD')

Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  string S="NO";
  int A,B,C;
  cin>>A>>B>>C;
  if(A+C==2*B) S="YES";
  cout<<S;
return 0;}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;

signed main() {
int tt;
cin>>tt;
while(tt){
  vector<int> byou(86401);
  rep(i,tt){
    string t1,t2;
    cin>>t1>>t2;
    int iri,de;
    iri=(((int)t1[0]-48)*10+((int)t1[1]-48))*3600+(((int)t1[3]-48)*10+(int)t1[4]-48)*60+((int)t1[6]-48)*10+(int)t1[7]-48;
    de=(((int)t2[0]-48)*10+((int)t2[1]-48))*3600+(((int)t2[3]-48)*10+(int)t2[4]-48)*60+((int)t2[6]-48)*10+(int)t2[7]-48;
    byou[iri]++;
    byou[de]--;
  }
  vector<int>s(86402);
int tmax=0;
  rep(i,86401){
    s[i+1]=s[i]+byou[i];
    tmax=max(tmax,s[i+1]);
  }

  cout<<tmax<<endl;
  cin>>tt;
}
}



Measured memory_bytes: 4248
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  ll x; cin >> x;
  vector<ll> cnt(51), pat(51);
  cnt[0] = 1;
  pat[0] = 1;
  rep(i, 51) {
    if(i) {
      cnt[i] = 2*cnt[i-1]+3;
      pat[i] = 2*pat[i-1]+1;
    }
  }
  auto dfs = [&](auto dfs, int lev, ll x) -> ll {
    if(x == 0) return 0;
    if(lev == 0) return 1;
    if(x < cnt[lev-1]+2) {
      return dfs(dfs, lev-1, x-1);
    } else if(x == cnt[lev-1]+2) {
      return pat[lev-1]+1;
    } else {
      return pat[lev-1]+1+dfs(dfs, lev-1, x-cnt[lev-1]-2);
    }
  };
  cout << dfs(dfs, n, x) << endk;
  return 0;
}


Measured memory_bytes: 3600
require 'set'

N = gets.to_i
S = gets.chomp.chars.map(&:to_i)
idx = Hash.new
S.each.with_index do |n, i|
  idx[n] ||= []
  idx[n].push(i)
end

ans = 0
(0..999).each do |n|
  n1, n2, n3 = n.to_s.rjust(3, '0').chars.map(&:to_i)
  idx1 = idx[n1]
  next unless idx1
  i1 = idx1[0]
  idx2 = idx[n2]
  next unless idx2
  i2 = idx2.bsearch { |i2| i2 > i1 }
  next unless i2
  idx3 = idx[n3]
  next unless idx3
  i3 = idx3.bsearch { |i3| i3 > i2 }
  next unless i3
  ans += 1
end
puts ans


Measured memory_bytes: 4348
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
using ll = long long; 
using P = pair<int,int>;
using vv = vector<vector<ll>>;
template <class _t> inline bool chmax (_t& a,_t b){if(a<b){a=b;return true;}return false;}
template <class _t> inline bool chmin (_t& a,_t b){if(a>b){a=b;return true;}return false;}

const long long inf = 1ll << 60;
const long long mod = 1000000007;

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

int main() {
    int n; cin >> n;
    int ans = 0;
    for(int i=1;i<=n;i+=2){
	int t=0;
	for(int j=1;j<=i;j++){
	    if(i%j==0)t++;
	}
	if(t==8)ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int N;
const int MAX_N = 1.0e5 + 100;
int a[MAX_N];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> a[i];

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (i+1 < a[i] && a[a[i] -1] == i+1) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


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


int main()
{
  string s;
  cin >> s;

  int min = 200100;
  int max = -1;
  for (int i = 0; i < s.size(); i++)
  {
    if(s.at(i) == 'A'){
        
        if(min > i){
          min = i;
        }
      }
    else if (s.at(i) == 'Z')
    {
      if(max < i){
        max = i;
      }
    }
  }
  int ans = max - min + 1;
  cout << ans << endl;
}


Measured memory_bytes: 640
def is_5mod1_prime(n):
    if n == 1:
        return False
    if n % 5 != 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


N = int(input())
primes = []
for i in range(55555):
    i += 1
    if is_5mod1_prime(i):
        primes.append(i)

ans = primes[:N]
print(' '.join([str(a) for a in ans]))


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

inline int read()
{
	int ret=0; char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	return ret;
}

const int N = 2005;
const int M = 1002005;
const int INF = 0x7fffffff;


int tot,n,a[105],b[106],ccc[105],d[105],ans,S,T,c[M][3],aa[N];
queue<int> q;
int dep[N];

bool bfs()
{
    while(!q.empty()) q.pop();
    memset(dep,0,sizeof(dep));
    q.push(S); dep[S] = 1;
    while(!q.empty())
    {
        int cc = q.front(); q.pop();
        for(int i=aa[cc]; i; i=c[i][1])
        {
            if(c[i][2]>0 && !dep[c[i][0]])
            {
                dep[c[i][0]] = dep[cc]+1;
                q.push(c[i][0]); 
            }
        }
    }
    if(dep[T]) return true;
    else return false;
}

int dfs(int pos,int cur)
{
    if(pos==T) return cur;
    int rst = cur;
    for(int i=aa[pos]; i; i=c[i][1])
    {
        if(dep[c[i][0]]==dep[pos]+1 && c[i][2] && rst)
        {
            int flow = dfs(c[i][0],min(c[i][2],rst));
            if(flow>0)
            {
                c[i][2] -= flow;
                rst -= flow;
                c[i^1][2] += flow;
            }
        }
    }
    return cur-rst;
}

int dinic()
{
    int ans = 0;
    while(bfs()) ans += dfs(S,INF);
    return ans;
}

void addedge(int u,int v,int val)
{
    c[++tot][0]=v; c[tot][1]=aa[u]; aa[u]=tot; c[tot][2]=val;
}

int main()
{
	n=read();
	for(int i=1; i<=n; ++i)a[i]=read(),b[i]=read();
	for(int i=1; i<=n; ++i)ccc[i]=read(),d[i]=read();
	
	S=1; T=n*3; tot=1;
	for(int i=1; i<=n; ++i){
		addedge(S,i+1,1);
        addedge(i+1,S,0);
	}
	for(int i=1; i<=n; ++i)
	for(int j=1; j<=n; ++j)if(a[i]<ccc[j]&&b[i]<d[j]){
		addedge(i+1,j+n+1,1);
        addedge(j+n+1,i+1,0);
	}
	for(int i=1; i<=n; ++i){
		addedge(i+n+1,T,1);
        addedge(T,i+n+1,0);
	}
	printf("%d\n",dinic()); 
}

Measured memory_bytes: 384
from itertools import product
import sys

a = []
for line in sys.stdin:
        a.append(int(line.strip()))

p = list(product(range(0, 10), range(0, 10), range(0, 10), range(0, 10)))
for n in a:
    cnt = 0;
    for e in p:
        if sum(e) == n:
            cnt += 1
    print(cnt)

Measured memory_bytes: 8372
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		long result = 0;
		for(int i = 1; i <= n; i++){
			int l = n / i * i;

			result += ((long)n / i) * (i + l) / 2;
		}

		System.out.println(result);
	}
}

Measured memory_bytes: 27208
#include <stdio.h>
int main(){
  int a,b,c,i,j = 0;
  scanf("%d %d %d",&a,&b,&c);
  for(i = a ; i <= b ; i++){
    if(c % i ==0) j++;
  }
  printf("%d\n",j);
  return 0;
}

Measured memory_bytes: 596
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use List::Util qw/sum/;

my $n = <STDIN>;
my @x = split /\s+/, <STDIN>;
my @y = sort {$a <=> $b} @x;
my $center = $y[$n / 2];

for (0..($n - 1)) {
    if ($n % 2 == 1 && $x[$_] <= $center) {
        print "$y[$n / 2 + 1]\n";
    } elsif ($n % 2 == 0 && $x[$_] >= $center) {
        print "$y[$n / 2 - 1]\n";
    } else {
        print "$center\n";
    }
}


Measured memory_bytes: 51848
while True:
    s=input().split()
    op=s[1]
    if not (op=="+" or op=="-" or op=="*" or op=="/"):
        break
    a=int(s[0])
    b=int(s[2])
    if op=="+":
        print(a + b)
    elif op=="-":
        print(a - b)
    elif op=="*":
        print(a * b)
    elif op=="/":
        print(int(a / b))


Measured memory_bytes: 5596
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

typedef long long ll;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e3 + 50;

int main() {
	int sx, sy, ex, ey;
	scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
	for(int i = sx; i < ex; ++i) putchar('R');
	for(int i = sy; i < ey; ++i) putchar('U');
	for(int i = sx; i < ex; ++i) putchar('L');
	for(int i = sy; i < ey; ++i) putchar('D');
	putchar('D');
	for(int i = sx; i <= ex; ++i) putchar('R');
	for(int i = sy; i <= ey; ++i) putchar('U');
	putchar('L');
	putchar('U');
	for(int i = sx; i <= ex; ++i) putchar('L');
	for(int i = sy; i <= ey; ++i) putchar('D');
	putchar('R');
	putchar('\n');
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d,k,l;
    cin>>a>>b>>c>>d;
    k=a/d;
    if(a%d!=0)
    {
        k++;
    }
    l=c/b;
    if(c%b!=0)
    {
        l++;
    }
    if(l<=k)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n;
P p[100010];
set<P> st;//second,firstの順
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> p[i].first;
		p[i].second = i;
	}
	sort(p, p + n, greater<P>());
	int ans = 0;
	rep(i, n) {
		int s0, s1, t0, t1;
		if (st.upper_bound(make_pair(p[i].second, INF)) != st.end()) {
			P m = *st.upper_bound(make_pair(p[i].second, INF));
			s0 = m.first - 1;
			if (st.upper_bound(m) != st.end())s1 = st.upper_bound(m)->first - 1;
			else s1 = n - 1;
		}
		else {
			s0 = n - 1;
			s1 = n - 1;
		}
		if (st.upper_bound(make_pair(p[i].second, INF)) != st.begin()) {
			P m = *(--st.upper_bound(make_pair(p[i].second, INF)));
			t0 = m.first + 1;
			if (st.lower_bound(m) != st.begin())t1 = (--st.lower_bound(m))->first + 1;
			else t1 = 0;
		}
		else {
			t0 = 0;
			t1 = 0;
		}
		ans += p[i].first * ((s0 - p[i].second + 1) * (t0 - t1) + (s1 - s0) * (p[i].second - t0 + 1));
		st.insert(make_pair(p[i].second, p[i].first));
	}
	cout << ans << endl;
}

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

long long gcd(long long x, long long y){
    if(x < y) swap(x, y);
    long long r = x % y;
    if(r == 0) return y;
    else return gcd(y, r);
}

long long lcm(long long x, long long y){
    return x * y / gcd(x, y);
}

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

    long long a, b;
    cin >> a >> b;
    cout << lcm(a, b) << endl;

    return 0;
}

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

def dfs(s):
    ret = 0
    if int(s) > n:
        return ret
    if all(s.count(i) > 0 for i in '753'):
        ret += 1
    for i in '753':
        ret += dfs(s + i)
    return ret

print(dfs('0'))

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
a = [0] * N
b = [0] * N

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

a, b = zip(*sorted(zip(a, b)))

for i in range(N):
    K -= b[i]
    if K <= 0:
        print(a[i])
        exit()
    else:
        continue

Measured memory_bytes: 26056
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int N, K;
    cin >> N >> K;

    long long ans = 0;
    long long temp = N / K;
    ans += temp * temp * temp;
    if(K % 2 == 0 && N >= K / 2){
        long long temp2 = (N - (K / 2)) / K + 1;
        ans += temp2 * temp2 * temp2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256