Harryxun/stf_run huggingface dataset:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
L = [tuple(map(int, input().split())) for _ in range(M)]

L.sort(key=lambda x: x[1], reverse=True)

flag = True
num = 0
now = 0
while flag:
    if num >= M:
        break
    for i in range(L[num][0]):
        if L[num][1] > A[now]:
            A[now] = L[num][1]
            now += 1
        else:
            flag = False
            break
    num += 1
print(sum(A))



### FIXED CODE ###

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
L = [tuple(map(int, input().split())) for _ in range(M)]

L.sort(key=lambda x: x[1], reverse=True)

flag = True
num = 0
now = 0
while flag:
    if num >= M:
        break
    for i in range(L[num][0]):
        if now < N and L[num][1] > A[now]:
            A[now] = L[num][1]
            now += 1
        else:
            flag = False
            break
    num += 1
print(sum(A))
a,b,c,d = map[int,input().split()]
right = a + b
left = c + d
 
if right < left:
  print('Right')
elif left < right:
  print('Left')
else:
  print('Balanced')

### FIXED CODE ###

a,b,c,d = map(int,input().split())
right = a + b
left = c + d
 
if right < left:
  print('Right')
elif left < right:
  print('Left')
else:
  print('Balanced')
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
s = sum(a)
card = []

for _ in range(m):
    b, c = map(int, input().split())
    card += [c] * b
card.sort(reverse=True)

i = 0
while card[i] > a[i]:
    s += card[i] - a[i]
    i += 1
print(s)

### FIXED CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
bc = [list(map(int, input().split())) for _ in range(m)]

bc.sort(reverse=True, key=lambda x:x[1])

i = 0
for b,c in bc:
    for j in range(i, min(n, i+b)):
        if a[j]<c:
            a[j] = c
    i = i+b
print(sum(a))
N=int(input())
A=[int(i) for i in input().split()]
mod=10**9+7
deni=[1]*(N+1)#(k)!を格納
quot=[1]*(N+1)#(k)!の逆数を格納
for i in range(1,N+1):
    deni[i]=(deni[i-1]*(i+1))%mod
for i in range(1,N+1):
    t=pow(i+1,mod-2,mod)
    quot[i]=(quot[i-1]*t)%mod
deni=[1]+deni
quot=[1]+quot
box=[[0,0]]*(N+1)
for i in range(N):
    if box[A[i]-1][0]==1:
        k_1=box[A[i]-1][1]
        k_2=N-i
        break
    box[A[i]-1]=[1,i]
K=k_1+k_2
ans =[]
for k in range(1,N+2):
    if k==1:
        ans.append(N)
    elif K>=k-1:
        s=deni[N+1]
        s=(s*quot[k])%mod
        s=(s*quot[N+1-k])%mod
        t=deni[K]
        t=(t*quot[k-1])%mod
        t=(t*quot[K-k+1])%mod
        #print(s,t)
        ans.append((s-t)%mod)
    else:
        s=deni[N+1]
        s=(s*quot[k])%mod
        s=(s*quot[N-k+1])%mod
        #print(s)
        ans.append(s)
#print(ans)
print('\n'.join(map(str,ans)))

### FIXED CODE ###

N=int(input())
A=[int(i) for i in input().split()]
mod=10**9+7
deni=[1]*(N+1)#(k)!を格納
quot=[1]*(N+1)#(k)!の逆数を格納
for i in range(1,N+1):
    deni[i]=(deni[i-1]*(i+1))%mod
for i in range(1,N+1):
    t=pow(i+1,mod-2,mod)
    quot[i]=(quot[i-1]*t)%mod
deni=[1]+deni
quot=[1]+quot
box=[[0,0]]*(N+1)
for i in range(N+1):
    if box[A[i]-1][0]==1:
        k_1=box[A[i]-1][1]
        k_2=N-i
        break
    box[A[i]-1]=[1,i]
K=k_1+k_2
ans =[]
for k in range(1,N+2):
    if k==1:
        ans.append(N)
    elif K>=k-1:
        s=deni[N+1]
        s=(s*quot[k])%mod
        s=(s*quot[N+1-k])%mod
        t=deni[K]
        t=(t*quot[k-1])%mod
        t=(t*quot[K-k+1])%mod
        #print(s,t)
        ans.append((s-t)%mod)
    else:
        s=deni[N+1]
        s=(s*quot[k])%mod
        s=(s*quot[N-k+1])%mod
        #print(s)
        ans.append(s)
#print(ans)
print('\n'.join(map(str,ans)))
def insertion_sort(target_list, leng):
    '????????????????????????????????\???????????§??????????????????????????¨?????????'
    sorted_list = [target_list.pop(0)]
    for target in target_list[:]:
        print(('{} ' * (leng - 1)).format(*sorted_list, *target_list[0:-1]), end='')
        print(target_list[-1])
        for i, num in enumerate(sorted_list):
            if num > target:
                sorted_list[i:i] = [target]
                break
        else:
            sorted_list.append(target)
        target_list.pop(0)
    print(('{} ' * (N - 1)).format(*sorted_list[0:-1]), end='')
    print(sorted_list[-1], end='')

N = int(input())
A = [int(s) for s in input().split()]
insertion_sort(A, N)

### FIXED CODE ###

def insertion_sort(target_list):
    sorted_list = list()
    for target in target_list[:]:
        for i, num in enumerate(sorted_list):
            if num > target:
                sorted_list[i:i] = [target]
                break
        else:
            sorted_list.append(target)
        target_list.pop(0)
        print(' '.join(str(s) for s in sorted_list + target_list))

N = int(input())
A = [int(s) for s in input().split()]
insertion_sort(A)
S=input()
if S=="MON" :
	print(1)
else if S=="TUE" :
	print(2)
else if S=="WED" :
	print(3)
else if S=="THU" :
	print(4)
else if S=="FRI" :
	print(5)
else if S=="STA" :
	print(6)
else if S=="SUN" :
	print(7)

### FIXED CODE ###

S=input()
if S=="SUN" :
	print(7)
if S=="MON" :
	print(6)
if S=="TUE" :
	print(5)
if S=="WED" :
	print(4)
if S=="THU" :
	print(3)
if S=="FRI" :
	print(2)
if S=="SAT" :
	print(1)
A,B,C=map(int,input().split())

if C%(((B//A +1)*A)%B) == 0:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

A,B,C=map(int,input().split())
for i in range(1,B):
  if A*i %B==C:
    print("YES")
    exit(0)
print("NO")
import itertools

def resolve():
    n, m = map(int, input().split())
    S = [[0]*m for i in range(m)]
    MOD = (10 ** 9) + 7

    for i in range(m):
        a, b = map(int, input().split())
        S[a-1][b-1] = 1
        S[b-1][a-1] = 1

    ans = 0
    for p in itertools.permutations(range(0, m)):
        if p == (0,2,3,4,5,6,1):
            pass
        if p[0] != 0:
            break;
        tmp = 1
        for i, v in enumerate(p):
            if i + 1 < m:
                tmp *= S[v][p[i+1]]
        ans += tmp

    print(ans % MOD)
    
if __name__ == '__main__':
    resolve()

### FIXED CODE ###

# サンプルコード計算量お試し

import itertools

N, M = map(int, input().split())
adj_matrix = [[0]* N for _ in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    adj_matrix[a-1][b-1] = 1
    adj_matrix[b-1][a-1] = 1

cnt = 0

for each in itertools.permutations(range(N)):
    if each[0] != 0:
        break
    factor = 1
    for i in range(N-1):
        factor *= adj_matrix[each[i]][each[i+1]]
    cnt += factor

print(cnt)
n, m = map(int, input().split())
par = [i for i in range(n)]
rank = [1] * n
root = [[] for i in range(m)]
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])  # 経路圧縮
        return par[x]

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

def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    if rank[x] < rank[y]:
        rank[y] += rank[x]
        par[x] = y
    else:
        rank[x] += rank[y]
        par[y] = x


for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    unite(a, b)
    root[a].append(b)
    root[b].append(a)

flg = True
for i in range(1, n - 1):
    if not same(0,i):
        flg = False

if not flg:
    print("No")
    exit()
else:
    print("Yes")
    for i in range(1, n):
        print(min(root[i])+1)
        

### FIXED CODE ###

from collections import deque


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

    for _ in range(m):
        a, b = map(int, input().split())
        a, b = a - 1, b - 1
        g[a].append(b)
        g[b].append(a)

    q = deque([0])
    chk = [False] * n
    res = [0] * n

    while q:
        x = q.popleft()
        for y in g[x]:
            if chk[y]:
                continue
            chk[y] = True
            res[y] = x
            q.append(y)
    print("Yes")
    for i in res[1:]:
        print(i + 1)


if __name__ == '__main__':
    main()
S = list(input())

ans = 753

for i in range(len(S)-2):
    sa = abs(753-(int(S[i])*100 + int(S[i+1])*10 + int(S[i+2])))
    ans = min(sa,ans)
             
print(ans

### FIXED CODE ###

S = list(input())

ans = 753

for i in range(len(S)-2):
    sa = abs(753-(int(S[i])*100 + int(S[i+1])*10 + int(S[i+2])))
    ans = min(sa,ans)
             
print(ans)
N,Q=map(int,input().split())
S=input()
c=[0]
t = 0
for i in range(1,N):
    t += 1 if  S[i-1:i+1]=='AC' else 0
    c.append(t)
for _ in range(Q):
    l,r=map(int, intput().split))
    print(c[r]-c[l])


### FIXED CODE ###

N,Q=[int(i) for i in input().split()]
S=input()

c=[0]
t = 0
for i in range(1,N):
   t += 1 if  (S[i-1]=='A' and S[i] == 'C') else 0
   c.append(t)

for _ in range(Q):
    l,r=[int(x)-1 for x in input().split()]
    print(c[r]-c[l])
import sys
N, M = map(int, input().split())
if M & 1:
    print(-1)
    sys.exit()
Edge = [[] for _ in range(N)]
Dim = [0]*N
for _ in range(M):
    a, b = map(int, sys.stdin.readline().split())
    a -= 1
    b -= 1
    Edge[a].append(b)
    Edge[b].append(a)
    Dim[a] += 1
    Dim[b] += 1
Ans = []
used = set()
for i in sorted(range(N), key = lambda x: Dim[x]%2, reverse = True):
    Edge[i].sort(key = lambda x: Dim[x], reverse = True)
    while Dim[i] > 1:
        while (i, Edge[i][-1]) in used:
            Edge[i].pop()
        j1 = Edge[i].pop()
        while (i, Edge[i][-1]) in used:
            Edge[i].pop()
        j2 = Edge[i].pop()
        Ans.append((i+1, j1+1))
        Ans.append((i+1, j2+1))
        Dim[i] -= 2
        Dim[j1] -= 1
        Dim[j2] -= 1
        used.add((i, j1))
        used.add((i, j2))
        used.add((j1, i))
        used.add((j2, i))
assert len(Ans) == M,''

for a in Ans:
    print(*a)

### FIXED CODE ###

import sys
readline = sys.stdin.readline
write = sys.stdout.write
sys.setrecursionlimit(2*10**6)
class UF():
    def __init__(self, num):
        self.par = [-1]*num
        self.size = [1]*num
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            x = self.par[x]
            return self.find(x)
    
    def union(self, x, y):
        rx = self.find(x)
        ry = self.find(y)
        if rx != ry:
            if self.par[rx] < self.par[ry]:
                self.par[ry] = rx
                self.size[rx] += self.size[ry] 
            elif self.par[rx] > self.par[ry]:
                self.par[rx] = ry
                self.size[ry] += self.size[rx]
            else:
                self.par[rx] -= 1
                self.par[ry] = rx
                self.size[rx] += self.size[ry]
            return True
        return False

def getpar(Edge, p):
    N = len(Edge)
    par = [0]*N
    par[0] = -1
    par[p]  -1
    stack = [p]
    visited = set([p])
    while stack:
        vn = stack.pop()
        for vf in Edge[vn]:
            if vf in visited:
                continue
            visited.add(vf)
            par[vf] = vn
            stack.append(vf)
    return par

def topological_sort_tree(E, r):
    Q = [r]
    L = []
    visited = set([r])
    while Q:
        vn = Q.pop()
        L.append(vn)
        for vf in E[vn]:
            if vf not in visited:
                visited.add(vf)
                Q.append(vf)
    return L

N, M = map(int, readline().split())

Edge = []
for _ in range(M):
    a, b = map(int, readline().split())
    a -= 1
    b -= 1
    Edge.append((a, b))

tr = [[] for _ in range(N)]
ans = []
eo = [0]*N
T = UF(N)
for a, b in Edge:
    if T.union(a, b):
        tr[a].append(b)
        tr[b].append(a)
    else:
        ans.append((a+1, b+1))
        eo[a] ^= 1

L = topological_sort_tree(tr, 0)
P = getpar(tr, 0)
for l in L[1:][::-1]:
    if eo[l]:
        ans.append((l+1, P[l]+1))
    else:
        ans.append((P[l]+1, l+1))
        eo[P[l]] ^= 1
if M % 2 == 0:
    for a, b in ans:
        write('{} {}\n'.format(a, b))
else:
    write('-1\n')
X=int(input())
g=X//500
h=X-500*g
i=h//5
j=1000*g+5*i
input(j)

### FIXED CODE ###

X=int(input())
g=X//500
h=X-500*g
i=h//5
j=1000*g+5*i
print(j)
n=int(input()[:5]);a=set(input())
while a&set(str(n)):n+=1
print(n)

### FIXED CODE ###

n=int(input().split()[0]);a=set(input())
while a&set(str(n)):n+=1
print(n)
n = int(input())
a = list(map(int,input().split()))
res = 1
exc = False
for i in a:
	res *= i
	if res > 10**18:
      exc = True
      print(-1)
if not exc:
  print(res)

### FIXED CODE ###

n = int(input())
lim = 10**18
ans,exc = 1,False
a = list(map(int,input().split()))
# print(a)
if 0 in a:
  print(0)
else:
  for x in a:
    ans *= x
    if ans > lim:
      exc = True
      print("-1")
      break
  if not exc:
    print(ans)
n = int(input())
As = [int(input()) for _ in range(n)]
visited = [-1 for i in range(n)]


def rec(visited, prev_i, i, depth):
    if visited[i] > 0:
        return visited[i]
    if As[i] == 2:
        visited[i] = 1
        return depth
    if prev_i == As[i] - 1:
        return visited[i]
    visited[i] = rec(visited, i, As[i] - 1, depth + 1)
    return visited[i]


ret = rec(visited, -1, 1 - 1, 1)
print(ret)


### FIXED CODE ###

n = int(input())
As = [int(input()) for _ in range(n)]
cnt = 0
current_button = 0
for _ in range(n):
    current_button = As[current_button] - 1
    cnt += 1
    if current_button == 1:
        break
if current_button != 1:
    print(-1)
else:
    print(cnt)
L= int(input())
A = (L/3)*(L/3)*(L/3)
print (A)


### FIXED CODE ###

from math import *


N,M = list(map(int,input().split(" ")))
A = (N*(N-1))/2+(M*(M-1))/2
print (int(A))
def main():
    inp=list(map(lambda x:int(x),input().split()))
    A=inp[0]
    B=inp[1]

    res=B
    if 6<=B=<12:
        res=res//2
    elif B<=5:
        res=0

    print(res)

if __name__=="__main__":
    main()
    


### FIXED CODE ###

def main():
    inp=list(map(lambda x:int(x),input().split()))
    A=inp[0]
    B=inp[1]

    res=B
    if A>=6 and A<=12:
        res=res//2
    elif A<=5:
        res=0

    print(res)

if __name__=="__main__":
    main()
x = input().split(" ")
a = int(x[0)
b = int(x[1])

print((a * b), ((a + b) * 2))

### FIXED CODE ###

a, b = map(int, input().split())
print(a * b, (a + b) * 2)
n = int(input())
A = [list(map(int,input().split())) for i in range(n)]

# B = [[[0, 0] for i in range(n)] for j in range(n)]
D = {}
for i in range(n):
    for j in range(i+1, n):
        dy = A[i][1] - A[j][1]
        dx = A[i][0] - A[j][0]
        try:
            D[(dx, dy)] += 1
        except:
            D[(dx, dy)] = 1

ans = n - max(list(D.values()))
print(ans)

### FIXED CODE ###

n = int(input())
A = [list(map(int,input().split())) for i in range(n)]

# B = [[[0, 0] for i in range(n)] for j in range(n)]
if n == 1:
    print(1)
else:

    D = {}
    for i in range(n):
        for j in range(n):
            if i != j:
                dy = A[i][1] - A[j][1]
                dx = A[i][0] - A[j][0]
                try:
                    D[(dx, dy)] += 1
                except:
                    D[(dx, dy)] = 1
    # print(D)
    ans = n - max(list(D.values()))
    print(ans)
s = list(input())
N = len(s)
cont = 0
for i in xrange(1,N):
    if s[i-1]==s[i]:
        cont += 1
        if s[i] == '0':
            del s[i]
            s.insert(i, '1')          
        else:
            del s[i]
            s.insert(i, '0')    
print(cont)

### FIXED CODE ###

A,B = map(int,input().split())

list= [A+A-1,B+B-1,A+B]
print(max(list))
n, A, B = map(int, input().split())
if A > B:
  print(0)
elif n == 1:
  if A != B:
    print(0)
  else:
    print(1)
else:
  print((B - A) * (N - 2) + 1)

### FIXED CODE ###

n, A, B = map(int, input().split())
if A > B:
  print(0)
elif n == 1:
  if A != B:
    print(0)
  else:
    print(1)
else:
  print((B - A) * (n - 2) + 1)
s = sorted([char for char in input()])
t = sorted([char for char in input()]).reverse()
print("Yes" if s < t else "No")


### FIXED CODE ###

s = sorted(input())
t = sorted(input())[:: -1]
print("Yes" if s < t else "No")
h, w = map(int, input().split())
S = [str(input()) for _ in range(h)]

#g = [[] for _ in range(h*w)]

n = h*w

def Find(x, par):
    if par[x] < 0:
        return x
    else:
        par[x] = Find(par[x], par)
        return par[x]

def Unite(x, y, par, rank):
    x = Find(x, par)
    y = Find(y, par)

    if x != y:
        if rank[x] < rank[y]:
            par[y] += par[x]
            par[x] = y
        else:
            par[x] += par[y]
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1

def Same(x, y, par):
    return Find(x, par) == Find(y, par)

def Size(x, par):
    return -par[Find(x, par)]

par = [-1]* n
rank = [0]*n

for y in range(h):
    for x in range(w):
        idx1 = y*w+x
        for dy, dx in (-1, 0), (1, 0), (0, -1), (0, 1):
            ny, nx = y+dy, x+dx
            if 0 <= ny < h and 0 <= nx < w:
                idx2 = ny*w+nx
                if S[y][x] != S[ny][nx]:
                    Unite(idx1, idx2, par, rank)

ans = 0
print(par)
d = {}
for i in range(n):
    if par[i] < 0:
        d[i] = [0, 0]

for i in range(n):
    y, x = divmod(i, w)
    if i in d:
        if S[y][x] == '#':
            d[i][0] += 1
        else:
            d[i][1] += 1
    else:
        if S[y][x] == '#':
            d[par[i]][0] += 1
        else:
            d[par[i]][1] += 1

ans = 0
for k, v in d.items():
    ans += v[0]*v[1]
print(ans)


### FIXED CODE ###

h, w = map(int, input().split())
S = [str(input()) for _ in range(h)]

#g = [[] for _ in range(h*w)]

n = h*w

def Find(x, par):
    if par[x] < 0:
        return x
    else:
        par[x] = Find(par[x], par)
        return par[x]

def Unite(x, y, par, rank):
    x = Find(x, par)
    y = Find(y, par)

    if x != y:
        if rank[x] < rank[y]:
            par[y] += par[x]
            par[x] = y
        else:
            par[x] += par[y]
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1

def Same(x, y, par):
    return Find(x, par) == Find(y, par)

def Size(x, par):
    return -par[Find(x, par)]

par = [-1]* n
rank = [0]*n

for y in range(h):
    for x in range(w):
        idx1 = y*w+x
        for dy, dx in (-1, 0), (1, 0), (0, -1), (0, 1):
            ny, nx = y+dy, x+dx
            if 0 <= ny < h and 0 <= nx < w:
                idx2 = ny*w+nx
                if S[y][x] != S[ny][nx]:
                    Unite(idx1, idx2, par, rank)

ans = 0
#print(par)
X = [[0, 0] for _ in range(n)]
K = []

for i in range(n):
    y, x = divmod(i, w)
    if par[i] < 0:
        K.append(i)
        if S[y][x] == '#':
            X[i][0] += 1
        else:
            X[i][1] += 1
    else:
        if S[y][x] == '#':
            X[Find(i, par)][0] += 1
        else:
            X[Find(i, par)][1] += 1

ans = 0
for k in K:
    ans += X[k][0]*X[k][1]
print(ans)
import heapq

class job:
    def __init__(self,name,date,award):
        self.name=name
        self.award=award
        self.date=date
    def __gt__(self,other):
        if self.award<other.award:
            return True
        elif self.award==other.award and self.date<other.date:
            return True
        elif self.award==other.award and self.date=other.date and self.name>other.name:
            return True
        else:
            return False
    def __lt__(self,other):
        if self.award>other.award:
            return True
        elif self.award==other.award and self.date>other.date:
            return True
        elif self.award==other.award and self.date=other.date and self.name<other.name:
            return False
        else:
            return False

jobs=[]
n,m=[int(i) for i in input().split()]
for i in range(n):
    info=[int(j) for j in input().split()]
    jobs.append(job(i,info[0],info[1]))
heapq.heapify(jobs)
ans=0
for i in range(m):
    while jobs:
        work=heapq.heappop(jobs)
#         print(work.award)
        if work.date+i<=m:
            ans+=work.award
            break
        
        
print(ans)
    
    

### FIXED CODE ###

class Work:
    count=0
    def __init__(self,payday,money):
        Work.count+=1
        self.count=Work.count
        self.payday=payday
        self.money=money
 #moneyが大きい方、同じなら早くもらえる方、それも同じなら最初に書いてある方が強い方
    def __ft__(self,other):
        if self.money>other.money:
            return True
        if self.money==other.money:
            if self.payday<other.payday:
                return True
            if self.payday==other.payday:
                if self.count<other.count:
                    return True
        return False

    def __gt__(self,other):
        if self.money<other.money:
            return True
        if self.money==other.money:
            if self.payday>other.payday:
                return True
            if self.payday==other.payday:
                if self.count>other.count:
                    return True
        return False

#バイトの数、いつまでに稼ぐのか 
n,limit=[int(i) for i in input().split()]

#バイトのリストを作り、クラスを入れる O(n)
baitolist=[]
for i in range(n):
    payday,money=[int(i) for i in input().split()]
    work=Work(payday,money)
    baitolist.append(work)

#日数でランク付け　O(n)
summoney=0    
rank=[[] for i in range(limit+1)]
for baito in baitolist:
    if baito.payday<=limit:
        rank[baito.payday].append(baito)

        
import heapq
accessible=[]
count=1


for i in range(limit):
    for baito in rank[count]:
        heapq.heappush(accessible,baito)
    if accessible!=[]:
        dowork=heapq.heappop(accessible)
        summoney+=dowork.money
    count+=1
    
    
print(summoney)
a=input()
if a<1200:
	print("ABC")
elif a<2800:
	print("ARC")
else:
  print("AGC")

### FIXED CODE ###

a=int(input())
if a<1200:
	print("ABC")
elif a<2800:
	print("ARC")
else:
	print("AGC")
A, B, N = map(int, input().split())
Y = A*x//B - A*(x//B)
print(Y)

### FIXED CODE ###

A, B, N = map(int, input().split())
Ymax=0
if A*N < B:
  print(0)
elif N<B:
  Ymax = A*N // B
  print(Ymax)
else:
  x = B-1
  Ymax = A*x//B - A*(x//B)
  print(Ymax)
#!/usr/bin/env python3

PARTS = ["eraser", "erase", "dreamer", "dream"]


def main():
    S = input()

    if judgeStr(S):
        print("YES")
    else:
        print("NO")


def judgeStr(target: str) -> bool:
    for item in PARTS:
        if target.startswith(item):
            tempStr = target.replace(item, "", 1)
            if tempStr == "" or judgeStr(tempStr):
                return True

    return False


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

PARTS = ["eraser", "erase", "dreamer", "dream"]
# PARTS2 = []


def main():
    global PARTS2
    sys.setrecursionlimit(100000)
    S = input()

    # for i in range(0, 4):
    #     for j in range(0, 4):
    #         PARTS2.append(PARTS[i] + PARTS[j])

    # PARTS2 = PARTS2 + PARTS

    if judgeStr2(S):
        print("YES")
    else:
        print("NO")


def judgeStr2(target: str) -> bool:
    currentStr = target
    while currentStr != "":
        isNextOK = False
        for item in PARTS:
            if not currentStr.startswith(item):
                continue

            tempStr = currentStr.replace(item, "", 1)
            if tempStr == "":
                return True

            for item2 in PARTS:
                if tempStr.startswith(item2):
                    isNextOK = True
                    break

            if isNextOK:
                currentStr = tempStr
                break
        if isNextOK:
            continue
        else:
            break
    return currentStr == ""


def judgeStr(target: str) -> bool:
    for item in PARTS:
        if target.startswith(item):
            tempStr = target.replace(item, "", 1)
            if tempStr == "" or judgeStr(tempStr):
                return True

    return False


if __name__ == "__main__":
    main()
N = int(raw_input())
As = [(int(i), 2) for i in raw_input().split(" ")]
Bs = [(int(i), 1) for i in raw_input().split(" ")]
Cs = [(int(i), 0) for i in raw_input().split(" ")]

l = sorted(As + Bs + Cs)


count = (0, 0, 0, 1)
for i in l:
    count[i] += count[i + 1]
print count[0]

### FIXED CODE ###



N = int(raw_input())
As = raw_input().split(" ")
Bs = raw_input().split(" ")
Cs = raw_input().split(" ")

As = [(int(i), 2) for i in As]
Bs = [(int(i), 1) for i in Bs]
Cs = [(int(i), 0) for i in Cs]

l = sorted(As + Bs + Cs, key=lambda x: x[0] + x[1] * 0.1)

ac = 0
bc = 0
cc = 0

for i in l:
    if i[1] == 2:
        ac += 1
    elif i[1] == 1:
        bc += ac
    elif i[1] == 0:
        cc += bc
print cc