akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)



int main(){
	ll x,y;
	cin >> x >> y;
	if(x%y==0){
		cout << -1 << endl;
	}else{
		cout << x << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,p,q,ct,x,z;
    cin>>n;
    ct=0;
    for(ll i=1;i<=n;i++)
    {
        x=i; z=0;
        while(x!=0)
        {
            x=x/10; z++;
        }
        if(z%2==1) ct++;
    }
    cout<<ct<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC98 C

#累積和を用いる
from itertools import accumulate

n = int(input())
s = list(input())

x = [0]+[1 if s[i] == 'W' else 0 for i in range(n)]
y = [1 if s[i] == 'E' else 0 for i in range(n)] + [0]

mx = list(accumulate(x))
my = list(accumulate(y[::-1]))
my = my[::-1]
mi = float('inf')
for i in range(n+1):
    a = mx[i]
    b = my[i]
    mi = min(mi,a+b)
print(mi)


Measured memory_bytes: 118084
# Union Find
class UnionFind():
    # parents:親要素の番号，要素が根なら-グループの要素数
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # xが所属するグループの根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # xとyのグループを併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r))
                         for r in self.roots())

    # def max_size_group(self):
    #     ret = 0
    #     for mem in self.all_group_members():
    #         ret = max(ret, len(self.members(mem)))
    #         # print(self.members(mem))
    #     return ret


N, M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    uf.union(a - 1, b - 1)
ans = 0
for i in range(N):
    ans = max(ans, uf.size(i))
print(ans)


Measured memory_bytes: 14592
def resolve():
    n = int(input())
    H = list(map(int, input().split()))
    max_c = 0
    c = 0
    for i in range(n-1):
        now = H[i]
        nxt = H[i+1]
        if now >= nxt:
            c += 1
        else:
            max_c = max(max_c, c)
            c = 0
    print(max(max_c,c)) 
resolve()

Measured memory_bytes: 20652
def solve():
    n = int(input())
    P = [int(i) for i in input().split()]
    count = 0
    for i in range(1, n - 1):
        PP = [P[i - 1], P[i], P[i + 1]]
        PP.sort()
        if P[i] == PP[1] and PP[1] != PP[2]:
            count += 1
    print(count)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 0;

ll s, w;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
	
	cin >> s >> w;
	if(w >= s){
		cout << "unsafe" << '\n';
	}
	else{
		cout << "safe" << '\n';
	}
}


Measured memory_bytes: 3636
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
	int a, b;
	void ans() {
		cin >> a >> b;
		string sgn[3] = { "Zero","Positive","Negative" };
		string res;
		if (a > 0) res = sgn[1];
		else if (b >= 0) res = sgn[0];
		else if ((b - a) % 2) res = sgn[1];
		else res = sgn[2];
		cout << res << "\n";
	}

};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	question q;
	q.ans();
	
	return 0;
}



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

int main() {
    string n;
   
 
   cin >> n;
  
   int sum = 700;
  
   for(int i = 0;i<3;i++){
     
     if(n[i]=='o'){
       
       sum = sum + 100;
       
     }
     

   }
  
   cout << sum << endl;
 
  return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

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

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

    int N;
    map<int, int> A;
    cin >> N;
    REP(i, N-1) {
        int a;
        cin >> a;
        A[a]++;
    }
    for(int i = 1; i <= N; ++i) {
        if(A.count(i) > 0) {
            cout << A[i] << endl;
        }
        else {
            cout << "0" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 16104
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,m;cin >> n >>m;
    vector<pair<pl,ll>> v(m);
    rep(i,m){
        cin >> v[i].fi.fi >> v[i].fi.se;
        v[i].se=i;
    }
    sort(all(v));
    vector<string> s(m);
    int k=1;
    rep(i,m){
        string res;
        if(i!=0){
            if(v[i].fi.fi!=v[i-1].fi.fi)k=1;
            else k++;
        }
        res+=to_string(k);
        while(res.size()<6){
            res='0'+res;
        }
        string form;
        int city=v[i].fi.fi;
        form+=to_string(city);
        while(form.size()<6){
            form='0'+form;
        }
        s[v[i].se]=form+res;
    }
    rep(i,m)cout << s[i] <<endl;
}

Measured memory_bytes: 9344
#include <iostream>

using namespace std;

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

    int a, b, c, x;
    int total = 0;
    cin >> a >> b >> c >> x;

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

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

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


int main(){
    int A,B,C;
    cin >> A >> B >> C;

    if(A < B + C)
        cout << B + C - A << endl;
    else
        cout << 0 <<endl;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int n, c[12], d, head;
int memo[12][48][5][5];

bool rec(int at, int r, int x, int y) {
    if (at == 12) return r == 0 && x == 0 && y == 0;
    if (memo[at][r][x][y] != -1) return memo[at][r][x][y];
    bool ans = false;
    rep (p, 2) rep (q, 5) {
        const int use = x + y + q + p*3 + 2*(head == at);
        if (use > 4 || use > c[at]+r || use < c[at]) continue;
        if (rec(at+1, r-use+c[at], y, q)) { ans = true; goto ret; }
    }
ret:
    return (memo[at][r][x][y] = ans);
}

bool solve() {
    rep (k, 12) {
        head = k;
        memset(memo, -1, sizeof(memo));
        if (rec(0, d, 0, 0)) return true;
    }
    return false;
}

int main() {
    scanf("%d", &n);
    rep (i, 3*n+1) {
        char buf[8];
        scanf("%s", buf);
        if (buf[0] == '*') d++;
        else c[atoi(buf)-1]++;
    }
    bool some = false;
    rep (i, 12) {
        c[i]++;
        if (solve()) printf("%d\n", i+1), some = true;
        c[i]--;
    }
    if (!some) printf("%d\n", -1);
    return 0;
}

Measured memory_bytes: 1092
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		String s = sc.next();
		sc.close();
		out.println(s.equals("AAA")||s.equals("BBB")?"No":"Yes");
	}
}


Measured memory_bytes: 21588
str = gets

a = (str[0] == str[1]) && (str[2] == str[3]) && (str[0] != str[2])
b = (str[0] == str[2]) && (str[1] == str[3]) && (str[0] != str[1])
c = (str[0] == str[3]) && (str[1] == str[2]) && (str[0] != str[1])

condition = a || b || c

condition ? result = "Yes" : result = "No"

print result


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int s[n];
  int i,j,sum=0;
  for(i=0;i<n;i++){
    cin >> s[i];
  }
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
        sum+=s[i]*s[j];
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int N,c[3][3];
int a[3],b[3];
bool s=0;
int main(void){
	for(int i=0;i<3;i++)for(int j=0;j<3;j++)cin>>c[i][j];
	for(int i=0;i<=c[0][0];i++){
		a[0]=i;
		b[0]=c[0][0]-i;
		a[1]=c[1][0]-b[0];
		a[2]=c[2][0]-b[0];
		b[1]=c[0][1]-a[0];
		b[2]=c[0][2]-a[0];
		if(c[1][1]==a[1]+b[1]&&c[2][1]==a[2]+b[1]&&c[1][2]==a[1]+b[2]&&c[2][2]==a[2]+b[2]){
			s=1;
			break;
		}
	}
	if(s)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
ll f(ll x,ll y,ll z){
    return x*x+y*y+z*z+x*y+y*z+z*x;
}
int main(void){
    ll n;
    cin>>n;
    ll c[n+1];
    rep(0,i,n+1)c[i]=0;
    for(ll x=1;f(x,1,1)<=n;++x){
        for(ll y=1;f(x,y,1)<=n;++y){
            for(ll z=1;f(x,y,z)<=n;++z){
                ++c[f(x,y,z)];
            }
        }
    }
    rep(1,i,n+1){
        cout<<c[i]<<endl;
    }
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    rep(i, 0, 8){
        string t = s.substr(0, i) + s.substr(n - 7 + i);
        if(t == "keyence"){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<sqrt(n);i++)
    {
        if(n%i==0)
        {
          c++;
        }
    }
    c=c*2;
    if(pow(sqrt(n),2)==(sqrt(n)*sqrt(n)))
        c++;
    return  c;
}
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
  long long int a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k<=a)
    cout<<k;
else if(k<=(a+b))
  cout<<a;
else 
    cout<<a-(k-(a+b));

 return 0;
}








Measured memory_bytes: 3568
package main

import (
	"fmt"
	"sort"
)

func change(n int, a []int) int {
	var l []int
	for _, n := range a {
		var c int
		for ; n%2 == 0; n /= 2 {
			c++
		}
		l = append(l, c)
	}
	sort.Ints(l)
	return l[0]
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	fmt.Println(change(n, a))
}


Measured memory_bytes: 512
s = input()
t = input()
sl = len(s)
tl = len(t)
d = sl -tl
ans = tl
for i in range(d + 1):
  tmp = 0
  for j in range(tl):
    if s[i + j] != t[j]:
      tmp += 1
  ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n; string a,b,c;
    cin>>n>>a>>b>>c;
    int ans=0;
    rep(i,n){
        ans+=(a[i]==b[i]&&b[i]==c[i])+(a[i]==b[i]||b[i]==c[i]||c[i]==a[i]);
    }
    cout<<2*n-ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define N 10005
using namespace std;
ll n,a[N],b[N],s;
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]), s-=a[i];
	for(int i=1;i<=n;i++) scanf("%lld",&b[i]), s+=b[i];
	if(s<0) return puts("No"), 0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]<b[i])
		{
			s-=(b[i]-a[i]+1)/2;
			if(s<0) return puts("No"), 0;
		}
	}
	puts("Yes");
}

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

int N;
vector<vector<pair<int,int>>> A;
int ans=0;

bool check2(vector<int> &is_shoujiki, int new_shoujiki) {
  for(auto a : A[new_shoujiki]) {
    if( is_shoujiki[a.first] == -1 ) {
      is_shoujiki[a.first] = a.second;
      if(a.second == 1) {
        if(check2(is_shoujiki, a.first)==false) {
          return false; 
        }
      }
    }
    else if( is_shoujiki[a.first] != a.second ) {
      return false;
    }
  }
  return true;
}

bool check(set<int> &shoujiki) {
  vector<int> is_shoujiki(N, -1);
  for(auto s : shoujiki) is_shoujiki[s]=1;

  for(auto s : shoujiki) {
    for(auto a : A[s]) {
      if( is_shoujiki[a.first] == -1 ) {
        is_shoujiki[a.first] = a.second;
        if(a.second == 1) {
          if(check2(is_shoujiki, a.first)==false) {
            return false; 
          }
        }
      }
      else if( is_shoujiki[a.first] != a.second ) {
        return false;
      }
    }
  }

  return true;
}


void dfs(set<int> &shoujiki, int max_shoujiki) {
  if((int)shoujiki.size() == max_shoujiki) {
    cerr << "aaa ";
    for(auto s : shoujiki) cerr << s << " ";
    cerr << endl;
    if(check(shoujiki)) {
      cerr << "ok" << endl;
      ans=max(max_shoujiki, ans);
    }
  }

  for(int i=*max_element(shoujiki.begin(), shoujiki.end()); i < N; i++) {
    if(shoujiki.count(i)) continue;
    shoujiki.insert(i);
    dfs(shoujiki, max_shoujiki);
    shoujiki.erase(i);
  }
}

signed main() {
  cin >> N;
  A.resize(N);

  for(int i=0; i<N; i++) {
    int a; cin >> a;
    A[i].resize(a);
    for(int j=0; j<a; j++) {
      int x,y;
      cin >> x >> y;
      A[i][j] = make_pair(x-1,y);
    }
  }

  for(int max_shoujiki=0; max_shoujiki <= N; max_shoujiki++) {
    set<int> shoujiki;
    dfs(shoujiki, max_shoujiki);
  }
  cout << ans << endl;

}

Measured memory_bytes: 256
"""
author : halo2halo
date : 30, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = readline().decode('utf8')
ans = 0
for i in range(2, len(S) + 1):
    ck = S[:-1 * i]
    if len(ck) % 2 == 0:
        if ck[:len(ck) // 2] == ck[len(ck) // 2:]:
            ans = len(ck)
            break
print(ans)


Measured memory_bytes: 3064
//Chandigarh University
//author:- shivamkr21
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin >> n;
    int ar[n];
    for(int i=0;i<n;i++)
    {
        cin>>m;
        ar[i]=m;
    }
    sort(ar,ar+n);
    int c;
    for(int i=ar[1];i>0;i--)
    {
        c=0;
        for(int j=0;j<n;j++)
        {
            if(ar[j]%i!=0)
            {
                c++;
            }
        }
        if(c<2)
        {
            cout << i;
            break;
        }
    }
    return 0;
}


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

typedef long long ll;

int main(){
  int x, y, z;
  cin >> x >> y >> z;
  
  int temp = x;
  x = y;
  y = temp;
  
  temp = x;
  x = z;
  z = temp;
  
  cout << x << ' ' << y << ' ' << z << endl;
  
  return 0;
}

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

#define F first
#define S second
#define pb push_back
#define mp make_pair

ll gcd(ll a, ll b){
	if (a == 0) return b;
	return gcd(b%a, a);
}

ll lcm(ll a, ll b){
	return (a/gcd(a, b))*b;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll n,k,i,j;

	cin >> n >> k;

	ll a[n];

	for(i=0;i<n;i++)
		cin >> a[i];


	for(i=0;i<n-k;i++)
	{
		if(a[i] >= a[i + k])
			cout << "No\n";
		else
			cout << "Yes\n";
	}



	
}

Measured memory_bytes: 5204
x, k, d = map(int, input().split())
x = abs(x)


lap, rem = divmod(x, d)
if lap >= k:
    print(x - k * d)
    exit()

nokori = k - lap
rem0, rem1 = rem, d - rem
if nokori % 2 == 0:
    print(rem0)
else:
    print(rem1)

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

using namespace std;

using ll = long long;

int main() {
   ios_base::sync_with_stdio(false);
   int N;
   cin >> N;
   vector<int> A(3 * N);
   for (int &x : A) cin >> x;
   sort(A.rbegin(), A.rend());
   ll ans = 0;
   for (int i = 1; i < 2 * N; i += 2) ans += A[i];
   cout << ans << "\n";
   return 0;
}


Measured memory_bytes: 1408
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(n):
        pa = LI()
        da = LI()
        e = collections.defaultdict(list)
        for i in range(n-1):
            a = i + 2
            b = pa[i]
            d = da[i]
            e[a].append((b,d))
            e[b].append((a,d))
        rf = collections.defaultdict(bool)
        s = None
        for k,v in e.items():
            if len(v) == 1:
                rf[k] = True
            else:
                s = k
        r = 0
        for k,v in e.items():
            for l,d in v:
                if k > l:
                    continue
                if rf[k] or rf[l]:
                    r += d
                else:
                    r += d * 3

        def search(s):
            d = collections.defaultdict(lambda: inf)
            d[s] = 0
            q = []
            heapq.heappush(q, (0, s))
            v = collections.defaultdict(bool)
            while len(q):
                k, u = heapq.heappop(q)
                if v[u]:
                    continue
                v[u] = True

                for uv, ud in e[u]:
                    if v[uv] or rf[uv]:
                        continue
                    vd = k + ud
                    if d[uv] > vd:
                        d[uv] = vd
                        heapq.heappush(q, (vd, uv))

            return d

        sd = search(s)
        sm = max(sd.values())
        for k,v in sd.items():
            if v == sm:
                s = k
        sd = search(s)
        sm = max(sd.values())

        return r - sm

    while 1:
        n = I()
        if n == 0:
            break
        rr.append(f(n))

    return '\n'.join(map(str,rr))


print(main())



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

int main() {
  int A, B, C, D;
  int Acnt, Ccnt = 0;
  cin >> A >> B >> C >> D;
    A -= D;
  while(A > 0) {
    A -= D;
    Acnt++;
  }
    C -= B;
  while(C > 0) {
    C -= B;
    Ccnt++;
  }
  if (Acnt < Ccnt) cout << "No";
  else        cout << "Yes";
}


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

using namespace std;

int main() {

    char b;
    scanf("%c", &b);
    
    if(b == 'A') cout << 'T' << endl;
    if(b == 'C') cout << 'G' << endl;
    if(b == 'G') cout << 'C' << endl;
    if(b == 'T') cout << 'A' << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int N=gi();
	    String S=gs();

	    int s=0;
	    int e=0;
	    int sc=0;
	    for (int i=0; i<N;i++) {
	    	char c=S.charAt(i);
	    	if(c=='(') {
	    		s++;
	    	} else {
	    		e++;
	    	}
	    	sc=Math.max(sc, e-s);
	    }

	    int s2=0;
	    int e2=0;
	    int ec=0;
	    for (int i=N-1; i>=0;i--) {
	    	char c=S.charAt(i);
	    	if(c=='(') {
	    		s2++;
	    	} else {
	    		e2++;
	    	}
	    	ec=Math.max(ec, s2-e2);
	    }

	    StringBuilder sb=new StringBuilder();
	    for(int i=0; i<sc;i++) {
	    	sb.append('(');
	    }
	    sb.append(S);
	    for(int i=0; i<ec;i++) {
	    	sb.append(')');
	    }
	    String ns=sb.toString();


        System.out.println(ns);
	}

	public static class Edge {
	    private int from;
	    private int to;
	    private long cost;

	    public Edge(int f, int t, long c) {
	    	this.from=f;
	    	this.to=t;
	    	this.cost=c;
	    }

	    public int gfrom() {
	    	return from;
	    }

	    public int gto() {
	    	return to;
	    }

	    public long gcost() {
	    	return cost;
	    }

	    public void sfrom(int f) {
	    	from=f;
	    }

	    public void sto(int t) {
	    	to=t;
	    }

	    public void scost(int c) {
	    	cost=c;
	    }
	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35596
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	const int mod = 1e9 + 7;
	int n, m; cin >> n >> m;
	ll s1 = 0, s2 = 0, a = 0, b = 0;
	int p;
	rep(i, n){
		int x; cin >> x;
		if(i) {
			(a += (x - p) * (ll)i) %= mod;
			(s1 += a) %= mod;
		}
		p = x;
	}
	rep(i, m){
		int x; cin >> x;
		if(i) {
			(b += (x - p) * (ll)i) %= mod;
			(s2 += b) %= mod;
		}
		p = x;
	}
	cout << s1 * s2 % mod << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int a[100] = { 0 };
	int n;
	while (cin >> n)
		a[n - 1]++;

	int ma = 0;
	REP(i, 100){
		ma = max(ma, a[i]);
	}
	REP(i, 100){
		if (a[i] == ma)
			cout << (i + 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
K,X=map(int,input().split())

def create_num(K,X):
    ans = [X-(K-1) + i for i in range(K*2-1)]
    return ans

if K == 1:
    print(X)
else:
    ans = create_num(K,X)
    L=[str(a) for a in ans]
    L=" ".join(L)
    print(L)



Measured memory_bytes: 2940
//#pragma GCC optimize(3)
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set> 
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll unsigned long long
#define db double
#define inf 201
#define INF (int)1e8 
#define mod (int)(1e9+7)
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;

ll Qpow(ll x,ll k){
	ll ans=1LL;
	while (k){
		if (k&1LL){
			ans=(ans*x)%mod;
		}
		x=(x*x)%mod;
		k/=2LL;
	}
	return ans;
}

ll getinv(ll x){
	return Qpow(x,mod-2LL);
}

const int lim=200;
ll fact[inf],invf[inf];

void pre_work(void){
	fact[0]=invf[0]=1LL;
	for (int i=1;i<=lim;i++){
		fact[i]=(fact[i-1]*(ll)i)%mod;
		invf[i]=getinv(fact[i]);
	}
	return;
}

ll C(int n,int m){
	return fact[n]*invf[m]%mod*invf[n-m]%mod;
}

int gcd(int n,int m){
	if (m==0){
		return n;
	}
	return gcd(m,n%m);
}

ll Polya(int n,int k){
	ll ans=0LL;
	for (int i=1;i<=n;i++){
		ans=(ans+Qpow(k,(ll)gcd(i,n)));
	}
	return ans*getinv(n)%mod;
}

int n,m,K;

struct edge{
	int y,nxt;
	edge(){}
	edge(int yy,int nn){
		y=yy,nxt=nn;
	}
}e[inf*2];
int ecnt,head[inf];

void addedge(int x,int y){
	ecnt++;
	e[ecnt]=edge(y,head[x]);
	head[x]=ecnt;
	return;
}

int dfn[inf],low[inf],sta[inf],top,T;
ll ans;
set <int> S;

void dfs(int u,bool p=0){
	dfn[u]=low[u]=++T;
	sta[++top]=u;
	for (int i=head[u];i;i=e[i].nxt){
		int v=e[i].y;
		if (!dfn[v]){
			dfs(v);
			low[u]=min(low[u],low[v]);
			if (low[v]>=dfn[u]){
				S.clear();
				int cntn=0,cntm=0;
				while (top){
					S.insert(sta[top]);
					cntn++;
					if (sta[top]==v){
						top--;
						break;
					}
					top--;
				}
				S.insert(u);
				cntn++;
				set <int>::iterator it;
				for (it=S.begin();it!=S.end();it++){
					int tmp=(*it);
					for (int k=head[tmp];k;k=e[k].nxt){
						if (S.count(e[k].y)){
							++cntm;
						}
					}
				}
				cntm/=2;
				if (cntm<cntn){
					ans=(ans*K)%mod;
				}
				else if (cntm==cntn){
					ans=(ans*Polya(cntn,K))%mod;
				}
				else{
					ans=(ans*C(cntm+K-1,K-1))%mod;
				}
			}
		}
		else{
			low[u]=min(low[u],dfn[v]);
		}
	}
	if (p){
		top--;
	}
	return;
}

int main(){
	pre_work();
	rd(n) rd(m) rd(K)
	int x,y;
	for (int i=1;i<=m;i++){
		rd(x) rd(y)
		addedge(x,y);
		addedge(y,x);
	}
	ans=1LL;
	for (int i=1;i<=n;i++){
		if (!dfn[i]){
			dfs(i,1);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] arg){
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long x = sc.nextLong();

    long ans =b/x-a/x;
    if(a%x==0) {
    ans+=1;
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 23380
x, n = map(int, input().split())
p = list(map(int, input().split()))

a = set()
for i in range(-100, 201):
    a.add(i)
for v in p:
    a.remove(v)
a = list(a)
b = list(map(lambda v: abs(v - x), a))
print(a[b.index(min(b))])


Measured memory_bytes: 9036
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
 
#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;
 
const ll inf = 1LL << 60;
 
template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
vector<vector<bool>> used;
vector<bool> visited;
vector<bool> now;
ll N;
mat graph;
vector<pair<ll, ll>> edges;
 
void dfs (ll v, ll from) {
    Rep (i, N-1) {
        used[v][i] = now[i];
    }
    for (ll e : graph[v]) {
        ll nv;
        if (edges[e].first == v) nv = edges[e].second;
        else nv = edges[e].first;
 
        if (nv == from) continue;
 
        now[e] = true;
        dfs(nv, v);
        now[e] = false;
    }
 
    return;
}
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    cin >> N;
    graph.assign(N, vec());
    edges.assign(N-1, pair<ll, ll>());
    Rep (i, N-1) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(i);
        graph[b].push_back(i);
        edges[i] = {a, b};
    }
 
    used.assign(N, vector<bool>(N-1, false));
    visited.assign(N, false);
    now.assign(N-1, false);
    visited[0] = true;
 
    dfs(0, -1);
 
    // Rep (i, N) {
    //     Rep (j, N-1) {
    //         cout << used[i][j] << " \n"[j==N-2];
    //     }
    // }
 
    ll M;
    cin >> M;
    vec u(M), v(M);
    vector<vector<bool>> cond(M, vector<bool>(N-1, false));
    Rep (i, M) {
        cin >> u[i] >> v[i];
        u[i]--; v[i]--;
        Rep (j, N-1) {
            cond[i][j] = cond[i][j] ^ used[u[i]][j];
            cond[i][j] = cond[i][j] ^ used[v[i]][j];
        }
    }
 
    ll ans = 0;
    Rep (mask, 1 << M) {
        ll cnt = 0;
        ll tmp = 1;
        vector<bool> check(N-1, false);
        Rep (i, M) {
            if (mask & (1 << i)) {
                cnt++;
                Rep (j, N-1) {
                    check[j] = check[j] | cond[i][j];
                }
            }
        }
 
        Rep (j, N-1) {
            if (!check[j]) tmp *= 2;
        }
 
        if (cnt % 2 == 0) ans += tmp;
        else ans -= tmp;
    }
 
    cout << ans << "\n";
 
}

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

#define ull unsigned long long int
#define ll long long int

const ll M=1e9+7;

ll mod(ll n){
	return (n%M + M)%M;	
}
ll add(ll a, ll b){
	return mod(mod(a)+mod(b));
}
ll mul(ll a, ll b){
	return mod(mod(a)*mod(b));
}
ll modpow(ll x, ll n) 
{ 
	if (n == 0) 
		return 1%M;
	if (n == 1)
		return x%M; 
	ll u = modpow(x,n/2); 
	u = mul(u,u); 
	if (n%2) 
		u = mul(u,x); 
	return u; 
}
ll gcd(ll a,ll b){
	if(b==0)
		return a;
	return gcd(b,a%b);
}
bool isPrime(ll n){
	int end = sqrt(n);
	for(int i=2;i<=end;i++)
		if(n%i==0)
			return false;
	return true;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  
    
    int t=1;

    while(t--){
    	int s;
    	cin>>s;

    	vector<int> dp(s+1);

    	for(int i=3;i<=s;i++){
    		int end = i-3;
    		for(int j=end;j>=3;j--){
    			dp[i]=add(dp[i],dp[j]);
    		}
    		dp[i]=add(dp[i],1);
    	}

    	cout<<dp[s]<<endl;
    }

    
    return 0;
}


Measured memory_bytes: 3712
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int S;
	cin >> S;

	if (S / 100 > 12 && S % 100 > 12 || S / 100 > 12 && S % 100 == 0 || S / 100 == 0 && S % 100 > 12 || S / 100 == 0 && S % 100 == 0) cout << "NA" << "\n";
	else if (S / 100 > 12 || S / 100 == 0) cout << "YYMM" << "\n";
	else if (S % 100 > 12 || S % 100 == 0) cout << "MMYY" << "\n";
	else cout << "AMBIGUOUS" << "\n";

	return 0;
}

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

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

    if(s[2]==s[3] && s[4]==s[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  rep(i, n) cin >> t[i];
  int tot = 0;
  rep(i, n) tot += t[i];
  int m;
  cin >> m;
  rep(i, m) {
    int p, x;
    cin >> p >> x;
    cout << tot + x - t[p - 1] << endl;
  }
  return 0;
}

Measured memory_bytes: 3600
n = int(input())
d = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(d[n-1])


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N, K, D = 0;
  cin >> N >> K;
    
  for(int i=0; i<N; i++){
    int x;
    cin >> x;
    if(K-x > x){
      D += 2*x;
    }
    else{
      D += 2*(K-x);
    }
   }
  cout << D << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string S; cin >> S;
    map<char,int> mp;
    for(auto c:S) mp[c]++;
    if(mp.begin()->second==2 && mp.rbegin()->second==2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    //cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}


int main(){
    int N; cin >> N;
    //const int n = N;
    int a[100010];
    map<int,int> mp;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        mp[a[i]]++;
    }
    int ans = 0;
    if (mp.size() % 2 == 1) ans = mp.size();
    else ans = mp.size()-1;
    cout << ans << endl;
}

Measured memory_bytes: 5376
//第 4 問: ABC 087 B - Coinsi (200 点)
/*
 * dreamererasereraserdream
erasereraserdream
reraserdream
NO
 */

import java.util.Scanner;

public class Main{

	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);

		String S = scan.next();
		StringBuilder sb = new StringBuilder();
		sb.append(S);

		/*
		String A = "";
		String B = "";
		String C = "";
		*/

		while(true) {

			int counter = sb.length();

			if (counter > 7) {

				if (sb.substring(0,8).equals("dreamera")){

					sb = sb.delete(0,5);

				}
				else if(sb.substring(0,7).equals("dreamer")){

					sb = sb.delete(0,7);

				}
				else if(sb.substring(0,6).equals("eraser")){

					sb = sb.delete(0,6);
					//System.out.println("Err");

				}
				else if ((sb.substring(0,5).equals("dream")) || (sb.substring(0,5).equals("erase"))) {

					sb = sb.delete(0,5);
					//System.out.println("Err2");

				}
				else {
					System.out.println("NO");
					//System.out.println("A");
					break;
				}

			//System.out.println(sb);

			}
			else if (counter == 7) {
				if(sb.toString().equals("dreamer")) {
					System.out.println("YES");
					break;
				}
				else {
					System.out.println("NO");
					//System.out.println("B");
					break;
				}

			}
			else if (counter == 6) {

				if(sb.toString().equals("eraser")) {
					System.out.println("YES");
					break;
				}
				else {
					System.out.println("NO");
					//System.out.println("C");
					break;
				}

			}
			else if (counter == 5) {
				if ((sb.toString().equals("dream")) || (sb.toString().equals("erase"))) {
					System.out.println("YES");
					break;
				}
				else{
					System.out.println("NO");
					//System.out.println("D");
					break;
				}
			}
			else {
				System.out.println("NO");
				//System.out.println("E");
				break;
			}

			//System.out.println(sb);

		}

	}
}



Measured memory_bytes: 30180
#include<bits/stdc++.h>
using namespace std;
struct amida{int h,p,q;};
int main(){
    int n,m,a;
    while(cin>>n>>m>>a,n){
        amida am[1001];
        for(int i=0;i<m;i++){
            cin>>am[i].h>>am[i].p>>am[i].q;
        }
        for(int i=1001;i>=0;i--){
            //cout<<am[j].h<<" "<<am[j].p
            for(int j=0;j<m;j++){
                if(am[j].h==i && (a==am[j].p || a==am[j].q)){
                    if(a==am[j].p){
                        a=am[j].q;
                    }
                    else a=am[j].p;
                    //cout<<"a="<<a<<endl;
                    break;
                }
                else continue;
            }
        }
        cout<<a<<endl;
    }
    return 0;
}




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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> jobs(m);
    priority_queue<int> pq;
    ll ans = 0;
    
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        if (a > m) continue;
        jobs[m - a].push_back(b);
    }
    
    for (int i = (m - 1); i >= 0; i--) {
        for (int u : jobs[i]) {
            pq.push(u);
        }
        
        if (!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5504
#include <iostream>
#include <vector>

const int mod = 1000000007;

int main(){
  int N, K;
  std::cin >> N >> K;

  std::vector<int> n_int;

  for(int i = 1; i <= N; i++){
    if(i*i > N) break;
    n_int.push_back(1);
  }
  int prev_max = n_int.size();
  for(int i = n_int.size(); i > 0; i--){
    int n = N/i-prev_max;
    if(n > 0) n_int.push_back(n);
    prev_max = N/i;
  }
  int nsize = n_int.size();

  long long int dp[2][nsize];

  dp[0][0] = n_int[0];
  for(int i = 1; i < nsize; i++){
    dp[0][i] = (dp[0][i-1]+n_int[i])%mod;
  }

  for(int k = 1; k < K; k++){
    int k2 = k%2;
    for(int i = 0; i < nsize; i++){
      dp[k2][i] = (n_int[i]*dp[1-k2][nsize-1-i])%mod;
      if(i > 0) dp[k2][i] = (dp[k2][i]+dp[k2][i-1])%mod;
    }
  }

  std::cout << dp[(K-1)%2][nsize-1] << std::endl;

  return 0;
}



Measured memory_bytes: 1660
n, k = map(int, input().split())

a = list(map(int, input().split()))
a_plus = [max(a[i], 0) for i in range(n)]

a_sum = [0]
a_plus_sum = [0]

for i in range(n):
    a_sum.append(a_sum[-1] + a[i])
    a_plus_sum.append(a_plus_sum[-1] + a_plus[i])

best = -1
best_lost = 10**16
for i in range(k, n+1):
    temp_lost = (a_plus_sum[i] - a_plus_sum[i-k]) - max((a_sum[i] - a_sum[i-k]), 0)
    if best_lost >  temp_lost:
        best_lost = temp_lost
        best = i
        
ans = a_plus_sum[n] - best_lost
print(max(ans, 0))

Measured memory_bytes: 18764
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
vector<int> vec(3);
cin >> vec.at(0) >> vec.at(1) >> vec.at(2);
sort(vec.begin(),vec.end());
int cnt = 0;
while (vec.at(1) < vec.at(2)) {
    vec.at(0)++;
    vec.at(1)++;
    cnt++;
}
while (vec.at(0) < vec.at(1)) {
    vec.at(0) += 2;
    cnt++;
}
if (vec.at(0) == vec.at(1)) {
cout << cnt << endl;
} else {
    cout << cnt +1 << endl;
}




return 0;
}


Measured memory_bytes: 256
s = input()
if s == s[::-1]:
    flag = True
else:
    flag = False
N = len(s)
if flag:
    new = s[0:int((N-1)/2)]
    if new == new[::-1]:
        flag = True
    else: flag = False

if flag:
    new = s[int((N+2)/2):N]
    if new == new[::-1]:
        flag = True
    else:
        flag = False

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#in1 = '10 10 5'
#in2 = ['1 6 1','4 1 3','6 9 4','9 4 2','3 1 3']

rx, uy, n = map(int, input().split())
#rx, uy, n = map(int, in1.split())

dy = 0
lx = 0

for idx1 in range(n):
    x, y, a = map(int, input().split())
    #x, y, a = map(int, in2[idx1].split())
    if a == 1:
        lx = max(lx, x)
    elif a == 2:
        rx = min(rx, x)
    elif a == 3:
        dy = max(dy, y)
    else:
        uy = min(uy, y)

if rx >= lx and uy >= dy:
    print((uy - dy) * (rx - lx))
else:
    print(0)


Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
using namespace std;

int main(){
  int n;
  long long a,b,x1,x1i,sum=0;
  cin >> n >> a >> b;
  vector<long long> x(n);
  for(int i = 0; i < n; i++){
    cin >> x.at(i);
  }
  x1=x.at(0);
  sort(x.begin(),x.end());
  for(int i = 0; i < n; i++){
    if(x.at(i)==x1){
      x1i=i;
      break;
    }
  }
  for(int i = 0; i < n-1; i++){
    if(i==x1i-1) continue;
    else sum+=min(a*(x.at(i+1)-x.at(i)),b);
  }
  if(x1i != 0) sum+=min(a*(x.at(n-1)-x.at(0)),b);
  cout << sum << endl;
}

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

/*再帰関数による最大公約数
int gcd(int x, int y){
    return y ? gcd(y, x % y) : x;
}
*/

//ループによる最大公約数
int gcd(int x, int y){
    int r;
    if (x < y) swap(x, y); //y < xを保証する

    while (y > 0)
    {
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}

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

    return 0;
}


Measured memory_bytes: 3108
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        for (int i = 0 ; i <= 100 ; i++) {
            c -= b;
            if (c <= 0) {
                System.out.println("Yes");
                return;
            }
            a -= d;
            if (a <= 0) {
                System.out.println("No");
                return;
            }
        }
    }

}

Measured memory_bytes: 35608