Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n = int(input())
s = []
for i in range(n):
    s.append(int(input()))

s.sort(reverse=True)

tmp = sum(s)

ruiseki = [tmp]
for i in range(n-1):
    ruiseki.append(ruiseki[-1] - s[i])

ans = 0
def DFS(depth, now):
    global ans

    if depth == n:
        if now%10 != 0:
            ans = max(ans, now)
        return
      
    if now + ruiseki[depth] <= ans:
        return

    DFS(depth+1, now+s[depth])
    DFS(depth+1, now)
DFS(0,0)
print(ans)

### FIXED CODE ###

n = int(input())
s = []

geta = 0
for i in range(n):
    a = int(input())
    if a % 10 == 0:
        geta += a
    else:
        s.append(a)

n = len(s)
s.sort(reverse=True)

tmp = sum(s)

ruiseki = [tmp]
for i in range(n-1):
    ruiseki.append(ruiseki[-1] - s[i])

ans = 0
def DFS(depth, now):
    global ans

    if depth == n:
        if now%10 != 0:
            ans = max(ans, now)
        return
    if now + ruiseki[depth] <= ans:
        return
    DFS(depth+1, now+s[depth])
    DFS(depth+1, now)
DFS(0,0)
if ans != 0:
    ans += geta
print(ans)
### BUGGY CODE ###

n,k = list(map(int, input().strip().split()))
step_array = list(map(int, input().strip().split()))
score_array = [0]
for i in range(0, n+1):
	for j in range(1, k+1):
		if i+j > n-1:
			break
		cost = abs(step_array[i] - step_array[i+j]) + score_array[i]
		if len(score_array) <= i+j:
			score_array.append(cost)
		elif(score_array[i+j]>cost):
			score_array[i+j] = cost
print(score_array[n-1])

### FIXED CODE ###

n,k = list(map(int, input().strip().split()))
step_array = list(map(int, input().strip().split()))
score_array = [0]
for i in range(0, n+1):
	for j in range(1, k+1):
		if i+j > n-1:
			break
		cost = abs(step_array[i] - step_array[i+j]) + score_array[i]
		if len(score_array) <= i+j:
			score_array.append(cost)
		elif(score_array[i+j]>cost):
			score_array[i+j] = cost
print(score_array[n-1])
### BUGGY CODE ###

k,n = map(int, input().split())
res = 0
for i in range(k+1):
    for j in range(k+1):
        if i + j > n : break
        h = n - i - j
        if h <= k:
            res +=1
            x =[i,j,h]
print(res)

### FIXED CODE ###

k,n = map(int, input().split())
res = 0
for i in range(k+1):
    for j in range(k+1):
        if i + j > n : break
        h = n - i - j
        if h <= k:
            res +=1
print(res)
### BUGGY CODE ###

N=int(input().strip())
a=[0]*(N-1)
b=[0]*(N-1)
flag=[[0 for i in range(N+1)] for j in range(N+1)] #[colors]*points
color=[]

for i in range(len(a)):
    a[i],b[i]=list(map(int,input().strip().split()))

for i in range(len(a)):# for points
    for c in range(len(color)+1):# for colors
        if flag[a[i]][c] == 0 and flag[b[i]][c] == 0:
            flag[a[i]][c]=1
            flag[b[i]][c]=1
            color.append(c)
            break

print(max(color)+1)
for i in color:
    print(i+1)

### FIXED CODE ###

import sys #追加
sys.setrecursionlimit(500*500) #追加

N=int(input().strip())
a=[0]*(N-1) # # of lines
b=[0]*(N-1)
#to=[[] for j in range(N-1)] # points
ans=[0]*(N-1)

class data:
    def __init__(self):
        self.to=[[] for j in range(N)] # N points
        self.id=[[] for j in range(N)] # N points

def dfs(v,p,c_p): # vertices & parent idx & color from parent
    lst=data.to[v] # children list
    c=1
    for i,child in enumerate(lst):
        if child==p:
            continue
        if c_p==c:
            c+=1
        ans[data.id[v][i]]=c
        c+=1
        dfs(child,v,c-1)

data=data()
for i in range(len(a)):
    a,b=list(map(int,input().strip().split()))
    a-=1
    b-=1
    data.to[a].append(b)
    data.id[a].append(i) # index of the line
    data.to[b].append(a)
    data.id[b].append(i)

#print(data.to)

dfs(0,-1,-1)
print(max(ans))
for i in range(len(ans)):
    print(ans[i])
### BUGGY CODE ###

import sys
#import numpy as np
from scipy.misc import comb

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

def main():
    N, M, K = i2nn()
    L = max(M, N)
    dp = [0] * L
    for i in range(1, L):
        dp[i] = dp[i-1] + i
    n = 0
    for i in range(N):
        n += (dp[i] + dp[N-1-i]) * M * M
    for i in range(M):
        n += (dp[i] + dp[M-1-i]) * N * N
    n = int(n / 2)
    r = comb(N*M-2, K-2, exact=True)
    n = n * r % (int(1e+9)+7)
    print(n)

main()


### FIXED CODE ###

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

MOD = int(1e+9) + 7

def comb(n, k):
    r = 1
    for i in range(n, max(n-k, k), -1):
        r *= i
    for i in range(1, min(n-k, k) + 1, 1):
        r //= i
    return r

class Comb:
    def __init__(self, MAX, MOD):
        MAX += 1
        fac = [0] * MAX
        finv = [0] * MAX
        inv = [0] * MAX
        fac[0] = fac[1] = 1
        finv[0] = finv[1] = 1
        inv[1] = 1
        for i in range(2, MAX):
            fac[i] = fac[i - 1] * i % MOD
            inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
            finv[i] = finv[i - 1] * inv[i] % MOD
        self.fac = fac
        self.finv = finv
        self.MOD = MOD
    
    def comb(self, n, k):
        fac = self.fac
        finv = self.finv
        MOD = self.MOD
        if (n < k):
            return 0
        if (n < 0 or k < 0):
            return 0
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

def main():
    # 行数, 列数, 駒数
    N, M, K = i2nn()
    # 配置コストの総和 % MOD

    # 例）N, M, K = 2, 2, 2
    # 駒が置ける場所は4箇所: N * M
    # 駒の配置は6通り: comb(4, 2) = comb(N*M, K)
    # K=2 の場合のコスト
    xcost = 0
    for i in range(1, M):
        # iをx座標の差とする
        # x座標のみに注目した場合、差がiとなるのは(M-i)通り
        #   M=4, i=1, => (1,2), (2,3), (3,4) = 3通り
        #   M=4, i=2, => (1,3), (2,4) = 2通り
        #   M=4, i=3, => (1,4) = 1通り
        # さらにy座標の組み合わせは, 左側がN通り, 右側がN通り
        #   (1,2) について M=2 の場合 ((1,1), (2,1)), ((1,1), (2,2)), ((1,2), (2,1)), ((1,2), (2,2))
        xcost = (xcost + i * (M-i) * (N*N)) % MOD
    ycost = 0
    for i in range(1, N):
        ycost = (ycost + i * (N-i) * (M*M)) % MOD
    cost = (xcost + ycost) % MOD
    # K=3 の場合、K=2 の場合のコストを NM-2 倍すればよい
    # 汎用的に考えると、 K=2 の場合のコストを comb(MN-2, K-2) 倍すればよい
    #cost = (cost * comb(M*N-2, K-2)) % MOD
    cost = (cost * Comb(N*M-2, MOD).comb(N*M-2, K-2)) % MOD
    print(cost)

main()
### BUGGY CODE ###

a, b ,x = map(int, input().split())
ans = 0
for i in range(a, b+1):
    if i%x == 0:
        ans+=1
print(ans)

### FIXED CODE ###

a, b ,x = map(int, input().split())
ans = 0
n_a = a//x
n_b = b//x
if a%x == 0:
    ans+=1
ans += n_b - n_a
print(ans)
### BUGGY CODE ###

n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

k = min(k, n-1)
dp = [0] * (n+1)

for i in range(2, k+1):
    dp[i] = min([dp[ki] + abs(h[i-1] - h[ki-1]) for ki in range(1,i)])

for i in range(k+1, n+1):
    dp[i] = min([dp[i-ki] + abs(h[i-1] - h[i-1-ki]) for ki in range(1,k+1)])

print(dp[n])

### FIXED CODE ###

import numpy as np

n, k = list(map(int, input().split()))
h = np.array(list(map(int, input().split())))

k = min(k, n-1)
dp = np.zeros(n+1)

for i in range(2, k+1):
    dp[i] = np.min(dp[1:i] + np.abs(h[i-1] - h[0:i-1]))

for i in range(k+1, n+1):
    dp[i] = (dp[i-k:i] + np.abs(h[i-1] - h[i-k-1:i-1])).min()
    
print(int(dp[n]))
### BUGGY CODE ###

def main():
    n, q = map(int, input().split(' '))
    import sys
    sys.setrecursionlimit(10**7)

    visit = set([])
    point = [0 for _ in range(n)]
    dic = [[] for _ in range(n)]
    for _ in range(n-1):
        a, b = map(int, input().split(' '))
        dic[a-1].append(b-1)
        dic[b-1].append(a-1)
    for _ in range(q):
        p, x = map(int, input().split(' '))
        point[p-1] += x
    next_visit = [[0, dic[0]]]
    visit.add(0)
    counter = 1
    while counter < n:
        t = next_visit.pop(0)
        for s in t[1]:
            if set([s]) <= visit:
                continue
            else:
                point[s] += point[t[0]]
                visit.add(s)
                counter += 1
                next_visit.append([s, dic[s]])
    print(" ".join(map(str, point)))
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n, q = map(int, input().split(' '))
    import sys
    from collections import deque
    sys.setrecursionlimit(10**7)

    visit = [True for _ in range(n)]
    point = [0 for _ in range(n)]
    dic = [[] for _ in range(n)]
    for _ in range(n-1):
        a, b = map(int, input().split(' '))
        dic[a-1].append(b-1)
        dic[b-1].append(a-1)
    for _ in range(q):
        p, x = map(int, input().split(' '))
        point[p-1] += x
    next_visit = deque()
    next_visit.append(0)
    visit[0] = False
    counter = 1
    while counter < n:
        t = next_visit.pop()
        for s in dic[t]:
            if visit[s]:
                point[s] += point[t]
                visit[s] = False
                counter += 1
                next_visit.append(s)
    print(*point)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import Counter
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


N=int(input())
A=list(input().split())
c=Counter(A)
itms=list(c.items())
lenC=len(c)
num=0

for i in range(lenC):
    itmsi=itms[i][1]
    if itmsi>=2:
        num+=cmb(itmsi,2)


for i in range(N):
    num2=c[A[i]]
    if num2>=3:
        print(num-cmb(num2,2)+cmb(num2-1,2))

    elif num2==2:
        print(num-1)
    else:
        print(num)



### FIXED CODE ###

from collections import Counter
'''
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
'''

def cmb(n,r):
    return n*(n-1)//2

N=int(input())
A=list(input().split())
c=Counter(A)
itms=list(c.items())#
lenC=len(c)
num=0

for i in range(lenC):
    itmsi=itms[i][1]
    if itmsi>=2:
        num+=cmb(itmsi,2)


for i in range(N):
    num2=c[A[i]]
    if num2>=3:
        print(num-cmb(num2,2)+cmb(num2-1,2))

    elif num2==2:
        print(num-1)
    else:
        print(num)
### BUGGY CODE ###

N = int(input())
res = [0 for i in range(100000)]
def lucas(N):
	if N == 0:
		return 2
	elif N == 1:
		return 1
	elif res[N] != 0:
		return res[N]
	return lucas(N-1) + lucas(N-2)

print(lucas(N))

### FIXED CODE ###

N = int(input())
res = [0 for i in range(100)]
res[0] = 2
res[1] = 1
for i in range(2, N+1):
	res[i] = res[i - 1] + res[i - 2]
print(res[N])
### BUGGY CODE ###

import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,k=map(int,input().split())
a=list(map(int,input().split()))

cnt=1
for i in range(k):
    cnt*=a[i]

for i in range(k,n):
    tmp=cnt
    cnt*=a[i]
    cnt//=a[i-k]
    # print(tmp,cnt)
    if tmp<cnt:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,k=map(int,input().split())
a=list(map(int,input().split()))

# cnt=1
# for i in range(k):
#     cnt*=a[i]

for i in range(k,n):
    # tmp=cnt
    # cnt*=a[i]
    # cnt//=a[i-k]
    # print(tmp,cnt)
    if a[i-k]<a[i]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict
from fractions import gcd

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, M = getlist()
	A = getlist()
	B = [int(A[i] // 2) for i in range(N)]
	LCM = B[0]
	for i in range(N - 1):
		GCD = gcd(LCM, B[i + 1])
		LCM = int(LCM * B[i + 1] / GCD)
		if LCM >= 10 ** 10:
			break

	if LCM > M:
		print(0)
	else:
		ans = (M - LCM) // (2 * LCM) + 1
		D = defaultdict(int)
		for i in range(N):
			x = B[i]
			val = 0
			while True:
				if x % 2 == 0:
					val += 1
				else:
					break
			D[val] += 1

		if D[val] != N:
			ans = 0
			
		print(ans)


if __name__ == '__main__':
	main()

### FIXED CODE ###

#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict
from fractions import gcd

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, M = getlist()
	A = getlist()
	B = [int(A[i] // 2) for i in range(N)]
	LCM = B[0]
	for i in range(N - 1):
		GCD = gcd(LCM, B[i + 1])
		LCM = int(LCM * B[i + 1] / GCD)
		if LCM >= 10 ** 10:
			break

	if LCM > M:
		print(0)
	else:
		ans = (M - LCM) // (2 * LCM) + 1
		D = defaultdict(int)
		for i in range(N):
			x = B[i]
			val = 0
			while True:
				if x % 2 == 0:
					val += 1
					x = int(x // 2)
				else:
					break
			D[val] += 1

		if D[val] != N:
			ans = 0

		print(ans)


if __name__ == '__main__':
	main()
### BUGGY CODE ###

q=[]
h,w=map(int,input().split())
arr=[[] for _ in range(h+2)]
for i in range(w+2):
  arr[0].append(True)
for i in range(h):
  arr[i+1].append(True)
  for j in input():
    if j=='#':
      arr[i+1].append(True)
    else:
      arr[i+1].append(False)
  arr[i+1].append(True)
for i in range(w+2):
  arr[h+1].append(True)
dx=[-1,0,1,0]
dy=[0,-1,0,1]
for i in range(1,h+1):
  for j in range(1,w+1):
    if arr[i][j]:
      q.append([i,j])
ans=0
while 1:
  nq=[]
  for y,x in q:
    for i in range(4):
      if not arr[y+dy[i]][x+dx[i]]:
        nq.append([y+dy[i],x+dx[i]])
        arr[y+dy[i]][x+dx[i]]=True
  if len(nq)==0:
    print(ans)
    break
  else:
    q=nq
    ans+=1

### FIXED CODE ###

import collections
q=collections.deque()
h,w=map(int,input().split())
arr=[[] for _ in range(h+2)]
for i in range(w+2):
  arr[0].append('#')
for i in range(h):
  arr[i+1].append('#')
  for j in input():
    arr[i+1].append(j)
  arr[i+1].append('#')
for i in range(w+2):
  arr[h+1].append('#')
dx=[-1,0,1,0]
dy=[0,-1,0,1]
for i in range(1,h+1):
  for j in range(1,w+1):
    if arr[i][j]=='#':
      q.append([i,j,0])
while 1:
  y,x,cnt=q.popleft()
  for i in range(4):
    if arr[y+dy[i]][x+dx[i]]=='.':
      q.append([y+dy[i],x+dx[i],cnt+1])
      arr[y+dy[i]][x+dx[i]]='#'
  if len(q)==0:
    print(cnt)
    break
### BUGGY CODE ###

count=0
mainasu=0
num=int(input())
An=[int(i) for i in input().split()]

for i in An[0:num]:
    mainasu+=1
    for w in An[mainasu:]:
        
        if i==w:
            count=1
            break
    if count>=1:
        break
    
if 0==count:
    print("YES")
    
else :
    print("NO")

### FIXED CODE ###

def duplication(lis):
    return len(lis) == len(set(lis)) 

num=int(input())
An=[int(i) for i in input().split()]


if duplication(An) == True:
    print("YES")
    
else :
    print("NO")
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))

hyoten = [1]*(n-k+1)
for i in range(n-k+1):
    for j in range(i, i+k):
        hyoten[i] *= a[j]

for i in range(n-k):
    if hyoten[i+1] > hyoten[i]:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n-k):
    if a[i] < a[i+k]:
        print("Yes")
    elif a[i] >= a[i+k]:
        print("No")
### BUGGY CODE ###

n = int(input())
s = list(input())
count = []
for i in range(n):
  c = 0
  for j in range(n):
    if j < i:
      if s[j] == "W":
        c += 1
    elif i < j:
      if s[j] == "E":
        c += 1
  count.append(c)
print(min(count))

### FIXED CODE ###


n = int(input())
s = list(input())
w_count, e_count = 0, 0
w_list, e_list = [], []
count = []
for i in range(n):
    if s[i] == "W":
        w_count += 1
    w_list.append(w_count)
    if s[n - i - 1] == "E":
        e_count += 1
    e_list.append(e_count)
e_list.reverse()
count.append(e_list[0])
for i in range(1, n - 1):
    count.append(w_list[i - 1] + e_list[i + 1])
count.append(w_list[n - 1])
print(min(count))
### BUGGY CODE ###

n, k = map(int, input().split())
aList = list(map(int, input().split()))
aSet = set(aList)
aCount = []
for i in aSet:
    aCount.append(aList.count(i))
aCount.sort()
aCount = aCount[:-k]
print(sum(aCount))


### FIXED CODE ###

n, k = map(int, input().split())
aList = list(map(int, input().split()))
num = [0 for _ in range(n + 1)]
for i in aList:
    num[i] += 1
num.sort()
num = num[:-k]
print(sum(num))
### BUGGY CODE ###

import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,k=mp()
a=lmp()
l=[]
i=0
while a[i] not in l:
    l.append(a[i])
    i=a[i]-1


x=l.index(a[i])
y=len(l)-x

if k<=x:
    print(l[k-1])
else:
    print(l[(k-x-1)%y+x])

### FIXED CODE ###

import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,k=mp()
a=lmp()
l=[]
i=0
ch=[0]*(n+1)
while True:
    if ch[i]==1:
        break
    else:
        ch[i]=1
        l.append(a[i])
        i=a[i]-1


x=l.index(a[i])
y=len(l)-x

if k<=x:
    print(l[k-1])
else:
    print(l[(k-x-1)%y+x])
### BUGGY CODE ###

import sys
input = sys.stdin.readline

a,b = map(int,input().split())

da = [[] for i in range(a)]
d = []
for i in range(b):
    k,kk = map(int,input().split())
    da[k-1].append(kk)
    d.append([k, kk])

for i in da:
    i.sort()
    i.reverse()


for i in d:
    p = (len(da[i[0]-1]) - da[i[0]-1].index(i[1])-1)

    n = str(i[0])
    m = str(p+1)

    n = "0"*(6-len(n)) + n
    m = "0"*(6-len(m)) + m

    print(n+m)

### FIXED CODE ###

import sys
input = sys.stdin.readline

a,b = map(int,input().split())
aa = []
d = []
for i in range(b):
    k,kk = map(int,input().split())
    d.append([k, kk,i+1])

da = sorted(d)

kkk = da[0][0]
ll = 0
for i in range(b):
    kkkk = da[i][0]
    if kkk == kkkk:
        ll += 1
    else:
        kkk = kkkk
        ll = 1
    aa.append([da[i][2],da[i][0],ll])
aa.sort()

for i in aa:
    m = str(i[1])
    n = str(i[2])
    m = "0"*(6-len(m))+m
    n = "0"*(6-len(n))+n
    print(m+n)
### BUGGY CODE ###

s = list(input())
s.reverse()
str = ""
for i in s:
    str+=i

#str_list = ["maerd", "remaerd", "esare", "resare"]
str = str.replace("resare","")
str = str.replace("remaerd","")
str = str.replace("maerd","")
str = str.replace("esare","")

"""while True:
    flag=0
    for l in str_list:
        if str.startswith(l):
            print("str:{},l:{}".format(str,l))
            str=str.lstrip(l)
            #ここで想定よりも１文字多く削除されてしまう(erasedream)
            print("str:{},l:{}".format(str,l))
            flag+=1
    if flag==0:
        break"""

if str == "":
    print("YES")
else:
    print("NO")

### FIXED CODE ###

s = list(input())
s.reverse()
str = ""
for i in s:
    str+=i
str = str.replace("resare","")
str = str.replace("esare","")
str = str.replace("remaerd","")
str = str.replace("maerd","")
if len(str)==0:
    print("YES")
else:
    print("NO")
### BUGGY CODE ###

n=int(input())
listn=list(map(int,input().split()))
count=0
for i in range(n):
	flag=True
	for j in range(0,i+1):
		if(listn[i]>listn[j]):
			flag=False
			break
	if(flag==True):
		count+=1
print(count)



### FIXED CODE ###

n=int(input())
listn=list(map(int,input().split()))
count=0
min1=listn[0]
for i in range(0,n):
	if(listn[i]>min1):
		pass
	else:
		min1=listn[i]
		count+=1
print(count)
### BUGGY CODE ###

import sys

n=int(input())
a=[]
i=1
while n!=1:
    i+=1
    b=0
    c=0
    while n%i==0:
        n=n//i
        b+=1
    while not c*(c+1)<=2*b<(c+1)*(c+2):
        c+=1
    a.append(c)
print(sum(a))
        

### FIXED CODE ###

n=int(input())
def f(x):
    z=1
    while not(z*(z+1)<=2*x<(z+1)*(z+2)):
        z+=1
    return z

x=[-1]*(10**6+1) #2以上の自然数に対して最小の素因数を表す
x[0]=0
x[1]=1
i=2
prime=[]
while i<=10**6:
    if x[i]==-1:
        x[i]=i
        prime.append(i)
    for j in prime:
        if i*j>10**6 or j>x[i]:break
        x[j*i]=j
    i+=1
if n==1:
    print(0)
    exit()
y=0
j=2
while j*j<=n:
    if n%j==0:
        y=1
    j+=1
if y==0:
    print(1)
    exit()
a=[]
q=0
for i in range(len(prime)):
    p=prime[i]
    while n%p==0:
        q+=1
        n=n//p
    if q>0:a.append(q)
    q=0

ans=0
for i in range(len(a)):
    ans+=f(a[i])
print(ans if n==1 else ans+1)
### BUGGY CODE ###

A, B, K = map(int, input().split())
s = set()
for i, n in enumerate(range(A, B+1)):
    if i+1 <= K:
        s.add(n)
for i, n in enumerate(reversed(range(A, B+1))):
    if i+1 <= K:
        s.add(n)
for i in sorted(s):
    print(i)

### FIXED CODE ###

A, B, K = map(int, input().split())
s = set()
for i, n in enumerate(range(A, B+1)):
    if i+1 <= K:
        s.add(n)
    if i+1 > K:
        break
for i, n in enumerate(reversed(range(A, B+1))):
    if i+1 <= K:
        s.add(n)
    if i+1 > K:
        break
for i in sorted(s):
    print(i)
### BUGGY CODE ###

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

if n%k == 0:
    print(0)
    exit()
    
if abs(n-k) > n:
    print(n)
    exit()

tmp = n
for i in range(1, int(n**0.5)+1):
    tmp = min(abs(n-i*k), tmp)
print(tmp)

### FIXED CODE ###

n, k = map(int, input().split())
a = n%k
print(min(a, k-a))