Harryxun/stf_run huggingface dataset:
N,Q = map(int,input().split())
S = input()
QUE = [ input().split() for _ in range(Q)]

N = len(S)

l = 0
r = N-1

for i in range(Q-1, -1, -1):
    t,d = QUE[i]
    if d == "L" and t == S[l]:
        l += 1
    if d == "R" and t == S[r]:
        r -= 1

print(max(0, r-l+1))

### FIXED CODE ###

N,Q = map(int, input().split())
S = input()
TD = [ input().split() for _ in range(Q)]


N = len(S)
ans = 0

# N-1 falls from right edge ? 
nowpos = N-1
fall_f = False
for i in range(Q):
    t,d = TD[i]
    nowChar = S[nowpos]
    if t == nowChar:
        if d == "L":
            nowpos -= 1
            if nowpos == -1:
                break
        if d == "R":
            nowpos += 1
            if nowpos == N:
                fall_f = True
                break

if fall_f:
    ok = N-1
    ng = -1
    mid = (ok+ng)//2
    while abs(ok - ng) > 1:
        nowpos = mid
        fall_f = False

        for i in range(Q):
            t,d = TD[i]
            nowChar = S[nowpos]
            if t == nowChar:
                if d == "L":
                    nowpos -= 1
                    if nowpos == -1: break
                if d == "R":
                    nowpos += 1
                    if nowpos == N:
                        fall_f = True
                        break
        if fall_f :
            ok = mid
        else:
            ng = mid

        mid = (ok+ng)//2

    ans += N - ok 

    

    
# 0 fallse from left edge  ?
nowpos = 0
fall_f = False
for i in range(Q):
    t,d = TD[i]
    nowChar = S[nowpos]
    if t == nowChar:
        if d == "L":
            nowpos -= 1
            if nowpos == -1:
                fall_f = True
                break
        if d == "R":
            nowpos += 1
            if nowpos == N:
                break
if fall_f:

    ok = 0
    ng = N
    mid = (ok+ng)//2
    while abs(ok - ng) > 1:

        nowpos = mid
        fall_f = False

        for i in range(Q):
            t,d = TD[i]
            nowChar = S[nowpos]
            if t == nowChar:
                if d == "L":
                    nowpos -= 1
                    if nowpos == -1: 
                        fall_f = True
                        break
                if d == "R":
                    nowpos += 1
                    if nowpos == N:
                        break
        if fall_f :
            ok = mid
        else:
            ng = mid

        mid = (ok+ng)//2

    ans= min( ans +  ok + 1,  N)

print(N - ans)
s = input()
K = int(input())

ans = []
for i in range(len(s)):
    if K >= ord('z')-ord(s[i])+1:
        K -= ord('z')-ord(s[i])+1
        ans.append('a')
    else:
        ans.append(s[i])

if K >= 1:
    ans[-1] = chr(ord(ans[-1])+K)

print(''.join(ans))


### FIXED CODE ###

s = input()
K = int(input())

ans = []
for i in range(len(s)):
    if K >= ord('z')-ord(s[i])+1 and s[i] != 'a':
        K -= ord('z')-ord(s[i])+1
        ans.append('a')
    else:
        ans.append(s[i])

if K >= 1:
    ans[-1] = chr(ord(ans[-1])+K % 26)

print(''.join(ans))
print((int((input())**(1/2)))**2)

### FIXED CODE ###

n=int(input())
num=int((n)**(1/2))
print((num)**2)
n = list(input())
l = len(n)

for i in range(l):
    n[i] = int(n[i])

score = 0

if l == 1:
    print(n[0])
else:
    if n.count(9) == l-1:
        if n[0] != 9:
            score += sum(n)
        else:
            score += 8 + 9*(l-1)
    else:
        if n[0] != 9:
            score += n[0]-1 + 9*(l-1)
        else:
            for j in range(n):
                if n[j] != 9:
                    n[j-1] = 8
                    score += 8 + 9*(l-1)
                    break
    print(score)

### FIXED CODE ###

n = list(input())
l = len(n)

for i in range(l):
    n[i] = int(n[i])

score = 0

if l == 1:
    print(n[0])
else:
    if n.count(9) == l:
        score = sum(n)
    elif n.count(9) == l-1:
        if n[0] != 9:
            score += sum(n)
        else:
            score += 8 + 9*(l-1)
    else:
        if n[0] != 9:
            score += n[0]-1 + 9*(l-1)
        else:
            for j in range(l):
                if n[j] != 9:
                    n[j-1] = 8
                    score += 8 + 9*(l-1)
                    break
    print(score)
N = int(input())

if N % 10 = 3:
 print('bon')
elif N % 10 = 0:
 print('pon')
elif N % 10 = 1:
 print('pon')
elif N % 10 = 6:
 print('pon')
elif N % 10 = 8:
 print('pon')
else:
 print('hon')


### FIXED CODE ###

N = int(input())

if N % 10 == 3:
 print('bon')
elif N % 10 == 0:
 print('pon')
elif N % 10 == 1:
 print('pon')
elif N % 10 == 6:
 print('pon')
elif N % 10 == 8:
 print('pon')
else:
 print('hon')
import copy
import numpy as np
n = int(input())
x = list(map(int,input().split()))
m,k = map(int,input().split())
a = list(map(int,input().split()))
b = []
x2 = []
c = []
for i in range(1,n):
  b.append(i-1)
  x2.append(x[i]-x[i-1])
for i in range(m):
  to = a[i]-1
  b[to],b[to-1] = b[to-1],b[to]
bai = np.zeros((n-1,n-1))
for i in range(n-1):
  xx = b[i]
  bai[xx,i] = 1
bai = np.mat(bai)
bai = bai**k
x2 = np.dot(x2,bai)
x2 = np.array(x2)
s = x[0]
print(s)
for i in x2[0]:
  s += i
  print(s)

### FIXED CODE ###

n = int(input())
x = list(map(int,input().split()))
m,k = map(int,input().split())
a = list(map(int,input().split()))
b = []
x2 = []
c = []
for i in range(1,n):
  b.append(i-1)
  x2.append(x[i]-x[i-1])
for i in range(m):
  to = a[i]-1
  b[to],b[to-1] = b[to-1],b[to]
c = [-1] * (n-1)
for i in range(n-1):
  c[b[i]] = i
for i in range(60):
  x3 = [0]*(n-1)
  if k&(1<<i):
    for i in range(n-1):
      x3[c[i]] = x2[i]
    x2 = x3
  c2 = [-1] * (n-1)
  for i in range(n-1):
    c2[i] = c[c[i]] 
  c = c2
s = x[0]
print(s)
for i in x2:
  s += i
  print(s)
# 累積和
N, K = map(int, input().split())
S = input()

p = '1'
count = 0
cs = []
for c in S:
  if c != p:
    cs.append(count)
    p = c
    count = 1
  else:
    count += 1
cs.append(count)
if p != '0':
  cs.append(0)

if len(cs) < 2 * K:
  print(N)

for i in range(1, len(cs)):
  cs[i] += cs[i - 1]

result = cs[2 * K]
for i in range(2, len(cs) - 2 * K, 2):
  t = cs[2 * K + i] - cs[i - 1]
  if t > result:
    result = t
print(result)


### FIXED CODE ###

n, k = map(int, input().split())
s = list(map(int, input()))
j = 1
r = 0
t = []
for i in range(n):
  if s[i] == j:
    r += 1
  else:
    t.append(r)
    r = 1
    j ^= 1
t.append(r)
if j == 0:
  t.append(0)
if k >= (len(t) - 1) // 2:
  print(sum(t))
else:
  result = sum(t[:2 * k + 1])
  j = sum(t[:2 * k + 1])
  i = 2
  while i + 2 * k < len(t):
    j += t[i + 2 * k - 1] + t[i + 2 * k] - (t[i - 2] + t[i - 1])
    result = max(result, j)
    i += 2
  print(result)
n=int(input())
A=list(map(int,input().split()))
ans=deque([])
from collections import deque
d=deque(A)
for i in range(0,n):
    if i%2==0:
        ans.append(d[i])
    if i%2==1:
        ans.insert(0,d[i])
if n%2==1:
    ans=list(ans)[::-1]
print(" ".join(map(str, ans)))

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
from collections import deque
ans=deque([])
d=deque(A)
for i in range(0,n):
    if i%2==0:
        ans.append(d[i])
    if i%2==1:
        ans.appendleft(d[i])
a=list(ans)
if n%2==1:
    c=a[::-1]
else:
    c=a
print(" ".join(map(str, c)))
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
t_ = set(t)
for i in range(len(t_):
  if t.count(t_[i]) > d.count(t_[i]):
    print("NO")
    exit()
print("YES")


### FIXED CODE ###

import collections

n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
dc = collections.Counter(d)
tc = collections.Counter(t)
for i in tc:
    if tc[i] > dc[i]:
        print("NO")
        exit()
print("YES")
s = input()
k = int(input())

cnt = 0
while s[cnt]=="1":
    cnt += 1
    
if cnt == 0:
    print(s[0])
elif cnt >= k:
    print(1)
else:
    print(s[cnt])

### FIXED CODE ###

s = input()
k = int(input())

cnt = 0
while cnt<len(s) and s[cnt]=="1":
    cnt += 1

if cnt == 0:
    print(s[0])
elif cnt >= k:
    print(1)
else:
    print(s[cnt])
N = int(input())
s = list(map(int, input().split()))

m = s[0]
M = s[N-1]

lis = []
ans = 0

for i in range(m,M + 1):
  for j in range(N):
  	ans += (s[j] - i) ** 2
  lis.append(ans)
  ans = 0
  
print(min(lis))

### FIXED CODE ###

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

m = s[0]
M = s[N-1]

lis = []
ans = 0

for i in range(1000):
  for j in range(N):
  	ans += (s[j] - i) ** 2
  lis.append(ans)
  ans = 0
  
print(min(lis))
A = input("Please input 1st number: ")
B = input("Please input 2nd number: ")

if int(A) >= 1 and int(A) <= 100:
  if int(B) >= 1 and int(B) <= 100:
    C = int(A) * int(B)
    print("We have" + str(A) + " x " + str(B) + " = " + str(C) + ".")
  else:
    print("Please check Number B side")
else:
  print("Please check Number A side")

print("check end.")


### FIXED CODE ###

a, b = map(int, input().split())
print(a*b)
import collections
sys.setrecursionlimit(10**6)
def dfs(visited,v,adj):
    visited[v]=True 
    for i in adj[v]:
        if not visited[i]:
            dfs(visited,i,adj)  
adj=collections.defaultdict(list)
n,m=map(int,input().split()) 
visited=[False]*n  
for i in range(m):
    u,v=map(int,input().split()) 
    adj[u-1].append(v-1)  
    adj[v-1].append(u-1) 
c=0 
for i in range(n):
    if not visited[i]:
        dfs(visited,i,adj) 
        c+=1 
print(c-1)

### FIXED CODE ###

import collections
import sys
sys.setrecursionlimit(10**6)
def dfs(visited,v,adj):
    visited[v]=True 
    for i in adj[v]:
        if not visited[i]:
            dfs(visited,i,adj)  
adj=collections.defaultdict(list)
n,m=map(int,input().split()) 
visited=[False]*n  
for i in range(m):
    u,v=map(int,input().split()) 
    adj[u-1].append(v-1)  
    adj[v-1].append(u-1) 
c=0 
for i in range(n):
    if not visited[i]:
        dfs(visited,i,adj) 
        c+=1 
print(c-1)
n,a,b=map(int,input().split())
if abs(a-b)%2==0:
    print(abs(a-b)//2)
else:
    if n-b>a-1:
        print(a+(b-a-1)//2)
    else:
        print(n-b+1(b-a-1)//2)

### FIXED CODE ###

n,a,b=map(int,input().split())
if abs(a-b)%2==0:
    print(abs(a-b)//2)
else:
    if n-b>a-1:
        print(a+(b-a-1)//2)
    else:
        print(n-b+1+(b-a-1)//2)
N = int(input())
inputs = [int(input()) for i in range(N)]

points = [int(s) for s in inputs]
points_sorted = sorted(points)

get_point = sum(points)

idx = 0
if get_point % 10 != 0:
    print(get_point)
else:
    while points_sorted[idx] % 10 == 0:
        idx += 1
        if idx == N:
            print(0)
    print(get_point - points_sorted[idx])

### FIXED CODE ###

N = int(input())
inputs = [int(input()) for i in range(N)]

points = [int(s) for s in inputs]
points_sorted = sorted(points)

get_point = sum(points_sorted)
non_10 = [x for x in points_sorted if (x % 10 != 0)]

if get_point % 10 != 0:
    print(get_point)
elif non_10 == []:
    print(0)
else:
    print(get_point - min(non_10))
import sys
n = list(map(int, input().split()))

if n[0] == 1 or n[1] == 1:
    print(0)

if n[0] % 2 == 0:
    print(int((n[0]/2)*n[1])
    sys.exit()
else:
    if n[1] % 2 == 0:
        print(int(n[0]*(n[1]/2)))
        sys.exit()
    else:
        a = ((n[0]-1)*n[1])/2
        b = n[1] - int(n[1]/2)
        print(int(a+b))
        sys.exit()
    


### FIXED CODE ###

from decimal import Decimal
import sys
n = list(map(int, input().split()))

if n[0] == 1 or n[1] == 1:
    print(1)
    sys.exit()

if n[0] % 2 == 0:
    print(Decimal(int((n[0]/2)*n[1])))
    sys.exit()
else:
    if n[1] % 2 == 0:
        print(Decimal(int(n[0]*(n[1]/2))))
        sys.exit()
    else:
        a = ((n[0]-1)*n[1])/2
        b = n[1] - int(n[1]/2)
        print(Decimal(int(a+b)))
        sys.exit()
def main():
    n = int(input())
    a = list(map(int, input().split()))

    # Only when there is no bit duplication in a group,
    # it always meets the condition.
    # l <= true_l < true_r < r
    ans = n
    l = 0
    now = a[0]
    for r in range(1, n):
        if now & a[r] == 0:
            now = now ^ a[r]
            continue

        now = now ^ a[r]
        for new_l in range(r-1, l-1, -1):
            if a[new_l] & a[r] != 0:
                break
        try:
            new_l += 1
        except:
            while True:
                pass
        for i in range(l, new_l):
            now = now ^ a[i]

        ans += (r-l) * (r-l-1) // 2 - (r-new_l) * (r-new_l-1) // 2

        l = new_l

    r += 1
    ans += (r-l) * (r-l-1) // 2

    print(ans)

main()

### FIXED CODE ###

def main():
    n = int(input())
    a = list(map(int, input().split()))

    if n == 1:
        print(1)
        exit()

    # Only when there is no bit duplication in a group,
    # it always meets the condition.
    # l <= true_l < true_r < r
    ans = n
    l = 0
    now = a[0]
    for r in range(1, n):
        if now & a[r] == 0:
            now = now ^ a[r]
            continue

        now = now ^ a[r]
        for new_l in range(r-1, l-1, -1):
            if a[new_l] & a[r] != 0:
                break
        # else:
            # print('Error')
            # exit()
        new_l += 1

        for i in range(l, new_l):
            now = now ^ a[i]

        ans += (r-l) * (r-l-1) // 2 - (r-new_l) * (r-new_l-1) // 2

        l = new_l

    r += 1
    ans += (r-l) * (r-l-1) // 2

    print(ans)

main()
n,k = map(int,input().split())
x = [[] for _ in range(n+1)]
for _ in range(n-1):
  a,b = map(int,input().split())
  x[a].append(b)
  x[b].append(a)
ans = k
def search(i):
  l = len(x[i])
  if l == 0:
    return
  global ans
  for j in range(l):
    ans = (ans*(k-2-j))%1000000007
  for child in x[i]:
    x[child].remove(i)
    search(child)
l1 = len(x[1])
for j in range(l1):
  ans = (ans*(k-1-j))%1000000007
for child1 in x[1]:
  x[child1].remove(1)
  search(child1)
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)
n,k = map(int,input().split())
x = [[] for _ in range(n+1)]
for _ in range(n-1):
  a,b = map(int,input().split())
  x[a].append(b)
  x[b].append(a)
ans = k
def search(i):
  l = len(x[i])
  if l == 0:
    return
  global ans
  for j in range(l):
    ans = (ans*(k-2-j))%1000000007
  for child in x[i]:
    x[child].remove(i)
    search(child)
l1 = len(x[1])
for j in range(l1):
  ans = (ans*(k-1-j))%1000000007
for child1 in x[1]:
  x[child1].remove(1)
  search(child1)
print(ans)
import math
a, b = map(int, input().split())
print(int(a * b / math.gcd(a, b)))


### FIXED CODE ###

from fractions import gcd

a, b = map(int, input().split())
print(int(a * b / gcd(a, b)))
n = int(input())
nums = map(int, input().split())

nums.sort()
counts = 0

for i in range(n):
  start, end = 0, i - 1
  while start < end:
    if nums[start] + nums[end] > nums[i]:
      counts += end - start
      end -= 1
    else:
      start += 1
print(counts)


### FIXED CODE ###

n = int(input())
nums = list(map(int, input().split()))
nums.sort()

counts = 0

for i in range(n):
  start, end = 0, i - 1
  while start < end:
    if nums[start] + nums[end] > nums[i]:
      counts += end - start
      end -= 1
    else:
      start += 1
print(counts)
l = map(int, input().split())
print(str(l[0]*l[1]) + " " + str(l[0]*2+l[1]*2))


### FIXED CODE ###

l = list(map(int, input().split()))
print(str(l[0]*l[1]) + " " + str(l[0]*2+l[1]*2))
import math
N, M = map(int, input().split())
tmp = [1]
if N == 1:
    print(M)
else:
    for i in range(2, int(math.ceil(M**0.5))):
        if M % i == 0:
            tmp.append(i)
            tmp.apend(M/i)
    ans = 1
    for x in tmp:
        if m / x >= N:
            ans = max(ans, x)
    print(ans)


### FIXED CODE ###

import math
N, M = map(int, input().split())
tmp = [1]
if N == 1:
    print(M)
else:
    for i in range(2, int(math.ceil(M**0.5))):
        if M % i == 0:
            tmp.append(i)
            tmp.append(int(M/i))
    ans = 1
    for x in tmp:
        if M / x >= N:
            ans = max(ans, x)
    print(ans)
n =int(raw_input())
lis=[]
for i in range(1,26):
    lis.add(4*i)
for i in range(1,15):
    lis.add(7*i)
for i in range(1,20):
    for j in range(1,20):
        lis.add(4*i+7*j)
if n in lis:
    print "Yes"
else:
    print "No"


### FIXED CODE ###

n =int(raw_input())
lis=[]
for i in range(1,26):
    lis.append(4*i)
for i in range(1,15):
    lis.append(7*i)
for i in range(1,20):
    for j in range(1,20):
        lis.append(4*i+7*j)
if n in lis:
    print "Yes"
else:
    print "No"
import math
a, b = map(int, input().split())
print(a*b//math.gcd(a,b))

### FIXED CODE ###

from fractions import gcd
a, b = map(int, input().split())
print(a*b//gcd(a,b))
r=int(input())
if r < 1200:
  print("ABC")
elif r < 2800:
  print("ARC")
else:
  orint("AGC")

### FIXED CODE ###

r=int(input())
if r < 1200:
  print("ABC")
elif r < 2800:
  print("ARC")
else:
  print("AGC")
a,b,c = map(int, input().split())

if (a>b) and (a>c):
    ans = 10*a+b+c
elif = (b>a) and (b>c):
    ans = 10*b+a+c
else:
    ans = 10*c+a+b
print(ans)

### FIXED CODE ###

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

A = 10*a+b+c
B = 10*b+a+c
C = 10*c+a+b
print(max(A, B, C))
N = int(input())
list = list(map(int, input().split()))
print("Yes" if max(list) < sum(list) - max(list) else "No"))

### FIXED CODE ###

N = int(input())
list = list(map(int, input().split()))
print("Yes" if 2*max(list) < sum(list) else "No")
n = int(input())
P =[]
s = 0
for _ in range(n):P.append([int(-i) for i in input().split()])
P.append(P[0])
for j in range(n):s += P[j][1]*P[j+1][0] -  P[j][0] * P[j+1][1]
print(s*0.5)

### FIXED CODE ###

x=range(int(input())-1,-1,-1)
P=[]
for _ in x:P+=[[int(i) for i in input().split()]]
P+=[P[0]]
for j in x:_+=P[j+1][1]*P[j][0]-P[j][1]*P[j+1][0]
print(_*0.5)
n = int(input())
a = list(map(int, input().split()))
print(n * 2 - 1)
ma, mi = max(a), min(a)
ima, imi = a.index(ma), a.index(mi)
if abs(ma) > abs(mi):
    for i in range(1, n + 1):
        print(ima + 1, i)
    for i in range(1, n):
        print(i, i + 1)
else:
    for i in range(1, n + 1):
        print(imi + 1, i)
    for i in range(1, n):
        print(i + 1, i) 

### FIXED CODE ###

from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
c = Counter(a)
c = c.most_common()
ans = 0
c.sort(key=lambda x:x[1])
for i in range(len(set(a)) - k):
    ans += c[i][1]
print(ans)
X, t=input(int, split())

print(max(X-t),0)

### FIXED CODE ###

x,t=map(int, input().split())

print(max(x-t,0))
print('ABC' if input()[1] == 'R' else 'ARC)

### FIXED CODE ###

print('ABC' if input()[1] == 'R' else 'ARC')
M = map(int,input().split())
print(48 - M)

### FIXED CODE ###

print(48 - int(input()))
import math
N, a, b = map(int,input().split())
p = 10 ** 9 +7
def fc(t,k):
  if t == 0:
    return 1
  elif t % 2 == 1:
    return (fc(t//2,k)) **2 * k
  else:
    return (fc(t//2,k)) ** 2
A = math.factorial(a)
B = math.factorial(b)
n_c_a = 1
n_c_b = 1
for i in range(a):
  n_c_a *= n-i
for j in rnage(b):
  n_c_b *= n-j
m_a = n_c_a // A % p
m_b = n_c_b // A % p
print((fc(N,2) - 1 - m_a - m_b) % p)


### FIXED CODE ###

N, a, b = map(int,input().split())
p = pow(10,9) + 7
def comb(n,r):
  bunshi = 1
  for i in range(n-r+1, n+1):
    bunshi =bunshi * i % p
  bunbo = 1
  for i in range(1, r+1):
    bunbo = bunbo * i % p
  return bunshi * pow(bunbo, p-2, p)
print((pow(2,N, p) - 1 - comb(N,a) - comb(N,b)) % p)
x=int(input())
for i in range(-200,200):
  for j in range(-200,200):
    if i**5-j**5==x
    prtin(i,j)
    exit()


### FIXED CODE ###

x=int(input())
for i in range(-200,200):
  for j in range(-200,200):
    if i**5-j**5==x:
      print(i,j)
      exit()
# http://drken1215.hatenablog.com/entry/2020/01/26/225000

H, N = map(int, input().split())
dp = [float("inf") for i in range(H+1)]

dp[0] = 0

for i in range(N):
  a, b = map(int, input().split())
  
  for j in range(H):
    dp[min(j+a, H)] = min(dp[min(j+a, H)], dp[j] + b)


print(dp[H])

### FIXED CODE ###



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


ans = 0
while H > 0:
  ans += 1
  H -= A

print(ans)
A = int(input())
B = int(input())
X = A + B
Y = A - B
Z = A * B
if X >= Y:
    if X >= Z:
        print('',X)
    else:
        print('',Z)
else:
    if Y >= Z:
        print('',Y)
    else:
        print('',Z)

### FIXED CODE ###


S = input().split()
X = int(S[0])+int(S[1])
Y = int(S[0])-int(S[1])
Z = int(S[0])*int(S[1])
if X >= Y:
    if X >= Z:
        print(X)
    else:
        print(Z)
else:
    if Y >= Z:
        print(Y)
    else:
        print(Z)
cart = [4,1,4,1,2,1,2,1]
while True:
	try:
		que = map(int, raw_input().split())
		mx,mxcart = 0, "99999999"
		for sp in range(8):
			sm = 0
			for num in range(8):
				if cart[(sp+num)%8] <= que[num]:
					sm += cart[(sp+num)%8]
				else:
					sm += que[num]
			if sm = mx:
				mx = sm
				mxcart = "".join(map(str, cart[sp:]+cart[:sp]))
			elif sm == mx:
				acart = "".join(map(str, cart[sp:]+cart[:sp]))
				if int(mxcart) > int(acart):
					mxcart = acart
		print " ".join(map(str, mxcart))
	except:
		break

### FIXED CODE ###

c = [4,1,4,1,2,1,2,1]
while True:
	try:
		que = map(int, raw_input().split())
		mx,mxc = 0, "99999999"
		for sp in range(8):
			sm = 0
			for num in range(8):
				sm += c[(sp+num)%8] if c[(sp+num)%8] <= que[num] else que[num]
			if sm > mx:
				mx = sm
				mxc = "".join(map(str, c[sp:]+c[:sp]))
			elif sm == mx:
				ac = "".join(map(str, c[sp:]+c[:sp]))
				if int(mxc) > int(ac):
					mxc = ac
		print " ".join(map(str, mxc))
	except:
		break
print(a,b,c,l[a]+l[b]>l[c])


### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
l.sort()

# a, bをfixしてcを探索
# n*n*logn
# c_i < a+b をにぶたん
def binary_search(list, item):
    # listからitem未満の最大のindexを取得
    low = 0
    high = len(list) - 1
    if list[high] < item:
        return high+1
    if list[low] >= item:
        return low
    while True:
        mid = (low + high) //2
        guess = list[mid]
        if high - low <= 1:
            return high
        if guess >= item:
            high = mid
        else:
            low = mid

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        a = l[i]
        b = l[j]
        c = binary_search(l, b+a)
        ans += c-(j+1)
print(ans)
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#define STR 10
int main(){
    char a;
    scanf("%c",&a);
    if(isupper(a)==0){
        printf("a");
    }else{
        printf("A");
    }
    return 0;
}

### FIXED CODE ###

c=input()
if c.isupper():
    print('A')
else:
    print('a')
X = raw_input()
print X//3

### FIXED CODE ###

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

X = input()
print X//3
import sys

n,a,b,c = map(int,input().split())
d = {'A':a,'B':b,'C':c}

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

ans = []
for i in range(n):

	if d[s[i][0]] <= 0 and d[s[i][1]] <= 0:
		print('No')
		sys.exit()
	if d[s[i][0]] < d[s[i][1]]:
		d[s[i][1]] -= 1
		d[s[i][0]] += 1
		ans.append(s[i][0])
	elif d[s[i][0]] > d[s[i][1]]:
		d[s[i][0]] -= 1
		d[s[i][1]] += 1
		ans.append(s[i][1])
	else:
		if i < n-1 and d[s[i+1].strip(s[i])] == 0:
			d[s[i+1].strip(s[i+1].strip(s[i]))] += 1
			ans.append(s[i+1].strip(s[i+1].strip(s[i])))
print('Yes')
for i in range(len(ans)):
	print(ans[i])



### FIXED CODE ###

import sys

n,a,b,c = map(int,input().split())
d = {'A':a,'B':b,'C':c}

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

ans = []
for i in range(n):

	if d[s[i][0]] <= 0 and d[s[i][1]] <= 0:
		print('No')
		sys.exit()
	if d[s[i][0]] < d[s[i][1]]:
		d[s[i][1]] -= 1
		d[s[i][0]] += 1
		ans.append(s[i][0])
	elif d[s[i][0]] > d[s[i][1]]:
		d[s[i][0]] -= 1
		d[s[i][1]] += 1
		ans.append(s[i][1])
	else:
		if i < n-1 and s[i+1].strip(s[i]) != '' and d[s[i+1].strip(s[i])] == 0:
			string = s[i+1].strip(s[i+1].strip(s[i]))
			d[string] += 1
			d[s[i].strip(string)] -= 1
			ans.append(s[i+1].strip(s[i+1].strip(s[i])))
		else:
			d[s[i][0]] += 1
			d[s[i][1]] -= 1
			ans.append(s[i][0])
print('Yes')
for i in range(len(ans)):
	print(ans[i])