Harryxun/stf_run huggingface dataset:
a = list(map(int,input().split()))
N = a[0]
Q = a[1]
numofac = [0 for i in range(N)]
S = input()
appear = 0
index = 1
while index < N:
    if S[index-1] == "A" and S[index] == "C":
        appear += 1
        numofac[index] = appear
        numofac[index+1] = appear
        index += 2
    else:
        numofac[index] = appear
        index += 1
for i in range(Q):
    q = list(map(int,input().split()))
    print(str(numofac[q[1]-1] - numofac[q[0]-1]))

### FIXED CODE ###

a = list(map(int,input().split()))
N = a[0]
Q = a[1]
numofac = [0 for i in range(N)]
S = input()
appear = 0
index = 1
while index < N:
    if S[index-1] == "A" and S[index] == "C":
        appear += 1
        numofac[index] = appear
        if index != N-1:
            numofac[index+1] = appear
        index += 2
    else:
        numofac[index] = appear
        index += 1
for i in range(Q):
    q = list(map(int,input().split()))
    print(str(numofac[q[1]-1] - numofac[q[0]-1]))
n = int(input())
ans = 1
A = list(map(int,input().split()))
for x in A:
  if x = 0:
    print(0)
    exit(0)
  ans *= x
if ans > 10**18:
  print(-1)
  exit(0)
print(ans)

### FIXED CODE ###

n = int(input())
ans = 1
A = list(map(int,input().split()))
if 0 in A:
  print(0)
  exit(0)
for x in A:
  ans *= x
  if ans > 10**18:
    print(-1)
    exit(0)
print(ans)
a,b=input()
print("H"if(a==b) else"D")

### FIXED CODE ###

a,b=input().split()
print("H"if(a==b) else"D")
N,M=(int(x) for x in input().split())
a=[int(input()) for i in range(M)]

x=[0 if i in a else 1 for i in range(N+1)]
for i in range(2,N+1):
    if x[i]!=0:
        x[i]=x[i-1]+x[i-2] 

print(x[N]%((10e+9)+7))

### FIXED CODE ###

N,M=(int(x) for x in input().split())
a=[int(input()) for i in range(M)]

x=[0]*(N+1)
j=0
if N!=0:
    x[0]=1
if N>1 and M!= 0 and a[0]==1:
    j+=1
else:
    x[1]=1

for i in range(2,N+1): 
    if j==M or i!=a[j]:
        x[i]=x[i-1]+x[i-2]
    else:
        x[i]=0
        j+=1
print(int(x[N]%(1000000007)))
strs = input()

for str in strs:
  if i % 2 == 0:
    if (i == "L") or (i == "U") or (i == "D"):
      continue
    else:
      print("No")
      break
  else:
    if (i == "R") or (i == "U") or (i == "D"):
      continue
    else:
      print("No")
      break
else:
  print("Yes")
    

### FIXED CODE ###

strs = input()
 
for i in range(len(strs)):
  if i % 2 != 0:
    if (strs[i] == "L") or (strs[i] == "U") or (strs[i] == "D"):
      continue
    else:
      print("No")
      break
  else:
    if (strs[i] == "R") or (strs[i] == "U") or (strs[i] == "D"):
      continue
    else:
      print("No")
      break
else:
  print("Yes")
List = map(int, input().split())
if List.count("5")==2 and List.count("7")==1:
  	print("YES")
else:
	print("NO")




### FIXED CODE ###

List = input().split()
if List.count("5")==2 and List.count("7")==1:
  	print("YES")
else:
	print("NO")
from fractions import gcd

def lcm(*args):
    ans = 1
    for x in args:
        ans = ans * x // gcd(ans, x)
    return ans

n, m = map(int, input().split())
a = [int(x) for x in input().split()]

def solve(a):
    tmp = None
    for ta in a:
        if tmp is None:
            tmp = log(ta)
        else:
            if tmp == log(ta):
                continue
            else:
                print(0)
                return
    l = lcm(*a)
    print(m // l - m // (2*l))

solve(a)

### FIXED CODE ###

from fractions import gcd

def lcm(*args):
    ans = 1
    for x in args:
        ans = ans * x // gcd(ans, x)
    return ans

n, m = map(int, input().split())
a = [int(x) for x in input().split()]

def log(x):
    ans = 0
    while x % 2 == 0:
        ans += 1
        x //= 2
    return ans

def solve(a):
    tmp = None
    for ta in a:
        if tmp is None:
            tmp = log(ta)
        else:
            if tmp == log(ta):
                continue
            else:
                print(0)
                return
    l = lcm(*a)
    print(m // (l//2) - m // l)

solve(a)
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = [0] * (X * Y)
E = [0] * (K * Z)
m, n = 0, 0

for i in range(X):
    for j in range(Y):
        D[m] = A[i] + B[j]
        m += 1

for k in range(K):
    for l in range(Z):
        E[n] = sorted(D)[:: -1][: K][k] + C[l]
        n += 1

for p in range(K):
    print(sorted(E)[:: -1][p])


### FIXED CODE ###

X, Y, Z, K = map(int, input().split())
A, B, C = [sorted(list(map(int, input().split())))[:: -1][: K] for _ in range(3)]
D = []
for ai in A:
    for bi in B:
        D.append(ai + bi)

D = sorted(D)[:: -1][: K]

res = []
for di in D:
    for ci in C:
        res.append(di + ci)

res = sorted(res)[:: -1][: K]

for ans in res:
    print(ans)
import math

def lcm(x,y):
    return (x*y)//math.gcd(x,y)

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

### FIXED CODE ###

import fractions

def lcm(x,y):
    return (x*y)//fractions.gcd(x,y)

a,b=map(int,input().split())
print(lcm(a,b))
import numoy as np
N,M = list(map(int,input().split()))
A = input().split()

count = 0
A = np.array(A,dtype='int64')
B = np.cumsum(A)
C = np.append([0],B)

L = (1 for i in range(len(C)) for t in range(len(C)) if i<t and (C[t] - C[i])%M==0)
print(len(list(L)))

### FIXED CODE ###

import collections
import numpy as np

N,M = list(map(int,input().split()))
A = input().split()

A = np.array(A,dtype='int64')
C = np.append([0],np.cumsum(A))
L = [i%M for i in C]
L_c = collections.Counter(L)

ans = 0
for i in L_c.values():
    S = i * (i-1) / 2
    ans+=S
    
print(int(ans))
n,k = map(int,input().split())
dls = list(map(str,input().split()))
while 1:
    s = str(n)
    for i in dls:
        if i in s:
            break
    else:
        print(n)
        exit()
    n += 1

### FIXED CODE ###

s = list(input())
k = int(input())
for i in range(len(s)):
    if s[i] != "a" and (123-ord(s[i])) <= k:
        k -= (123-ord(s[i]))
        s[i] = "a"
    if i == len(s)-1:
        s[i] = (chr((((ord(s[i])+(k%26))-97)%26)+97))

print("".join(s))



# a = "z"
# a = ord(a)
# print(a)
N = int(input())
edges = [list(map(int,input().split())) for _ in range(N-1)]
A = [[]for _ in range(N+1)]
ans = [-1]*(N+1)
for u,v,w in edges:
    A[u].append([v,w])
    A[v].append([u,w])

ans[1] = 0
def dfs(r):
    for a in A[r]:
        n = a[0]
        d = a[1]
        if ans[n] == -1:
            ans[n] = ans[r] + d
            dfs(n)
dfs(1)
for a in ans[1:]:
    if a % 2 == 0:
        print(0)
    else:
        print(1)


### FIXED CODE ###

import sys
sys.setrecursionlimit(500*500)
N = int(input())
edges = [list(map(int,input().split())) for _ in range(N-1)]
A = [[]for _ in range(N+1)]
ans = [-1]*(N+1)
for u,v,w in edges:
    A[u].append([v,w%2])
    A[v].append([u,w%2])

ans[1] = 0
def dfs(r):
    for a in A[r].copy():
        n = a[0]
        d = a[1]
        if ans[n] == -1:
            ans[n] = (ans[r] + d) % 2
            dfs(n)
dfs(1)
for a in ans[1:]:
    print(a%2)
import sys, math

def input():
    return sys.stdin.readline()[:-1]

def main():
    H, N = map(int,input().split())
    M = [list(map(int,input().split())) for k in range(N)]

    dp = [10**9 for k in range(H+1)]
    dp[0] = 0
    for e in M:
        A, B = e[0], e[1]
        for k in range(A+1):
            dp[k] = min(dp[k],B)
        for k in range(A+1,H+1):
            dp[k] = min(dp[k],dp[k-A]+B)

    print(dp[H])

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys, math

def input():
    return sys.stdin.readline()[:-1]

def main():
    H, N = map(int,input().split())
    M = [list(map(int,input().split())) for k in range(N)]

    dp = [10**9 for k in range(10**4+1)]
    dp[0] = 0
    for e in M:
        A, B = e[0], e[1]
        for k in range(A+1):
            dp[k] = min(dp[k],B)
        for k in range(A+1,H+1):
            dp[k] = min(dp[k],dp[k-A]+B)

    print(dp[H])

if __name__ == '__main__':
    main()
import math
A, B, K = map(int, input().split())

answer = []
ans = 1
max_ans = math.gcd(A, B)
while ans <= max_ans:
    if A % ans == 0 and B % ans == 0:
        answer.append(ans)
        ans += 1
    else:
        ans += 1
answer = sorted(answer, reverse=True)

print(answer[K-1])


### FIXED CODE ###

import fractions
A, B, K = map(int, input().split())

answer = []
ans = 1
max_ans = fractions.gcd(A, B)
while ans <= max_ans:
    if A % ans == 0 and B % ans == 0:
        answer.append(ans)
        ans += 1
    else:
        ans += 1
answer = sorted(answer, reverse=True)

print(answer[K-1])
s = input()
cnt = 0
for i in s:
  if i == '1':
    cnt += 1:
print(cnt)

### FIXED CODE ###

s = input()
cnt = 0
for i in s:
  if i == '1':
    cnt += 1
print(cnt)
import sys
from collections import defaultdict
from collections import deque

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

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

A = list(map(int, input().split()))
A.sort(reverse=True)

NUM = [0] * N
ACN = [0] * N
cnt = 0
mx = A[0]

# cnt and accumulation
for a in A:
    d = mx - a
    cnt += 1
    NUM[d] += 1
    ACN[d] = cnt

# P Number Problem
PROBLEM_P = 0
p = P
for i in range(0, A[0]+1):
    if NUM[i] == 0:
        continue

    p -= NUM[i]

    if p < 0:
        PROBLEM_P = i
        break

    if i == (A[0]+1) and p > 0:
        print(N)
        exit()

#print("NUM", NUM)
#print("PROBLEM_P", PROBLEM_P)

# R Number Problem
R = PROBLEM_P + M

# P-1 Problem
ans = 0
NG_POINT = (P-1) * M
NG_POINT += (N - ACN[R]) * M
MV = M * V

# p problem num
num_p = ACN[PROBLEM_P] - P

print(1)
exit()

for r in range(R, -1, -1):
    need_point = M
    total = (need_point * NUM[r]) + NG_POINT

    for q in range(r-1, PROBLEM_P, -1):
        if NUM[q] == 0:
            continue
        total += NUM[q] * (q - r + M)

    total += num_p * (PROBLEM_P - r + M)

    if total >= MV:
        ans = r
        break
    else:
        NG_POINT += NUM[r] * M

print(ACN[ans])


### FIXED CODE ###

import sys
from collections import defaultdict
from collections import deque

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


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

A = list(map(int, input().split()))
A.sort(reverse=True)

# A_P -> A_X (A_P - M = A_X)
A_P = A[P-1]
A_X = A[P]
i_X = P
for i in range(P, len(A)):
    if (A_P - A[i]) > M:
        A_X = A[i-1]
        i_X = i-1
        break
    elif i == (len(A)-1):
        A_X = A[i]
        i_X = i
    else:
        continue

NG_POINT = (P-1) * M


def isPossible(i):
    if (i+1) < P:
        return True
    elif i > i_X:
        return False

    MV = M * V
    ax = A[i]
    score = ax + M

    total = M + NG_POINT
    total += (N - i - 1) * M

    for j in range(i-1, P-2, -1):
        total += score - A[j]

    #print("i", i, "total", total, "NG_POINT", NG_POINT)

    if total >= MV:
        return True

    return False


left = 0
right = i_X

if not isPossible(left):
    print(1)
    exit()

if isPossible(i_X):
    print(i_X + 1)
    exit()

#print("A", A, "i_X", i_X)

for _ in range(i_X):
    #print("left", left, isPossible(left), "right", right, isPossible(right))
    if (left + 1) == right:
        break

    mid = (left + right) // 2

    if isPossible(mid):
        left = mid
    else:
        right = mid

print(left + 1)
a=input()
if a[3]!=8:
    a[3]=8
    print(a)

### FIXED CODE ###

a=input()
print("2018"+a[4:])
a,b = list(map(int,input().split()))

if a >= 10 or b >= 10:
  print(-1)
else:
  print(a*b)


### FIXED CODE ###

r = int(input())

print(r**2)
n,k = list(map(int,input().split()))
p = list(map(int,input().split()))
c = list(map(int,input().split()))
was = [False]*n
sums = []
for i in range(n):
    if not was[i]:
        iWas = [False]*n
        pos = i
        sumn = [c[i]]
        while not iWas[pos]:
            iWas[pos] = True
            was[pos] = True
            pos = p[pos]-1
            sumn+=[c[pos]]
        sumn = sumn[:-1]
        sums.append(sumn)
m = -9999999999999999999999999
for i in range(len(sums)):
    totS = sum(sums[i])
    l = len(sums[i])
    for g in range(len(sums[i])):
        arr = []
        s = 0
        for j in range(l):
            s+=sums[i][(g+j)%l]
            arr.append(s)

        if totS > 1:
            add = max(arr[:k%l]+[-99999999999999999999])
            if add != -99999999999999999999:
                m = max(m,totS*(k//l)+max(max(arr[:k%l]),0))
            else:
                m = max(m,totS*(k//l))

        else:

            m = max(m, max(arr[:min(l,k)]))
print(m)




### FIXED CODE ###

t = input()
if "RRR" in t:
    print(3)
elif "RR" in t:
    print(2)
elif "R" in t:
    print(1)
else:
    print(0)
import sys
sys.setrecursionlimit(10000)

def gcd(a, b):
    if b == 1:
        return 1
    r = a % b
    if r == 0:
        return b
    else:
        return gcd(b, r)

def lcm(A, n):
    if n == 2:
        return A[0]* (A[1] // gcd(A[0], A[1]))
    #lcm(A, n)はA[0]-A[n-1]までの最小公倍数を求める
    temp = lcm(A, n-1)
    return temp * (A[n-1] // gcd(temp, A[n-1]))

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
ans = lcm(a, n)
print(str(ans))

### FIXED CODE ###

def gcd(a, b):
    if b == 1:
        return 1
    # a > b　を仮定
    r = a % b
    if r == 0:
        return b
    else:
        return gcd(b, r)

#def lcm(A, n):
#    if n == 2:
#        return A[0]*A[1] // gcd(A[0], A[1])
#    #lcm(A, n)はA[0]-A[n-1]までの最小公倍数を求める
#    a = lcm(A, n-1)
#    return a* A[n-1] // gcd(a, A[n-1])

n = int(input())
#a = []
T1 = int(input())
for i in range(n-1):
    T2 = int(input())
    T1 = T1*T2 // gcd(T1, T2)
    #a.append(int(input()))
#a.sort(reverse = True)
#ans = lcm(a, n)
print(str(T1))
t = input().replace(' ','')
if t % 4 == 0:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

a,b,c = map(str,input().split())
t = int(b+c)
if t % 4 == 0:
    print('YES')
else:
    print('NO')
a,b,c = int(map(input().split()))
if a == b:
    print(c)
elif a == c:
    print(b)
else:
    print(a)

### FIXED CODE ###

a,b,c = map(int,input().split())
if a == b:
    print(c)
elif a == c:
    print(b)
else:
    print(a)
c = str(input())

if c.lowercase():
  print('a')
  else:
    print('A')

### FIXED CODE ###

c = str(input())

if c.islower():
    print('a')
else:
    print('A')
x = int(input())

if x == 1:
  print(0)
  
if X == 0:
  print(1)
  


### FIXED CODE ###

print(1 - int(input()))
values = [int(input()) for i in range(int(input()))]
maxv = - 1000000
minv = values[0]

for value in enumerate(values):
    maxv = max(maxv, value - minv)
    minv = min(minv, value)
print(maxv)


### FIXED CODE ###

values = [int(input()) for _ in range(int(input()))]
maxv = values[1] - values[0]
minv = values[0]

for val in values[1:]:
    maxv = max(maxv, val - minv)
    minv = min(minv, val)         # 今までの最小値を保持(自分と自分を比較しない様に、最大値の評価後に計算)
print(maxv)
# coding: utf-8
import sys

def dfs(x, y, fru):
    field[x][y] = '.'
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)
    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] == '@':
                dfs(i,j,'@')
                count+=1
            elif field[i][j] == '#':
                dfs(i,j,'#')
                count+=1
            elif field[i][j] == '*':
                dfs(i,j,'*')
                count+=1
    print(count)
while(True):
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        sys.exit()
    field = []
    for i in range(H):
        field.append(list(input()))
    solv(H,W)

### FIXED CODE ###

# coding: utf-8
# @????????? #?????? *?????????
import sys
sys.setrecursionlimit(10000000)

def dfs(x, y, fru):
    # ???????????¨?????????.???????????????
    field[x][y] = '.'
    # 4??????????????????
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)
    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] != '.':
                dfs(i,j,field[i][j])
                count+=1
            # elif field[i][j] == '#':
            #     dfs(i,j,'#')
            #     count+=1
            # elif field[i][j] == '*':
            #     dfs(i,j,'*')
            #     count+=1
    print(count)

f = 0
while(f == 0):
    H, W = map(int, input().split())
    if H != 0 and W != 0:
        field = [] # ????¨??????¨?????????
        for i in range(H):
            field.append(list(input()))
        solv(H,W)
    else:
        f = 1
N = int(input())
H = list(map(int, input().split()))
max = 0

for i in range(N):
  cnt = 0
  if i != N-1:
    now = i
    while H[now] <= H[now+1]:
      now += 1
      cnt += 1
      if now > N-1:
        break
    if max < cnt:
      max = cnt
  cnt = 0
  if i != 0:
    now = i
    while H[now] <= H[now-1]:
      now -= 1
      cnt += 1
      if now < 0:
        break
    if max < cnt:
      max = cnt
print(max)


### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))
H.reverse()
max = 0
cnt = 0
 
for i in range(N-1):
  if H[i] <= H[i+1]:
    cnt += 1
  else:
    cnt = 0
  if cnt > max:
    max = cnt
if cnt > max:
  max = cnt
print(max)
N = int(input())
ans = [0]*(N+1)
for i in range(1,int((N-2)**0.5)):
    for j in range(1,i+1):
        for k in range(1,j+1):
            a = i**2 + j**2 + k**2 + i*j + j*k + k*i
            if a > N:
                continue
            t = 1
            if (i == j and j > k) or (i>j and j==k):
                t = 3
            elif i > j and j > k:
                t = 6
            ans[a] += t
for i in range(1,N+1):
    print(ans[i])

### FIXED CODE ###

N = int(input())
t = 1
if N > 1:
    t = int((N-2)**0.5)
ans = [0]*(N+1)
for i in range(1,t):
    for j in range(1,i+1):
        for k in range(1,j+1):
            a = i**2 + j**2 + k**2 + i*j + j*k + k*i
            if a > N:
                continue
            t = 1
            if (i == j and j > k) or (i>j and j==k):
                t = 3
            elif i > j and j > k:
                t = 6
            ans[a] += t
for i in range(1,N+1):
    print(ans[i])
x = int(input())
a = [0]
for i in range(10**5):
  if i**2<x:
    a.add(i**2)
  else:
    break
print(max(a))

### FIXED CODE ###

x = int(input())
for i in range(10**5):
  if i**2>x:
    a=((i-1)**2)
    break
print(a)
import math

def lcm(x, y):
  return (x * y) // math.gcd(x, y)

A, B = list(map(lambda x: int(x), input().split()))

print(lcm(A, B))

### FIXED CODE ###

import fractions

A, B = list(map(lambda x: int(x), input().split()))

print(int((A * B) / fractions.gcd(A, B)))
n,m = map(int,input().split())
a = []
d = [0]*m
for _ in range(n):
    tmp = list(map(int,input().split()))
    a.append(tmp[1:])
for b in a:
    for c in b:
        d[c] += 1
cnt = 0
for p in d:
    if p == n:
        cnt+=1
print(cnt)

### FIXED CODE ###

n,m = map(int,input().split())
a = []
d = [0]*m
for _ in range(n):
    tmp = list(map(int,input().split()))
    a.append(tmp[1:])
for b in a:
    for c in b:
        d[c-1] += 1
cnt = 0
for p in d:
    if p == n:
        cnt+=1
print(cnt)
main():
  ans = func(input())
  print(ans)
  
  
def func(sentence):
  unique_list = set(sentence)
  for s in unique_list:
    if sentence.count(s) % 2 != 0:
      return('No')
      break
  return('Yes')

if __name__ == '__main__':
  main()

### FIXED CODE ###

def main():
  ans = func(input())
  print(ans)
  
  
def func(sentence):
  unique_list = set(sentence)
  for s in unique_list:
    if sentence.count(s) % 2 != 0:
      return('No')
      break
  return('Yes')

if __name__ == '__main__':
  main()
s = input()

isOdd = True
for i in range(len(s)):
    if i % 2 == 1:
        if s[i] != 'L' and s[i] != 'U' and s[i] != 'D':
            isOdd = False

isEven = True
for i in range(len(s)):
    if i == 0 or i % 2 == 0:
        if s[i] != 'R' and s[i] != 'U' and s[i] != 'D':
            isEven = False

if isOdd == True or isEven == True:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

s = input()

isOdd = True
for i in range(len(s)):
    if i % 2 == 1:
        if s[i] != 'L' and s[i] != 'U' and s[i] != 'D':
            isOdd = False

isEven = True
for i in range(len(s)):
    if i == 0 or i % 2 == 0:
        if s[i] != 'R' and s[i] != 'U' and s[i] != 'D':
            isEven = False

if isOdd == True and isEven == True:
    print("Yes")
else:
    print("No")
n = int(input().split())
list[] = map(int, input()split())

sum = 0
for i in range(n)
    sum += list[i]

print(min(list), max(list), sum)


### FIXED CODE ###

#
# 4d
#


def main():
    n = int(input())
    a = list(map(int, input().split()))
    print(f"{min(a)} {max(a)} {sum(a)}")


if __name__ == '__main__':
    main()
def weight(n, p, c):
    global count
    global m
    
    if n % c[0] == 0:
        count = min(count, p + n // c[0])
        return count
    elif p + n // c[0] >= count:
        return n
    elif c[0] < n:
        return min(weight(n - c[0], p + 1, c), weight(n, p, c[1:]))
    else:
        return weight(n, p, c[1:])

N, W = map(int, input().split())
lisv = []
lisw = []

for i in range(n):
    v, w = map(int, input().split())
    lisv.append(v)
    lisw.append(w)

for j in range(n):
    pass
print(weight(N, 0, lisw))

#print(coin(n, 0, mon))


### FIXED CODE ###

N,W=map(int,input().split())
dp=[[0 for i in range(W+1)]for j in range(N+1)]
goods=[]
for i in range(N):
    v,w=map(int,input().split())
    goods.append([v,w])

    
for i in range(N):
    v=goods[i][0]
    w=goods[i][1]
    for j in range(W+1):
        dp[i+1][j]=max(dp[i][j],dp[i+1][j])
        next_w=j+w
        next_v=dp[i][j]+v
        if(next_w<=W and next_v>dp[i+1][next_w]):
            dp[i+1][next_w]=next_v

ans=0
for i in range(W+1):
    ans=max(ans,dp[N][i])
print(ans)
S = input()
length =len(S)
count = 0

for i in range(len):
  if S[i] = '?':
    S[i] = D

print(S)

### FIXED CODE ###

S = input()
length =len(S)
S = list(S)
count = 0

for i in range(length):
  if S[i] == '?':
    S[i] = 'D'

answer = "".join(S)
print(answer)
A,B = map(int,input().split())

ans = A-B*2

if(x>=0):
  print(ans)
else:
  print("0")

### FIXED CODE ###

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

ans = A-B*2

if(ans>=0):
  print(ans)
else:
  print("0")
n=int(input())
s=list(input())
ans=s.count('R')*s.count('G')*s.count('B')
for i in range(n):
  if s[i]=='R':
    s[i]=1
    elif s[i]=='G':
      s[i]=2
    elif s[i]=='B':
      s[i]=4
for i in range(n):
   for j in range(i+1,n):
      k=2*j-i
      if k>=n:
        continue
      if s[i]+s[j]+s[k]==7:
        ans-=1
print(ans)


### FIXED CODE ###

n=int(input())
s=list(input())
ans=s.count('R')*s.count('G')*s.count('B')
for i in range(n):
  if s[i]=='R':
    s[i]=1
  elif s[i]=='G':
    s[i]=2
  elif s[i]=='B':
    s[i]=4
for i in range(n):
   for j in range(i+1,n):
      k=2*j-i
      if k>=n:
        continue
      if s[i]+s[j]+s[k]==7:
        ans-=1
print(ans)
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N = int(input())
    SP = [input().split() for _ in range(N)]

    SP = enumerate(SP)
    SP = sorted(SP, key=lambda x: (x[1][1], -x[1][0]))
    for i in SP:
        print(i[0])    

if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N = int(input())
    SP = [input().split() for _ in range(N)]

    SP = enumerate(SP)
    SP = sorted(SP, key=lambda x: (x[1][0], -int(x[1][1])))
    for i in SP:
        print(i[0]+1)    

if __name__ == '__main__':
    resolve()
a = input()
b = list[map(int, a.split())]
b.sort()
print(b[0]+" " + b[1]+ " " +b[2])


### FIXED CODE ###

a = input()
b = list(map(int, a.split()))
b.sort()
print(str(b[0])+" " + str(b[1])+ " " +str(b[2]))
a,b,c = input()
if a == b && b == c:
  print(No)
else:
  print(Yes)

### FIXED CODE ###

a,b,c = input()
if a == b == c:
  print('No')
else:
  print("Yes")