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

int main(){
    int M,N;
    cin>>M>>N;
    double P[M][N];//???,???
    for(int i=0;i<M;i++){
        for(int j=0;j<N;j++) cin>>P[i][j];
    }
    double DP[1<<M][N];//[S][n]:=S??????????????£????????????n??????????????????????±??????????????????????????????????????????¶???????¢????
    fill(DP[0],DP[1<<M],0);
    for(int m=0;m<M;m++){
        double p=1;
        for(int n=N-1;n>=0;n--){
            p*=P[m][n];
            DP[1<<m][n]=p;
        }
    }
    for(int s=0;s<(1<<M);s++){
        for(int n=0;n<N;n++){
            for(int m=0;m<M;m++){
                if((s&(1<<m))==0) continue;
                double sum=0,p=1;
                for(int nn=n;nn<N;nn++){
                    sum+=p*(1-P[m][nn])*DP[s^(1<<m)][nn];
                    p*=P[m][nn];
                }
                sum+=p;
                DP[s][n]=max(DP[s][n],sum);
            }
        }
    }
    cout.precision(10);
    cout<<fixed;
    cout<<DP[(1<<M)-1][0]<<endl;

    return 0;
}

Measured memory_bytes: 11468
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n-1);
    rep(i,n-1){
        cin >> b[i];
    }
    a[0]=b[0];
    a[n-1]=b[n-2];
    for(int i=1;i<n-1;i++){
        a[i]=min(b[i-1],b[i]);
    }
    int sum=0;
    rep(i,n){
        sum+=a[i];
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3644
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

def T(k):
    orig_k = k
    sk = 0
    while k > 0:
        sk += k % 10
        k //= 10
    return orig_k / sk

d = {}
MAX = int(1e15) + 1e9
for i in range(1, 9999):
    t = i
    while t < MAX:
        d[t] = T(t)
        t = t * 10 + 9

keys = sorted(list(d.keys()))

# for k in keys:
#     print(k, d[k])

mn = None
ans = []
for k in reversed(keys):
    if mn == None:
        ans.append(k)
        mn = d[k]
    else:
        if mn >= d[k]:
            ans.append(k)
            mn = min(mn, d[k])

ans.reverse()

K = int(input())
ans = ans[:K]
for a in ans:
    print(a)


Measured memory_bytes: 81880
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 500000;
const int MOD = 1000000007;

string S;
ll dp[MAX + 1][4] = {0};

void abc104d() {
  int n = S.size();
  dp[0][0] = 1;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < 4; j++) {
      if (S[i] == '?') {
        dp[i + 1][j] += 3 * dp[i][j];
      } else {
        dp[i + 1][j] += dp[i][j];
      }
      dp[i + 1][j] %= MOD;
    }

    if (S[i] == 'A' || S[i] == '?') {
      dp[i + 1][1] += dp[i][0];
      dp[i + 1][1] %= MOD;
    }
    if (S[i] == 'B' || S[i] == '?') {
      dp[i + 1][2] += dp[i][1];
      dp[i + 1][2] %= MOD;
    }
    if (S[i] == 'C' || S[i] == '?') {
      dp[i + 1][3] += dp[i][2];
      dp[i + 1][3] %= MOD;
    }
  }

  cout << dp[n][3] << "\n";
  return;
}

int main() {
  cin >> S;
  abc104d();
  return 0;
}


Measured memory_bytes: 4608
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int Q;
int num[101010];
int l[101010], r[101010];
bool is_prime[101010];

void prime_init() {
  repe(i, 2, 100000) { is_prime[i] = true; }
  repe(i, 2, 100000) {
    if (is_prime[i]) {
      for (int j = i + i; j <= 100000; j += i) {
        is_prime[j] = false;
      }
    }
  }
}

int main() {
  prime_init();
  num[2] = 0;
  repe(i, 3, 100000) {
    if (is_prime[i] && is_prime[(i + 1) / 2]) {
      num[i] = num[i - 1] + 1;
    } else {
      num[i] = num[i - 1];
    }
  }

  cin >> Q;
  rep(i, 0, Q) { cin >> l[i] >> r[i]; }
  rep(i, 0, Q) { cout << num[r[i]] - num[l[i] - 1] << endl; }
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

ll N;
ll A[100005];
ll B[100005];

int main(){
	cin >> N;
	rep(i, N + 1) cin >> A[i];
	rep(i, N) cin >> B[i];


	ll ans = 0;
	rep(i, N) {
		if(A[i] >= B[i]) {
			ans += B[i];
		} else {
			ans += A[i];
			B[i] -= A[i];
			ll rem = min(B[i], A[i+1]);
			ans += rem;
			A[i+1] -= rem;
		}
	}
	cout << ans << endl;


}



Measured memory_bytes: 5100
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<string.h>

#define size 100005

int main()
{
    int n, i, arr[size], count=0, temp, a, b, pos_1, pos_2, flag=0;
    scanf("%d", &n);

    for(i=1; i<=n; i++)
        scanf("%d", &arr[i]);

    for(i=1; i<n; i++)
    {
        if(arr[i]>arr[i+1])
            count++;
    }
    if(count==1)
    {
        for(i=1; i<n; i++)
        {
            if(arr[i]>arr[i+1])
            {
                temp = arr[i];
                arr[i]=arr[i+1];
                arr[i+1]=temp;
            }
        }
    }
    else if(count==2)
    {
        for(i=1; i<n; i++)
        {
            if(arr[i]>arr[i+1])
            {
                pos_1 = i;
                a = arr[pos_1];
                break;
            }
        }
        for(i=pos_1+1; i<n; i++)
        {
            if(arr[i]>arr[i+1])
            {
                pos_2 = i+1;
                b = arr[pos_2];
                break;
            }
        }
        arr[pos_1] = b;
        arr[pos_2] = a;
    }

    for(i=1; i<n; i++)
    {
        if(arr[i]>arr[i+1])
            flag++;
    }

    if(flag==0)
        printf("YES\n");
    else
        printf("NO\n");

    return 0;
}


Measured memory_bytes: 1640
#include<bits/stdc++.h>
using namespace std;
int main(void){
	string s;
	int i;
	array<int,26>arr;
	bool flg=true;
	cin>>s;
	arr.fill(0);
	for(i=0;i<s.size();i++)	arr[s[i]-'a']++;
	for(i=0;i<26;i++){
		if(arr[i]%2!=0){
			flg=false;
			break;
		}
	}
	cout<<((flg)?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    ll n;
    cin >> n;

    map<ll, int> mp;

    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            n /= i;
            mp[i]++;
        }
    }
    if (n > 1) {
        n /= n;
        mp[n]++;
    }

    int r = 0;
    for (auto [i, k] : mp) {
        int s = 0;
        for (int j = 1;; j++) {
            s += j;
            if (s > k) break;
            r++;
        }
    }

    cout << r << endl;

    return 0;
}

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

int main()
{
	int N;
	cin>>N;
	
	int p[100];
	for(int i=0;i<N;i++){
		cin>>p[i];
	}
	
	sort(p,p+N);
	
	int score=0;
	for(int i=1; i<=N;i++){
		if(((p+N)-lower_bound(p,p+N,i))>=i){
			score=i;
		}
		else{
			break;
		}
	}
	
	cout<<score<<endl;
	
	return 0;
}

Measured memory_bytes: 3148
def solve():
    n = int(input())
    dp = [0 for _ in range(n+1)] 

    for i in range(1, n+1):
        options = find_options(i)
        selected = min(map(lambda x: [x, dp[i - x]], options), key=lambda x: x[1])
        dp[i] = selected[1] + 1

    print(dp[n])

def find_options(n):
    sixs = find_sixs(n)
    nines = find_nines(n)
    options = [1]
    options.extend(sixs)
    options.extend(nines)
    return options


def find_sixs(n):
    sixs = 1
    powers = [] 
    count = 0
    while n > sixs:
        count += 1
        sixs *= 6
        powers.append(sixs)
    
    if sixs == n:
        return powers
    else:
        powers.pop()
    return powers

def find_nines(n):
    nines = 1
    powers = [] 
    count = 0
    while n > nines:
        count += 1
        nines *= 9
        powers.append(nines)
    
    if nines == n:
        return powers
    else:
        powers.pop()
    return powers

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3992
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
//cout << fixed << setprecision(15) << y << endl;
//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int A, B, M;
  double H;
  cin >> A >> B >> H >> M;
  H += M / 60.0;
  double ag_h = H / 12.0;
  double ag_m = M / 60.0;
  double angle = degreeToRadian(abs(ag_h - ag_m)) * 360;
  double ans = A*A + B*B - 2*A*B*cos(angle);
  cout << fixed << setprecision(15) << sqrt(ans) << endl;
  return 0;
}


Measured memory_bytes: 4156
//F5で実行 Shift+F5で停止
//F9でブレークポイント
#include<cmath>
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
//Ctrl+PageUpで上部の大半を選択できる
// 1e18 = 10の18乗

//atcoder 1秒は O(10^8)以上でTLE

//関数の中で宣言するとスタック領域に確保してしまい、
//スタックオーバーフローの恐れあり

string S,T,U;
int A, B;

void _main() {
	cin >> S >> T >>  A >> B >> U;

	if (U == S)
		A--;
	else if (U == T)
		B--;

	cout << A << " " <<  B << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
        int number[1000];
        int n, m, allnum, i, j, round;

        while ( scanf( "%d %d", &n, &m ) ) {
                if ( n == 0 && m == 0 ) { break; }

                /* 0r$rBT$C$F$$$k?M$r1$K$9$k */
                for ( i = 0 ; i < n ; i++ ) { number[i] = 1; }

                i = 0;
                allnum = 0;
                j = 0;
                while ( 1 ) {
                        if ( number[i%n] == 1 ) { j++; }

                        if ( j == m ) {
                                number[i%n] = 0;
                                allnum++;
                                j = 0;
                        }

                        if ( allnum == n ) {
                                break;
                        }
                        i++;
                }
                printf( "%d\n", (i)%n+1 );
        }

        return 0;
}



Measured memory_bytes: 2040
//----------------------------------------------------------------
//E

#include <iostream>
using namespace std;
const long long INF = 1LL<<60;

const int MAX_N = 110;
const int MAX_V = 100100;

// 入力
int N;
long long W, weight[MAX_N], value[MAX_N]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[MAX_N][MAX_V];

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

    // 初期化
    for (int i = 0; i < MAX_N; ++i) for (int j = 0; j < MAX_V; ++j) dp[i][j] = INF;

    // 初期条件
    dp[0][0] = 0;

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {

            // i 番目の品物を選ぶ場合
            if (sum_v - value[i] >= 0) dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);

            // i 番目の品物を選ばない場合
            dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    // 最適値の出力
    long long res = 0;
    for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
        if (dp[N][sum_v] <= W) res = sum_v;
    }
    cout << res << endl;
}



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

int main(void)
{
    long long int b=0,c,i,j,k,n;
    char a[4];
    for(i=0;i<4;i++){
        cin >> a[i];
        if(a[i]=='+') b++;
        else b--;
    }

    cout << b;

    return 0;
}

Measured memory_bytes: 256
import numpy as np


def prepare(n, m):
    f = 1
    facts = [1]
    for i in range(1, n + 1):
        f = f * i % m
        facts.append(f)

    f = pow(f, m - 2, m)
    invs = [1] * (n + 1)
    invs[n] = f
    for i in range(n, 0, -1):
        f = f * i % m
        invs[i - 1] = f

    return facts, invs


def nik(n2, k, m):
    ret = 1
    yield ret
    for _ in range(k):
        ret = ret * n2 % m
        yield ret


n, m = map(int, input().split())

facts, invs = prepare(n, m)
fn = facts[n]

np_range = np.arange(2, n + 4, dtype=np.int64)
dp = np.zeros(n + 2, dtype=np.int64)
dp[0] = 1

nn2 = [2]
for i in range(n):
    nn2.append(nn2[-1] ** 2 % m)

ans = 0
parity = 1

for i in range(n + 1):
    n2 = pow(2, n - i, m)
    coef = np.fromiter(nik(n2, i, m), dtype=np.int64)
    ncr = fn * invs[i] * invs[n - i] % m
    left = (dp[:i + 1] * coef % m).sum() % m
    right = nn2[n - i]
    ans = (ans + ncr * left % m * right % m * parity) % m
    dp[1:i + 2] = (dp[1:i + 2] * np_range[:i + 1] + dp[:i + 1]) % m
    parity *= -1

print(ans)


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

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

  int h = S / 3600;
  S %= 3600;
  int m = S / 60;
  int s = S % 60;

  cout << h << ':' << m << ':' << s << endl;  
  return 0;
}


Measured memory_bytes: 3100
#pragma comment(linker, "/STACK:128777216")
#pragma GCC optimize("fast-maths")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <climits>
#include <ctime>
#include <random>
#include <complex>
using namespace std;

#define forx(_name, _from, _to, _value) for (int _name = _from; _name < _to; _name += _value)
#define rforx(_name, _from, _to, _value) for (int _name = _from; _name > _to; _name -= _value)
#define all(_STL_NAME) _STL_NAME.begin(), _STL_NAME.end()
#define rall(_STL_NAME) _STL_NAME.rbegin(), _STL_NAME.rend()
#define mp(_FIRST,_SECOND) make_pair(_FIRST, _SECOND)

typedef long long ll;
typedef unsigned long long llu;
typedef long double ld;
const ld eps = 1e-6;
mt19937 rndm;

void start() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout.precision(6); cout.setf(ios::fixed);
	string FILENAME = "\-_-/";
	rndm.seed(time(0));
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#else
	//freopen((FILENAME + ".in").c_str(), "rt", stdin);
	//freopen((FILENAME + ".out").c_str(), "wt", stdout);
#endif
}

int main() {
	/* File On */
	start();
	const int mod = 1000000007;
	int n;
	cin >> n;
	vector<ll> q(n);
	for (int i = 0; i < n; ++i)
		cin >> q[i];
	vector<ll> suf(n + 1);
	for (int i = n - 1; i >= 0; --i) {
		suf[i] = (suf[i + 1] + q[i]) % mod;
	}
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		ans = (ans + q[i] * suf[i + 1] % mod) % mod;
	}
	cout << ans;
#ifdef _DEBUG
	cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}

Measured memory_bytes: 6048
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

int N;
multiset<int>st;
signed main() {
	cin>>N;
	rep(i,1<<N){
		int a;cin>>a;st.insert(a);
	}
	vector<int>used={*--st.end()};st.erase(--st.end());
	rep(i,N){
		vector<int>v;
		for(int j:used){
			if(st.lower_bound(j)==st.begin()){
				cout<<"No"<<endl;return 0;
			}
			v.push_back(*--st.lower_bound(j));
			st.erase(--st.lower_bound(j));
		}
		for(int j:v)used.push_back(j);
	}
	cout<<"Yes"<<endl;
}



Measured memory_bytes: 15460
#include<stdio.h>
#include<math.h>
#define PI 3.14159265

int N;

typedef struct Position{
    double x;
    double y;
} pos;

pos p1={0.0, 0.0};
pos p2={100.0,0.0};

void printp(pos p){
    printf("%3.6f ",p.x);
    printf("%3.6f\n",p.y);
}

pos calc_pos(pos p, double len, double angle){
    p.x += cos(angle) * len;
    p.y += sin(angle) *len;
    return p;
}

void KochCurve(pos p, double len, double angle, int depth){
    double a = PI / 3;
    double l = len /3;
    if(depth>N)return;
    if (depth==0){
        depth++;
        printp(p1);
        KochCurve(p,len,angle,depth);
        printp(p2);
    }else{
        depth++;
        KochCurve(p,l,angle,depth);
        p = calc_pos(p,l,angle);
        printp(p);
        KochCurve(p,l,angle+a,depth);
        p = calc_pos(p,l,angle+a);
        printp(p);
        KochCurve(p,l,angle-a,depth);
        p = calc_pos(p,l,angle-a);
        printp(p);
        KochCurve(p,l,angle,depth);
        p = calc_pos(p,l,angle);
    }
}

int main(){
    scanf("%d",&N);
    KochCurve(p1,100.0,0,0);
    return 0;
}


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

int main (){
    int x;
    rep(i, 5){
        cin >> x;
        if(x == 0){
            cout << i + 1 << endl;
        }
    }
}

Measured memory_bytes: 3588
#include<stdio.h>

int main(void)
{
  int a,b,c,d;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&d);
  while(-1){
  c=c-b;
    if(c<=0){
    printf("Yes");break;
    }
   a=a-d;
    if(a<=0){
    printf("No");break;
    }
  }
 return 0;
}

Measured memory_bytes: 1728
#include<iostream>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string> 
#include<iomanip>
#include<queue>
#include<vector>
#include<set>
using namespace std;
#define pi 3.1415926535897932384
int main()
{
	
	double c,m,tt,a,b,h,x,y;
	cin>>a>>b>>c;
	x=c/a;
	if(x>=(a*b)/2){
		h=atan((a*b-x)*2/a/a);
		h=h*180/pi;
		cout<<setprecision(10)<<h<<endl;
	}
	else{
		h=atan(b*b/2/x);
		h=h*180.00000/pi;
		cout<<setprecision(10)<<h<<endl;
	}
	
}
	

 	
 	
	



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


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

    int N;
    cin >> N;
    long long L[N+1];
    L[0]=2;
    L[1]=1;
    for(int i=2;i<=N;i++){
        L[i]=L[i-1]+L[i-2];
    }
    cout << L[N] << endl;

}


Measured memory_bytes: 256
/*Largest Independent Set Problem

Definindo que dp[atual][0] é o máximo do vértice PRETO atual e
que dp[atual][1] é o máximo do vértice BRANCO atual (como exercício).

Percorrer os vértices recursivamente até a raiz e ir calculando
o máximo permitido no PRETO e BRANCO. O resultado final será
a soma do máximo deles.

Restrições:

PRETO: todos os seus filhos (ou vértices ligados) precisam ser BRANCOS! (evento dependente)
BRANCO: a cor de qualquer um dos seus filhos (vértices) NÃO IMPORTA! (evento independente)

*Eventos Dependentes: multiplicação
*Eventos Independentes: soma e multiplicação
*/

#include <bits/stdc++.h>

#define MAX 100003
#define MODULO 1000000007

using namespace std;

vector<int> grafo[MAX];
long long dp[MAX][2]; //valores das colunas -> 0 - PRETO e 1 - BRANCO 
long N;

//Semelhante ao conceito de DFS: marcar os visitados na matriz e percorrer recursivamente
void LIS(int vAtual, int vPosterior){

    dp[vAtual][0] = dp[vAtual][1] = 1; //Visitado

    //Percorrendo o grafo
    for(int i = 0; i < grafo[vAtual].size(); i++){
        int elemento = grafo[vAtual][i];
        
        if(elemento != vPosterior){
            //DFS
            LIS(elemento, vAtual);

            //PRETO
            dp[vAtual][0] = dp[vAtual][0] * dp[elemento][1] % MODULO;

            //BRANCO
            dp[vAtual][1] = dp[vAtual][1] * ((dp[elemento][0] + dp[elemento][1]) % MODULO) % MODULO;
        }
    }
}

int main(){

    cin >> N;

    for(long i = 1; i < N; i++){
        long valor1, valor2;
        cin >> valor1 >> valor2;

        grafo[valor1].push_back(valor2);
        grafo[valor2].push_back(valor1);
    }

    //Vértice de Início = 1
    LIS(1, 0);

    //Os resultados são armazenados nas primeiras posições do grafo (recursão)
    cout << (dp[1][0] + dp[1][1]) % MODULO << endl;
    
    return 0;
}

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

int n; // 都市の数
ll k; // テレポート回数
int a[MAX]; // 都市iのテレポート先
bool visited[MAX]; // 訪問状況
int ans;

int main() {
// input
    cin >> n >> k;
    rep(i, n) {
        cin >> a[i];
        a[i]--; // 0-indexedに修正
    }
// solve
    int pos = 0;
    int cnt = 0; // テレポート回数
    rep(i, n) {
        cnt++;
        visited[pos] = true; // 訪問済み
        pos = a[pos]; // 次のの都市
        if (visited[pos]) break; // 訪問した都市に戻ってくるとき終了
    }
    int loop_start = pos; // 最初に戻ってくる都市がループの始点
    if (cnt >= k) {
        pos = 0;
        rep(i, k) { // k回テレポートした先が答え
            pos = a[pos];
        }
        ans = pos;
    } else {
        pos = 0;
        rep(i, n) { // ループの始点までのテレポート回数
            if (pos == loop_start) break;
            pos = a[pos];
            cnt--;
            k--;
        }
        int loop_size = cnt; // ループの周期
        pos = loop_start;
        rep(i, k%loop_size) { // kを周期で割った余り分テレポートした先が答え
            pos = a[pos];
        }
        ans = pos;
    }
// output
    ans++; // 1-indexedに直す
    cout << ans << "\n";
}

Measured memory_bytes: 4620
#include <stdio.h>

typedef struct {
  char character;
  int value;
} card;

void BubbleSort(card *, int);
void SelectionSort(card *, int);
int isStable(card *, card *, int);

int main()
{
  int n, i;
  card C[36], C_in[36];

  scanf("%d", &n);
  for(i=0; i<n; i++) {
    scanf(" %c%d", &C[i].character, &C[i].value);
  }

  for(i=0; i<n; i++) {
    C_in[i] = C[i];
  }
  BubbleSort(C, n);
  SelectionSort(C_in, n);

  return 0;
}

void BubbleSort(card *C, int n)
{
  int i, j;
  card C_in[n], tmp;

  for(i=0; i<n; i++) {
    C_in[i] = C[i];
  }

  for(i=0; i<n; i++) {
    for(j=n-1; j>i; j--) {
      if(C[j].value < C[j-1].value) {
	tmp = C[j];
	C[j] = C[j-1];
	C[j-1] = tmp;
      }
    }
  }
  for(i=0; i<n; i++) {
    printf("%c%d", C[i].character, C[i].value);
    if(i == n-1) break;
    printf(" ");
  }
  isStable(C_in, C, n);

  return ;
}

void SelectionSort(card *C, int n)
{
  int i, j, min;
  card C_in[n], tmp;

  for(i=0; i<n; i++) {
    C_in[i] = C[i];
  }

  for(i=0; i<n; i++) {
    min = i;
    for(j=i; j<n; j++) {
      if(C[j].value < C[min].value)
	min = j;
    }
    tmp = C[i];
    C[i] = C[min];
    C[min] = tmp;
  }

  for(i=0; i<n; i++) {
    printf("%c%d", C[i].character, C[i].value);
    if(i == n-1) break;
    printf(" ");
  }
  isStable(C_in, C, n);

  return ;
}

int isStable(card *C_in, card *C, int n)
{
  int i, j, a, b, check = 1;

  for(i=0; i<n; i++) {
    for(j=i+1; j<n; j++) {
      for(a=0; a<n; a++) {
	for(b=a+1; b<n; b++) {
	  if((C_in[i].value == C_in[j].value) && (C_in[i].value == C[b].value && C_in[i].character == C[b].character) && (C_in[j].value == C[a].value && C_in[j].character == C[a].character))
	    check = 0;
	}
      }
    }
  }
  if(check == 1)
    printf("\nStable\n");
  else
    printf("\nNot stable\n");

  return ;
}

Measured memory_bytes: 612
/*
C - Modulo Summation
abc103
*/
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <cstring>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define PI 3.141592653589793
#define MOD 1000000007LL
typedef long long ll;
using namespace std;
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; }

int main() {
    int n, sum;
    vector<int> a(10101);

    cin >> n;
    REP(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    cout << sum - n << endl;

    return 0;
}

Measured memory_bytes: 3232
//circleinrect.cpp
#include <bits/stdc++.h>
using namespace std;
int main (){
  int w, h, x, y, r;
  string s;
  cin >> w >> h >> x >> y >> r;
  if ((x >= r) && ((w - x) >= r) && (y >= r) && ((h - y) >= r))
      s = "Yes";
  else s = "No";
  cout <<  s << endl;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define uqv(v) v.erase(unique(all(v)), v.end());
#define INF 1e9
#define LINF 1e18
#define gt(tp, x) get<x>(tp)

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef tuple <int, int, int> tp3;

int ans[303][303];
bool chk[303][303];
vector <pii> g[303];

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

	int n, m, l;
	cin >> n >> m >> l;
	for(int i = 1; i <= m; i++) {
		int u, v, w; cin >> u >> v >> w;
		if(w > l) continue;
		g[u].eb(v, w), g[v].eb(u, w);
	}

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			ans[i][j] = -1;
		}
	}

	for(int i = 1; i <= n; i++) {
		priority_queue <tp3> pq;
		pq.push(make_tuple(0, l, i));
		while(!pq.empty()) {
			int x = gt(pq.top(), 2), f = gt(pq.top(), 1), dg = -gt(pq.top(), 0);
			pq.pop();
			if(chk[i][x]) continue;
			chk[i][x] = true;
			ans[i][x] = dg;
			for(auto j : g[x]) {
				if(chk[i][j.fi]) continue;
				if(j.se > f) pq.push(make_tuple(-dg-1, l - j.se, j.fi));
				else pq.push(make_tuple(-dg, f - j.se, j.fi));
			}
		}
	}

	int q;
	cin >> q;
	while(q--) {
		int s, t;
		cin >> s >> t;
		cout << ans[s][t] << '\n';
	}
}


Measured memory_bytes: 3296
s=input()
arr=[]
i=0
while i<(len(s)):
    if s[i]=='A':
        arr.append('A')
        i+=1
        continue
    else:
        if (i+1)<len(s):
            if s[i:i+2]=='BC':
                arr.append('D')
                i+=2
                continue
            else:
                arr.append(s[i])
                i+=1
                continue
        else:
            arr.append(s[i])
            i+=1
temp=''.join(arr)
a=False
count=0
ans=0
# print(temp)
for i in range(len(temp)):
    if not a:
        if temp[i]=='A':
            count+=1
            a=True
    else:
        if temp[i]=='D':
            ans+=count
        elif temp[i]=='A':
            count+=1 
        else:
            # ans+=count
            # count-=1
            count=0 
            a=False
    # print(count,"iter ",i)
print(ans)

Measured memory_bytes: 5096
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5+5 , M = 998244353, OO = 0x3f3f3f3f;
typedef long long ll;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);
const double Pii = 3.14159265359;
ll n, m;

int main()
{
    FIO
    cin >> n >> m;
    if(n%2 == 1)
    {
        ll st = 1, en = (n/2)*2;
        for(int i=0; i<m; ++i)
        {
            cout << st << " " << en << endl;
            st++; en--;
        }
    }
    else
    {
        vector<ll> v;
        ll d1 = n-1;
        while(d1 > n/2)
        {
            v.push_back(d1);
            d1-=2;
        }
        ll d2 = (n/2)-1;
        if(d2%2 == 1) d2--;
        while(d2 > 0)
        {
            v.push_back(d2);
            d2-=2;
        }
        ll st = 1;
        for(int i=0; i<m; ++i)
        {
            cout << st << " " << st+v[i] << endl;
            st++;
        }
    }

    return 0;
}




Measured memory_bytes: 4148
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::collections::HashMap;

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = vec![];
    let mut b: Vec<i64> = vec![];
    for _ in 0..n {
        a.push(read());
        b.push(read());
    }

    a.sort();
    b.sort();

    if n % 2 == 1 {
        let cn = (n - 1) / 2;
        let dist = b[cn] - a[cn] + 1;
        println!("{}", dist);
    } else {
        let an = (n - 2) / 2;
        let bn = (n) / 2;
        println!("{}", ((b[bn] + b[an]) - (a[bn] + a[an])) + 1)
    }
}


Measured memory_bytes: 5812
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	string str;
	cin>>str;
	int size=str.size();
	for(int i=0;i<size;++i){
		if(i&1){
		}else{
			cout<<str[i];
		}
	}
	cout<<endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
bool palin(string s,int l,int r){
	while(l<r){
		if(s[l]!=s[r])
			return false;
		l++;
		r--;

	}
	return true;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE    
		freopen("input.txt", "r", stdin);     
		freopen("output.txt", "w", stdout);
	#endif

//----------------------------------------------------//
string s;
cin>>s;
int n = s.length();
bool x = palin(s,0,(n-1)/2-1);
bool y = palin(s,0,n-1);
if(x&&y){
	cout<<"Yes";
}
else{
	cout<<"No";
}





 






	#ifndef ONLINE_JUDGE
   		cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif

return 0;
}



Measured memory_bytes: 3660
#include <iostream>
//#include <fstream>
#include <vector>

using namespace std;

int main(int argc, const char * argv[]) {
//    ifstream in("input.txt");
//    cin.rdbuf(in.rdbuf());
    
    int N, X;
    cin >> N >> X;
    vector<int> L;
    
    int tmp;
    for (int i=0; i<N; i++){
        cin >> tmp;
        L.push_back(tmp);
    }
    
    int bump = 1;
    int stair = 0;
    
    vector<int>::iterator it = L.begin();
    
    while (1){
        if (L.size() == 0)break;
        stair += *it;
        if (stair > X)break;
        bump++;
        it++;
        if (it == L.end())break;
        
    }
    
    cout << bump <<endl;
    
    return 0;
}

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


const long long MAXVAL = (long long) 1e18 + 1;
const long long MOD = 1000000007;
const int INF = 1000000000 + 1;

long long poww(int x, long long pow) {
  if (pow == 0ll ) return 1;
  if (pow == 1ll) return x % MOD;
  long long ans = poww(x, pow >> 1) % MOD;
  ans = (ans * ans) % MOD;
  if ((pow & 1) == 1) {
    ans = (ans * x ) % MOD;
  }
  return ans % MOD;
}

ll gcd(ll x, ll y) {
  if (x == 0) return y;
  while (y) {
    x %= y;
    swap(x, y);
  }
  return x;
}

struct inter {
  int x,d,num;
};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q = 1;
  //cin >> q;
  cout << fixed << setprecision(6);

  while (q-- >0) {
    int n;
    cin >> n;
    int k;
    cin >> k;
    int a[n];
    int b[n][2];
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    if (k > n) {
      for (int i = 0; i < n; ++i) {
        cout << n << " ";
      }
      cout << endl;
      continue;
    }
    while (k-- > 0) {
      int curmin = n + 1;
      for (int i = 0; i <n ; ++i) b[i][0] = b[i][1] = 0;
      for (int i = 0; i < n; ++i) {
        curmin = min(curmin, a[i]);
        int start = max(0, i - a[i]);
        int end = min(i + a[i], n - 1);
        b[start][0]++;
        b[end][1]++;
      }
      if (curmin == n) break;
      int cur = 0;
      for (int i = 0; i < n; ++i) {
        cur += b[i][0];
        a[i] = cur;
        cur -= b[i][1];
        assert (cur >= 0);
      }
      assert (cur == 0);
    }
    for (int i = 0; i < n; ++i) {
      cout << a[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}



Measured memory_bytes: 5936
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
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;}

// 入力
int N;
long long a[100010][3];

// DP table
long long dp[100010][3];

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

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    long long res = 0;
    for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
    cout << res << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 




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


int main() {
    string s; cin >> s;
    ll ans = 100;
    rep(i, 0, 26){
        char c = 'a' + i;
        ll dis = 0;
        ll bf = 0;
        bool f = true;
        rep(j, 0, sz(s)){
            if(s[j] == c){ 
                if(bf == 0 && f){ dis = j; f = false;}
                chmax(dis, j-bf-1);
                bf = j;
            }
        }
        chmax(dis, sz(s)-1-bf);
        chmin(ans, dis);
    }
    co(ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9

int h,w;
char a[110][110];
int main(){
  cin>>h>>w;
  rep(i,h)rep(j,w){
    cin>>a[j+1][i+1];
  }

  rep(i,h+2){
    rep(j,w+2){
      if(i==0||j==0||i==h+1)cout<<'#';
      else if(j==w+1&&i!=0&&i!=h+1)cout<<'#';
      else cout<<a[j][i];
    }
    cout<<endl;
  }

}


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

int main() {
    ll n;
    cin >> n;
    vector<int> a(n);
    ll ans = 0;
    for(int i = 0; i < n-1; ++i) {
        cin >> a[i];
    }
    ans = a[0] + a[n-2];
    for(int i = 0; i < n-2; ++i) {
        ans += min(a[i], a[i+1]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio> 
using namespace std;
int f[1000005];
char s[1000005];
int main(){
	int n;
	scanf("%d",&n);
	scanf("%s",s+1);
	for (int i=1;i<=n;i++)
		if (s[i]=='W') f[i]=0;
		else f[i]=1;
	int head=1,tail=n,s=0;
	while(head<tail){
		while (head<tail && f[head]) head++;
		while (head<tail && !f[tail]) tail--;
		if (head<tail){
			s++;
			f[head]=1;
			f[tail]=0;
			head++,tail--;
		}
	}
	printf("%d\n",s);
	return 0;
}

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


int gcd(int x, int y){
    if(y>0){
        int r;
        r = x % y;
        return gcd(y, r);
    }else{
        return x;
    }
}

int main(){
    int x,y;

    cin >> x >> y; 

    if(x<y){
        int c;
        c = y;
        y = x;
        x = c;
    }
    cout << gcd(x, y)<< endl;
}

Measured memory_bytes: 3108
s = input()

n = len(s)
f = int((n-1)/2)
b = int((n+3)/2)

s_r = s[::-1]

s_f = s[:f]
s_f_r = s_f[::-1]

s_b = s[b-1:n]
s_b_r = s_b[::-1]

#print(s_b)

if(s_r == s and s_f == s_f_r and s_b == s_b_r):
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

#define FOR(i,n) for(ll i=0;i<n;i++) 
#define RFOR(i,n) for(ll i=n-1;i>=0;--i)
#define COUT(str) cout << str << endl

//宣言　
int ans; 

//入力
int a,b  ;
char op  ;

int main() {

	cin >> a >> op >> b;

	if (op == '-') ans = a - b;

	else ans = a + b;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n=int(input())
s=input()
a="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
s=list(s)
a=list(a)
for i in range(len(s)):
    if a.index(s[i]) + n >= 26:
        s[i]=a[int(a.index(s[i])+n-26)]
    else:
        s[i]=a[int(a.index(s[i])+n)]
s="".join(s)
print(s)        

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int N,M,X[100000],Y[99999],ans;
int main(){
    cin>>N>>M;
    for(int i=0 ; i<M ; i++)cin>>X[i];
    sort(X,X+M);
    ans=X[M-1]-X[0];
    for(int i=0 ; i<M-1 ; i++){
        Y[i]=X[i+1]-X[i];
    }
    sort(Y,Y+M-1);
    for(int i=M-2 ; i>=0 ; i--){
        if(N==1)break;
        N--;
        ans-=Y[i];
    }
    cout<<ans;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

ll ans;

string s;

vector<pair<char,ll> > t;

int main()
{
	cin >> s;
	for (int i = 0;i < s.size();i++)
	{
		if (i < s.size() - 1 && s[i] == 'B' && s[i + 1] == 'C')
		{
			if (t.size() && t.back().first == 'D')
				t.back().second++;
			else
				t.push_back(make_pair('D',1));
			i++;
		}
		else
		{
			if (t.size() && t.back().first == s[i])
				t.back().second++;
			else
				t.push_back(make_pair(s[i],1));
		}
	}
	for (int i = 0;i < t.size() - 1;i++)
		if (t[i].first == 'A' && t[i + 1].first == 'D')
		{
			if (i + 2 < t.size() && t[i + 2].first == 'A')
				t[i + 2].second += t[i].second;
			ans += t[i].second * t[i + 1].second;
		}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main() {
    string s;

    cin >> s;

    reverse(s.begin(), s.end());

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

    for (int i = 0; i < 4; i++) {
        reverse(t[i].begin(), t[i].end());
    }

    while (s.size()) {
        for (int i = 0; i < 4; i++) {
            if (s.substr(0, t[i].size()) == t[i]) {
                s = s.substr(t[i].size());
                break;
            }

            if (i == 3) {
                cout << "NO" << endl;
                return 0;
            }
        }
    }

    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 512
# include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;
typedef long long ll;


// %% begin matrix %%

typedef vector<double> vec;
typedef vector<vec> mat;

void pretty_print(mat g) {
  rep (i, g.size()) {
    rep (j, g[0].size()-1) {
      cout << g[i][j] << ' ';
    }
    cout << g[i][g[0].size()-1] << endl;
  }
}


mat mul(mat A, mat B) {
  mat C(A.size(), vec(B.size()));
  rep (i, A.size()) {
    rep (k, B.size()) {
      rep (j, B[0].size()) {
        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }
  return C;
}

// %% end matrix %%


vec jordan(mat &A, vec &b) {
  int n = A.size();

  // ?????§?????°??????
  mat B(n, vec(n+1));
  rep (i, n) {
    rep (j, n) {
      B[i][j] = A[i][j];
    }
    B[i][n] = b[i];
  }


  rep (i, n) {
    int pivot = i;

    // ?????????
    for (int j = i; j < n; j++) {
      if (abs(B[j][i]) > abs(B[pivot][i])) {
        pivot = j;
      }
    }
    swap(B[i], B[pivot]);

    if (abs(B[i][i]) < 0.0000001) {
      return vec();
    }

    for (int j = i+1; j <= n; j++) B[i][j] /= B[i][i];
    rep (j, n) {
      if (i != j) {
        for (int k = i+1; k <= n; k++) {
          B[j][k] -= B[j][i] * B[i][k];
        }
      }
    }
  }

  vec x(n);
  rep (i, n) {
    x[i] = B[i][n];
  }

  return x;
}




int main() {
  double a, b, c, d, e, f;

  while (cin >> a >> b >> c >> d >> e >> f) {

    mat A = {
      {a, b},
      {d, e}
    };

    vec B = {
      c, f
    };

    vec x = jordan(A, B);
    // cout << x[0] << " " << x[1] << endl;
    printf("%4.3f %4.3f\n", x[0], x[1]);
  } 
}

Measured memory_bytes: 3264
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int N=5005;
int n,k;string s,ans;
string rev(string str){
	reverse(str.begin(),str.end());
	return str;
}
int main(){
	scanf("%d%d",&n,&k),cin>>s;
	char ch=*min_element(s.begin(),s.end());
	if(k>=14){rep(i,1,n)putchar(ch);puts("");return 0;}
	while(k--){
		s+=rev(s);
		if(!k){
			ans="";
			rep(i,0,n)if(s[i]==ch){
				string t=s.substr(i,n);
				if(ans==""||t<ans){
					ans=t;
				}
			}
			cout<<ans<<endl;
		}else{
			ans="";
			rep(i,0,n)if(s[i]==ch){
				string t=s.substr(i,n);
				if(ans==""||t<ans){
					ans=t;
				}
			}
			s=rev(ans);
		}
	}
	return 0;
}

Measured memory_bytes: 3708
import java.io.InputStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		InputStream is = System.in;
		solve(is);
	}

	private static void solve(InputStream is) {
		try (Scanner cin = new Scanner(is)) {
			int n = cin.nextInt();
			int[] a = new int[n];
			int ans = 0;

			for (int i = 0; i < n; i++) {
				a[i] = cin.nextInt();
			}

			for (int i = 0; i < n;) {
				if (a[i] % 2 == 0) {
					a[i] /= 2;
					ans++;
				} else {
					i++;
				}
			}

			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 36248
import math
n,d=map(int,input().split())
x=[]
for i in range(n):
    x.append(list(map(int,input().split())))
count=0
for i in range(n):
    for j in range(i+1,n):
        distance=0
        for k in range(d):
            distance+=(x[i][k]-x[j][k])**2
        if math.sqrt(distance)==int(math.sqrt(distance)):
            count+=1
print(count)

Measured memory_bytes: 9140
while True:
    H, W = map(int, input().split())
    if not(H or W):
        break
    print('#' * W)
    for i in range(H-2):
        print('#', end='')
        print('.' * (W - 2), end='')
        print('#')
    print('#' * W, end='\n\n')

Measured memory_bytes: 7640
# coding: utf-8

N = int(input())
ao = {}
ao2 = []
memo = {}
for i in range(N):
    ao_t = input()
    ao2.append(ao_t)

M = int(input())
aka = {}
aka2 = []
for i in range(M):
    aka_t  = input()
    aka2.append(aka_t)


for i in ao2:
    try:
        ao[i] += 1
    except:
        ao[i] = 1

for i in aka2:
    try:
        aka[i] += 1
    except:
        aka[i] = 1




ans = 0
meno = 0

memo2 = {}

for k, v in ao.items():
    try:
        memo = aka[k]
        memo2[k] = v - memo
    except:
        memo2[k] = v

flag = 0
for k, v in sorted(memo2.items(), key=lambda x: -x[1]):
    if flag == 0:
        if v < 0:
            print(0)
        else:
            print(v)
    flag = 1




















Measured memory_bytes: 3064
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	sc.Split(bufio.ScanWords)
	var n = nextInt()
	var q = nextInt()

	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, 0)
	}

	for i := 0; i+1 < n; i++ {
		a := nextInt()
		b := nextInt()
		a--
		b--
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}

	value := make([]int, n)
	for i := 0; i < q; i++ {
		p := nextInt()
		x := nextInt()
		p--
		value[p] += x
	}

	used := make([]bool, n)
	queue := make([]int, n)
	index := 0

	pushBack := func(x int) {
		queue[index] = x
		index++
	}

	pushBack(0)
	used[0] = true

	for i := 0; i < n; i++ {
		cur := queue[i]
		for _, u := range g[cur] {
			if used[u] {
				continue
			}
			used[u] = true
			value[u] += value[cur]
			pushBack(u)
		}
	}

	for _, x := range value {
		fmt.Println(x)
	}
}


Measured memory_bytes: 21504
import java.util.Scanner;

// https://atcoder.jp/contests/agc034/submissions/5769395
// https://atcoder.jp/contests/agc034/submissions/5749660

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		try (Scanner sc = new Scanner(System.in)) {
			int fieldSize = sc.nextInt(); // N
			int sNow = sc.nextInt() - 1; // A
			int hNow = sc.nextInt() - 1; // B 
			int sGoal = sc.nextInt() - 1; // C
			int hGoal = sc.nextInt() - 1; // D
			String s = sc.next();
			
			boolean q1 = s.substring(sNow, sGoal).contains("##");
			boolean q2 = s.substring(hNow,hGoal).contains("##");
			
			boolean res = false;
			res = !(q1 || q2);
			
			if (sGoal > hGoal) {
				/*
				 * 開始視点がH君よりうしろのS君のゴールが、H君より後ろにある場合、
				 * 追い抜く必要がある。
				 * 追い抜くには、H君のゴール地点の１つ後ろまでを含めte
				 * ”...”があれば、途中でH君を追い抜ける。
				 * 1. 　”.hGol.”
				 */
				res &= s.substring(hNow-1, hGoal+2).contains("...");
			}
			
			System.out.println(res ? "Yes" : "No");
			
		} catch (Exception e) {
			// TODO: handle exception
		}

	}

}


Measured memory_bytes: 28224