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

s,c = map(int,input().split())
scc = 0

for i in range(s):
    if c > 0:
        c -= 2
        s -= 1
        scc += 1
    if s == 0:
        break
        
scc += c // 4

print(scc)

### FIXED CODE ###

s,c = map(int,input().split())
scc = 0

tmp = c // 2
scc += min(s,tmp)
c -= scc*2
        
scc += c // 4

print(scc)
### BUGGY CODE ###

import bisect

N = int(input())
A = [int(input()) for _ in range(N)]

ans = [A[0]]

for a in A[1:]:
    if a <= ans[0]:  # 色を増やすしかない
        ans.insert(0, a)
    else:  # 既存の色のどこかに追加
        idx = bisect.bisect_left(ans, a)
        ans[idx-1] = a

print(len(ans))


### FIXED CODE ###

import bisect
import collections

N = int(input())
A = [int(input()) for _ in range(N)]

ans = collections.deque([A[0]])

for a in A[1:]:
    if a <= ans[0]:  # 色を増やすしかない
        ans.appendleft(a)
    else:  # 既存の色のどこかに追加
        idx = bisect.bisect_left(ans, a)
        ans[idx-1] = a
    # print(a, ans)

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

import collections
import itertools
import functools
import math
import scipy.special

if __name__ == "__main__":
    k, s = map(int, input().split())
    res = 0
    mi = min(k, s)
    ma = max(k, s)
    for i in range(mi + 1):
        for j in range(mi + 1):
            res += int(0 <= s - i - j and s - i - j <= k)
    print(res)

### FIXED CODE ###

import collections
import itertools
import functools
import math
import scipy.special

if __name__ == "__main__":
    k, s = map(int, input().split())
    res = 0
    for i in range(k + 1):
        for j in range(k + 1):
            if 0 <= s - i - j <= k:
                res += 1
    print(res)
### BUGGY CODE ###

def calc_gcd2(a, b):
    if b == 0:
        return a
    else:
        return calc_gcd2(b, a % b)
    
def calc_gcd3(a, b, c):
    gcd_ab = calc_gcd2(a, b)
    return calc_gcd2(gcd_ab, c)
    
K = int(input())
tanget_num = range(1, K+1)
sum_ = 0
for i in tanget_num:
    for j in tanget_num:
        for k in tanget_num:
            sum_ = sum_ + calc_gcd3(i, j, k)
print(str(sum_))

### FIXED CODE ###

import math

K = int(input())
tanget_num = range(1, K+1)
sum_  = sum([math.gcd(i, math.gcd(j, k)) for i in tanget_num for j in tanget_num for k in tanget_num])

print(str(sum_))
### BUGGY CODE ###

import fractions 
#from functools import reduce
import functools

MOD = 10**9+7


def main():
    # N = int(input())
    # A = list(map(int, input().split()))
    N, *A = map(int, open(0).read().split())
            
    x = 1
    for a in A:
        x *= a //  fractions.gcd(x, a)
        
    b = sum(x//a%MOD for a in A)
    print(b%MOD)
    
if __name__== "__main__":
    main()


### FIXED CODE ###

import fractions 
#from functools import reduce
import functools

MOD = 10**9+7


def main():
    # N = int(input())
    # A = list(map(int, input().split()))
    N, *A = map(int, open(0).read().split())
            
    x = 1
    for a in A:
        x *= a //  fractions.gcd(x, a)
        
    b = sum(x//a for a in A)
    print(b%MOD)
    
if __name__== "__main__":
    main()
### BUGGY CODE ###

n=int(input())
l=list(map(int, input().split()))
# n=5
# l=[4,2,5,1,3]
count=0
for i in range(1,len(l)+1):
#     print(l[:i])
#     print(l[i-1])
    if min(l[:i])==l[i-1]:
        count+=1
    
    
    
print(count)

### FIXED CODE ###

n=int(input())
l=list(map(int, input().split()))
# n=5
# l=[4,2,5,1,3]
count=0

import heapq

tmp=l[0]
for i in range(1,len(l)+1):
    if tmp>=l[i-1]:
        count+=1
        tmp=l[i-1]
    
    
print(count)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
n = int(sys.stdin.readline())
a = [x for x in sys.stdin.readline().split()]
b = []
for i in range(n):
    b = b[::-1]
    b.insert(0, a[i])
print(" ".join(b))

### FIXED CODE ###

import sys
n = int(sys.stdin.readline())
a = [x for x in sys.stdin.readline().split()]
b = [a[i] for i in range(n) if i % 2 != 0]
rb = b[::-1]
c = [a[i] for i in range(n) if i % 2 == 0]
rc = c[::-1]

if n % 2 == 0:
    ans = rb + c
else:
    ans = rc + b

ans = " ".join(ans)
print(ans)
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

bit = [0] * 60
for a in A:
    i = 0
    while a > 0:
        bit[i] += a & 1
        i += 1
        a >>= 1

ans = 0
for i, x in enumerate(bit):
    x = x*(n-x)
    for _ in range(i):
        x *= 2
        x %= mod
    ans += x
    ans %= mod
print(ans)


### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

bit = [0] * 60
for a in A:
    i = 0
    while a > 0:
        bit[i] += a & 1
        i += 1
        a >>= 1

ans = 0
for i, x in enumerate(bit):
    x = x*(n-x)
    for _ in range(i):
        x *= 2
        x %= mod
    ans += x
    ans %= mod
print(ans)
### BUGGY CODE ###

a,b,c,d,e,f=map(int,input().split())
maxsugar=f*e/(100+e)
maxwater=f*100/(100+e)
#print(maxsugar,maxwater)
sugar=[]
for i in range(int(maxsugar)//min(c,d)+2):
    for j in range(int(maxsugar)//min(c,d)+2):
        x=i*c+j*d
        if x<=maxsugar:
            sugar.append(x)
#print(sugar)
water=[]
for i in range(int(maxwater//100+2)//min(a,b)+5):
    for j in range(int(maxwater//100+2)//min(a,b)+5):
        y=i*a+j*b
        water.append(y)
#print(water)
water.remove(0)
ansl=[]
for i in sugar:
    for j in water:
        z=i/(j*100+i)
        xyz=i+j*100
        if xyz<=f and z<=e/(100+e):
            ansl.append((i,j,z))
s,t,r=sorted(ansl,key=lambda x:x[-1])[-1]
print(s+t*100,s)

### FIXED CODE ###

a,b,c,d,e,f=map(int,input().split())
maxsugar=f*e/(100+e)
maxwater=f*100/(100+e)
#print(maxsugar,maxwater)
sugar=[]
for i in range(int(maxsugar)//min(c,d)+2):
    for j in range(int(maxsugar)//min(c,d)+2):
        x=i*c+j*d
        if x<=maxsugar:
            sugar.append(x)
#print(sugar)
water=[]
for i in range(int(maxwater//100+2)//min(a,b)+5):
    for j in range(int(maxwater//100+2)//min(a,b)+5):
        y=i*a+j*b
        water.append(y)
#print(water)
water.remove(0)
ansl=[]
for i in sugar:
    for j in water:
        z=i/(j*100+i)
        xyz=i+j*100
        if xyz<=f and z<=e/(100+e):
            ansl.append((i,j,z))
s,t,r=sorted(ansl,key=lambda x:x[-1])[-1]
print(s+t*100,s)
### BUGGY CODE ###

from collections import Counter

N = int(input())
a = list(map(float, input().split()))

dp = [[[0]*(N+1) for _ in range(N+1)] for _ in range(N+1)]
c = Counter(a)

# メモ化再帰ではpypy3でもTLEするのでforループを使う
# j==k==0の場合を計算 → k==0の場合を計算 → 一般の場合を計算
for k in range(c[3]+1):
    for j in range(c[3]+c[2]-k+1):
        for i in range(N-j-k+1):
            if i+j+k == 0:
                continue
            else:
                tmp = N
                if i > 0: # IndexError防止
                    tmp += dp[i-1][j][k]*i
                if j > 0:
                    tmp += dp[i+1][j-1][k]*j
                if k > 0:
                    tmp += dp[i][j+1][k-1]*k
                dp[i][j][k] = tmp/(i+j+k) # 割り算をまとめないとTLE

print(dp[c[1]][c[2]][c[3]])

### FIXED CODE ###

def main():
    from collections import Counter

    N = int(input())
    a = list(map(float, input().split()))

    dp = [[[0]*(N+1) for _ in range(N+1)] for _ in range(N+1)]
    c = Counter(a)

    # メモ化再帰ではpypy3でもTLEするのでforループを使う
    # j==k==0の場合を計算 → k==0の場合を計算 → 一般の場合を計算
    for k in range(c[3]+1):
        for j in range(c[3]+c[2]-k+1):
            for i in range(N-j-k+1):
                if i+j+k == 0:
                    continue
                else:
                    tmp = N
                    if i > 0: # IndexError防止
                        tmp += dp[i-1][j][k]*i
                    if j > 0:
                        tmp += dp[i+1][j-1][k]*j
                    if k > 0:
                        tmp += dp[i][j+1][k-1]*k
                    dp[i][j][k] = tmp/(i+j+k) # 割り算をまとめないとTLE

    print(dp[c[1]][c[2]][c[3]])

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

def main():
    N, M = map(int, input().split())
    search = M//N + 1
    for s in range(search, 0, -1):
        sum_array = s * N
        if sum_array > M:
            continue
        remain = M - sum_array
        if remain % s == 0:
            print(s)
            return

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N, M = map(int, input().split())
    search = M//N + 1
    for s in range(search, 0, -1):
        sum_array = s * N
        if sum_array > M:
            continue
        remain = M - sum_array
        if remain % s == 0:
            print(s)
            return

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

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def merge(A, left, mid, right):
    global count

    n1 = mid - left
    n2 = right - mid
    L = [0 for _ in range(n1 + 1)]
    R = [0 for _ in range(n2 + 1)]

    for m in range(n1):
        L[m] = A[left + m]

    for n in range(n2):
        R[n] = A[mid + n]

    L[n1], R[n2] = 1e9, 1e9
    i, j = 0, 0

    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

    return None


def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    array_length = int(_input[0])
    array = list(map(int, _input[1].split()))
    assert array_length == len(array)
    count = 0
    merge_sort(A=array, left=0, right=array_length)
    print(*array)
    print(count)

### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def merge(A, left, mid, right):
    global count

    L = A[left:mid] + [1e9]
    R = A[mid:right] + [1e9]

    i, j = 0, 0

    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return None


def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)
    return A


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    array_length = int(_input[0])
    array = list(map(int, _input[1].split()))
    assert array_length == len(array)
    count = 0
    print(*merge_sort(A=array, left=0, right=array_length))
    print(count)
### BUGGY CODE ###

import sys

N = int(input())
l = list(map(int, input().split()))

def solve():
    if 0 in l:
        return (0)
        sys.exit()

    x = 1
    for i in range(N):
        x = x * l[i]

    if x > (1000000000000000000):
        x = -1
        return str(x)
    else:
        return str(x)

print(solve())

### FIXED CODE ###

import sys

N = int(input())
l = list(map(int, input().split()))

def solve():
    if 0 in l:
        return (0)
        sys.exit()

    x = 1
    for i in range(N):
        x = x * l[i]
        if x > (1000000000000000000):
            x = -1
            break

    return str(x)

print(solve())
### BUGGY CODE ###

n = int(input())
An = list(map(int, input().split()))
ans = 1

for i in An:
  ans = ans * i
  if ans > 10 ** 18:
    ans = -1
    continue
if ans < 0:
  print(-1)
else:  
  print(ans)

### FIXED CODE ###

n = int(input())
An = list(map(int, input().split()))
ans = 1

if 0 in An:
  print(0)
  exit(0)

for i in An:
  ans = ans * i
  if ans > 10 ** 18:
    print(-1)
    exit(0)

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

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

X = 0
town = 1
counted = [0 for _ in range(N)]
for k in range(N):
  X += 1
  counted[k] = town
  town = A[town-1]
  if town in counted:
    ini = counted.index(town)
    Q = X - ini
    break
if K >= ini:    
  num = (K-ini) % Q
  print(counted[ini+num])
else:
  print(counted[K])


### FIXED CODE ###

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

X = 0
town = 1
counted = [0 for _ in range(N)]
List = [0 for _ in range(N)]
for k in range(N):
  X += 1
  counted[k] = town
  town = A[town-1]
  if List[town-1] == 1:
    ini = counted.index(town)
    Q = X - ini
    break
  else:
    List[town-1] = 1
if K >= ini:    
  num = (K-ini) % Q
  print(counted[ini+num])
else:
  print(counted[K])
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")

MOD = 1000000007  # type: int


def GCD(a, b):
    if a == 0:
        return b
    else:
        return GCD(b % a, a)


# def power(x, y):
#     if y == 0:
#         return 1
#     elif y == 1:
#         return x % MOD
#     elif y % 2 == 0:
#         return power(x, y//2)**2 % MOD
#     else:
#         return power(x, y//2)**2 * x % MOD


# def div(a, b):
#     return (a * power(b, MOD-2)) % MOD


def LCM(a, b):
    return a*b//GCD(a, b)
    # return div(power(a, b), GCD(a, b))


def solve(N: int, A: "List[int]"):

    # 最小公倍数
    lcm = 1
    for a in A:
        lcm = LCM(lcm, a)
    print(sum([lcm//a for a in A]) % MOD)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from collections import Counter
import math
MOD = 1000000007  # type: int


def factorial(n):
    prime_count = Counter()

    for i in range(2, int(math.sqrt(n)) + 2):
        while n % i == 0:
            n /= i
            prime_count[i] += 1
    if n > 1:
        prime_count[int(n)] += 1

    return prime_count


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % MOD
    elif y % 2 == 0:
        return power(x, y//2)**2 % MOD
    else:
        return power(x, y//2)**2 * x % MOD


def div(a, b):
    return (a * power(b, MOD-2)) % MOD


def solve(N: int, A: "List[int]"):

    lcm = Counter()
    for a in A:
        c = factorial(a)
        for k in c:
            lcm[k] = max(c[k], lcm[k])
    # print(lcm)

    LCM = 1
    for k, v in lcm.items():
        LCM *= power(k, v)
        LCM %= MOD
    # print(LCM)

    tot = 0
    for a in A:
        tot += div(LCM, a)
    print(tot % MOD)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


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

n = int(input())
s = input()

total = 0

for i in range(n-3):
    a = s[i]
    for j in range(i+1, n-1):
        if s[j] == a:
            continue
        else:
            b = s[j]
            for k in range(j+1, n):
                if k-j != j-i:
                    if s[k] != a and s[k] != b:
                        total += 1
print(total)

### FIXED CODE ###

n = int(input())
s = input()

# total number of pairs fullfilling first condition 
r = s.count('R')
g = s.count('G')
b = len(s) - r - g
total = r*g*b

# j-i = k-j
for p in range(1, (n-1)//2 + 1):
    for i in range(0, n-(2*p)):
        si, sj, sk = s[i], s[i+p], s[i+2*p]
        if si != sj and sj != sk and sk != si:
            total -=  1
print(total)
### BUGGY CODE ###

import numpy as np
import sys
from collections import deque

n,m = map(int,input().split())
ab = [[int(i) for i in input().split()] for i in range(m)]
abl=[[] for i in range(n)]
for i in range(len(ab)):
    abl[ab[i][0]-1].append(ab[i][1])
    abl[ab[i][1]-1].append(ab[i][0])

an=[0]*(n-1)
i=1
wk=deque([i])
wwk=deque([])
il=deque(abl[0])

while any(wk):
    i=wk.pop()
    il=abl[i-1]
    while any(il):
        iwk=il.pop()
        if an[iwk-2]==0 and iwk>1:
            wwk.append(iwk)
            an[iwk-2]=i
            if all(an):
                print('Yes')
                for i in an:
                    print(i)
                sys.exit()
    if not(any(wk)):
        wk=deque(wwk)
        wwk=deque([])
print('No')

### FIXED CODE ###

def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()
### BUGGY CODE ###

import fractions
from functools import reduce
n = int(input())
a = list(map(int, input().split()))
def lcm_base(x, y):
    return (x*y) // fractions.gcd(x, y)

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

l = lcm(a)
mod = 10**9+7
total = 0
for i in a:
    total += l//i
    total %= mod
print(total)

### FIXED CODE ###

#GCD, LCM
def gcd_base(a, b):
    while b!=0:
        a, b = b, a%b
    return a

def lcm(num_list):
    ans = 1
    for i in num_list:
        ans = ans * i // gcd_base(ans, i)
    return ans

n = int(input())
a = list(map(int, input().split()))
l = lcm(a)
mod = 10**9+7
total = 0
for i in a:
    total += l//i
print(total%mod)
### BUGGY CODE ###

N, M = map(int, input().split())
price = []
keys = []
dp = [float('inf') for i in range(1<<N)]
dp[0] = 0
for k in range(M):
    price.append(int(input().split()[0]))
    keys.append(list(map(int,input().split())))
for p,key in zip(price,keys):
    key_open = 0
    for k in key:
        key_open |= 1 << (k-1)
        for j in range(1 << N):
            dp[j|key_open] = min(dp[j|key_open], dp[j] + p)

if dp[(1<<N)-1] == float('inf'):
    dp[(1<<N)-1] = - 1
print(dp[(1 << N) - 1])

### FIXED CODE ###

N, M = map(int, input().split())
price = []
keys = []
dp = [float('inf') for i in range(1<<N)]
dp[0] = 0
for k in range(M):
    price.append(int(input().split()[0]))
    keys.append(list(map(int,input().split())))
for p,key in zip(price,keys):
    key_open = 0
    for k in key:
        key_open |= 1 << (k-1)
        for j in range(1 << N):
            dp[j|key_open] = min(dp[j|key_open], dp[j] + p)

if dp[(1<<N)-1] == float('inf'):
    dp[(1<<N)-1] = - 1
print(dp[(1 << N) - 1])
### BUGGY CODE ###

s=input()
x = [0]*2019
for i in range(len(s)):
  x[int(s[i:])%2019] += 1

ans = x[0]
for i in range(2019):
  ans += x[i]*(x[i]-1)//2
print(ans)

### FIXED CODE ###

s=[int(x) for x in reversed(list(input()))]
n=len(s)
x=[0]*2019
dp = 0
dim = 1
for si in s:
  dp = (dp + si*dim) % 2019
  x[dp] += 1
  dim = dim * 10 % 2019
ans = x[0]
for i in range(2019):
  ans += x[i]*(x[i]-1)//2
print(ans)
### BUGGY CODE ###

n = input()
l = len(n)
count = 0
for i in range(l-3):
  for j in range(i+3, l):
    integer = int(n[i:j+1])
    if integer % 2019 == 0:
      count += 1
print(count)

### FIXED CODE ###

n = input()
mod = [0]*2019
mod[0] += 1
T = 0
d = 1 # 桁数
for i, s in enumerate(n[::-1]):
  T += int(s) * d
  T %= 2019
  d = (d * 10) % 2019
  mod[T] += 1
  
res = 0  
for m in mod:
  res += m*(m-1)/2
print(int(res))
### BUGGY CODE ###

import math
N, K = map(int, input().split())
lightPow = list(map(int, input().split()))

for i in range(K):
  newLightPow = [0]*N
  #print(lightPow)
  for pos in range(1, N+1):
    count = 0
    low = math.ceil(pos-(lightPow[pos-1]+0.5))
    high = math.floor(pos+(lightPow[pos-1]+0.5))
    low = min(max(1, low), N)
    high = min(max(1, high), N)
    for area in range(low, high+1):
      #print(area)
      newLightPow[area-1] += 1
    #print("pos:"+str(pos))
    #print("low"+str(low)+" high"+str(high))
    #print(newLightPow)
  lightPow = newLightPow
  check = True
  for pow in lightPow:
    if (pow < (N-1)) :
      check = False
    if not (check):
      break
  if (check):
    break
  
print(*lightPow)


### FIXED CODE ###

import math
N, K = map(int, input().split())
lightPow = list(map(int, input().split()))

for i in range(K):
  newLightPow = [0]*(N+1)
  #print(lightPow)
  for pos in range(1, N+1):
    low = pos - lightPow[pos-1]
    high = pos + lightPow[pos-1]
    low = min(max(1, low), N)
    high = min(max(1, high), N)
    newLightPow[low-1] += 1
    newLightPow[high] -= 1
    #print("pos:"+str(pos))
    #print("low"+str(low)+" high"+str(high))
    #print(newLightPow)
    
  check = True
  for i in range(0, N):
    if (i > 0):
      newLightPow[i] += newLightPow[i-1]
    if (newLightPow[i] < N):
      check = False
  lightPow = newLightPow
  if (check):
    break

print(*lightPow[:-1])
### BUGGY CODE ###

a=input()
H,N=int(a.split()[0]),int(a.split()[1])
b=input()
list=[]
for i in range(N):
  list.append(int(b.split()[i]))
if(sum(list)>=H):
  print('Yes')
else:
  print('No')

### FIXED CODE ###

a=input()
H,N=int(a.split()[0]),int(a.split()[1])
b=input().split()
list=list(map(int, b))
if(sum(list)>=H):
  print('Yes')
else:
  print('No')
### BUGGY CODE ###

s = input()
count = 0
num = 1
while(num != 0):
  num = s.count('BW')
  s = s.replace('BW','WB')
  count += num
print(count)

### FIXED CODE ###

S = list(input())
W_i = [i for i,j in enumerate(S) if j == 'W']
W_n = S.count('W')
cur = 0
ans = 0
for i in W_i:
  ans += i-cur
  cur += 1
print(ans)
### BUGGY CODE ###

# coding: utf-8
# Your code here!
X=(input())
ans=0
pre=[]
pre=X
    
while True:
    X=X.replace("ST","")
    if pre==X:
        break
    else:
        pre=X

print(len(X))


### FIXED CODE ###

X=list(input())
N=len(X)
count=0

for x in X:
    if x=="S":
        count+=1
    else:
        if count>0:
            count-=1
            N-=2
print(N)
### BUGGY CODE ###

n, p = map(int, input().split())
s = list(str(input()))
cnt = 0

for i in range(n):
    for j in range(n - i):
        num=''.join(s[j:j+i + 1])
        if int(num) % p == 0:
            cnt += 1
print(cnt)


### FIXED CODE ###

from collections import Counter

n, p = map(int, input().split())
s = input()

ans = 0

if p in {2, 5}:
    lst = set(i for i in range(0, 10, p))
    for i, num in enumerate(s):
        if int(num) in lst:
            ans += i + 1
else:
    num = [int(s[-1]) % p]
    for i in range(1, len(s)):
        tmp = num[-1] + pow(10, i, p) * int(s[-i - 1])
        num.append(tmp % p)
    mod = [1] + [0] * (p - 1)
    for i in num:
        ans += mod[i]
        mod[i] += 1
print(ans)
### BUGGY CODE ###

N,M=list(map(int,input().split()))
cards=list(map(int,input().split()))
for i in range(M):
    time,val=list(map(int,input().split()))
    tmp=[val for _ in range(time)]
    cards.extend(tmp)
cards=sorted(cards)[::-1]
print(sum(cards[:N]))



### FIXED CODE ###

from collections import Counter
N,M=list(map(int,input().split()))
cards=list(map(int,input().split()))
all_c=Counter(cards)

for i in range(M):
    time,val=list(map(int,input().split()))
    try:
        all_c[val]+=time
    except:
        all_c[val]=time

tmp=list(all_c.keys())
tmp.sort(reverse=True)
total=0
sum_time=0
for i in tmp:
    if sum_time>=N:
        break
    sum_time+=all_c[i]
    if sum_time<N:
        total+=i*all_c[i]
    else:
        total+=i*(all_c[i]+N-sum_time)
print(total)