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

import sys
input = sys.stdin.readline
N,M=map(int,input().split())
list1=list(map(int,input().split()))
list2=list(set(list1))
listBC=[[list2[i],list1.count(list2[i])] for i in range(len(list2))]
listC=[list2[i] for i in range(len(list2))]
for _ in range(M):
  B,C=map(int,input().split())
  listBC+=[[C,B]]
listBC.sort(reverse=True)
i=-1
SUM=0
ans=0
while SUM<N:
  i+=1
  ans+=listBC[i][0]*listBC[i][1]
  SUM+=listBC[i][1]
ans-=listBC[i][0]*(SUM-N)  
print(ans)

### FIXED CODE ###

N,M = map(int, input().split())
listA = list(map(int, input().split()))
listA.sort()
 
listBC = [list(map(int, input().split())) for i in range(M)]
listBC = sorted(listBC, key=lambda x: x[1], reverse=True)
countB = 0
 
for i in range(M):
  B, C = listBC[i][0], listBC[i][1]
  listA += [C]*B
  countB += B
  if countB >= N:
    break

listA.sort(reverse=True)
print(sum(listA[:N]))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
    S = list(input()[:-1]) 
    S = S[::-1]

    dp = [[0] * 15 for _ in range(len(S) + 5)]
    MOD = 10**9 + 7

    dp[0][0] = 1

    for i in range(len(S)):
        for j in range(13):
            if S[i] != '?':
                k = int(S[i])
                dp[i+1][(j+k*10**i)%13] += dp[i][j]
                dp[i+1][(j+k*10**i)%13] %= MOD
            else:
                for k in range(10):
                    dp[i+1][(j+k*10**i)%13] += dp[i][j]
                    dp[i+1][(j+k*10**i)%13] %= MOD


    print(dp[len(S)][5])


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    S = list(input())

    dp = [0] * 13
    dp[0] = 1
    mod = 10**9 + 7
    digit = 1
    for i in range(len(S)-1,-1,-1):
        nextdp = [0] * 13
        if S[i] == '?':
            for j in range(10):
                for k in range(13):
                    nextdp[(j * digit + k) % 13] += dp[k]
                    # あらかじめ10*9 + 7で割って余りを出しておく
                    nextdp[(j * digit + k) % 13] %= mod
        else:
            j = int(S[i])
            for k in range(13):
                nextdp[(j * digit + k) % 13] += dp[k]
                # あらかじめ10*9 + 7で割って余りを出しておく
                nextdp[(j * digit + k) % 13] %= mod
        
        digit *= 10
        # A * 桁数の13で割ったあまりは (A % 13) * (桁数 % 13)のため、桁数を13で割っておく
        digit %= 13
        dp = nextdp
    
    print(dp[5])

main()
### BUGGY CODE ###

N = int(input())
S = input()
R, G, B = [],[],[]
for i,s in enumerate(S):
    if s=='R':
        R.append(i)
    elif s=='G':
        G.append(i)
    else:
        B.append(i)

R.sort()
G.sort()
B.sort()

ans = len(R)*len(G)*len(B)
for r in R:
    for g in G:
        if r*2-g in B:
            ans -= 1
        if g*2-r in B:
            ans -= 1
        if (r+g)/2 in B:
            ans -= 1

print(ans)



### FIXED CODE ###

N = int(input())
S = input()
R, G, B = [],[],[]
for i,s in enumerate(S):
    if s=='R':
        R.append(i)
    elif s=='G':
        G.append(i)
    else:
        B.append(i)

R.sort()
G.sort()
B.sort()

from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
 
ans = len(R)*len(G)*len(B)
if ans > 0:
    for r in R:
        for g in G:
            for p in [r*2-g,g*2-r,(r+g)/2]:
                if p<=B[-1] and p>=B[0]:
                    ind = bisect_left(B,p)
                    if p == B[ind]:
                        ans -= 1

print(ans)
### BUGGY CODE ###

from bisect import bisect_left as bl, bisect_right as br
from collections import deque
N, M = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

S = sorted(A)
D = {a: i for i, a in enumerate(S)}

BB = [0] * (N+1)
for i in range(N):
    BB[D[A[i]] + 1] = B[i]

for i in range(1, N+1):
    BB[i-1] ^= BB[i]

A = [D[a] for a in A]
X = [[] for _ in range(N+1)]
DD = {}
for i in range(M):
    l, r = map(int, input().split())
    l = bl(S, l)
    r = bl(S, r+1)
    X[l].append(r)
    X[r].append(l)
    DD[(l<<18) + r] = i
    DD[(r<<18) + l] = i

Q = deque([i for i in range(N+1)])
P = [-1] * (N+1)
CH = [[] for _ in range(N+1)]
R = []
while Q:
    i = deque.pop(Q)
    if P[i] < 0: R.append(i)
    for j in X[i]:
        if P[j] >= 0: continue
        if j != P[i]:
            R.append(j)
            P[j] = i
            CH[i].append(j)
            X[j].remove(i)
            deque.append(Q, j)

ANS = []
for i in R[1:][::-1]:
    if BB[i]:
        BB[i] ^= 1
        BB[P[i]] ^= 1
        if P[i] < 0:
            print(-1)
            exit()
        ANS.append(DD[(i<<18) + P[i]] + 1)
if sum(BB) == 0:
    print(len(ANS))
    print(*sorted(ANS))
else:
    print(-1)

### FIXED CODE ###

import sys
input = sys.stdin.readline

# from bisect import bisect_left as bl, bisect_right as br
# from collections import deque
N, M = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

S = sorted(A)
D = {a: i for i, a in enumerate(S)}

BB = [0] * (N+1)
for i in range(N):
    BB[D[A[i]] + 1] = B[i]

for i in range(1, N+1):
    BB[i-1] ^= BB[i]

def bl(L, k):
    l, r = -1, len(L)
    while r - l > 1:
        m = (l+r) // 2
        if L[m] >= k:
            r = m
        else:
            l = m
    return r

A = [D[a] for a in A]
X = [[] for _ in range(N+1)]
DD = {}
for i in range(M):
    l, r = map(int, input().split())
    l = bl(S, l)
    r = bl(S, r+1)
    X[l].append(r)
    X[r].append(l)
    DD[(l<<18) + r] = i
    DD[(r<<18) + l] = i

# Q = deque([i for i in range(N+1)])
# Q = [i for i in range(N+1)]
P = [-1] * (N+1)
CH = [[] for _ in range(N+1)]
R = []
done = [0] * (N+1)
for ii in range(N+1):
    Q = [ii]
    while Q:
        i = Q.pop()
        if P[i] < 0:
            R.append(i)
            done[i] = 1
        for j in X[i]:
            if P[j] >= 0: continue
            if j != P[i] and done[j] == 0:
                R.append(j)
                done[j] = 1
                P[j] = i
                CH[i].append(j)
                # X[j].remove(i)
                # deque.append(Q, j)
                Q.append(j)

ANS = []
for i in R[1:][::-1]:
    if BB[i]:
        BB[i] ^= 1
        BB[P[i]] ^= 1
        if P[i] < 0:
            print(-1)
            exit()
        ANS.append(DD[(i<<18) + P[i]] + 1)
if sum(BB) == 0:
    print(len(ANS))
    print(*sorted(ANS))
else:
    print(-1)
### BUGGY CODE ###

n=int(input())
A=list(map(int,input().split()))
ans=[]
for i in range(n):
    l=A[:i]+A[i+1:]
    sum=0
    for a in l:
        sum=sum^a
    ans.append(sum)
ans=' '.join(map(str,ans))
print(ans)

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
ans=[]
sum=0
for a in A:
    sum=sum^a
for a in A:
    ans.append(sum^a)
ans=' '.join(map(str,ans))
print(ans)
### BUGGY CODE ###

def main():
    k = int(input())
    s = input()
    n = len(s)

    def cmb1(n, r, mod):
        if ( r<0 or r>n ):
            return 0
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod

    mod = 10**9+7 #出力の制限
    N = n+k
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル

    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )

    def power(a, n, mod):
        bi=str(format(n,"b")) #2進数
        res=1
        for i in range(len(bi)):
            res=(res*res) %mod
            if bi[i]=="1":
                res=(res*a) %mod
        return res

    ans = 0
    for i in range(k+1):
        temp = power(25, i, mod)
        temp *= cmb1(i+n-1, n-1, mod)
        temp %= mod
        temp *= power(26, k-i, mod)
        temp %= mod
        ans += temp
    print(ans%mod)

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    k = int(input())
    s = input()
    n = len(s)

    def cmb1(n, r, mod):
        if ( r<0 or r>n ):
            return 0
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod

    mod = 10**9+7
    N = 2*10**6
    fac = [1]*(N+1)
    finv = [1]*(N+1)
    for i in range(N):
        fac[i+1] = fac[i] * (i+1) % mod
    finv[-1] = pow(fac[-1], mod-2, mod)
    for i in reversed(range(N)):
        finv[i] = finv[i+1] * (i+1) % mod

    def cmb1(n, r, mod):
        if r <0 or r > n:
            return 0
        r = min(r, n-r)
        return fac[n] * finv[r] * finv[n-r] % mod

    def power(a, n, mod):
        bi=str(format(n,"b")) #2進数
        res=1
        for i in range(len(bi)):
            res=(res*res) %mod
            if bi[i]=="1":
                res=(res*a) %mod
        return res

    ans = 0
    for i in range(k+1):
        temp = power(25, i, mod)
        temp *= cmb1(i+n-1, n-1, mod)
        temp %= mod
        temp *= power(26, k-i, mod)
        temp %= mod
        ans += temp
    print(ans%mod)

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

from heapq import*
h,w=map(int,input().split())
grid=[["#"]*(w+2)]+[list("#"+input()+"#")for x in range(h)]+[["#"]*(w+2)]

stack=[]
for y in range(1,h+1):
    for x in range(1,w+1):
        if grid[y][x]=="#":
            grid[y][x]=0
            stack.append((y,x))

for i in range(h*w):
    tmp=[]
    for my,mx in stack:
        for y,x in ([0,1],[1,0],[-1,0],[0,-1]):
            if grid[my+y][mx+x]==".":
                grid[my+y][mx+x]=i+1
                tmp.append([my+y,mx+x])
    stack=tmp
print(max(max(i[1:-1])for i in grid[1:-1]))

### FIXED CODE ###

from heapq import*
h,w=map(int,input().split())
grid=[["#"]*(w+2)]+[list("#"+input()+"#")for x in range(h)]+[["#"]*(w+2)]

stack=[]
for y in range(1,h+1):
    for x in range(1,w+1):
        if grid[y][x]=="#":
            grid[y][x]=0
            stack.append((y,x))

for i in range(h*w):
    tmp=[]
    for my,mx in stack:
        for y,x in ([0,1],[1,0],[-1,0],[0,-1]):
            if grid[my+y][mx+x]==".":
                grid[my+y][mx+x]=i+1
                tmp.append([my+y,mx+x])
    stack=tmp
    if len(tmp)==0:
        print(i)
        break
### BUGGY CODE ###

import math
n=int(input())
for i in range(1,n+1):
  square=[j**2 for j in range(1,(int(math.sqrt(2*i))+1))]
  cnt=0
  for x in square:
    for y in square :
      if y>x:
        for z in square:
          if x+y+z==2*i and z>y and x+y>z and y+z>x and z+x>y:
           cnt +=6
  for x in square:
    for y in square:
      if 2*x>y and x!=y:   
        if x+x+y==2*i:
          cnt +=3
  for x in square:
    if x+x+x==2*i:
      cnt+=1
  print(cnt)

### FIXED CODE ###

import math
import collections
n=int(input())
m=int(math.sqrt(n)+1)
a=[]
for x in range(1,m):
  for y in range(1,m):
    for z in range(1,m):
      if x**2+y**2+z**2+x*y+y*z+z*x<=n:
        a.append(x**2+y**2+z**2+x*y+y*z+z*x)
c=collections.Counter(a)
for i in range(1,n+1):
  print(c[i])
### BUGGY CODE ###

#!/usr/bin/env python3
from collections import deque

h, w = map(int, input().split())
maze = [[i == "#" for i in input()] for _ in range(h)]

dx = [1, 0]
dy = [0, 1]

que = deque([])
que.append((0, 0, maze[0][0], 1 if maze[0][0] else 0))
count = 10**5

while que:
    x, y, b, c = que.pop()
    if x == h - 1 and y == w - 1:
        count = min(count, c)
    elif c < count:
        for i in range(2):
            nx = x + dx[i]
            ny = y + dy[i]

            if not (0 <= nx < h and 0 <= ny < w):
                continue
            que.append((nx, ny, maze[nx][ny], c + (not b and maze[nx][ny])))
print(count)


### FIXED CODE ###

#!/usr/bin/env python3
from collections import deque

h, w = map(int, input().split())
maze = [[i == "#" for i in input()] for _ in range(h)]

dx = [1, 0]
dy = [0, 1]

que = deque([])
que.append((0, 0, maze[0][0], 1 if maze[0][0] else 0))
count = [[h + w] * w for _ in range(h)]

while que:
    x, y, b, c = que.pop()
    if c >= count[x][y]:
        continue
    count[x][y] = c
    if x == h - 1 and y == w - 1:
        continue
    for i in range(2):
        nx = x + dx[i]
        ny = y + dy[i]

        if not (0 <= nx < h and 0 <= ny < w):
            continue
        que.append((nx, ny, maze[nx][ny], c + (not b and maze[nx][ny])))
print(count[h - 1][w - 1])
### BUGGY CODE ###

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

ct = [0] * (n + 1)
e = [[] for _ in range(n + 1)]

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

for _ in range(q):
    p, q = map(int, input().split())
    target = [p]
    while len(target):
        t = target.pop()
        ct[t] += q
        for nt in e[t]:
            target.append(nt)

print(*ct[1:])


### FIXED CODE ###

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

ct = [0] * (n + 1)
e = [[] for _ in range(n + 1)]

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

qs = [0] * (n + 1)
for _ in range(q):
    p, q = map(int, input().split())
    qs[p] += q

target = [1]
while len(target):
    t = target.pop()
    ct[t] += qs[t]
    for nt in e[t]:
        target.append(nt)
        ct[nt] += ct[t]

print(*ct[1:])
### BUGGY CODE ###

N = int(input())
X = input()

dp = [-1] * 200001
dp[0] = 0
dp[1] = 1
dp[2] = 1
dp[3] = 2
dp[4] = 1
dp[5] = 2
dp[6] = 1
dp[7] = 2
dp[8] = 1
dp[9] = 2
dp[10] = 1


def popcount(n: int):
    bin_n = bin(n)
    return str(bin_n).count('1')


for i in range(N):
    count = 0
    if X[i] == '1':
        tmp = int(X)
        tmp -= 10 ** (N - i - 1)
    else:
        tmp = int(X)
        tmp += 10 ** (N - i - 1)
    tmp = int(str(tmp), 2)

    while True:
        if tmp == 0:
            print(count)
            break
        else:
            count += 1
            tmp = tmp % popcount(tmp)
            origin = tmp
            if dp[tmp] != -1:
                print(count + dp[tmp])
                break
            else:
                count += 1
                tmp = tmp % popcount(tmp)


### FIXED CODE ###

N = int(input())
S = input()
X = int(S, 2)
pcx = S.count('1')
# ビット反転で1が0になる場合
pc1 = X % (pcx - 1) if pcx > 1 else 0
# ビット反転で0が1になる場合
pc2 = X % (pcx + 1)


def f(j):
    cnt = 0
    while j:
        j %= bin(j).count('1')
        cnt += 1
    return cnt


for i, y in enumerate(S):
    k = N - i - 1
    if y == "0":  # modを分配するときは、分配してからもう１回modを作用させれば良い
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)
### BUGGY CODE ###

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

t = ta[0][0]
a = ta[0][1]

for i in range(n):
    tt = ta[i][0]
    aa = ta[i][1]
    while t > tt or a > aa:
        tt += ta[i][0]
        aa += ta[i][1]
    t = tt
    a = aa

print(t+a)

### FIXED CODE ###

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

t = 1
a = 1

for i in range(n):
    x = max(t//ta[i][0], a//ta[i][1])
    if t > ta[i][0] * x or a > ta[i][1] * x:
        x += 1
    t = ta[i][0] * x
    a = ta[i][1] * x

print(t+a)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

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

root = {}
for i in range(n-1):
    a, b = map(int, input().split())
    root.setdefault(a, []).append(b)
    root.setdefault(b, []).append(a)
    
cnt = [0] * (n+1)
for i in range(q):
    p, x = map(int, input().split())
    cnt[p] += x

check = []
def rec(node, checked):
    checked.append(node)
    for k in root[node]:
        if not k in checked:
            cnt[k] += cnt[node]
            rec(k, checked)

rec(1, check)
print(" ".join(map(str, cnt[1:])))

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(300000)

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

root = [[] for _ in range(n+1)]
for i in range(n-1):
    a, b = map(int, input().split())
    root[a].append(b)
    root[b].append(a)
    
cnt = [0 for _ in range(n+1)]
for i in range(q):
    p, x = map(int, input().split())
    cnt[p] += x

def rec(node, parent):
    for i in root[node]:
        if i == parent:
            continue
        cnt[i] += cnt[node]
        rec(i, node)

rec(1, 1)
print(" ".join(map(str, cnt[1:])))
### BUGGY CODE ###

def main():
    a,b = map(int,input().split())
    if a-b+1>=673:
        print(0)
    else:
        mini = 2020
        for i in range(a,b+1):
            for j in range(a,i):
                joke = i*j%2019
                if joke<mini:
                    mini = joke
        print(mini)
main()

### FIXED CODE ###

def main():
    a,b = map(int,input().split())
    if a-b+1>=2019:
        print(0)
    else:
        mini = 2020
        for i in range(a,b+1):
            for j in range(a,i):
                joke = i*j%2019
                if joke<mini:
                    mini = joke
                    if mini == 0:
                        print(0)
                        return 0
        print(mini)
main()
### BUGGY CODE ###

S = str(input())
s = int(S)
n = len(S)
count = 0
for i in range(1,n+1):
    for j in range(i+4,n+1):
        si = s%10**(n-i+1)
        sij = si//10**(n-j)
        if sij!= 0 and sij % 2019 == 0:
            count+=1

print(count)

### FIXED CODE ###

from collections import Counter

s = input()
a = [0]
mod = 2019

for i,j in enumerate(s[::-1]):
    a.append(a[-1] + int(j)*pow(10,i,mod))
    a[-1] %= mod
b = Counter(a)

ans = 0
for i in b.values():
    ans += i*(i-1)//2
print(ans)
### BUGGY CODE ###

N,K = map(int, input().split())
A = list(map(int, input().split()))
p = 1
p_hist = []
p_hist_index = [-1] * (N+1)
while p not in p_hist:
    p_hist_index[p] = len(p_hist)
    p_hist.append(p)
    p = A[p-1]
end_loop = p_hist[-1]
end_loop_idx = p_hist_index[end_loop]
start_loop = A[end_loop - 1]
start_loop_idx = p_hist_index[start_loop]
if K < start_loop_idx:
    print(p_hist[K])
else:
    print(p_hist[(K-start_loop_idx)%(end_loop_idx-start_loop_idx+1)+start_loop_idx])


### FIXED CODE ###

N,K = map(int, input().split())
A = list(map(int, input().split()))
p = 1
p_hist = []
p_hist_set = set()
p_hist_index = [-1] * (N+1)
while p not in p_hist_set:
    p_hist_index[p] = len(p_hist)
    p_hist.append(p)
    p_hist_set.add(p)
    p = A[p-1]
end_loop = p_hist[-1]
end_loop_idx = p_hist_index[end_loop]
start_loop = A[end_loop - 1]
start_loop_idx = p_hist_index[start_loop]
if K < start_loop_idx:
    print(p_hist[K])
else:
    print(p_hist[(K-start_loop_idx)%(end_loop_idx-start_loop_idx+1)+start_loop_idx])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
 
[n,q]=[int(x) for x in input().split()]
ab=[[int(x) for x in input().split()] for _ in range(n-1)]
px=[[int(x) for x in input().split()] for _ in range(q)]
 
bubungi=[[x] for x in range(1,n+1)]
ab.sort()
for node in ab[::-1]:
    bubungi[node[0]-1]=bubungi[node[0]-1]+bubungi[node[1]-1]
 
scores=[0,]*n
for q in px:
    for i in bubungi[q[0]-1]:
        scores[i-1]+=q[1]
 
print(*scores)

### FIXED CODE ###


n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]
 
neigh = {}
 
scores = [0] * n
 
for i in range(q) :
    scores[px[i][0] - 1] += px[i][1]
#print(*scores) 
for i in range(n - 1) :
    neigh.setdefault(ab[i][0], []).append(ab[i][1])
#print(neigh)

sortKey = sorted(neigh.keys())
 
for k in sortKey :
    for e in neigh[k]:
        scores[e-1]+=scores[k-1]
 
print(*scores)
### BUGGY CODE ###

import itertools
n,k=map(int,input().split())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
c=itertools.combinations(range(n),2)
d=itertools.combinations(range(n),2)
ans=10**25
for i0 in range(n):
    for i1 in range(n):
        for j0 in range(n):
            for j1 in range(n):
                i=[i0,i1]
                j=[j0,j1]
                #print(i,j)
                lx=min(l[i[0]][0],l[i[1]][0])
                rx=max(l[i[0]][0],l[i[1]][0])
                dy=min(l[j[0]][1],l[j[1]][1])
                uy=max(l[j[0]][1],l[j[1]][1])
                tk=0
                for p in l:
                    if lx<=p[0]<=rx and dy<=p[1]<=uy:
                        tk+=1
                if tk>=k:
                    ans=min(ans,(uy-dy)*(rx-lx))
print(ans)


### FIXED CODE ###

import itertools
n,k=map(int,input().split())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
c=itertools.combinations(range(n),2)
d=itertools.combinations(range(n),2)
ans=10**25
for i0 in range(n):
    for i1 in range(i0,n):
        for j0 in range(n):
            for j1 in range(j0,n):
                i=[i0,i1]
                j=[j0,j1]
                #print(i,j)
                lx=min(l[i[0]][0],l[i[1]][0])
                rx=max(l[i[0]][0],l[i[1]][0])
                dy=min(l[j[0]][1],l[j[1]][1])
                uy=max(l[j[0]][1],l[j[1]][1])
                tk=0
                for p in l:
                    if lx<=p[0]<=rx and dy<=p[1]<=uy:
                        tk+=1
                if tk>=k:
                    ans=min(ans,(uy-dy)*(rx-lx))
print(ans)
### BUGGY CODE ###

n = int(input())
a = list()
b = list()
for i in range(n):
    x = input()
    a.append(int(x))
b = sorted(a)
for i in range(n):
    if b[-1] == a[i] and a.count(b[-1]) == 1:
        print(b[-2])
    else:
        print(b[-1])

### FIXED CODE ###

n = int(input())
a = list()
for i in range(n):
    x = input()
    a.append(int(x))
second = sorted(a)[-2]
m = max(a)
for i in range(n):
    if m == a[i]:
        print(second)
    else:
        print(m)
### BUGGY CODE ###

import fractions as math
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
    t=1
    for i in numbers:
      t=lcm_base(t,i)
    return t
N=int(input())
A=list(map(int,input().split()))
tmp=lcm_list(A)
ans=0
for i in A:
  ans+=tmp//i
  ans%=(10**9+7)
print(int(ans))


### FIXED CODE ###

import fractions 
N=int(input())
A=list(map(int,input().split()))
t=A[0]
for i in range(1,N):
  t=(t*A[i])//fractions.gcd(t,A[i])
ans=0
for i in range(N):
  ans+=t//A[i]
print(ans%(10**9+7))
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
ans = max(A)
for i in range(N):
  if A[i] == ans:
    a = A[:i] + A[i+1:]
    print(max(a))
  else:
    print(ans)

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
a = sorted(set(A))
max_count = A.count(a[-1])

for i in range(N):
  if len(a) > 1:
    if A[i] != a[-1]:
      print(a[-1])
    else:
      if max_count > 1:
        print(a[-1])
      else:
        print(a[-2])
  else:
    print(a[-1])
### BUGGY CODE ###

li = list(map(int,input().split()))
for i in range(li[0],li[1]+1):
    if i<=li[0]+li[2]-1 or i>=li[1]-li[2]+1:
        print(i)


### FIXED CODE ###

li = list(map(int,input().split()))
for i in range(li[0],min(li[1]+1,li[0]+li[2])):
    print(i)
for k in range(li[1]-li[2]+1,li[1]+1):
    if k>li[0]+li[2]-1:
        print(k)
### BUGGY CODE ###

n=input()
m=len(n)
l=n.count("?")
for i in range(l):
  s=n.find("?")
  n=n[:s]+"D"+n[s+1:]
  
print(n)

### FIXED CODE ###

n=input()
m=len(n)
li=[]
for i in range(m):
  li.append(n[i])

for i in range(len(li)):
  if li[i]=="?":
    li[i]="D"
  else:
    pass

print("".join(li))