akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
ll dp[55][55][5000];

signed main(){
	//cout << fixed << setprecision(10);
	ll n,m,x; cin>>n>>m>>x;
	vl c(n);
	vvl g(n,vl(m));
	rep(i,0,n){
		cin>>c[i];
		rep(j,0,m){
			cin>>g[i][j];
		}
	}
	ll ans=MOD;
	rep(i,0,1<<n){
		vl cnt(m);
		ll cost=0;
		rep(j,0,n){
			if(i>>j&1){
				cost+=c[j];
				rep(k,0,m)cnt[k]+=g[j][k];
			}
		}
		bool ok=true;
		rep(k,0,m)if(cnt[k]<x)ok=0;
		if(ok)chmin(ans,cost);
	}
	cout <<(ans==MOD ? -1:ans) <<endl;
		


	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#define fs first
#define se second

using namespace std;
typedef long long llong;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int H, W, n;

pll seg[1 << 20];
vector<int> X, Y;

void init(int i, int s, int e, int v) {
    seg[i] = pll(v - X[s], 0);
    if (s == e) return;
    int m = (s + e) / 2;
    init(i << 1, s, m, v);
    init(i << 1 | 1, m + 1, e, v);
}

void update(int i, int s, int e, int x, int y, int v) {
    if (e < x || y < s) return;
    if (x <= s && e <= y) {
        seg[i].fs += v;
        seg[i].se += v;
        return;
    }
    int m = (s + e) / 2;
    update(i << 1, s, m, x, y, v);
    update(i << 1 | 1, m + 1, e, x, y, v);
    seg[i].fs = max(seg[i << 1].fs, seg[i << 1 | 1].fs) + seg[i].se;
}

const llong inf = 1e18;
llong query(int i, int s, int e, int x, int y) {
    if (e < x || y < s) return -inf;
    if (x <= s && e <= y) return seg[i].fs;
    int m = (s + e) / 2;
    return max(query(i << 1, s, m, x, y), query(i << 1 | 1, m + 1, e, x, y)) + seg[i].se;
}

int find(int x) {
    return lower_bound(X.begin(), X.end(), x) - X.begin();
}

void update(vector<pii> &st, int x, int y, int mx) {
    while (!st.empty() && st.back().se >= y) {
        pii e = st.back();
        st.pop_back();
        int s = st.empty() ? 0 : st.back().fs;
        update(1, 0, X.size() - 1, find(s), find(e.fs) - 1, mx - e.se);
    }
    int s = st.empty() ? 0 : st.back().fs;
    update(1, 0, X.size() - 1, find(s), find(x) - 1, y - mx);
    st.emplace_back(x, y);
}

int dnc(vector<pii> &P, int s = 0, int e = Y.size() - 1) {
    if (e - s <= 1) return W + Y[e] - Y[s];
    int m = (s + e) / 2;
    int Hs = Y[s], Hm = Y[m], He = Y[e];
    X.clear();
    X.push_back(0);
    for (pii i : P) X.push_back(i.fs);
    X.push_back(W);
    X.erase(unique(X.begin(), X.end()), X.end());
    init(1, 0, X.size() - 1, He - Hs);
    int ret = 0;
    vector<pii> U, D;
    for (int i = 0, j = 0; i < X.size(); ++i) {
        ret = max(ret, (int)query(1, 0, X.size() - 1, 0, i) + X[i]);
        while (j < P.size() && P[j].fs <= X[i]) {
            if (Hm <= P[j].se) update(U, P[j].fs, P[j].se - Hm, He - Hm);
            if (Hm >= P[j].se) update(D, P[j].fs, Hm - P[j].se, Hm - Hs);
            ++j;
        }
    }
    vector<pii> L, R;
    for (pii i : P) {
        if (Hm > i.se) L.push_back(i);
        if (Hm < i.se) R.push_back(i);
    }
    ret = max(ret, dnc(L, s, m));
    ret = max(ret, dnc(R, m, e));
    return ret;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> W >> H >> n;
    vector<pii> P;
    Y.push_back(0);
    Y.push_back(H);
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        if (x == 0 || x == W || y == 0 || y == H) continue;
        P.emplace_back(x, y);
        Y.push_back(y);
    }
    sort(Y.begin(), Y.end());
    Y.erase(unique(Y.begin(), Y.end()), Y.end());
    sort(P.begin(), P.end());
    printf("%d\n", dnc(P) << 1);
    return 0;
}


Measured memory_bytes: 33888
try:
     (n)  =  int(input())
except:
    exit

i = 1
end_check = False
while True:
    x = i
    if ( x % 3 == 0):
        print(' {}'.format(i),end="")
        end_check = True

    while end_check == False:
        if ( x % 10 == 3):
            print(' {}'.format(i),end="")
            end_check = True
        x = x // 10
        if (x == 0):
            end_check =True

    i += 1
    if (i > n ):
            break
    end_check = False
print ("")


Measured memory_bytes: 5876
#include <stdio.h>
#include <math.h>

int main(void){
    double a, b, c, d, e, f;
    double det;
    double x, y;
    while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF){
        det = a * e - b * d;
        if(det != 0){
            x = (e * c - b * f) / det;
            y = (a * f - d * c) / det;
            // 答えが-0になる場合は0に直さないと通らないので直す
            x = (x == fabs(x)) ? fabs(x) : x;
            y = (y == fabs(y)) ? fabs(y) : y;
            printf("%.3f %.3f\n", x , y);
        }
    }
    return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,L,R,S;
  S = 0;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> L >> R;
    S += (R - L + 1);
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // ver2.2.2
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ

int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}

int stpow(int n){
   if(n==0)return 1;
   int a=1;
   rep(i,1,n+1)a=a*i%MOD;
   return a;
 }

signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n;
  cin >> n;
  string s,t;
  cin >> s;
  rep(i,0,n){
    t += "WB";
  }
  //cout<<t<<endl;
  Vi a(2*n);
  int ct=0;
  rep(i,0,2*n){
    if(s[i]!=t[i]) {
      ct++;
      a[i] = 1;
    }
  }
  //cout<<ct<<endl;
  //Vout(a);
  
  if(s.back()=='W'||s[0]=='W'){cout<<0<<endl;return 0;}
  if(ct!=n){cout<<0<<endl;return 0;}
  int ans = stpow(n);
  
  int now=0;
  repreq(i,2*n-1,0){
    if(a[i]==0) now++;
    else {
      ans = ans*now%MOD;
      now--;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
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; }

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

    ll N; cin >> N;
    vl A(N); REP(i, N) cin >> A[i];
    vl sum(N+1); 
    REP(i, N) 
    {
        sum[i+1] += sum[i] + A[i];
        sum[i+1] %= MOD;
    }
    ll ans = 0;
    REP(i, N)
    {
        ll t = (sum[N] - sum[i+1] + MOD) % MOD;
        ans += A[i] * t;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6364
a, b, c, x, y = list(map(int, input().split()))
res = a * x + b * y
for i in range(1, max(x, y) + 1):
    res = min(res, a * max(x - i, 0) + b * max(y - i, 0) + 2 * c * i)
print(res)

Measured memory_bytes: 3060
#include<stdio.h>
#define NUM 10000

int main(){
  int i,j,count=0,n;
  int a[NUM];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  for(i=0;i<n;i++){
    for(j=2;j*j<=a[i];j++){
      if(a[i]%j==0){
	count++;
	break;
      }
    }
    
  }

  printf("%d\n",n-count);

}



Measured memory_bytes: 2056
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

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

    bool flag =0;
    for(int i = 0; i < 5; i++)
    {
        for(int j = 0; j < 5; j++)
        {
            int d = N[i]-N[j];
            d = abs(d);
            if (d>k) {
                flag = 1;
                break;
            }
            
        }
        if (flag) {
            break;
        }
        
    }

    if (!flag) {
        cout << "Yay!" << endl;
    }else
    {
        cout << ":(" << endl;
    }
    
}

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

int n;
int main(){
    std::cin >> n;
    std::vector<int> a(n+1);
    int light=1;
    for (int i = 1; i <= n; i++) {
        /* code */
        std::cin >> a.at(i);
    }
    int i;
    for (i = 1; i < n+1; i++) {
        light=a.at(light);
        if(light==2){
            std::cout << i << std::endl;
            break;
        }
    }
    if(i==n+1){
        std::cout << -1 << std::endl;
    }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
 
unsigned long long int matrix(unsigned long long int p[], int n)
{
	unsigned long long int arr[n+1][n+1];
	unsigned long long int color[n+1][n+1];
	for(int i=1;i<=n;i++)
	{arr[i][i]=0;
	color[i][i]=p[i-1];
	}
	

	
	for(int l=2;l<=n;l++)
	{
		for(int i=1;i<=n-l+1;i++)
		{
			int j=i+l-1;
			arr[i][j]=1000000000000000;
			for(int k=i;k<=j-1;k++)
			{
			   unsigned	long long int pp=arr[i][k]+arr[k+1][j]+color[i][k]+color[k+1][j];
				if(pp<arr[i][j])
				{arr[i][j]=pp;
				color[i][j]=color[i][k]+color[k+1][j];
			    }
			}
		}
	}
	

   
	return arr[1][n];
}
 
 
 
int main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin>>n;
	
	unsigned long long int arr[n];
	for(int i=0;i<n;i++)
	cin>>arr[i];
	
	cout<<matrix(arr,n)<<endl;
    
	
	return 0;
} 

Measured memory_bytes: 2816
#include <stdio.h>

int main()
{
    int i,j,temp;
    long long int m[10];
    for(i=0;i<10;i++)
        {
            scanf("%lld",&m[i]);
        }
    for(i=0;i<9;i++)
    {
        for(j=0;j<10-i-1;j++)
        {
            if (m[j] < m[j+1])
            {
                temp = m[j];
                m[j] = m[j+1];
                m[j+1] = temp;
            }
        }
    }
    for(i=0;i<3;i++)
    {
        printf("%lld\n",m[i]);
    }
    return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"
using namespace std;
int main() {
	int X,Y,A,B,C;
	cin >> X >> Y >> A >> B >> C; 
	multiset<long long>AppleA; 
	multiset<long long>AppleB;
	multiset<long long>Apple;
	for (int n = 0;n<A;++n) {
		long long  num;
		cin >> num;
		AppleA.insert(num);
	}
	for (int n = 0; n < B; ++n) {
		long long num;
		cin >> num;
		AppleB.insert(num);
	}
	{
		int count = 0;
		for (auto itr = AppleA.begin(); itr != AppleA.end(); ++itr) {
			if (count >= A-X) {
				Apple.insert(*itr);
			}
			count++;
		}
	}
	{
		int count = 0;
		for (auto itr = AppleB.begin(); itr != AppleB.end(); ++itr) {
			if (count >= B-Y) {
				Apple.insert(*itr);
			}
			count++;
		}
	}
	for (int n = 0; n < C; ++n) {
		long long num;
		cin >> num;
		Apple.insert(num);
	}
	long long ans = 0;
	int count = 0;
	for (auto itr = Apple.begin(); itr != Apple.end(); ++itr){
		if (count >= C) {
			ans += *itr;
		}
		count++;
	}
	cout <<ans << endl;
	return 0;
}


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

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

   cout << max(a, b) + max(min(a, b), max(a, b)-1) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
char s[3001],t[3001];int ans[3001][3001];
int last[3001][3001];
int main()
{
    scanf("%s%s",s+1,t+1);
    vector<char> vec;
    ans[0][0]=ans[1][0]=ans[0][1]=0;

    for (int i=1;s[i];++i)
    for (int j=1;t[j];++j){
        ans[i][j]=max(ans[i-1][j],ans[i][j-1]);
        if (ans[i][j]==ans[i-1][j]) last[i][j]=1; else last[i][j]=2;
        if(s[i]==t[j] && ans[i-1][j-1]+1>ans[i][j]){
            last[i][j]=3;
            ans[i][j]=ans[i-1][j-1]+1;
        }

    }
    int t1=1,t2=1;while (s[t1]) t1++;while(t[t2]) t2++;
    --t1;--t2;


    while(t1 && t2){
        //printf("%d %d %d\n",t1,t2,last[t1][t2]);
        if (last[t1][t2]==1) t1--;
        else if (last[t1][t2]==2) t2--;
        else vec.push_back(s[t1]),--t1,--t2;
    }

    for (int i=0;i<vec.size();++i)
        printf("%c",vec[ vec.size()-i-1 ]);
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

string a;

int main(){
    cin >> a;
    int ans = 0;
    rep(i,a.size()/2-(a.size()%2 == 0)){
        string s = a.substr(0,i+1);
        string t = a.substr(i+1,i+1);
        if(s == t)ans = max(2*(i+1),ans);
    }
    cout << ans << endl;
}

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

int ans;
string S, T;
int main() {
	cin >> S >> T;
	for (int i = 0; i < S.length(); i++) {
		if (S[i] != T[i]) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3892
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n;
    if(n%2==0) m=n/2;
    else m=(n/2)+1;
    double ans=double(m)/double(n);
    cout<<fixed<<setprecision(10)<<ans<<endl;
    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <deque>
#include <cmath>

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

using namespace std;

inline double comb(const int n, int r)
{
  if (n == 0)
  {
    return 0;
  }
  if (r == 0)
  {
    return 1;
  }
  if (r == 1)
  {
    return n;
  }
  if (n == r)
  {
    return 1;
  }

  if (r > n / 2)
  {
    r = n / 2;
  }

  double result = 1;
  for (double i = 1; i <= r; i++)
  {
    result *= (n - i + 1) / i;
  }

  return (result);
}

int main()
{
  int n, m;

  cin >> n >> m;

  int res = 0;

  // 偶数同士
  if (n != 1)
    res += comb(n, 2);

  // 奇数同士
  if (m != 1)
    res += comb(m, 2);

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  int d[100001] = {};
  int sum = 0;
  REP(i, n){
    cin >> a[i];
    d[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  while(q--){
    int b, c;
    cin >> b >> c;
    int tmp = d[b];
    d[b] = 0;
    d[c] += tmp;
    sum = sum - tmp * b + tmp * c;
    cout << sum << endl;
  }
}

Measured memory_bytes: 4772
//:::: Alien :::://
// Muhammad Eid //
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define prINT pair<int, int>

//const int N = 100 +5;

void Mo35(){ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}

int main(){
Mo35();

    int n; cin>> n;
    cout<< n*(n+1)*0.5;

return 0;
}


Measured memory_bytes: 3796
#include <iostream>

using namespace std;

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

  string res;
  for (int i = 0; i < inputString.size(); i++) {
    if (inputString[i] == 'B' && inputString.size() != 0) {
      res = res.substr(0, res.size() - 1);
    }
    else if (inputString[i] == '1' || inputString[i] == '0') {
      res += inputString[i];
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
    long long n,i=1,x=0;
    char ans[20];
    scanf("%lld",&n);
    while(1){
        if(n>(long long)ceil(pow(26,i))){
            n = n-(long long)ceil(pow(26,i));
        }
        else{
            n-=1;
            for(int j=0;j<i;j++){
                ans[x]=(97+n%26);
                x++;
                n/=26;
            }
            break;
        }
        i++;
    }
    for(i=x-1;i>=0;i--) printf("%c",ans[i]);
}

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

// Ï·e[u
map < char, string > M;
map < string, char > D;

int main( void )
{
	M['A'] = "00000";
	M['B'] = "00001";
	M['C'] = "00010";
	M['D'] = "00011";
	M['E'] = "00100";
	M['F'] = "00101";
	M['G'] = "00110";
	M['H'] = "00111";
	M['I'] = "01000";
	M['J'] = "01001";
	M['K'] = "01010";
	M['L'] = "01011";
	M['M'] = "01100";
	M['N'] = "01101";
	M['O'] = "01110";
	M['P'] = "01111";
	M['Q'] = "10000";
	M['R'] = "10001";
	M['S'] = "10010";
	M['T'] = "10011";
	M['U'] = "10100";
	M['V'] = "10101";
	M['W'] = "10110";
	M['X'] = "10111";
	M['Y'] = "11000";
	M['Z'] = "11001";
	M[' '] = "11010";
	M['.'] = "11011";
	M[','] = "11100";
	M['-'] = "11101";
	M['\''] = "11110";
	M['?'] = "11111";

	D["101"]		= ' ';
	D["000000"]		= '\'';
	D["000011"]		= ',';
	D["10010001"]	= '-';
	D["010001"]		= '.';
	D["000001"]		= '?';
	D["100101"]		= 'A';
	D["10011010"]	= 'B';
	D["0101"]		= 'C';
	D["0001"]		= 'D';
	D["110"]		= 'E';
	D["01001"]		= 'F';
	D["10011011"]	= 'G';
	D["010000"]		= 'H';
	D["0111"]		= 'I';
	D["10011000"]	= 'J';
	D["0110"]		= 'K';
	D["00100"]		= 'L';
	D["10011001"]	= 'M';
	D["10011110"]	= 'N';
	D["00101"]		= 'O';
	D["111"]		= 'P';
	D["10011111"]	= 'Q';
	D["1000"]		= 'R';
	D["00110"]		= 'S';
	D["00111"]		= 'T';
	D["10011100"]	= 'U';
	D["10011101"]	= 'V';
	D["000010"]		= 'W';
	D["10010010"]	= 'X';
	D["10010011"]	= 'Y';
	D["10010000"]	= 'Z';

	string in;
	while ( 1 )
	{
		getline( cin, in );
		if ( cin.eof() )
			break;

		string encode;
		for ( string::iterator it = in.begin(); it != in.end(); it++ )
		{
			encode += M[*it];
		}

		string decode = "";

		int index = 0;
		while ( 1 )
		{
			bool found = false;
			for ( int i = 3; i < 9; i++ )
			{
				if ( encode.size() < index + i )
					break;
				string t = encode.substr( index, i );
				if ( D.find( t ) != D.end() )
				{
					// ­©
					decode += D[t];
					index += i;
					found = true;
				}
			}
			if ( !found ) break;
		}

		cout << decode << endl;
	}

	return 0;
}

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

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

typedef unsigned long long ull;
typedef long long ll;

const int INF = 1001001001;

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

    int count = 1;
    map<int, bool> a;
    rep(i, 1000000) {
        if (a[s]) break;
        a[s] = true; 
        s = (s%2 == 0) ? s/2 : 3*s + 1;
        count++;
        // cout << count << endl;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(int n){
    cout << "Yes" << endl;
}

void no (int n){
    cout << "No" << endl;
}

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    int le = -1;
    int ri = n;
    while (ri - le > 1){
        while (s[le+1] == 'R') le++;
        while (s[ri-1] == 'W') ri--;
        s[le+1] = 'R';
        s[ri-1] = 'W';
        ans++;
    }
    cout << ans-1 << endl;
}

Measured memory_bytes: 3828
# -*- coding: utf-8 -*-
# モジュールのインポート
import itertools


def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    A = list(map(int, input().split()))

    return N, A


def main(A: list) -> None:
    """
    メイン処理.

    Args:\n
        A (list): 整数列(1 <= A_i <= 10^9)
    """
    # 求解処理
    ans = 0
    for A_i, A_j in itertools.combinations(A, r=2):
        ans = max(ans, abs(A_i - A_j))

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, A = get_input()

    # メイン処理
    main(A)


Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0;
    vector<int> V(3);
    char tmp, tmp2;
    string S, S2;
    bool flag=true;
    
    cin >> S >> S2 ;
    
    // ans = A+2*(B-A);
    // cout << ans << endl;

    if(S[0]==S2[2] && S[1]==S2[1] && S[2]==S2[0])
    	cout << "YES" <<endl;
    else
    	cout << "NO" <<endl;

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if(A+B==C || B+C==A || C+A==B)
    // 	puts("Yes");
    // else
    // 	puts("No");
}


Measured memory_bytes: 256
void main() {
	auto ip = readAs!(float[]), T = ip[0], X = ip[1];
	writefln("%.6f", T / X);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
from collections import deque
n,m = map(int,input().split())
edge_list = [[] for i in range(n)]
depth_list = [-1 for i in range(n)]
ans_list = [-1 for i in range(n)]
depth_list[0] = 0
ans_list[0] = 0
for m in range(m):
  a,b = map(int,input().split())
  a = a-1
  b = b-1
  edge_list[a].append(b)
  edge_list[b].append(a)
q = deque()
q.append(0)

while len(q) > 0:
  node = q.popleft()
  connects = edge_list[node]
  for c in connects:
    if depth_list[c] == -1:
      depth_list[c] = depth_list[node] + 1
      q.append(c)
      ans_list[c] = node
      
if -1 in ans_list:
  print("No")
else:
  print("Yes")
  for _ in ans_list[1:]:
    print(_ + 1)

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

#define int long long

void print(int* a , int n){
	for(int i = 0 ; i < n ; i++) cout << a[i] <<" " ; cout << endl ;
}

int32_t main() {
		int n ;
		cin >> n ;
		int a[n] , b[n] ;
		for(int i = 0 ; i < n ; i++){
			cin >> a[i] ;
		}
		if(is_sorted(a,a+n)){
			cout << "YES" ; return 0 ;
		}
		
		for(int i = 0 ; i < n ; i++){
			for(int j = i+1 ; j < n ; j++){
				swap(a[i],a[j]) ;
				// print(a,n);
				if(is_sorted(a,a+n)){
					cout <<"YES" ; return 0 ;
				}
				swap(a[i],a[j]) ;
			}
		}
		cout << "NO" ;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
        int r,c;
        int T[101][101];

        cin>>r>>c;

        for (int i = 0; i < r ; ++i) {
            for (int j = 0; j < c ; ++j) {
                cin>>T[i][j];
            }
        }
        //??¨??¨??????????????????????¨????sum
        for (int i = 0; i < r ; ++i) {
            int sum = 0;
            for (int j = 0; j < c ; ++j) {
                sum +=T[i][j];
                cout << T[i][j]<<" ";
            }
            cout << sum << endl;
        }
        //??????sum
        for (int i = 0; i < c ; ++i) {
            int sum = 0;
            for (int j = 0; j < r ; ++j) {
                sum += T[j][i];
            }
                cout << sum << " ";
            }
        //??????
        int sum = 0;
        for (int i = 0; i < r ; ++i) {
            for (int j = 0; j < c ; ++j) {
                sum += T[i][j];
            }
        }
        cout << sum << endl;
        return 0;
}

Measured memory_bytes: 1200
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
h, w = map(int, input().split())
n = h*w
fld = ''.join([input().rstrip()for _ in range(h)])


def to_v(i, j):
    return i*w+j


def generate_v2(v):
    i, j = divmod(v, w)
    if 0 < i:
        yield v-w
    if i < h-1:
        yield v+w
    if 0 < j:
        yield v-1
    if j < w-1:
        yield v+1


def dfs(v, c=0):
    if visited[v]:
        return
    visited[v] = 1
    cnt[c] += 1
    for v2 in generate_v2(v):
        if fld[v] == fld[v2]:
            continue
        dfs(v2, c ^ 1)


visited = [0]*n
ans = 0
for v in range(n):
    if visited[v]:
        continue
    cnt = [0, 0]
    dfs(v)
    ans += cnt[0]*cnt[1]
print(ans)

Measured memory_bytes: 273928
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

const int N = 1000;

main(){
  int n, it[N], st[N];
  while(cin >> n && n){
    fill(it, it+N, -2);
    fill(st, st+N, 0);
    for(int i=0;i<n;i++){
      string a, b, c;
      cin >> a >> a >> b >> c;
      int t = atoi(a.substr(0, 2).c_str()) * 60 + atoi(a.substr(3).c_str());
      int id = atoi(c.c_str());
      if(b == "I"){
        if(id == 0){
          for(int j=0;j<N;j++) if(it[j] == -1) it[j] = t;
        }
        if(it[0] == -2) it[id] = -1;
        else it[id] = t;
      }else{
        if(id == 0){
          for(int j=0;j<N;j++){
            if(it[j] >= 0){
              st[j] += t - it[j];
              it[j] = -1;
            }
          }
        }
        if(it[0] != -2) st[id] += t - it[id];
        it[id] = -2;
      }
    }
    int ans = 0;
    for(int i=1;i<N;i++) ans = max(ans, st[i]);
    cout << ans << endl;
  }
}

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

using namespace std;
using ll = long long;

int main() {
    int N = 0;
    cin >> N;
    vector<int> A(N,0);
    int now = 1000000000;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        cin >> A.at(i);
        ans = 0;
        while(!(A.at(i)%2)) {
            ans++;
            //cout << ans << endl;
            //cout << "###" << endl;
            A.at(i) /= 2;
        }
        //cout << ans << endl;
        now = min(ans,now);
    }
    cout << now << endl;



    return 0;
}

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

int curr_sol(int sol[], int h[], int i, int j) {
    return sol[j] + abs(h[i] - h[j]);
}

int main() {
    int n, k;
    cin >> n >> k;
    int h[n + 1], sol[n + 1];
    cin >> h[0];
    sol[0] = 0;
    for (int i = 1; i < n; i ++) {
        cin >> h[i];
        sol[i] = curr_sol(sol, h, i, i - 1);
        for (int j = i - 2; j >= 0 && i - j <= k; j --) {
            sol[i] = min(sol[i], curr_sol(sol, h, i, j));
        }
    }
    cout << sol[n - 1];
    return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)

ll calcNumOfCombination(ll n, ll r) {
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}


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

    int count = 0;
    int sum = 0;

    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                sum = 500 * i + 100 * j + 50 * k;
                if (sum == x) {
                    count++;
                }
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N, M;
    ll K;
    cin >> N >> M >> K;
    ll A[N], B[M];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < M; i++) {
        cin >> B[i];
    }
    int ans = 0;
    ll c[M + 1]{};
    for (int i = 0; i < M; i++) {
        c[i + 1] = c[i] + B[i];
    }
    ll t = 0;
    for (int i = 0; i <= N; i++) {
        if (i != 0) {
            t += A[i - 1];
        }
        if (t > K) break;
        int l = -1;
        int r = M + 1;
        while (r - l > 1) {
            int m = (l + r) / 2;
            if (t + c[m] <= K) {
                l = m;
            } else {
                r = m;
            }
        }
        ans = max(ans, i + l);
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;
long long n,w[110],v[110],W,dp[110][101000],x;
long long Rec(long long i,long long value){
if(value <0)
    return 2e9;
if(i==n)
    return value==0?0:2e9;
if(dp[i][value]!=-1)
    return dp[i][value];

return dp[i][value]=min(Rec(i+1,value),Rec(i+1,value-v[i])+w[i]);

}
int main()
{
    cin>>n>>W;
    for(long long i=0; i<n; i++)
        scanf("%164d%164d",&w[i],&v[i]);

    memset(dp,-1,sizeof(dp));
    for(long long i=0; i<100099; i++)
        if(Rec(0,i) <= W)
            x=max(x,i);


    cout<<x<<endl;;

    return 0;
}


Measured memory_bytes: 87040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
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 (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    V<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    ll l = 0, r = 1e18;
    auto ok = [&](ll x) {
        int cnt = 0;
        for(int i = 0; i < n; i++) {
            ll ni = a[i];
            cnt += (ni + x - 1) / x - 1;
        }
        return cnt <= k;
    };
    while(r - l > 1) {
        ll mid = (r + l) / 2;
        if(ok(mid)) r = mid;
        else l = mid;
    }
    cout << r << endl;
}

Measured memory_bytes: 4744
import itertools

n, m, x = map(int, input().split())
c = []
a = []
for _ in range(n):
    c_a = list(map(int, input().split()))
    c.append(c_a[0])
    a.append(c_a[1:])

min_money = 10**6 * 12
for num in range(1, n + 1):
    for choices in itertools.combinations(range(n), num):
        is_ok = True
        for j in range(m):
            understand_rate = 0
            for i in choices:
                understand_rate += a[i][j]
            if understand_rate < x:
                is_ok = False
                break
        if is_ok:
            money = 0
            for i in choices:
                money += c[i]
            min_money = min(min_money, money)
if min_money == 10**6 * 12:
    print(-1)
else:
    print(min_money)


Measured memory_bytes: 9224
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

int main()
{
	int N;
	while (cin >> N, N)
	{
		vector<long long int>data;
		data.resize(N + 1);
		data[0] = 0;
		for (size_t i = 1; i <= N; i++)
		{
			cin >> data[i];
			data[i] += data[i - 1];
		}
		long long int ans = INT_MIN;
		for (size_t i = 0; i < N + 1; i++)
		{
			for (size_t j = i+1; j < N + 1; j++)
			{
				ans = max(ans, data[j] - data[i]);
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> C(N);
    for(size_t i=0;i<N; i++) cin >> A[i];
    for(size_t i=0;i<N; i++) cin >> B[i];
    for(size_t i=0;i<N; i++) cin >> C[i];


    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    ll comb_count = 0;
    for(size_t j=0;j<N; j++)
    {
        auto A_it = upper_bound(A.begin(), A.end(), B[j]-1);
        size_t A_end = distance(A.begin(), A_it);
        auto C_it = lower_bound(C.begin(), C.end(), B[j]+1);
        size_t C_start = distance(C.begin(), C_it);
        comb_count += A_end * (C.size() - C_start);
    }
    cout << comb_count << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 5540
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/

int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
	//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
	string s;
	cin>>s;
	while(1)
	{
		int len=s.length();
		if(len<5)
		{
			cout<<"NO"<<endl;
			break;
		}

        if(len>=11&&s.substr(0,11)=="dreameraser")
		{
			s.erase(0,11);
		}
		else if(len>=10&&s.substr(0,10)=="dreamerase")
		{
			s.erase(0,10);
		}else if(s.substr(0,7)=="dreamer")
		{
			s.erase(0,7);
		}else if(s.substr(0,5)=="dream")
		{
			s.erase(0,5);
		}else if(s.substr(0,6)=="eraser")
		{
			s.erase(0,6);
		}else if(s.substr(0,5)=="erase")
		{
			s.erase(0,5);
		}

		if(s.length()==0)
		{
			cout<<"YES"<<endl;
			break;
		}
		if(len==s.length())
        {
            cout<<"NO"<<endl;
			break;
        }
	}
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 512
#include <cstdio>
#include <vector>
using namespace std;
#define Nil -1

struct Tree
{
  int parent, left, right;
};

void preorderPrint(int id, Tree t[])
{
  printf(" %d", id);
  if (t[id].left != Nil)
    preorderPrint(t[id].left, t);
  if (t[id].right != Nil)
    preorderPrint(t[id].right, t);
}

void inorderPrint(int id, Tree t[])
{
  if (t[id].left != Nil)
    inorderPrint(t[id].left, t);
  printf(" %d", id);
  if (t[id].right != Nil)
    inorderPrint(t[id].right, t);
}

void postorderPrint(int id, Tree t[])
{
  if (t[id].left != Nil)
    postorderPrint(t[id].left, t);
  if (t[id].right != Nil)
    postorderPrint(t[id].right, t);
  printf(" %d", id);
}

int main()
{
  int n;
  Tree trees[25];
  scanf("%d", &n);

  for (int i = 0; i < 25; i++)
    trees[i].parent = trees[i].left = trees[i].right = Nil;

  for (int i = 0; i < n; i++)
  {
    int id, left, right;
    scanf("%d%d%d", &id, &left, &right);
    trees[id].left = left;
    trees[id].right = right;
    if (left != Nil)
      trees[left].parent = id;
    if (right != Nil)
      trees[right].parent = id;
  }

  int root;
  for (int i = 0; i < n; i++)
    if (trees[i].parent == -1)
      root = i;

  printf("Preorder\n");
  preorderPrint(root, trees);
  printf("\n");
  printf("Inorder\n");
  inorderPrint(root, trees);
  printf("\n");
  printf("Postorder\n");
  postorderPrint(root, trees);
  printf("\n");

  return 0;
}

Measured memory_bytes: 2728
#include <stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  int a[n];
  int i;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  int ans = 5000000;
  for(i=-100;i<=100;i++){
    int tmp = 0;
    int j;
    for(j=0;j<n;j++){
      tmp += (a[j] - i) * (a[j] - i);
    }
    if(tmp < ans){
      ans = tmp;
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  string tar;
  cin>>tar;
  int ans=0;
  for(int i=0;i<n;i++)
    {
      string tmp;
      cin>>tmp;
      //first
      for(int a=0;a<tmp.size();a++)
	{
	  if(tmp[a]==tar[0])
	    {
	      for(int b=a+1;b<tmp.size();b++)
		 {
		   if(tmp[b]==tar[1])
		     {
		       bool flag=false;
		       int cnt=2;
		       for(int c=b+(b-a);c<tmp.size();c+=(b-a))
			 {
			   if(tar[cnt]!=tmp[c])
			     break;
			   if(cnt>=tar.size()-1)
			     {
			       flag=true;
			       break;
			     }
			   cnt++;
			 }
		       if(flag)
			 {
			   ans++;
			   a=b=tmp.size()+2;
			 }
		     }
		 }
	    }
	}

    }
  cout<<ans<<endl;

}

Measured memory_bytes: 1208
#include <stdio.h>
#include <string.h>
#include <utility>
#include <queue>
#define INF 100000007
#define RMAX 1000
#define CMAX 1000

using namespace std;

typedef pair<int,int> P;
typedef pair<P,int> PP;

int main(void){
	int r, c, a1, a2, b1, b2, p[RMAX][CMAX], cmin[RMAX][CMAX],x, y, tx, ty, dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0}, i, j, cst;
	queue<PP> que;
	scanf("%d%d%d%d%d%d",&r,&c,&a1,&a2,&b1,&b2);
	memset(p,0,sizeof(p));
	for(i = 0;i < RMAX;i++){
		for(j = 0;j < CMAX;j++) cmin[i][j] = INF;
	}
	cmin[a1][a2] = 0;
	p[a1][a2] = 1;
	que.push(PP(P(a1,a2),0));
	while(que.size()){
		x = que.front().first.first, y = que.front().first.second, cst = que.front().second;
		que.pop();
		if(((x == 0 && cst + 1 <= cmin[r - 1][y]) || (x == r - 1 && cst + 1 <= cmin[0][y]))){
			if(x == r - 1) tx = 0;
			else tx = r - 1;
			if(cst + 1 == cmin[tx][y]){
				p[tx][y] = (p[x][y] + p[tx][y]) % INF;
			}
			else{
				p[tx][y] = p[x][y];
				cmin[tx][y] = cst + 1;
				que.push(PP(P(tx,y),cst + 1));
			}
		}
		if(((y == 0 && cst + 1 <= cmin[x][c - 1]) || (y == c - 1 && cst + 1 <= cmin[x][0]))){
			if(y == c - 1) ty = 0;
			else ty = c - 1;
			if(cst + 1 == cmin[x][ty]){
				p[x][ty] = (p[x][y] + p[x][ty]) % INF;
			}
			else{
				p[x][ty] = p[x][y];
				cmin[x][ty] = cst + 1;
				que.push(PP(P(x,ty),cst + 1));
			}
		}
		for(i = 0;i < 4;i++){
			if(x + dx[i] >= 0 && x + dx[i] < r && y + dy[i] >= 0 && y + dy[i] < c && cst + 1 <= cmin[x + dx[i]][y + dy[i]]){
				if(cmin[x + dx[i]][y + dy[i]] == cst + 1){
					p[x + dx[i]][y + dy[i]] = (p[x][y] + p[x + dx[i]][y + dy[i]]) % INF;
				}
				else{
					p[x + dx[i]][y + dy[i]] = p[x][y];
					cmin[x + dx[i]][y + dy[i]] = cst + 1;
					que.push(PP(P(x + dx[i],y + dy[i]),cst + 1));
				}
			}
		}
	}
	printf("%d\n",p[b1][b2]);
	return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(ll i=0;i<(n);i++)


using namespace std;


vector<vector<ll>> map2d(vector<vector<ll>>& a){
    ll h = a.size();
    ll w = a[0].size();
    vector<vector<ll>> m(h+1, vector<ll>(w+1, 0));
    rep(hx, h){
        rep(wx, w) m[hx + 1][wx + 1] = a[hx][wx];
    }
    rep(hx, h + 1){
        rep(wx, w) m[hx][wx + 1] += m[hx][wx];
    }
    rep(hx, h){
        rep(wx, w + 1) m[hx + 1][wx] += m[hx][wx];
    }
    return m;
}

ll sum2d(vector<vector<ll>>& m, ll u, ll l, ll h, ll w){
    return  m[u+h][l+w] - m[u][l+w] - m[u+h][l] + m[u][l];
}

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> x(n);
    vector<ll> y(n);
    vector<char> c(n);
    rep(i, n) cin >> x[i] >> y[i] >> c[i];

    ll kk = 2*k;
    vector<vector<ll>> list(kk, vector<ll>(kk, 0));
    
    rep(i, n){
        ll ix = x[i]%kk;
        ll iy = y[i]%kk;
        if(k <= iy && k <= ix){
            iy %= k;
            if(c[i] == 'W') ix %= k;
            c[i] = 'W';
        }
        else if(k <= iy){
            if(c[i] == 'B') iy %= k, c[i] = 'W';
        }
        else if(k <= ix){
            if(c[i] == 'B') ix %= k, c[i] = 'W';
        }
        else{
            if(c[i] == 'B') ix += k, c[i] = 'W';
        }

        list[iy][ix]++;
    }

    auto m = map2d(list);

    // .|*
    // -+-
    // .|.
    ll maxx = 0;
    rep(cy, k){
        rep(cx, k){
            ll v = sum2d(m, cy, cx, k, k);
            v += sum2d(m, 0, 0, cy, cx);
            v += sum2d(m, 0, cx+k, cy, kk-(cx+k));
            v += sum2d(m, cy+k, 0, kk-(cy+k), cx);
            v += sum2d(m, cy+k, cx+k, kk-(cy+k), kk-(cx+k));
            maxx = max(maxx, max(v, n-v));
        }
    }

    cout << maxx << endl;


    return 0;
}


Measured memory_bytes: 64640