Harryxun/stf_run huggingface dataset:
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
BC = []

for i in range(M):
    b,c = map(int,input().split())
    BC.append((b,c))

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

ind = 0
for b,c in BC:
    for i in range(b):
        if A[ind]>=c or ind==N:
            print(sum(A))
            exit()
        else:
            A[ind]=c
            ind+=1

print(sum(A))



### FIXED CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
BC = []

for i in range(M):
    b,c = map(int,input().split())
    BC.append([b,c])

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

ind = 0
ans = 0
for b,c in BC:
    if c > A[min(ind+b,N-1)]:
        ans += c * min(b,N-ind)
        ind += b
    else:
        while c > A[ind]:
            ans += c
            ind += 1
    if ind >= N:
        print(ans)
        exit()
print(ans + sum(A[ind:]))
import sys

input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def func(N, mod):
    F = [1]
    for i in range(1, N + 1):
        F.append(F[-1] * i % mod)
    return F


INV = {}


def inv(a, mod):
    if a in INV:
        return INV[a]
    r = pow(a, mod - 2, mod)
    INV[a] = r
    return r


def C(F, a, b, mod):
    return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod


def main():
    N, W = read_values()
    I = [tuple(read_values()) for _ in range(N)]

    w0 = I[0][0]
    if w0 > W:
        print(0)
        return

    dp = [
        [[0 for _ in range(N * 3 + 100)] for __ in range(N + 10)]
        for ___ in range(N + 10)
    ]

    for i, (w1, v) in enumerate(I):
        w = w1 - w0
        for k in range(N):
            for j in range(N * 3 + 5):
                dp[i + 1][k][j] = max(dp[i][k][j], dp[i + 1][k][j])
                dp[i + 1][k + 1][j + w] = max(dp[i][k][j] + v, dp[i + 1][k + 1][j + w])

    res = 0
    for k in range(N + 1):
        r = W - k * w0
        if r < 0:
            continue
        for i in range(W - k * w0 + 1):
            res = max(res, dp[N][k][i])
    print(res)


if __name__ == "__main__":
    main()



### FIXED CODE ###

import sys

input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def func(N, mod):
    F = [1]
    for i in range(1, N + 1):
        F.append(F[-1] * i % mod)
    return F


INV = {}


def inv(a, mod):
    if a in INV:
        return INV[a]
    r = pow(a, mod - 2, mod)
    INV[a] = r
    return r


def C(F, a, b, mod):
    return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod


def main():
    N, W = read_values()
    dp = [
        [[0 for _ in range(N * 3 + 10)] for __ in range(N + 10)]
        for ___ in range(N + 10)
    ]
    I = [tuple(read_values()) for _ in range(N)]

    w0 = I[0][0]
    if w0 > W:
        print(0)
        return

    for i, (w1, v) in enumerate(I):
        w = w1 - w0
        for k in range(N):
            for j in range(N * 3 + 5):
                dp[i + 1][k][j] = max(dp[i][k][j], dp[i + 1][k][j])
                dp[i + 1][k + 1][j + w] = max(dp[i][k][j] + v, dp[i + 1][k + 1][j + w])

    res = 0
    for k in range(N + 1):
        r = min(W - k * w0, 3 * N + 5)
        if r < 0:
            continue
        for i in range(r + 1):
            res = max(res, dp[N][k][i])
    print(res)


if __name__ == "__main__":
    main()
N = int(input())
stone = list(map(input().split()))
R = stone.count('R')
ans = stone.count('W', 0, R-1)
print(ans)

### FIXED CODE ###

N = int(input())
stone = input()
R = stone.count('R')
ans = stone.count('W', 0, R)
print(ans)
n, k = list(map(int, input().split(" ")))
a = abs(n - k)
n = n - a * (n // a)
n_last = abs(n - k)
if n_last < n:
    n = n_last
print(n)

### FIXED CODE ###

n, k = list(map(int, input().split(" ")))
n = n - k * (n // k)
n_last = abs(n - k)
if n_last < n:
    n = n_last
print(n)
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

A, B, C, D = tuple(map(int, input().split()))

s = -1
c = C * (A // C + 1)
if c <= B:
    s += (B - c) // C + 1
        
d = D * (A // D + 1)
if d <= B:
    s += (B - d) // D + 1
    
cd_lcm = lcm(C, D)
cdl = cd_lcm * (A // cd_lcm + 1)
if cdl <= B:
    s -= (B - cdl) // cd_lcm + 1

print(B - A - s)

### FIXED CODE ###


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

A, B, C, D = tuple(map(int, input().split()))

s = -1
c = C * (A // C + 1)
if A % C == 0:
    c = A
if c <= B:
    s += (B - c) // C + 1
        
d = D * (A // D + 1)
if A % D == 0:
    d = A
if d <= B:
    s += (B - d) // D + 1
    
cd_lcm = lcm(C, D)
cdl = cd_lcm * (A // cd_lcm + 1)
if A % cd_lcm == 0:
    cdl = A
if cdl <= B:
    s -= (B - cdl) // cd_lcm + 1

print(B - A - s)
N = int(input())
A = list(map(int, input().split(' ')))


while not len(A) == 0:
    a = max(A)
    if A.count(a) >= 4:
        print(a**2)
        exit()
    elif A.count(a) >=2:
        while a in A:A.remove(a)
        while not len(A) == 0:
            a2 = max(A)
            if  A.count(a2) >= 2:
                print(a*a2)
                exit()
            else:
                while a2 in A:A.remove(a)
    else:
        while a in A:A.remove(a)

print(0)


### FIXED CODE ###

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

x = 0
y = 0
S = set()

for a in A:
    if a in S:
        if a < x:
            continue
        elif a > y:
            x = y
            y = a
        else:
            x = a
        S.remove(a)
    else:
        S.add(a)

print(x*y)
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, x = map(int, input().split())
    A = list(map(int, input().split()))

    A_origin = A.copy()

    if A[0] > x:
        A[0] = x

    for i in range(0, N - 1):
        if A[i] + A[i + 1] > x:
            A[i + 1] -= A[i] + A[i + 1] - x

    res = 0
    for i in range(N):
        res += abs(A_origin[i] - A[i])

    print(res)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, x = map(int, input().split())
    A = list(map(int, input().split()))

    A_origin = A.copy()

    if A[0] > x:
        A[0] = x

    for i in range(0, N - 1):
        if A[i] + A[i + 1] > x:
            A[i + 1] -= A[i] + A[i + 1] - x

    res = 0
    for i in range(N):
        res += abs(A_origin[i] - A[i])

    print(res)


if __name__ == '__main__':
    main()
def tax(p,x):
    return p*(100+x) // 100 # 整数除算

def solve(X,Y,S):
    ans = 0
    oldsum = 0
    for a in range(1,S):
        for b in range(1,S-a+1): #税抜き価格a,bの総和はS以下である
            oldsum = tax(a,X)+tax(b,X) #税制改定前の税込合計額
            if oldsum == S: # 新税でのtax(a,Y)+tax(b,Y) について検討 
                newsum = tax(a,Y)+tax(b,Y) 
                if newsum > ans:
                    ans =newsum
            if oldsum > S:
                break # b増加ならばsum増加のため
    return(ans)

while True:
    X,Y,S = map(int, input().split())
    if a == 0:
        break
    print(solve(X,Y,S))


### FIXED CODE ###

def tax(p,x):
    return p*(100+x) // 100 # 整数除算

def solve(X,Y,S):
    ans = 0
    oldsum = 0
    newsum = 0
    for a in range(1,S):
        for b in range(1,S-a+1): #税抜き価格a,bの総和はS以下である
            oldsum = tax(a,X)+tax(b,X) #税制改定前の税込合計額
            if oldsum == S: # 新税でのtax(a,Y)+tax(b,Y) について検討 
                newsum = tax(a,Y)+tax(b,Y) 
                if newsum > ans:
                    ans =newsum
            if oldsum > S:
                break # b増加ならばsum増加のため
    return ans

while True:
    X,Y,S = map(int, input().split())
    if X == 0:
        break
    print(solve(X,Y,S))
a,b=map(int,input().split(''))
m=a*b
if m%2==1:
  print('Odd')
else:
  print('Even')

### FIXED CODE ###

a,b=map(int,input().split())
m=a*b
if m%2==1:
  print('Odd')
else:
  print('Even')
# coding : utf-8

import numpy as np

A = input()

if(A[0]!=A[1] and A[0]!=A[2] and A[1]!=A[2])
	print("Yes")
else:
	print("No")

### FIXED CODE ###

# coding : utf-8

import numpy as np

A = input()

if(A[0]!=A[1] and A[0]!=A[2] and A[1]!=A[2]):
	print("Yes")
else:
	print("No")
g=lambda:map(int,input().split())
_,m=g()
ml,mr=0,10**5
for _ in range(m):
    l,r=g()
    ml=max(ml,l)
    mr=min(mr,r)
print([0,mr-ml+1][mr>=ml])


### FIXED CODE ###

a,b=map(int,input().split())
print(b if a>=13 else b//2 if 6<=a<=12 else 0)
import bisect
N, M, X = map(int, input().split())
C = [0] * N
A = [0] * N
for i in range(N):
    x = list(map(int, input().split()))
    C[i] = x[0]
    A[i] = [0] * M
    for j in range(M):
        A[i][j] = x[j + 1]
cnt = [0] * (2 **N)
ans_list = []
for i in range(2 ** N):
    bag = []
    cnt[i] = [0] * M
    for j in range(N):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            bag.append(C[j])  # フラグが立っていたら bag に果物を詰める
            for k in range(M):
                cnt[i][k] += A[j][k]
    if bisect.bisect_left(cnt[i], X) == 0:
        ans_list.append(sum(bag))
if ans_list == []:
    print(-1)
else:
    print(min(ans_list)

### FIXED CODE ###

import bisect
N, M, X = map(int, input().split())
C = [0] * N
A = [0] * N
for i in range(N):
    x = list(map(int, input().split()))
    C[i] = x[0]
    A[i] = [0] * M
    for j in range(M):
        A[i][j] = x[j + 1]
cnt = [0] * (2 ** N)
ans_list = []
for i in range(2 ** N):
    bag = []
    cnt[i] = [0] * M
    for j in range(N):
        if ((i >> j) & 1):
            bag.append(C[j])
            for k in range(M):
                cnt[i][k] += A[j][k]
    cnt[i].sort()
    if bisect.bisect_left(cnt[i], X) == 0:
        ans_list.append(sum(bag))
if ans_list == []:
    print(-1)
else:
    print(min(ans_list))
H, W, D = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for _ in range(Q)]

# 1 -> 1+D ->
# 2 -> 2+D ->
# 3 -> 3+D -> みたいなものを事前に計算

P = []
for k in range(1, D + 1):
    q = []
    for d in range(k, H * W + 1, D):
        for i in range(H):
            try:
                n = A[i].index(d)
                q.append([i, n])
                break
            except:
                continue
    P.append(q)

d = []

for p in P:
    c = 0
    q = [0]
    for i in range(len(p) - 1):
        c += abs(p[i][0] - p[i + 1][0])
        c += abs(p[i][1] - p[i + 1][1])
        q.append(c)
    d.append(q)

for l, r in LR:
    i = l % D - 1
    s = (l + i) // D
    e = (r + i) // D
    print(d[i][e] - d[i][s])


### FIXED CODE ###

from collections import defaultdict

H, W, D = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for _ in range(Q)]

# 1 -> 1+D ->
# 2 -> 2+D ->
# 3 -> 3+D -> みたいなものを事前に計算

# 辞書で管理する
# d[A[i][j]] = [i,j] みたいな感じ
d = defaultdict(list)
for i in range(H):
    for j in range(W):
        d[A[i][j]].append([i, j])


p = []
for s in range(1, D + 1):
    c = 0
    q = [0]
    for i in range(s + D, H * W + 1, D):
        i0, j0 = d[i - D][0]
        i1, j1 = d[i][0]
        c += abs(i0 - i1) + abs(j0 - j1)
        q.append(c)

    p.append(q)


for l, r in LR:
    i = l % D - 1
    s = (l - 1) // D
    e = (r - 1) // D
    print(p[i][e] - p[i][s])
import sys
input = sys.stdin.readline
from collections import deque

N = int(input().strip())
from itertools import combinations
nodes = list(combinations(range(N), 2))
graph = {i:set() for i in nodes}
for x in range(N):
  l = list(map(int,input().split()))
  y = l[0]-1
  prev = (min(x,y),max(x,y))
  for y in l[1:]:
    y -= 1
    now = (min(x,y),max(x,y))
    graph[prev].add(now)
    prev = now

d = {k:1 for k in nodes}
f = {k:0 for k in nodes}
in_cnt = {k:0 for k in nodes}
for x in nodes:
  for y in graph[x]:
    in_cnt[y] += 1
ret = []
q = deque([i for i in nodes if not in_cnt[i]])
if not q:
  print(-1)
  exit()
ans = 0
while q:
  x = q.popleft()
  ret.append(x)
  f[x] = 1
  for y in graph[x]:
    if f[y]:
      print(-1)
      exit()
    d[y] = max(d[y],d[x]+1)
    ans = max(ans,d[y])
    in_cnt[y] -= 1
    if not in_cnt[y]:
      q.append(y)
if [i for i in range(N) if in_cnt[i]]:
  print(-1)
  exit()

print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input().strip())
M = N*(N-1)//2

graph = [[] for i in range(M)]
in_cnt = [0 for i in range(M)]
for x in range(1,N+1):
  l = list(map(int,input().split()))
  y = l[0]
  b,s = max(x,y),min(x,y)
  prev = (b-1)*(b-2)//2+s-1
  for y in l[1:]:
    b,s = max(x,y),min(x,y)
    now = (b-1)*(b-2)//2+s-1
    graph[prev].append(now)
    in_cnt[now] += 1 
    prev = now

d = [1 for k in range(M)]
q = [i for i in range(M) if not in_cnt[i]]

if not q:
  print(-1)
  exit()
ans = 0
while q:
  x = q.pop()
  for y in graph[x]:
    d[y] = max(d[y],d[x]+1)
    ans = max(ans,d[y])
    in_cnt[y] -= 1
    if not in_cnt[y]:
      q.append(y)
if [i for i in range(M) if in_cnt[i]]:
  print(-1)
  exit()

print(ans)
N,H = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(n)]
A,B = zip(*AB)

a = max(A)
B = [b for b in B if b > a] #投げる
B.sort(reverse = True)

answer = 0
hp = H
attack_cnt = 0

for b in B:
  if hp <= 0:
    break
  attack_cnt += 1
  hp -= b

if hp > 0:
  attack_cnt += (hp-1)//a + 1

print(attack_cnt)


### FIXED CODE ###

N,H = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
A,B = zip(*AB)

a = max(A) #振る
B = [b for b in B if b > a] #投げる
B.sort(reverse = True)

answer = 0
hp = H
attack_cnt = 0

for b in B:
  if hp <= 0:
    break
  attack_cnt += 1
  hp -= b

if hp > 0:
  attack_cnt += (hp-1)//a + 1

print(attack_cnt)
def main():
    N, K = map(int, input().split())
    A = tuple(map(int, input().split()))
    d = {}
    d2 = {}
    d[0] = [0]
    s = 0
    for i in range(1, N+1):
        s = (s + A[i-1]) % K
        t = (s-i) % K
        if t in d:
            d[t].append(i)
        else:
            d[t] = [i]
        d2[i] = t
    a = 0
    x = [0] * K
    for i in range(1, N+1):
        t = d[d2[i]]
        for j in t[x[d2[i]]:]:
            if i - K < j and j < i:
                a += 1
            elif j >= i:
                break
            else:
                x[d2[i]] = j

    return a

print(main())


### FIXED CODE ###

def main():
    N, K = map(int,input().split())
    A = list(map(int, input().split()))
    s = 0
    d = {}
    d[0] = {0}
    r = 0
    l = [0] * (N + 1)
    for i, v in enumerate(A, start=1):
        if i - K >= 0:
           x = l[i - K]
           d[x].remove(i-K)
        s += v % K
        s %= K
        t = (s - i) % K
        l[i] = t
        if t in d:
            r += len(d[t])
            d[t].add(i)
        else:
            d[t] = {i}
    return r
print(main())
n = int(input())
li = map(int,input().split())
li = list(li)
li.sort()
s=0
for i in range(n-1):
  s+=li[i]
if s<=li[-1]:
  print(No)
else:
  print(Yes)

### FIXED CODE ###

n = int(input())
li = map(int,input().split())
li = list(li)
li.sort()
s=0
for i in range(n-1):
  s+=li[i]
if s<=li[-1]:
  print("No")
else:
  print("Yes")
a = str(input())
b = str(input())
if a = 'chokudai' and b = 'chokudaiz' or a = 'a' and b = 'aa':
    print("Yes")
elif a = 'snuke' and b = 'snukee':
    print("No")

### FIXED CODE ###

s = input()
t = input()
check = t[:-1]
a = len(s)
b = len(t) - 1
if a == b:
    if s == check:
        print("Yes")
    else:
        print("No")
else:
    print("No")
import math
x1,y1,x2,y2 = map(int,input().split())
d = math.sqrt((x1-x2)**2 + (y1-y2)**2)
print(d)

### FIXED CODE ###

import math
x1,y1,x2,y2 = map(float,input().split())
d = math.sqrt((x1-x2)**2 + (y1-y2)**2)
print(d)
N, M = map(int, input().split())

l = []

for i in range(N):
    l.append(list(map(int, input().split())))

lis = [[] for i in range(N)]

for i in range(N):
    lis[l[i][0] - 1].append(l[i][1])
    lis[l[i][1] - 1].append(l[i][0])


# 隣接行列
# list = [[0 for c in range(M)] for r in range(N)]
#
# for i in range(M):
#     tmp_n, tmp_m = map(int, input().split())
#     list[tmp_n - 1][tmp_m - 1] = 1
#
#
# def dot(index1, index2):
#     results = [[0 for c in range(M)] for r in range(N)]
#     for (i, j) in zip(index1, zip(*index2)):
#         print(i,j)
#     return results



# 再起関数
# def travel(now, nextnodes, visited):
#     ends.append(visited)
#     visited.append(now + 1)
#     for node in nextnodes:
#         if node in visited:
#             continue
#         travel(node - 1, lis[node - 1], visited[:])
#
#
# travel(0, lis[0], [])

que = [[0, lis[0], []]]
ends = []

while que:
    now, nextnodes, visited = que.pop()
    ends.append(visited)
    visited.append(now + 1)
    for node in nextnodes:
        if node in visited:
            continue
        que.append([node - 1, lis[node - 1], visited[:]])

print(len(list(filter(lambda i: len(i) is 3, ends))))

### FIXED CODE ###

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

l = []

for i in range(M):
    l.append(list(map(lambda x: int(x) - 1, input().split())))

lis = [[] for i in range(N)]

for i in range(M):
    lis[l[i][0]].append(l[i][1])
    lis[l[i][1]].append(l[i][0])


# 隣接行列
# list = [[0 for c in range(M)] for r in range(N)]
#
# for i in range(M):
#     tmp_n, tmp_m = map(int, input().split())
#     list[tmp_n - 1][tmp_m - 1] = 1
#
#
# def dot(index1, index2):
#     results = [[0 for c in range(M)] for r in range(N)]
#     for (i, j) in zip(index1, zip(*index2)):
#         print(i,j)
#     return results



# 再起関数
# def travel(now, nextnodes, visited):
#     ends.append(visited)
#     visited.append(now + 1)
#     for node in nextnodes:
#         if node in visited:
#             continue
#         travel(node - 1, lis[node - 1], visited[:])
#
#
# travel(0, lis[0], [])

que = [[0, lis[0], []]]
ends = []

while que:
    now, nextnodes, visited = que.pop()
    ends.append(visited)
    visited.append(now)
    for node in nextnodes:
        if node in visited:
            continue
        que.append([node, lis[node], visited[:]])

print(len(list(filter(lambda ii: len(ii) is N, ends))))
n,m = [int(i) for i in input().split()]
l = [[int(i) for i in input().split()] for _ in range(n)]
ans = np.zeros(10**5+1,dtype = np.int64)
start = 0
end = 0
for i,j in l:
    end += j
    ans[start:end] = i
    start = end
    
print(ans[m-1])

### FIXED CODE ###

a,b = [int(i) for i in input().split()]

temp = 0
l = sorted([[int(i) for i in input().split()] for _ in range(a)],key = lambda x: x[0])
for i in l:
    temp += i[1]
    if temp >= b:
        ans = i[0]
        break
print(ans)
import sys
readline = sys.stdin.readline
n = int(readline())
print(sum([int(i) for i in readline().split()] - n)

### FIXED CODE ###

import sys
readline = sys.stdin.readline
n = int(readline())
print(sum([int(i) for i in readline().split()]) - n)
import numpy as np

[H, W, M] = map(int, input().split())
mp = np.zeros((H+1, W+1), dtype=np.int64)
#for i in range(M):
#    [h, w] = map(int, input().split())
#    mp[h][w] = 1

colsum = np.sum(mp, axis=0)
rowsum = np.sum(mp, axis=1)

#maxcol = max(colsum)
#maxrow = max(rowsum)

#colchk = np.where(colsum==maxcol)
#rowchk = np.where(rowsum==maxrow)

#for i in range(len(rowchk[0])):
#    for j in range(len(colchk[0])):
#        if mp[rowchk[0][i]][colchk[0][j]] == 0:
#            print(int(max(colsum)+max(rowsum)))
#            quit()

print(int(max(colsum)+max(rowsum))-1)


### FIXED CODE ###

import numpy as np

[H, W, M] = map(int, input().split())
colsum = np.zeros(W+1)
rowsum = np.zeros(H+1)
bombs = []
rowbombs = [set() for i in range(H+1)]
for i in range(M):
    [h, w] = map(int, input().split())
    rowsum[h] += 1
    colsum[w] += 1
    bombs.append([h, w])
    rowbombs[h].add(w)

maxcol = max(colsum)
maxrow = max(rowsum)

colchk = np.where(colsum==maxcol)
rowchk = np.where(rowsum==maxrow)

for i in range(len(rowchk[0])):
    for j in range(len(colchk[0])):
        if colchk[0][j] not in rowbombs[rowchk[0][i]]:
            print(int(max(colsum)+max(rowsum)))
            quit()

print(int(max(colsum)+max(rowsum))-1)
a = input().split()
s = {}
for i in a:
    s |= i
print(len(s))

### FIXED CODE ###

a = input().split()
s = {a[0]}
for i in a:
    s |= {i}
print(len(s))
def solve(i,m):
    if m==0:
        return True
    if i>=n:
        return False
    res=solve(i+1,m) or solve(i+1,m-A[i])
    return res

n=int(input())
A=[]*n
A=list(input().split())
for i in range(n):
    A[i]=int(A[i])
m=int(input())
B=list(input().split())
ans=[]
for i in range(m):
    B[i]=int(B[i])
    ans=solve(0,B[i])
    if ans==True:
        print("yes")
    else:
        print("no")



### FIXED CODE ###

n = int(input())
A = list(map(int,input().split()))
m = int(input())
B = list(map(int,input().split()))

T = [[0]*2001 for i in range(n)]

T[0][0] = 1
T[0][A[0]] = 1
for i in range(1,n):
    for j in range(2001):
        T[i][j] = T[i-1][j]
        if (j - A[i] >=0) and (T[i-1][j-A[i]] == 1):
            T[i][j] = 1
    
for i in range(m):
    if T[n-1][B[i]] == 1: print("yes")
    else: print("no")
n = int(input())
ans, index6, index9, num6, num9 = 0, 0, 0, 0, 0
INF = float('inf')

def a10_to_n(x, n):
    if x//n:
        return a10_to_n(x//n, n)+str(x%n)
    else:
        return str(x)

def index(n, num6, index6, num9, index9):
    val = str(a10_to_n(n, 6))
    for i, j in enumerate(val):
        if int(j) != 0:
            num6 = int(j)
            index6 = len(val)-i-1
            break
    val = str(a10_to_n(n, 9))
    for i, j in enumerate(val):
        if int(j) != 0:
            num9 = int(j)
            index9 = len(val)-i-1
            break
    return num6, index6, num9, index9

num6, index6, num9, index9 = index(n, num6, index6, num9, index9)
while index6 > 1 or index9 > 1:
    if 6**index6 <= 9**index9:
        n -= num9*9**index9
        ans += num9
    else:
        n -= num6*6**index6
        ans += num6
    num6, index6, num9, index9 = index(n, num6, index6, num9, index9)
    
a = [INF for _ in range(n+1)]
a[n] = 0
for i in range(n, -1, -1):
    if i-9 >= 0:
        a[i-9] = min(a[i]+1, a[i-9])
    if i-6 >= 0:
        a[i-6] = min(a[i]+1, a[i-6])
    if i-1 >= 0:
        a[i-1] = min(a[i]+1, a[i-1])
print(ans+a[0])


### FIXED CODE ###

n = int(input())
index6, index9, num6, num9 = 0, 0, 0, 0
INF = float('inf')    
a = [INF for _ in range(n+1)]
a[n] = 0

for i in range(n, -1, -1):
    if a[i] == INF:
        continue
    j = 1
    while i-9**j >= 0:
        a[i-9**j] = min(a[i]+1, a[i-9**j])
        j += 1
    j = 1
    while i-6**j >= 0:
        a[i-6**j] = min(a[i]+1, a[i-6**j])
        j += 1
    if i-1 >= 0:
        a[i-1] = min(a[i]+1, a[i-1])
print(a[0])
N, M = map(int, input().split())
accepted = [0] * N
penalties = [0] * N
for _ in range(M):
    p, ac = input().split()
    p, ac = int(p), ac == "AC"
    accepted[p] |= ac
    penalties[p] += not accepted[p]
print(sum(accepted), sum(p for ac, p in zip(accepted, penalties) if ac))


### FIXED CODE ###

N, M = map(int, input().split())
accepted = [0] * N
penalties = [0] * N
for _ in range(M):
    p, ac = input().split()
    p, ac = int(p) - 1, ac == "AC"
    accepted[p] |= ac
    penalties[p] += not accepted[p]
print(sum(accepted), sum(p for ac, p in zip(accepted, penalties) if ac))
def checkFunction(c):
    count = 0

    while c[-1] == 'W':
        c = c[:-1]
    while True:
        # print(count, c)
        if not ('WR' in c):
            return count
        while c[0] == 'R':
            c = c[1:]
        if c.index('R') == len(c) - 1:
            return count + 1
        else:
            c = c.replace('WR', 'RR',1)[:-1]
            count += 1

N = int(input())
c= input()

print(checkFunction(c))



### FIXED CODE ###


def check(N, c):
    RinRight = c.count('R')
    WinLeft = 0
    r = RinRight
    for i in range(N):
        if c[i] == 'R':
            RinRight -= 1
        else: # c[i] == 'W'
            WinLeft +=1
        r = min(r, max(RinRight,WinLeft))

    return r


N = int(input())
c= input()
print(check(N,c))
n=int(input())
ans = 0
for i in range(n+1):
	if a%3 != 0 and a%5 !=0:
  		ans += i
print(ans)
  
  


### FIXED CODE ###

n=int(input())
ans = 0
for i in range(n+1):
	if i%3 != 0 and i%5 !=0:
  		ans += i
print(ans)