akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
 
using namespace std;
 
int main(){
 
    int height,width,tmp;
    scanf("%d %d",&height,&width);
 
    int** table = new int*[height+1];
    table[0] = new int[width+1];
    for(int i=0; i < width+1; i++)table[0][i] = 0;
 
    int max_r = 0;
 
    for(int i=1; i <= height; i++){
        table[i] = new int[width+1];
        table[i][0] = 0;
        for(int k=1; k <= width; k++){
            scanf("%d",&tmp);
            table[i][k] = 1-tmp;
            if(tmp != 1){
                table[i][k] = min(table[i-1][k-1],min(table[i][k-1],table[i-1][k]))+1;
                max_r = max(max_r,table[i][k]);
 
            }
 
        }
    }
 
    printf("%d\n",max_r*max_r);
 
    return 0;
}


Measured memory_bytes: 10448
#include<stdio.h>

int main(){
    int x,y;
    int h,w,ans = 0;
    scanf("%d %d",&y,&x);
    scanf("%d %d",&h,&w);
    ans = x * y - (x*h + y*w - h*w);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
use std::cmp;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let n: usize = read_as_vec()[0];

    let mut v: Vec<usize> = vec![0; n + 1];

    for i in 1..=n {
        for j in (i..=n).step_by(i) {
            v[j] += 1;
        }
    }

    let mut ans = 0;
    for i in 1..=n {
        ans += i * v[i];
    }

    println!("{}", ans);
}


Measured memory_bytes: 80200
#!/usr/bin/env python
# -*- coding: utf-8 -*-


class Node(object):

  def __init__(self):
    self.fixed = False
    self.supply = 300
    self.tank = 0
    self.edges = []

  def __repr__(self):
    return str(self)

  def __str__(self):
    return '{}/{}({})'.format(self.supply, self.tank, int(self.fixed))


def main():
  n, m, tank = map(int, input().split())
  nodes = [Node() for _ in range(n)]

  for _ in range(m):
    a, b, c = map(int, input().split())

    nodes[a - 1].edges.append((nodes[b - 1], c))
    nodes[b - 1].edges.append((nodes[a - 1], c))

  queries = [list(map(int, input().split())) for _ in range(int(input()))]
  results = [[None] * len(nodes) for _ in range(len(nodes))]

  for start in range(len(nodes)):
    for node in nodes:
      node.fixed = False
      node.supply = 300
      node.tank = 0

    nodes[start].supply = 0
    nodes[start].tank = tank

    while True:
      targets = [n for n in nodes if not n.fixed ]

      if len(targets) == 0:
        break

      target = min(targets, key=lambda n: (n.supply, -n.tank))
      target.fixed = True

      for n, d in target.edges:
        if n.fixed or d > tank:
          continue

        if d > target.tank:
          new_supply = target.supply + 1
          new_tank = tank - d
        else:
          new_supply = target.supply
          new_tank = target.tank - d

        if (new_supply, -new_tank) < (n.supply, -n.tank):
          n.supply = new_supply
          n.tank = new_tank

    for end in range(len(nodes)):
      results[start][end] = nodes[end].supply

  for start, end in queries:
    if results[start - 1][end - 1] == 300:
      print(-1)
    else:
      print(results[start - 1][end - 1])


if __name__ == '__main__':
  main()


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

int main(){
  int N; cin >> N;
  long long sum=0;
  vector<long long> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
    sum+=A[i];
  }
  
  long long mind=sum;
  long long t=0;
  for(int i=0; i<N; i++){
    t+=A[i];
    mind=min(mind,abs(sum-2*t));
  }
  cout << mind << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
using namespace std;

int n, a, b, c;
int x[100], y[100], h[100];

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i] >> h[i];
    }

    a = h[0];
    b = x[0];
    c = y[0];

    for(int i = 0; i < n; i++){
        if(h[i] > 0){
            a = h[i];
            b = x[i];
            c = y[i];
        }
    }


    for (int k = 0; k < 101; k++)
    {
        for (int j = 0; j < 101; j++)
        {
            bool succ = true;
            int height = a + abs(b - k) + abs(c - j);
            for (int i = 0; i < n; i++)
            {
                if (max(height - abs(x[i] - k) - abs(y[i] - j), 0) != h[i])
                {
                    succ = false;
                    break;
                }
            }
            if (succ)
            {
                cout << k << " " << j << " " << height << endl;
                return 0;
            }
        }
    }
}

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

int main(){
//srandom((unsigned long)time(NULL));
long long n;
cin>>n;
vector<tuple<long long,long long>> r;
rep(i,n){
    long long x,y;
    cin>>x>>y;
    r.emplace_back(x,y);
}

vector<int> a(n);
rep(i,n) a[i]=i;

 double sum=0.0;
 do{ 
     for(int i=0;i<n-1;i++){
         double x,y,X,Y;
         tie(x,y)=r[a[i]];
         tie(X,Y)=r[a[i+1]];
        //  cout<<"x,y="<<x<<y<<endl;
        //  cout<<"X,Y="<<X<<Y<<endl;
        //  cout<<"root="<<sqrt((x-X)*(x-X)+(y-Y)*(y-Y))<<endl;
         sum+=sqrt((x-X)*(x-X)+(y-Y)*(y-Y));
     }
 } while(next_permutation(a.begin(),a.end()));
long long num=1;
for(int i=1;i<=n;i++) num*=i;

cout<<fixed<<setprecision(8)<<sum/num<<endl;

return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;


ll MOD = 1000000007;


int main()
{
	int N;
	cin >> N;
	int M = N;

	int digit=0;
	int ans = 0;
	int ten = 1;
	while (M != 0)
	{
		++digit;
		ten *= 10;

		if (digit % 2 == 1)
		{
			if (M < 10)
			{
				ans += N - ten / 10 + 1;
			}
			else
			{
				ans += ten - ten/10;
			}
		}
		M /= 10;
	}

	cout << ans << endl;


	return 0;
}

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

using ll = long long;
using P = pair<int,int>;

int main(){
    ll n, d;
    cin >> n >> d;
    d = d*d;
    int cnt = 0;
    rep(i,n){
        ll x, y;
        cin >> x >> y;
        if (x*x + y*y <= d){
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;
int a[300000],b[300000];
int main()
{
	int n,y,m,d,s,i,p,j;
	for(i=2; i<=123456*2; i++)
	{
		p=1;
		for(j=2; j<sqrt(i)+1; j++)
				if(i%j==0)
				{
					p=0;
					break;
				}
		if(p==1) a[i]=1;
	}
	a[2]=1;
	for(i=2; i<=123456*2; i++)
		a[i]+=a[i-1];
	j=0;
	do
	{
		cin >> n;
		b[j]=a[2*n]-a[n];
		j++;
	}while(n!=0);
	for(i=0; i<j-1; i++)
	cout << b[i] <<endl;
}



Measured memory_bytes: 4064
s = input()
k = int(input())
buf = dict()
for i in range(len(s)):
    for j in range(1,6):
        if j > len(s):
            break
        buf[s[i:i+j]] = True
keys = buf.keys()
buf = list(buf)
buf.sort()
#print(buf)
print(buf[k-1])


Measured memory_bytes: 40304
#include<cstdio>
#include<vector>
#include<queue>

using namespace std;


const int INF = 1 << 19;


struct FlowEdge {
  FlowEdge(int f, int t, int c, int _flow) : from(f), to(t), cap(c), flow(_flow) {}
  int from, to, cap, flow;
};


class Dinic {
public:
  Dinic(int n) : n(n), m(0) {
    adj.resize(n+2);
  }

  void add_edge(int u, int v, int cap) {
    edges.push_back(FlowEdge(u, v, cap, 0));
    edges.push_back(FlowEdge(v, u, 0, 0));
    adj[u].push_back(m);
    adj[v].push_back(m+1);
    m += 2;
  }

  int max_flow() {
    int flow = 0;
    int s = 0, t = n+1;
    for (;;) {
      if (!bfs(s, t)) break;
      ptr.assign(n+2, 0);
      while (int f = dfs(s, t, INF)) {
        flow += f;
      }
    }

    return flow;
  }

private:
  bool bfs(int s, int t) {
    level.assign(n+2, -1);
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
      int v = que.front(); que.pop();
      for (size_t i = 0; i < adj[v].size(); ++i) {
        int pos = adj[v][i];
        FlowEdge &e = edges[pos];
        if (e.cap > e.flow && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
      }
    }
    return level[t] > 0;
  }

  int dfs(int s, int t, int f) {
    if (f == 0) return 0;
    if (s == t) return f;
    for (int &iter=ptr[s]; iter < (int)adj[s].size(); ++iter) {
      int pos = adj[s][iter];
      FlowEdge &e = edges[pos];
      if (level[e.to] != level[e.from]+1 || e.cap - e.flow < 1)
        continue;
      int d = dfs(e.to, t, min(f, e.cap-e.flow));
      if (d > 0) {
        edges[pos].flow += d;
        edges[pos^1].flow -= d;
        return d;
      }
    }
    return 0;
  }

private:
  int n, m;
  vector<FlowEdge> edges;
  vector<vector<int> > adj;
  vector<int> level, ptr;
  queue<int> que;
};


void solve(int x, int y, int e) {
  Dinic dinic(x+y);

  for (int i = 0; i < e; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    int u = a+1, v = b+x+1;
    dinic.add_edge(u, v, 1);
  }

  // source edge
  int s = 0;
  for (int i = 1; i <= x; ++i) {
    dinic.add_edge(s, i, 1);
  }
  // sink edge;
  int t = x+y+1;
  for (int i = x+1; i <= x+y; ++i) {
    dinic.add_edge(i, t, 1);
  }

  printf("%d\n", dinic.max_flow());
}

int main() {

  int x, y, e;
  scanf("%d %d %d", &x, &y, &e); 

  solve(x, y, e);
  return 0;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define bs binary_search
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ipr pair<ll,ll>
#define ps push_back
#define fs first
#define sc second
#define endl "\n"
#define mod 1000000007
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll a,b;
	cin>>a>>b;

	ll c,k,l;
	k=(a)+(a-1);
	l=(b)+(b-1);
	c=(a+b);
	ll an=max(k,max(c,l));
	cout<<an;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=2010,Maxm=200010;
const int inf=2147483647;
const int mod=1000000007;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
void upd(int&x,int y){x+=y;if(x>=mod)x-=mod;}
int n,a[Maxm],b[Maxm],f[Maxn][Maxn<<1],g[Maxn][Maxn<<1];
int fac[Maxn<<2],fin[Maxn<<2],inv[Maxn<<2];
void pre()
{
	int n=8000;
	fac[0]=1;for(int i=1;i<=n;i++)fac[i]=(LL)fac[i-1]*i%mod;
	inv[0]=inv[1]=1;for(int i=2;i<=n;i++)inv[i]=(LL)(mod-mod/i)*inv[mod%i]%mod;
	fin[0]=1;for(int i=1;i<=n;i++)fin[i]=(LL)fin[i-1]*inv[i]%mod;
}
int C(int n,int m)
{
	if(n<m)return 0;
	return(LL)fac[n]*fin[m]%mod*fin[n-m]%mod;
}
int main()
{
//	freopen("out.txt","w",stdout);
	int ans=0;
	n=read();pre();
	for(int i=1;i<=n;i++)a[i]=read(),b[i]=read(),f[a[i]][b[i]+2000]++,g[a[i]][b[i]+2000]++;
	for(int i=2000;i>=0;i--)
	for(int j=4000;j>=0;j--)
	{
		upd(f[i][j],f[i+1][j]);
		if(i)upd(f[i][j],f[i][j+1]);
	}
	for(int i=2000;i>=0;i--)
	for(int j=4000;j>=0;j--)
	{
		upd(g[i][j],g[i+1][j]);
		upd(g[i][j],g[i][j+1]);
	}
	for(int i=0;i<=4000;i++)upd(ans,(LL)g[0][i]*f[0][4000-i]%mod);
//	for(int i=0;i<=4000;i++)
//	if(f[0][i])printf("%d %d\n",i,f[0][i]);
//	printf("%d\n",ans);
	for(int i=1;i<=n;i++)upd(ans,mod-C(a[i]*2+b[i]*2,a[i]*2));
//	printf("%d\n",C(a[i]*2+b[i]*2,a[i]*2));
//	printf("%d\n",ans);
	ans=(LL)ans*((mod+1)/2)%mod;
	printf("%d",ans);
}

Measured memory_bytes: 65024
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 2e5;
const int posp[4] = {3, 2, 1, 0}, negp[4] = {1, 0, 3, 2}, parp[4] = {2, 3, 0, 1};
const bool post[4] = {1, 1, 0, 0}, negt[4] = {0, 1, 1, 0}, part[4] = {1, 1, 0, 0};

int n, x[N + 1], y[N + 1], u[N + 1], id[256], ans = 0x7fffffff;
char c;
vector<int> pos[4][N * 2 + 1], neg[4][N * 2 + 1], par[4][N + 1];
vector<int>::iterator it;

int main(){
	id['U'] = 0, id['R'] = 1, id['D'] = 2, id['L'] = 3;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d%d %c", x + i, y + i, &c);
		u[i] = id[c];
		if(u[i] == 0 || u[i] == 2)
			par[u[i]][x[i]].push_back(y[i]);
		else par[u[i]][y[i]].push_back(x[i]);
		pos[u[i]][N + y[i] - x[i]].push_back(x[i]);
		neg[u[i]][x[i] + y[i]].push_back(x[i]);
	}
	for(int i = 0; i < 4; i++)
		for(int j = 0; j <= N; j++)
			sort(par[i][j].begin(), par[i][j].end());
	for(int i = 0; i < 4; i++)
		for(int j = N * 2; ~j; j--){
			sort(pos[i][j].begin(), pos[i][j].end());
			sort(neg[i][j].begin(), neg[i][j].end());
		}
	for(int i = 1; i <= n; i++){
		if(u[i] == 0 || u[i] == 2){
			if(part[u[i]]){
				if(par[parp[u[i]]][x[i]].size() && *--par[parp[u[i]]][x[i]].end() > y[i])
					ans = min(ans, *lower_bound(par[parp[u[i]]][x[i]].begin(), par[parp[u[i]]][x[i]].end(), y[i]) - y[i]);
			}else if(par[parp[u[i]]][x[i]].size() && *par[parp[u[i]]][x[i]].begin() < y[i])
				ans = min(ans, y[i] - *--lower_bound(par[parp[u[i]]][x[i]].begin(), par[parp[u[i]]][x[i]].end(), y[i]));
		}else{
			if(part[u[i]]){
				if(par[parp[u[i]]][y[i]].size() && *--par[parp[u[i]]][y[i]].end() > x[i])
					ans = min(ans, *lower_bound(par[parp[u[i]]][y[i]].begin(), par[parp[u[i]]][y[i]].end(), x[i]) - x[i]);
			}else if(par[parp[u[i]]][y[i]].size() && *par[parp[u[i]]][y[i]].begin() < x[i])
				ans = min(ans, x[i] - *--lower_bound(par[parp[u[i]]][y[i]].begin(), par[parp[u[i]]][y[i]].end(), x[i]));
		}
		if(post[u[i]]){
			if(pos[posp[u[i]]][N + y[i] - x[i]].size() && *--pos[posp[u[i]]][N + y[i] - x[i]].end() > x[i])
				ans = min(ans, (*lower_bound(pos[posp[u[i]]][N + y[i] - x[i]].begin(), pos[posp[u[i]]][N + y[i] - x[i]].end(), x[i]) - x[i]) * 2);
		}else if(pos[posp[u[i]]][N + y[i] - x[i]].size() && *pos[posp[u[i]]][N + y[i] - x[i]].begin() < x[i])
			ans = min(ans, (x[i] - *--lower_bound(pos[posp[u[i]]][N + y[i] - x[i]].begin(), pos[posp[u[i]]][N + y[i] - x[i]].end(), x[i])) * 2);
		if(negt[u[i]]){
			if(neg[negp[u[i]]][x[i] + y[i]].size() && *--neg[negp[u[i]]][x[i] + y[i]].end() > x[i])
				ans = min(ans, (*lower_bound(neg[negp[u[i]]][x[i] + y[i]].begin(), neg[negp[u[i]]][x[i] + y[i]].end(), x[i]) - x[i]) * 2);
		}else if(neg[negp[u[i]]][x[i] + y[i]].size() && *neg[negp[u[i]]][x[i] + y[i]].begin() < x[i])
			ans = min(ans, (x[i] - *--lower_bound(neg[negp[u[i]]][x[i] + y[i]].begin(), neg[negp[u[i]]][x[i] + y[i]].end(), x[i])) * 2);
	}
	if(ans == 0x7fffffff) printf("SAFE");
	else printf("%d", ans * 5);
	return 0;
}

Measured memory_bytes: 118000
import itertools

INF = 10**18

N, M, X = map(int, input().split())
C = [0]*N
A = [[] for i in range(N)]
for i in range(N):
    src = list(map(int, input().split()))
    C[i] = src[0]
    A[i] = src[1:]
ans = INF
for ptn in itertools.product([0,1], repeat=N):
    point = [0]*M
    m = 0
    for j in range(N):
        if ptn[j]:
            m += C[j]
            for ii, a in enumerate(A[j]):
                point[ii] += a
    ok = True
    for j in range(M):
        if point[j] < X:
            ok = False
            break
    if ok:
        ans = min(ans, m)
if ans == INF:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9240
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    auto tmp = readln.split.to!(long[]);
    const D = tmp[0], G = tmp[1];
    struct Po { long p, c; }
    auto po = new Po[D];
    auto completePointList = new long[D];
    foreach (i; 0..D) {
        tmp = readln.split.to!(long[]);
        const p = tmp[0], c = tmp[1];
        po[i] = Po(p,c);
        completePointList[i] = 100 * (i+1) * p + c;
    }

    long calc(bool[] s) {
        long problem = 0;
        long point = 0;
        foreach (i, b; s) {
            if (!b) continue;
            point += 100 * (i+1) * po[i].p + po[i].c;
            problem += po[i].p;
        }
        foreach_reverse (i; 0..D) {
            if (s[i]) continue;
            if (point >= G) return problem;
            const cnt = cast(long)min(po[i].p-1, ceil((G - point) / (100.0 * (i+1))));
            problem += cnt;
            point += 100 * (i+1) * cnt;
        }
        return point < G ? 114514 : problem;
    }

    long func(long i, bool[] s) {
        if (i == D) {
            return calc(s);
        }
        return min(func(i+1, s.dup ~ false), func(i+1, s.dup ~ true));
    }
    writeln(func(0,[]));
}



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

#define ll long long
#define mx 200005

int a[mx+10];
char ch[mx+10];
int n,k;

map<int,ll>mp;
map<int,ll>ans;
set<int>s;

void solve()
{
    scanf("%d",&n);

    for(int i=0;i<n;i++)scanf("%d",&a[i]),s.insert(a[i]),mp[a[i]]++;
    ll tem=0;
    for(auto it:s)
    {
        int val=it;
        if(mp[val]>=2)tem+=(mp[val]*(mp[val]-1))/2;
    }

    for(int i=0;i<n;i++)
    {
        ll re=tem;
        if(mp[a[i]]>=2)
        {
            re-=(mp[a[i]]*(mp[a[i]]-1))/2;

        }
        if(mp[a[i]]>2)
        {
            re+=((mp[a[i]]-1)*(mp[a[i]]-2))/2;

        }
        printf("%lld\n",re);
    }

   return;
}

int main()
{
    int t=1;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 16256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <stdlib.h>
using namespace std;
typedef long long int lld;
typedef long double ld;
int n;
int arr[333333];
int vis[333333],vis2[333333];
vector<int> v;
int main(void){
	scanf("%d",&n);
	for(int e=0;e<n;e++) scanf("%d",&arr[e]);
	sort(arr,arr+n);
	int tmp = 1;
	for(int e=1;e<n;e++){
		if(arr[e]!=arr[e-1]){
			v.push_back(tmp);
			tmp = 1;
		}else tmp++;
	}
	int lm = 0;
	v.push_back(tmp);
	for(int e=0;e<v.size();e++) lm = max(lm,v[e]);
	for(int e=0;e<v.size();e++) vis[v[e]]++;
	for(int len=1;len<=n;len++){
		if(v.size()<len){
			printf("0\n");
			continue;
		}
		for(int p=0;p<=lm;p++) vis2[p] = vis[p];
		int lmm = lm,ans=0;
		while(true){
			int tot = len,nlmm=0;
			vector<pair<int,int> > v2;
			for(int p=lmm;p>=1;p--){
				if(vis2[p]==0) continue;
				if(vis2[p]>=tot){
					v2.push_back(make_pair(p-1,tot));
					v2.push_back(make_pair(p,-tot));
					tot = 0;
					break;
				}else{
					v2.push_back(make_pair(p-1,vis2[p]));
					v2.push_back(make_pair(p,-vis2[p]));
					tot -= vis2[p];
				}
			}
			if(tot) break;
			ans++;
			for(int e=0;e<v2.size();e++){
				vis2[v2[e].first] += v2[e].second;
			}
			for(int p=lmm;p>=1;p--) if(vis2[p]){
				lmm = p;
				break;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3572
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
	long[] a = new long[n+1];
	for(int i = 0; i<n; i++) {
	    a[i] = Long.parseLong(sc.next());
	}

	long sum = 0;
	int right = 0;
	int left = 0;
	long ans = 0;

	for(left = 0; left<n; left++) {
	    while(right < n &&(sum ^ a[right]) == (sum + a[right])) {
		sum += a[right];
		right++;
	    }
	    ans += right - left;
	    if(left == right) ++right;
	    else {
		sum -= a[left];
	    }
	}

	System.out.println(ans);
    }
}

Measured memory_bytes: 60928
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll llmin(ll a,ll b){
    if(a>=b) return b;
    return a;
}
ll llmax(ll a,ll b){
    if(a<=b) return b;
    return a;
}

ll ltmp;
string stmp;
double dtmp;


long long koyaku_max(long long a,long long b){
    long long r;
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

vll enum_divisors(long long N) {
    vll res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}

/*
max 448,000,000
count_map['0']=0;
for(auto x : count_map) {
    string key = x.first;
    ll value = x.second;
}
*/

vector<ll> prime_numbers;
void getPrimeNumbers(ll n_max){
    bool is_prime[n_max+1];
    for( int ni = 0 ; ni <=n_max ; ni++ ){
        is_prime[ni]=true;
    }
   is_prime[0]=is_prime[1]=false;
    for( int number = 2 ; number <=n_max ; number++ ){
        if(is_prime[number]){
            prime_numbers.push_back(number);
            for( int ni = number*2 ; ni <=n_max ; ni+=number ){
                is_prime[ni]=false;
            }
        }
    }
}

int main(){

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

    cin >> A;
    cin >> B;
    map<ll,ll> count_map;

    //A = 1000000000000;
    //B = 1000000000000;

    C = koyaku_max(A,B);

    vll yakusu = enum_divisors(C);

    rep(yi,yakusu.size()){
        //cout << yakusu[yi] << endl;
        count_map[yakusu[yi]]=1;
    }

    ll cnt = 1;
    for( ll yi = 1 ; yi <yakusu.size() ; yi++ ){
        ll val = yakusu[yi];
        if(count_map[val]==1){
            cnt++;
            for( ll yii = yi+1 ; yii <yakusu.size() ; yii++ ){
                ll val2 = yakusu[yii];
                if(val2 % val == 0) count_map[val2]=0;
            }
        }
    }

    cout << cnt << endl;

    

}

Measured memory_bytes: 3980
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, e) for (int i = 0, _##i = (e); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
#define ARR(...) vector<int>({__VA_ARGS__})
#define ARS(...) vector<string>({__VA_ARGS__})
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef complex<double> base;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    for (auto p : v) cout << p << ",";
    cout << "]";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const set<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __DJKIM613
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

const int MAXN = 1e5 + 10;
int N;
int K;
long long DP[MAXN];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    cin >> N >> K;
    
    memset(DP, -1, sizeof(DP));
    DP[0] = 0;

    rep(i, N){
        ll a, b;
        cin >> a >> b;
        repr(j, K + 1, a) {
            if(DP[j - a] == -1) continue;
            if(DP[j] == -1) DP[j] = DP[j - a] + b;
            else get_max(DP[j], DP[j - a] + b);
        }
    }

    ll ans = 0;
    rep(i, K + 1) get_max(ans, DP[i]);
    cout << ans << '\n'; 
    return 0;
}

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

int main(){
	int n,ans;
	while(cin >> n){
		ans = 0;
		for(int a = 0; a < 10; ++a){
			for( int b = 0; b < 10; ++b){
				for( int c = 0; c < 10; ++c){
					for( int d = 0; d < 10; ++d ){
						if(n == a + b + c + d)++ans;
					}
				}
			}
		}
		cout << ans << '\n';
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)

/* exchange */
#define chmin(a, b) (a) = min((ll)(a), (ll)(b))
#define chmax(a, b) (a) = max((ll)(a), (ll)(b))

/* output */
#define I(x) cin >> x;
#define D(x) cerr << (x) << " ";
#define BR cerr << "\n";
#define P(x) cout << (x) << endl;
#define FIX cout << fixed << setprecision(10);

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;

int main(void){
  ll K;
  I(N);
  I(K);
  vl A(N);
  REP(i, N) {
    I(A[i]);
  }
  REP(i, N-K) {
    if (A[i] < A[i+K]) {
      P("Yes");
    } else {
      P("No");
    }
  }
}


Measured memory_bytes: 4840
import sys
a,b = map(int, input().split())
ans = None
if a==b:
    print("Draw")
    sys.exit()
    
if a==1:
    print("Alice")
    sys.exit()

if b == 1:
    print("Bob")
    sys.exit()
    
print("Alice" if a > b else "Bob")

    

Measured memory_bytes: 2940
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i32,
        b: i32,
        c: i32
    }

    let mut cnt: i32 = 0;
    let mut _b: i32 = b;
    for i in 0..c {
        _b -= a;
        if _b < 0 {
            break;
        }
        cnt += 1;
    }

    println!("{}", cnt);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) {
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

int main() {
	string s;
	cin >> s;
	if (s == "ARC"){
		cout << "ABC" << endl;
	} else {
		cout << "ARC" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3624
while 1:
    n,m = map(int, raw_input().split())
    if n==m==0: break
    p = [[0,m-i] for i in xrange(1,m+1)];
    for i in xrange(n):
        mark = raw_input().split()
        for i in xrange(m): p[i][0] += int(mark[i])
    p.sort(reverse=True)
    s = [str(m-p[i][1]) for i in range(m)]
    print " ".join(s)

Measured memory_bytes: 4228
#include<stdio.h>

int main()
{
    int n, x, i, j, ans;

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

        ans = 0;
        for(i = 3; i <= n; i++) {
            for(j = 2; j < i; j++) {
                if(1 <= x - i - j && x - i -j < j) ans++;
            }
        }
        printf("%d\n", ans);

        scanf("\n");
    }
}



Measured memory_bytes: 2024
def abc087_b():
    a = int(input())
    b = int(input())
    c = int(input())
    x = int(input())
    count = 0

    for i in range(a + 1):
        for j in range(b + 1):
            for k in range(c + 1):
                if (500 * i + 100 * j + 50 * k) == x:
                    count += 1
    print(count)


abc087_b()

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#define INF 1e6
using namespace std;

struct node{
  int a,b,c;
};
int dp[41][410][410];
int main(){
  int n,ma,mb,i,j,k;
  cin >> n >> ma >> mb;
  node med[n];
  for(i=0;i<n;i++)cin >> med[i].a >> med[i].b >> med[i].c;
  for(i=0;i<=n;i++){
    for(j=0;j<410;j++){
      for(k=0;k<410;k++){
        dp[i][j][k]=INF;
      }
    }
  }
  for(i=0;i<n;i++)dp[i][0][0]=0;
  for(i=0;i<n;i++){
    for(j=0;j<=400;j++){
      for(k=0;k<=400;k++){
        if(dp[i][j][k]==INF)continue;
        dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
        dp[i+1][j+med[i].a][k+med[i].b]=min(dp[i+1][j+med[i].a][k+med[i].b],
          dp[i][j][k]+med[i].c);
      }
    }
  }
  int ret = INF;
  for(i=1;i<=400;i++){
    for(j=1;j<=400;j++){
      if(i*mb==j*ma)ret=min(ret,dp[n][i][j]);
    }
  }
  ret = ret==INF ? -1 : ret;
  cout << ret << endl;
  //if(ret==INF)cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 27136
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i <= 0; --i)

using ll = long long;
using namespace std;

constexpr int INF = 2147483647; // 2 * 1e9
constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	bool f[26] = {false};
	REP(i, s.size()){
		f[s[i] - 'a'] = true;
	}
	char a = 0;
	REP(i, 26){
		if(!f[i]) {
			a = i + 'a'; 
			break;
		}
	}
	if(a != 0)
	cout << a << "\n";
	else cout << "None\n";
	return 0;
}


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

const int NMAX = 100001;
const long long INF = 1e18;

struct edge {  
  int to;
  int en;
  int snuuk;
};

vector<long long> de(NMAX, INF);
vector<long long> ds(NMAX, INF);
vector<pair<long long, int>> d;
vector<vector<edge>> G(NMAX);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int n, m, start, goal;
  cin >> n >> m >> start >> goal;
  vector<long long> ans(n, INF);
  start--;
  goal--;
  for(int i = 0; i < m; i++){  
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    edge e1 = {v, a, b};
    edge e2 = {u, a, b};
    G[u].push_back(e1); 
    G[v].push_back(e2); 
  }
  //start to goal
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
  pair<long long, int> p = make_pair(0, start); 
  de[start] = 0;
  pq.push(p);
  while(!pq.empty()){  
    pair<long long, int> p = pq.top();
    pq.pop();
    long long minn = p.first;
    int v = p.second; 
    if(minn > de[v]) continue;
    for(int i = 0; i < G[v].size(); i++){  
      if(de[G[v][i].to] > G[v][i].en + minn){  
        de[G[v][i].to] = G[v][i].en + minn;
        pq.emplace(de[G[v][i].to], G[v][i].to); 
      }  
    }
  } 
  //goal to start
  p = make_pair(0, goal); 
  ds[goal] = 0;
  pq.push(p);
  while(!pq.empty()){  
    pair<long long, int> p = pq.top();
    pq.pop();
    long long minn = p.first;
    int v = p.second; 
    if(minn > ds[v]) continue;
    for(int i = 0; i < G[v].size(); i++){  
      if(ds[G[v][i].to] > G[v][i].snuuk + minn){  
        ds[G[v][i].to] = G[v][i].snuuk + minn;
        pq.emplace(ds[G[v][i].to], G[v][i].to); 
      }  
    }
  } 
  for(int i = 0; i < n; i++){  
    d.push_back(make_pair(de[i] + ds[i], i));   
  }
  sort(d.begin(), d.end()); 
  for(int i = 0; i < n; i++){  
    long long minn = d[i].first;
    long long t = d[i].second;
    for(int j = t; j >= 0; j--){  
      if(ans[j] == INF) ans[j] = minn; 
      else break;
    } 
  }
  for(int i = 0; i < n; i++){  
    cout << (long long)1e15 - ans[i] <<endl; 
  }
}


Measured memory_bytes: 14624
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
    ll n,i,j=100000000000000000LL,cc=0;
    cin>>n;
    ll ara[5];
    for(i=0;i<5;i++){
        cin>>ara[i];
        j=min(j,ara[i]);
    }
    ll x=(n-1)/j;

    cout<<x+5<<endl;
return 0;
}


Measured memory_bytes: 4992
package main

import (
	"fmt"
)

func main() {
	var n, q int
	fmt.Scan(&n)

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

	fmt.Scan(&q)

	// ?????????:0, true:1, false:-1
	memo := make([][2000]int, n)

	var solve func(int, int) bool
	solve = func(i, m int) bool {
		if m == 0 {
			return true
		}

		if i >= n || m < 0 {
			return false
		}

		if memo[i][m] != 0 {
			if memo[i][m] == 1 {
				return true
			}
			return false
		}

		unused := solve(i+1, m)
		used := solve(i+1, m-a[i])
		res := unused || used
		if res {
			memo[i][m] = 1
		} else {
			memo[i][m] = -1
		}

		return res
	}

	for i := 0; i < q; i++ {
		var m int
		fmt.Scan(&m)
		if solve(0, m) {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

Measured memory_bytes: 1460
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C: Energy Drink Collector
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = 100000;

/* typedef */

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

/* global variables */

pii ps[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < n; i++)
    scanf("%d%d", &ps[i].first, &ps[i].second);
  sort(ps, ps + n);

  ll sum = 0;
  for (int i = 0; m > 0 && i < n; i++) {
    int &ai = ps[i].first, &bi = ps[i].second;
    int mb = min(m, bi);
    sum += (ll)ai * mb;
    m -= mb;
  }

  printf("%lld\n", sum);
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

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

    if (a < b) {
        std::cout << "a < b" <<std::endl;
    } else if (a > b) {
        std::cout << "a > b" <<std::endl;
    } else {
        std::cout << "a == b" <<std::endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize "trapv"
#define ll long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k; cin>>n>>k;
    ll x = 1;
    for (int i=1;i<=n;i++) {
        x = min(x+k, 2ll*x);
    }
    cout<<x;
    return 0;
}

Measured memory_bytes: 3596
def main():
    N = int(input())
    c = [[0]*10 for _ in range(10)]
    for n in range(1, N+1):
        s = str(n)
        c[int(s[0])][int(s[-1])] += 1
    ans = 0
    for i in range(1, 10):
        for j in range(1, 10):
            # if c[i][j]*c[j][i]:
            #     print(i, j, c[i][j]*c[j][i])
            ans += c[i][j] * c[j][i]
    print(ans)
    # print(*c, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 40428
n = int(input())
p = [int(i) for i in input().split()]

count = 0

for i in range(n-2):
    if p[i] <= p[i+1] < p[i+2] or p[i+2] <= p[i+1] < p[i] or (p[i] == p[i+2] and p[i+1] < p[i]):
        count += 1

print(count)


Measured memory_bytes: 3060
s = input()[::-1]
l = ["dream", "dreamer", "erase", "eraser"]
start = 0

for i in range(len(l)):
  l[i] = l[i][::-1]
  
def f():
  i = 0
  j = 0
  while j <= len(s):
    can = False
    for d in l:
      if s[i:i+len(d)] == d:
        i += len(d)
        can = True

    if i == len(s) and can == True:
      return 'YES'

    if can == False:
      return 'NO'
    j += 1

  return 'YES'

print(f())

Measured memory_bytes: 3316
import heapq
import fractions


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            while temp % i == 0:
                arr.append(i)
                temp //= i

    if temp != 1:
        arr.append(temp)

    if arr == []:
        arr.append(n)

    arr.sort()
    return arr


N, P = map(int, input().split())

# リストを優先度付きキューへ
factors = factorization(P)
heapq.heapify(factors)

# 因数の数がNより少ないなら1になる
if len(factors) < N:
    print(1)
    exit(0)

# 因数の数がNと一致するなら最小値の因数が解になる
if len(factors) == N:
    print(min(factors))
    exit(0)

# 因数の数がNより大きい時、
# 因数の数がNとおなじになるまで、小さい値同士を掛ける。
# 同じ値になったら最小値を出力する。
ans = []
while True:
    if len(ans) < N:
        ans.append(heapq.heappop(factors))
    else:
        if len(factors) == 0:
            break

        idx = ans.index(min(ans))
        ans[idx] = ans[idx]*heapq.heappop(factors)

if N == 1:
    print(ans[0])
else:
    gcd = fractions.gcd(ans[0], ans[1])
    if N == 2:
        print(gcd)
    else:
        for i in range(2, N):
            gcd = fractions.gcd(gcd, ans[i])
        print(gcd)


Measured memory_bytes: 5048
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
int main() {
  cin >> n;
  i64 ans = 1ll << 60;
  for (i64 x = 1; x <= min(i64(1000000), n); ++x) {
    if (n % x == 0) ans = min(ans, x + n / x - 2);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public static void Main()
    {
        string s = Console.ReadLine();
        int K = Cin<int>();
        SortedSet<string> set = new SortedSet<string>();
        for (int i = 1; i <= 5; i++)
        {
            for (int j = 0; j < s.Length - i + 1; j++)
            {
                var ss = s.Substring(j, i);
                if (!set.Contains(ss)) set.Add(ss);
            }
        }
        Console.WriteLine(set.ElementAt(K-1));
    }
}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    public static T Cin<T>()
    {
        if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s);
        if (typeof(T) == typeof(int)) return (T)(object)int.Parse(queue.Dequeue());
        else if (typeof(T) == typeof(long)) return (T)(object)long.Parse(queue.Dequeue());
        else if (typeof(T) == typeof(string)) return (T)(object)(queue.Dequeue());
        else if (typeof(T) == typeof(double)) return (T)(object)double.Parse(queue.Dequeue());
        else return (T)(object)(-1);
    }
    public static T Line<T>()
    {
        if (typeof(T) == typeof(int[]))
        {
            return (T)(object)Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        else if (typeof(T) == typeof(long[]))
        {
            return (T)(object)Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        else if (typeof(T) == typeof(string[]))
        {
            return (T)(object)Console.ReadLine().Split(' ').ToArray();
        }
        else if (typeof(T) == typeof(double[]))
        {
            return (T)(object)Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
        else return (T)(object)(-1);
    }
}

Measured memory_bytes: 13748
import math

N, D = [int(i) for i in input().split()]
X = []
for i in range(N):
    X.append([int(i) for i in input().split()])
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        distance = 0
        for d in range(D):
            distance += (X[i][d] - X[j][d]) ** 2
        if math.sqrt(distance).is_integer():
            ans += 1
print(ans)


Measured memory_bytes: 3060
import java.util.*;
class Main
{
  public static void main(String [] args)
  {
    Scanner s = new Scanner(System.in);
   int num = s.nextInt();
    int n = s.nextInt();
    
    HashSet<Integer>h = new HashSet<>();
    
   	for(int i = 0; i < n;i++)
      h.add(s.nextInt());
    
    int count = 0;
    boolean found = false;
    int prev = 0;
    
    while(!found)
    {
      if(!(h.contains(num - count))) found = true;
      prev = count; 
      if(count > 0)
           count = 0 - count;
      else
           count = 0 - count + 1;
     
    }
           
    System.out.println(num - prev);
                          
  }
}

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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

LL t[110];

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    LL a, b, c, d;
    cin >> a >> b >> c >> d;

    for(LL i = a; i < b; i++)
        t[i]++;

    for(LL i = c; i < d; i++)
        t[i]++;

    LL ans = 0;
    for(LL i = 0; i <= 110; i++)
        if(t[i] == 2)
            ans++;

    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# abc141/abc141_b
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    S = i2s()
    for s in S[1::2]:
        if s == 'R':
            print('No')
            return
    for s in S[0::2]:
        if s == 'L':
            print('No')
            return
    print('Yes')
    return

main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


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



int main() {
	ll N;
	cin >> N;

	vector<ll> W(N + 1);
	repn(i, N) cin >> W[i];

	vector<ll> S(N + 1);
	S[0] = 0;
	repn(i, N) S[i] = S[i - 1] + W[i];

	ll ans = INF;

	rep(i, N + 1) ans = min(ans, abs(S[N] - 2 * S[i]));

	cout << ans;


	system("PAUSE");
}

Measured memory_bytes: 504